cancel
Showing results for 
Search instead for 
Did you mean: 

Consume Webservice from PI Box

Former Member
0 Kudos

Dear Experts

I have created a Java Class that calls a webservice deployed in PI 7.1. Below is the java code

private String sendingDataToPISystem(String userName, String password, String endPointReference, String nameSpace, String serviceName, String localPart, Object inputData)

{

String returnValue = null;

try

{

QName serviceQName = new QName(nameSpace, serviceName);

QName portQName = new QName(nameSpace, localPart);

Service service = Service.create(new URL(endPointReference), serviceQName);

Map map = ((BindingProvider)service.getPort(portQName, serviceQName.getClass())).getRequestContext();

map.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPointReference);

map.put(BindingProvider.USERNAME_PROPERTY, userName);

map.put(BindingProvider.PASSWORD_PROPERTY, password);

service.addPort(portQName, HTTPBinding.HTTP_BINDING, new URI(endPointReference).toString());

Dispatch<Object> dispatch = service.createDispatch(portQName, Object.class, Service.Mode.PAYLOAD);

dispatch.invoke(inputData);

returnValue = "SUCCESS";

}catch(Exception exception)

{

returnValue = "FAILURE";

exception.printStackTrace();

}finally

{

return returnValue;

}

}

This code is not throwing any error but at the same time unable to make a call to webservice in PI box

Note: I am using NWDS CE 7.1 SP 10PAT0001

Please Advice what should be done, inorder to make my Java class work.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Hari,

I think you're trying to re-invent the wheel here. You could just as easily generate your Java code in NWDS automatically from the Outbound Service Interface in the PI ESR. You can configure NWDS to point to your PI ESR or Services Registry (if you're using that), import the WSDL for the Service & generate a Java web service client in NWDS.

One such guide to achieve this is this one:

[http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80d9fbfe-1e97-2c10-e9b3-ad9a10f1f6cb?quicklink=index&overridelayout=true]

There are many other such guides/blogs etc. in SDN, try a search.

Regards, Trevor

Former Member
0 Kudos

Hi Trevor,

As per the project requirement, we need to create a Java Project, and call the webservice deployed in PI box from here.

Please advice how to do this

Thanks in Advance

Former Member
0 Kudos

Hi Hari,

I understand what you're trying to do. What IDE are you using to create your Java Project?

If you're using SAP NWDS as your IDE then you can create your Java project in there, setup a connection to the SAP PI ESR or the SAP Services Registry or manually enter a URL to access the outbound service interface WSDL, generate your Java skeleton code based on the service WSDL and your work is almost done with the exception of a bit of customizing code where necessary.

The guide I've highlighted above is one example of how this can achieved but there are many others on SDN.

Regards, Trevor

Former Member
0 Kudos

Hi Trevor,

Thanks for your time.

I am using NWDS 7.1 CE, i have used WSDL Client option to create proxy classes.

now when i am running the proxy class i am getting the follwoing exception

javax.xml.ws.WebServiceException: java.io.IOException: Server returned HTTP response code: 401 for URL: http://olamxidev.olamnet.com:50000/dir/wsdl?p=1_a387f8dc1ead38fb9cd81a368ce0b7d9_portTypeBindingServ...

at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:164)

at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parseWSDL(RuntimeWSDLParser.java:190)

at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:68)

at com.sun.xml.internal.ws.wsdl.WSDLContext.<init>(WSDLContext.java:59)

at com.sun.xml.internal.ws.client.ServiceContextBuilder.build(ServiceContextBuilder.java:62)

at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:125)

at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:52)

at javax.xml.ws.Service.<init>(Service.java:57)

at com.olam.source.webservice.test.XIA387F8Dc1Ead38Fb9Cd81A368Ce0B7D9Service.<init>(XIA387F8Dc1Ead38Fb9Cd81A368Ce0B7D9Service.java:21)

at com.olam.source.webservice.test.CurrentAccountTestClient.currentAccountClientTest(CurrentAccountTestClient.java:39)

at com.olam.source.webservice.test.CurrentAccountTestClient.main(CurrentAccountTestClient.java:18)

Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://olamxidev.olamnet.com:50000/dir/wsdl?p=1_a387f8dc1ead38fb9cd81a368ce0b7d9_portTypeBindingServ...

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)

at java.net.URL.openStream(URL.java:1009)

at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:161)

... 10 more

to encouter this exception i have added the following statements in service class, but of no use.

Authenticator.setDefault(new Authenticator()

{

@Override

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("admin", "admin123".toCharArray());

}

})

Please advice, how to overcome this