[jboss-user] [JBoss Web Services] - Re: Consume a web service from another web service
florentine
do-not-reply at jboss.com
Mon Mar 19 16:21:23 EDT 2012
florentine [https://community.jboss.org/people/florentine] created the discussion
"Re: Consume a web service from another web service"
To view the discussion, visit: https://community.jboss.org/message/724833#724833
--------------------------------------------------------------
Thank you for you answer. I took a look at JNDI and it looks a lower level solution where you have to code more. I saw several examples on the internet on how to create a client for a web service and I can make them work also on my small piece of code above. The problem is that I can't make a web service calling another web service. It sounds to me a very basic functionality, but I was really able to find a complete example on how to do that. I tried to copy and paste the code of my client inside the HelloWorld.getHiWorld() method, but I keep getting a proxy error. How people normally make more webservices communicating between each other? any example from where I could get an idea?
This is my updated code with the client :
HelloWorldImpl.java
package hw1;
import hw2.HelloWorld2;
import java.net.MalformedURLException;
import java.net.URL;
import javax.jws.WebService;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
@WebService(serviceName="HelloWorldService", name="HelloWorld")
public class HelloWorldImpl implements HelloWorld {
@Override public String getHiWorld() {
URL url=null;
try {
url = new URL(" http://localhost:8080/HelloWorld2WS/HelloWorld2Service?wsdl http://localhost:8080/HelloWorld2WS/HelloWorld2Service?wsdl");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
QName qname = new QName(" http://hw2/ http://hw2/", "HelloWorld2Service");
Service service = Service.create(url, qname);
HelloWorld2 port = service.getPort(HelloWorld2.class);
return "Hi World" + port.getHiWorld();
}
public HelloWorldImpl() {
}
}
HelloWorld2Impl.java
package hw2;
import javax.jws.WebService;
@WebService(serviceName="HelloWorld2Service", name="HelloWorld2")
public class HelloWorld2Impl implements HelloWorld2 {
@Override
public String getHiWorld() {
return " again!";
}
public HelloWorld2Impl (){}
}
HelloWorldClient.java
package client;
import hw1.HelloWorld;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class HelloWorldClient {
public static void main(String[] args) throws Exception {
URL url = new URL(" http://localhost:8080/HelloWorldWS/HelloWorldService?wsdl http://localhost:8080/HelloWorldWS/HelloWorldService?wsdl");
QName qname = new QName(" http://hw1/ http://hw1/", "HelloWorldService");
Service service = Service.create(url, qname);
HelloWorld eif = service.getPort(HelloWorld.class);
System.out.println(eif.getHiWorld());
}
}
Finally, this is the error my JBoss server is giving me:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: hw2/HelloWorld2
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:129)
at $Proxy19.getHiWorld(Unknown Source)
at client.HelloWorldClient.main(HelloWorldClient.java:25)
Thank you!
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/724833#724833]
Start a new discussion in JBoss Web Services at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120319/f9f27a99/attachment.html
More information about the jboss-user
mailing list