Results 1 to 8 of 8

Thread: Creating Web Service Client using Spring-WS and Spring MVC

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    10

    Question Creating Web Service Client using Spring-WS and Spring MVC

    I'm am trying to write a client for a web service using:

    1. Spring-WS 1.0m3
    2. Spring MVC (Spring2.0)

    My code builds without error. But when it runs I get a java.lang.NullPointerException error. It's from the line
    Code:
    webServiceTemplate.sendAndReceive(source, result);
    in the client class below.

    I have been struggling with this for 2 weeks trying to get this to work.

    Is there anyone on this forum that can help me figure this out?

    I've googled and read what documentation exists. There's SO MUCH info on writing web services. But hardly anything on writing clients. (spring-ws has about 2.5 pages)

    Any help would be appreciated. Thanks.

    ===========================================
    I have a -servlet.xml file that has:

    Code:
    <bean id="webServiceClient" class="WebServiceClient">
            <property name="messageFactory">
                <bean class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
            </property>
            <property name="messageSender">
                <bean class="org.springframework.ws.transport.http.HttpUrlConnectionMessageSender">
                    <property name="url" value="http://vsdv1dev02:8080/sprint1/CatalogService"/>
                </bean>
            </property>
        </bean>

    and then I have a client class:

    Code:
    public class WebServiceClient {
    
        private static final String MESSAGE = "<com:getOffers><com:CatalogName>lucene</com:CatalogName></com:getOffers>";
                
        private WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    
        public void setMessageFactory(WebServiceMessageFactory messageFactory) {
            webServiceTemplate.setMessageFactory(messageFactory);
        }
    
        public void setMessageSender(WebServiceMessageSender messageSender) {
            webServiceTemplate.setMessageSender(messageSender);
        }
    
        public String simpleSendAndReceive() throws IOException {
            StreamSource source = new StreamSource(new StringReader(MESSAGE));
            StreamResult result = new StreamResult(System.out);
            //StringResult result = new StringResult();
            
            String thisResult = "";
            
            try
            {
                webServiceTemplate.sendAndReceive(source, result);
            }
            catch (Exception e)
            {
                e.printStackTrace(System.out);
            }
            
            return result.toString() + " and " + thisResult;
        }
    
    }
    finally in my dispatchservlet I have:

    Code:
    public class GciController implements Controller 
    {   
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException 
        {
            
            WebServiceClient wsc = new WebServiceClient();
            String result = "";
            
            try
            {
                result = wsc.simpleSendAndReceive();   
            }
            catch (Exception e)
            {
                result = e.toString() + ": testing";
            }
            
            return new ModelAndView("plan-summary.jsp", "result", result);
        }
    }
    ultimately I need to get the result in an object to pass back to the view.

  2. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    Could you also post the complete stack trace?
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3
    Join Date
    Apr 2007
    Posts
    10

    Default

    Here you go...

    Code:
               java.lang.NullPointerException
            at org.springframework.ws.context.DefaultMessageContext.<init>(DefaultMessageContext.java:51)
            at org.springframework.ws.client.support.WebServiceAccessor.createMessageContext(WebServiceAccessor.java:77)
            at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:191)
            at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:173)
            at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:151)
            at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:145)
            at WebServiceClient.simpleSendAndReceive(WebServiceClient.java:46)
            at GciController.handleRequest(GciController.java:24)
            at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
            at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:819)
            at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:754)
            at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:399)
            at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:354)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
            at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
            at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
            at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
            at java.lang.Thread.run(Thread.java:613)

  4. #4
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    In your code, your do:

    Code:
    WebServiceClient wsc = new WebServiceClient();
    while you should use dependency injection to inject the wsc instance. This results in the fact that the properties on the client are actually set, while now, there are not.

    So just create a setter for the client, and wire it up. That should do it.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  5. #5
    Join Date
    Aug 2007
    Location
    Boston
    Posts
    20

    Default got error

    hi,
    i am doing the same thing as above code...
    and i get this error

    nested exception is java.lang.ClassNotFoundException: org.springframework.ws.transport.http.HttpUrlConne ctionMessageSender

    nested exception is java.lang.ClassNotFoundException:
    org.springframework.ws.soap.saaj.SaajSoapMessageFa ctory

    which jars can provide me with the above packages?????

    thanks

  6. #6
    Join Date
    Aug 2007
    Location
    Boston
    Posts
    20

    Default Hi jodo

    are you able to resolve your error(the following one)?

    java.lang.NullPointerException
    org.springframework.ws.context.DefaultMessageConte xt.<init>(DefaultMessageContext.java:51)
    org.springframework.ws.client.support.WebServiceAc cessor.createMessageContext(WebServiceAccessor.jav a:77)
    org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:191)
    org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:173)
    org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:151)
    org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:145)
    nl.gridshore.samples.springws.integration.wsclient .impl.WebServiceClient.simpleSendAndReceive(WebSer viceClient.java:28)
    nl.gridshore.samples.springws.web.controllers.Cong ressRegistrationFormController.onSubmit(CongressRe gistrationFormController.java:34)
    org.springframework.web.servlet.mvc.SimpleFormCont roller.processFormSubmission(SimpleFormController. java:258)
    org.springframework.web.servlet.mvc.AbstractFormCo ntroller.handleRequestInternal(AbstractFormControl ler.java:249)
    org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
    org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:44)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:723)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:663)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:394)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:358)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)



    i get the same one... and i couldnt understand the reply.. can someone help me out?

  7. #7
    Join Date
    Aug 2007
    Location
    Boston
    Posts
    20

    Default Hi Arjen

    I didnt understand what do you mean by "create client and wire it up"!!
    I am amateur to spring-ws and dont get the concept of pom.xml.. do we really require pom.xml file?
    i will be very grateful if you can help me in this!

    how my pom.xml file should be if i have to use one? (if any documentation is available for this please direct me to that).

    thanks


    Quote Originally Posted by Arjen Poutsma View Post
    In your code, your do:

    Code:
    WebServiceClient wsc = new WebServiceClient();
    while you should use dependency injection to inject the wsc instance. This results in the fact that the properties on the client are actually set, while now, there are not.

    So just create a setter for the client, and wire it up. That should do it.

  8. #8
    Join Date
    Aug 2007
    Posts
    7

    Default pom.xml

    Hi,
    pom.xml is not related to spring. It's a maven configuration file. "Better Builds with Maven" is a free ebook available on the net for an introdution to maven or you can check Maven project's documentation.

    HTH,
    Chandana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •