We will assume that we only know the WSDL of the web service to simulate a real client development. To generate the proxy classes, we will use the built-in wsimport tool from the JDK. To access the web service, we will use Spring's JaxWsPortProxyFactoryBean. We are not using any Spring Web Service (WS) dependencies here.
What we'll do here is follow the same exact steps as shown in the Spring WS - MVC: Implementing a Client Tutorial. And we will just highlight the difference.
Here's are the changes you need to do to use Spring's JaxWsPortProxyFactoryBean
new applicationContext.xml
old applicationContext.xml
In the applicationContext we just removed the reference to spring-ws.xml and switched to jax-ws.xml
We need to declare this new config and delete the old one.
jax-ws.xml
For a detailed description of this configuration, please check the official Spring Reference: 19. Remoting and web services using Spring
We also need to update the primary controller.
new MainController
This controller declares two mappings:
/main - for showing the subscribe page /main/subscribe - for processing the subscriptionNotice we have injected an instance of a SubscriptionPort
In the Spring WS tutorial we have injected an instance of a WebServiceTemplate instead
Inside the doSubscribe() method, we process the subscription by delegating to the subscriptionJaxProxyService
Once we get a valid response, we add it to the model:
If there are validation errors, the client will throw a SoapFaultClientException so we need to catch that:
That's it. Everything else is exactly the same as with our previous tutorial. We've managed to integrate a Spring MVC application and utilized the JaxWsPortProxyFactoryBean.
To test the client and the web service provider, you need two instances of Tomcat or Jetty : one for the web service and one for the client. Make sure to set the ports accordingly. For the provider, I chose port 8081. For the client, I chose 8080. If you change the ports, you must update the spring-ws.xml configuration of the provider and the client as well. In case you forgot, the web service provider is in my other tutorial Spring WS 2 and Spring 3 MVC Integration Tutorial
To access the Subscribe Page, use the following URL:
http://localhost:8080/spring-ws-client-jaxproxy/krams/mainDownload the project
You can access the project site at Google's Project Hosting at http://code.google.com/p/spring-ws-2-0-0-rc2-tutorial/
You can download the project as a Maven build. Look for the spring-ws-client-jaxproxy.zip in the Download sections.
You can run the project directly using an embedded server via Maven.
For Tomcat: mvn tomcat:run
For Jetty: mvn jetty:run
If you want to learn more about Spring MVC and integration with other technologies, feel free to read my other tutorials in the Tutorials section.
|
Share the joy:
|
Is any one getting the following error:
ReplyDeleteCould not access remote service at [null]; nested exception is javax.xml.ws.WebServiceException: Unsupported endpoint address: /
Big Thank!, Thank you very much; Your Spring web services series tutorials helps me a lot.
ReplyDelete