5

I would like to acces the broker via OData in our java application. I have the java web service running properly. However I'm getting stuck because I don't know how to add the service reference in our eclipse environment. In VS it's ok, but with Eclipse, the extension for odata.svc is invalid, due to is not a wsdl but a WCF service. There is an article about OData and .NET for Tridion 2011, but nothing about JAVA.

Anybody has a clue how to get that working? We are thinking to use the odata4j API, but in this case we lost all the classes that the Web Service is providing.

2 Answers 2

10

Take a look at my blog post http://yatb.mitza.net/2013/07/a-java-service-oriented-architecture.html.

It explains a Service Oriented approach to consuming OData content from a web-application using Java (namely OData4J). There is an example of the actual OData call.

9

I'm not sure you have the right level of expectations there, as it seems that you would want Java/Eclipse to provide you the same benefits that Microsoft / .NET / LINQ provide when working with OData services.

The webservice and its capabilities are exactly the same independently of the client you use - .NET, Odata4j, JayData - but the client itself will expose more or less functionalities depending on its implementation. The Microsoft OData client is way ahead of everyone else on OData, but that has nothing to do with the service itself.

Here's a sample JSP I wrote sometime ago using OData4j, might help getting you started:

<%@page import="org.odata4j.core.OProperty"%>
<%@page import="org.odata4j.core.OEntity"%>
<%@page import="java.util.List"%>
<%@page import="org.odata4j.consumer.ODataConsumer"%>
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Insert title here</title>
    </head>
    <body>
     <%
     ODataConsumer client = ODataConsumer.create("http://odata-server:8080/cd_webservice/odata.svc");
     int PublicationId = client.getEntities("Publications").filter("Title eq 'Nexus 05 Website'").execute().first().getProperty("Id",Integer.class).getValue();

     %>
     <div><%=PublicationId %></div>
     <%
          List<OEntity> Keywords = client.getEntities("Keywords").filter("(PublicationId eq 17) and (TaxonomyId eq 305)").execute().toList();
          for(OEntity title : Keywords) {
            for(OProperty<?> p : title.getProperties()) {
             out.println(p.getName() + " = " + p.getValue() + "<br/>");
            }
        }
      %>
</body>
</html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.