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:
|
Subscribe by reader Subscribe by email Share
Is any one getting the following error:
ReplyDeleteCould not access remote service at [null]; nested exception is javax.xml.ws.WebServiceException: Unsupported endpoint address: /
i got the same exception...
DeleteBig Thank!, Thank you very much; Your Spring web services series tutorials helps me a lot.
ReplyDeleteHow can I modify this configuration in order to load the webservice endpoint address from DB ? My problem is that test environment address is different from production.
ReplyDeletei really likes your blog and You have shared the whole concept really well. and Very beautifully written,
ReplyDeletesoulful read! thanks for sharing.
gclub casino
gclub
gclub casino
Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
ReplyDeleteBest Industrial Training in Noida
Best Industrial Training in Noida
Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing.
ReplyDeleteBest BCA Colleges in Noida
ReplyDeleteI am very happy when read this blog post because blog post written in good manner and write on good topic. Thanks for sharing valuable information about the Web Design course.
Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
WOW! I Love it...
ReplyDeleteand i thing thats good for you >>
ทำนายฝัน
Thank you!