AnsweredAssumed Answered

ReadResource using JAX-WS is not working

Question asked by quaestor on Jul 3, 2013
Latest reply on Jul 8, 2013 by quaestor
Hi all!

I was asked to build a proof of concept about reading and writing resources in Clarity through Java. I am trying to make my code work since yesterday morning, but so far I could only log in Clarity and get the Session id.

Below is my code; could anyone tell me what is wrong, please?
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

import br.com.petrobras.clarity.stubs.AllObjectsPort;
import br.com.petrobras.clarity.stubs.AllObjectsService;
import br.com.petrobras.clarity.stubs.Auth;
import br.com.petrobras.clarity.stubs.Login;
import br.com.petrobras.clarity.stubs.NikuDataBus;
import br.com.petrobras.clarity.stubs.ObjectFactory;

public class WebClient {


private final static String WSDL_URL = "http://MY_SERVER/niku/wsdl/Object/AllObjects?tenantId=clarity?download=true";

private final static String USUARIO = "login";

private final static String SENHA = "password";


public WebClient() throws Exception {


AllObjectsPort proxy = instanciaWebClient();


ObjectFactory objectFactory = new ObjectFactory();



Auth auth = login(proxy);



NikuDataBus body = objectFactory.createNikuDataBus();



String xml =


"<NikuDataBus xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"../xsd/nikuxog_read.xsd\"><Header version=\"6.0.13\" action=\"read\" objectType=\"resource\" externalSource=\"NIKU\"><args name=\"include_contact\" value=\"true\"/><args name=\"include_management\" value=\"true\"/><args name=\"include_custom\" value=\"true\"/><args name=\"include_financial\" value=\"true\"/></Header><Query><Filter name=\"resourceID\" criteria=\"EQUALS\">some_resource_id</Filter></Query></NikuDataBus>"; 


JAXBElement<String> j = new JAXBElement<String>(new QName("http://www.niku.com/xog/Object", "body"), String.class, xml);


body.setAny(j);



//which one is the correct to get the resources, readResource or readResourceclass?


NikuDataBus readResource = proxy.readResource(body, auth);


NikuDataBus readResourceclass = proxy.readResourceclass(body, auth);



System.out.println(j.getValue());


System.out.println("readResource: " + readResource.getAny());


System.out.println("readResourceclass: " + readResourceclass.getAny());


}


private AllObjectsPort instanciaWebClient() {


URL wsdlUrl = null;


try {



wsdlUrl = new URL(WSDL_URL);


} catch (MalformedURLException e) {



throw new RuntimeException(e);


}


AllObjectsService allObjectsService = new AllObjectsService(wsdlUrl, new QName("http://www.niku.com/xog/Object", "AllObjectsService"));


AllObjectsPort allObjectsProxy = allObjectsService.getPort(AllObjectsPort.class);


return allObjectsProxy;

}


private Auth login(AllObjectsPort proxy) {


ObjectFactory objectFactory = new ObjectFactory();


Login login = objectFactory.createLogin();


login.setUsername(USUARIO);


login.setPassword(SENHA);


String sessionId = proxy.login(login);


Auth auth = new Auth();


auth.setUsername(USUARIO);


auth.setPassword(SENHA);


auth.setSessionID(sessionId);


return auth;

}


public static void main(String[] args) throws Exception {


WebClient webClient = new WebClient();

}
}
This is the output of my System.out.println:
<NikuDataBus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/nikuxog_read.xsd"><Header version="6.0.13" action="read" objectType="resource" externalSource="NIKU"><args name="include_contact" value="true"/><args name="include_management" value="true"/><args name="include_custom" value="true"/><args name="include_financial" value="true"/></Header><Query><Filter name="resourceID" criteria="EQUALS">some_resource_id</Filter></Query></NikuDataBus>
readResource: [XOGOutput: null]
readResourceclass: [XOGOutput: null]
If I use SoapUI to test the NikuDataBus content (that is, the xml snippet), it works fine everytime.

Could anyone please help me out? A sample of a Java JAX-WS working piece of code to read resources will also be great!

Kind regards,

QL

Outcomes