Announcement Announcement Module
Collapse
No announcement yet.
WebServices using Axis, What am I missing ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WebServices using Axis, What am I missing ?

    I have tried to expand the 4-step tutorial by making the increase-price into a web-service. I have used the JPetStore as basis for figuring out what to do.

    I have created a inteface :
    Code:
    package server;
    
    import bus.Product;
    
    
    public interface ProductManagerService {
        public void increasePrice(int pct) ;
    
           public Product getProduct(int id);
    
        
    }
    and a remote one :
    Code:
    package server;
    
    import bus.Product;
    
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    
    public interface RemoteProductManager extends Remote  {
    
    
        public void increasePrice(int pct) throws RemoteException;
    
    }
    I have implemented the first interface into Product manager :
    Code:
    public class ProductManager implements Serializable,ProductManagerService {
    Created the class reffered to in axis :
    Code:
    package server;
    
    import org.springframework.remoting.jaxrpc.ServletEndpointSupport;
    import bus.ProductManager;
    
    
    public class JaxRpcProductManager extends ServletEndpointSupport
            implements RemoteProductManager, ProductManagerService {
        private ProductManagerService prodman;
    
        protected void onInit() {
            System.out.println("Initiating ProductManager for RPC");
            this.prodman = (ProductManagerService) getWebApplicationContext().getBean("prodMan");
        }
        public void increasePrice(int pct) {
            System.out.println("Increasing price");
            prodman.increasePrice(pct);
        }
    
       
    
    }
    I also added the axisi-servlet to the web.xml (same way as in JPetStore).
    I created the server-config.wsdd and added this :
    Code:
     <service name="ProductManager" provider="java&#58;RPC">
      <parameter name="allowedMethods" value="*"/>
      <parameter name="className" value="server.JaxRpcProductManager"/>
         <beanMapping qname="springtut&#58;Product" xmlns&#58;springtut="urn&#58;springtut" languageSpecificType="java&#58;bus.Product"/>
     </service>
    The bean-mapping for product was added as an next-step expansion to a method : getProduct
    and for verifying that the autogenerated wsdl-file looks good.

    All of this makes the axis work fine, The servlet generates the correct responeses for all web-requests I make :
    /springapp/axis
    /springapp/axis/ProductManager
    /springapp/axis/ProductManager?wsdl

    Nothing wrong so far...

    Until I try to access the service....

    I test it using the DynamicInvoker-sample from the latest axis-distro (this is a nice utility for testing WebServices..)

    I get a response like this :
    Code:
    C&#58;\development\axis-1_2RC1>java samples.client.DynamicInvoker http&#58;//localhost&#58;8080/springapp/axis/ProductManager?wsdl increasePrice 10
    Reading WSDL document from 'http&#58;//localhost&#58;8080/springapp/axis/ProductManager?wsdl'
    Preparing Axis dynamic invocation
    Executing operation increasePrice with parameters&#58;
    pct=10
    Exception in thread "main" AxisFault
     faultCode&#58; &#123;http&#58;//schemas.xmlsoap.org/soap/envelope/&#125;Server.userException
     faultSubcode&#58;
     faultString&#58; java.lang.IllegalStateException&#58; No WebApplicationContext found&#58; no ContextLoaderListener registered?
     faultActor&#58;
     faultNode&#58;
     faultDetail&#58;
            &#123;http&#58;//xml.apache.org/axis/&#125;stackTrace&#58;java.lang.IllegalStateException&#58; No WebApplicationContext found&#58; no ContextLoaderListener registered?
            at org.apache.axis.message.SOAPFaultBuilder.createFault&#40;SOAPFaultBuilder.java&#58;221&#41;
            at org.apache.axis.message.SOAPFaultBuilder.endElement&#40;SOAPFaultBuilder.java&#58;128&#41;
            at org.apache.axis.encoding.DeserializationContext.endElement&#40;DeserializationContext.java&#58;1077&#41;
            at org.apache.xerces.parsers.SAXParser.endElement&#40;SAXParser.java&#58;1403&#41;
            at org.apache.xerces.validators.common.XMLValidator.callEndElement&#40;XMLValidator.java&#58;1550&#41;
            at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch&#40;XMLDocumentScanner.java&#58;1149&#41;
            at org.apache.xerces.framework.XMLDocumentScanner.parseSome&#40;XMLDocumentScanner.java&#58;381&#41;
            at org.apache.xerces.framework.XMLParser.parse&#40;XMLParser.java&#58;1098&#41;
            at javax.xml.parsers.SAXParser.parse&#40;Unknown Source&#41;
            at org.apache.axis.encoding.DeserializationContext.parse&#40;DeserializationContext.java&#58;225&#41;
            at org.apache.axis.SOAPPart.getAsSOAPEnvelope&#40;SOAPPart.java&#58;645&#41;
            at org.apache.axis.Message.getSOAPEnvelope&#40;Message.java&#58;424&#41;
            at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke&#40;MustUnderstandChecker.java&#58;62&#41;
            at org.apache.axis.client.AxisClient.invoke&#40;AxisClient.java&#58;173&#41;
            at org.apache.axis.client.Call.invokeEngine&#40;Call.java&#58;2737&#41;
            at org.apache.axis.client.Call.invoke&#40;Call.java&#58;2720&#41;
            at org.apache.axis.client.Call.invoke&#40;Call.java&#58;2396&#41;
            at org.apache.axis.client.Call.invoke&#40;Call.java&#58;2319&#41;
            at org.apache.axis.client.Call.invoke&#40;Call.java&#58;1776&#41;
            at samples.client.DynamicInvoker.invokeMethod&#40;DynamicInvoker.java&#58;237&#41;
            at samples.client.DynamicInvoker.main&#40;DynamicInvoker.java&#58;114&#41;
    
            &#123;http&#58;//xml.apache.org/axis/&#125;hostname&#58;fh_lt
    
    java.lang.IllegalStateException&#58; No WebApplicationContext found&#58; no ContextLoaderListener registered?
            at org.apache.axis.message.SOAPFaultBuilder.createFault&#40;SOAPFaultBuilder.java&#58;221&#41;
            at org.apache.axis.message.SOAPFaultBuilder.endElement&#40;SOAPFaultBuilder.java&#58;128&#41;
            at org.apache.axis.encoding.DeserializationContext.endElement&#40;DeserializationContext.java&#58;1077&#41;
            at org.apache.xerces.parsers.SAXParser.endElement&#40;SAXParser.java&#58;1403&#41;
            at org.apache.xerces.validators.common.XMLValidator.callEndElement&#40;XMLValidator.java&#58;1550&#41;
            at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch&#40;XMLDocumentScanner.java&#58;1149&#41;
            at org.apache.xerces.framework.XMLDocumentScanner.parseSome&#40;XMLDocumentScanner.java&#58;381&#41;
            at org.apache.xerces.framework.XMLParser.parse&#40;XMLParser.java&#58;1098&#41;
            at javax.xml.parsers.SAXParser.parse&#40;Unknown Source&#41;
            at org.apache.axis.encoding.DeserializationContext.parse&#40;DeserializationContext.java&#58;225&#41;
            at org.apache.axis.SOAPPart.getAsSOAPEnvelope&#40;SOAPPart.java&#58;645&#41;
            at org.apache.axis.Message.getSOAPEnvelope&#40;Message.java&#58;424&#41;
            at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke&#40;MustUnderstandChecker.java&#58;62&#41;
            at org.apache.axis.client.AxisClient.invoke&#40;AxisClient.java&#58;173&#41;
            at org.apache.axis.client.Call.invokeEngine&#40;Call.java&#58;2737&#41;
            at org.apache.axis.client.Call.invoke&#40;Call.java&#58;2720&#41;
            at org.apache.axis.client.Call.invoke&#40;Call.java&#58;2396&#41;
            at org.apache.axis.client.Call.invoke&#40;Call.java&#58;2319&#41;
            at org.apache.axis.client.Call.invoke&#40;Call.java&#58;1776&#41;
            at samples.client.DynamicInvoker.invokeMethod&#40;DynamicInvoker.java&#58;237&#41;
            at samples.client.DynamicInvoker.main&#40;DynamicInvoker.java&#58;114&#41;
    I get the same message in the server-logs.

    Also make note that the line "Initiating ProductManager.." never shows up in any log, as it does when I add the same line in JPetStore.

    So now my question is : What am I missing ??

  • #2
    Found it (I think)

    :idea:
    It seems that I also have to create the servlet-definition (in web.xml) :
    Code:
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
    			/WEB-INF/dataAccessContext-local.xml  /WEB-INF/applicationContext.xml
            </param-value>
       </context-param>
    
        <servlet>
            <servlet-name>context</servlet-name>
            <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    In my last attempt I also moved some definitions out of the springapp-servlet.xml into those two new configuration-files as well as moving the jdbc-parameters into a seperate properties-file.

    Now my response is :
    Code:
    C&#58;\development\axis-1_2RC1>java samples.client.DynamicInvoker http&#58;//localhost&#58;8080/springapp/axis/ProductManager?wsdl increasePrice 10
    Reading WSDL document from 'http&#58;//localhost&#58;8080/springapp/axis/ProductManager?wsdl'
    Preparing Axis dynamic invocation
    Executing operation increasePrice with parameters&#58;
    pct=10
    
    Done!
    And the prices is updatet.

    The key element here was probably the context-servlet I added in web.xml

    Since the docs on this subject still is missing, my next step is to start removing elements I suspect has been coded for the other three remoting-scenarioes.

    To make the springapp into a web-service would be a great addon to the existing tutorial. Best seperated into two paths: one for using jaxrpc and one for the other three remoting-methods (Hessian, Burlaup and HTTP-invoker) since those uses the same code... [/quote]

    Comment


    • #3
      Indeed, your Spring root application context has to be loaded before your Axis servlet.

      On Servlet 2.4 and most Servlet 2.3 containers, ContextLoaderListener will be fine to achieve this. On older servers, you might need ContextLoaderServlet, for example for WebLogic 8.1 (at least its early versions) and WebSphere 5.

      Effectively, ContextLoaderServlet will work on all web containers (that's why all our sample apps use it); it is just less elegant. As of Servlet 2.4, ContextLoaderListener is the recommended strategy.

      Juergen

      Comment


      • #4
        Thanks.
        An example of the listener would be nice...

        And, as I now am relatively well into my project, I have another 'problem' regarding the integration Spring-Axis.

        My application has a web-interface which uses some validation-classes (implements validator), and this class is invoked by the spring-servlet (i suspect).

        How can I reuse this validator on an instance created from a Axis-request ?

        Regards
        Frode Halvorsen

        Comment


        • #5
          Using validator, but how to bind data ?

          The validator was relatively easy to use, I found the code for this in another discussion : http://forum.springframework.org/showthread.php?t=10964

          But how do I 'bind' the data from the source-object (instanciated and populated by axis) to my spring-managed bean ? Like the spring-servlet does with request-command?

          I would hope there is an easier way than manually copying every property between those objects.

          Regards
          Frode
          Last edited by robyn; May 14th, 2006, 11:48 AM.

          Comment


          • #6
            I have also problems with cofnfiguring AXIS.

            Although I should be doing everything the same way as described here I'm not able to get the automatic wsdl generating to work (requests to /services/myservice?wsdl return status code 404) . But requests to /axis or /axis/myservice return correct result.

            What could possible cause this kind of behaviour?

            My web.xml:
            Code:
            <listener>       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            </listener>
            <servlet>
              <servlet-name>springapp</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <load-on-startup>1</load-on-startup>
            </servlet>   
            <servlet>
              <servlet-name>axis</servlet-name>
              <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
              <load-on-startup>5</load-on-startup>
            </servlet>
            <servlet-mapping>
              <servlet-name>axis</servlet-name>
              <url-pattern>/axis/*</url-pattern>
            </servlet-mapping>
            server-config.wsdd file:
            Code:
            <service name="PrivacyProfileService" provider="java&#58;RPC">
              <parameter name="allowedMethods" value="*"/>
              <parameter name="className" value="com.mgine.privacyprofile.service.server.JaxRpcPrivacyProfileService"/>
            </service> 
            <service name="Version" provider="java&#58;RPC">
              <parameter name="allowedMethods" value="getVersion"/>
              <parameter name="className" value="org.apache.axis.Version"/>
            </service>
            Thanks!

            Comment


            • #7
              Hi,

              <servlet-mapping>
              <servlet-name>axis</servlet-name>
              <url-pattern>/axis/*</url-pattern>
              </servlet-mapping>


              this should be correct because you tell the Axis Sevlet to listen on: /axis/*
              and not on /services/*

              mfg Gideon

              Comment


              • #8
                Thanks!

                It seems that the service list page generated by AXIS has invalid links to WSDL files. For some reason it tries to find them from /services/* whereas they are under axis/.

                I also had one jar file missing on my classpath on client side which caused the exception being thrown.

                Comment


                • #9
                  Axis servlet do not load.
                  Have deployed the jpetstore application and observed it exposes the axis services perfectly.
                  So it should be straight forward to compile a similar web.xml to load the axis servlet for another Spring application myapp:
                  Code:
                  	<servlet>
                  		<servlet-name>context</servlet-name>
                  		<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
                  		<load-on-startup>1</load-on-startup>
                  	</servlet>
                  	<servlet>
                  		<servlet-name>myapp</servlet-name>
                  		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                  		<load-on-startup>2</load-on-startup>
                  	</servlet>
                  	<servlet>
                  		<servlet-name>axis</servlet-name>
                  		<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
                  		<load-on-startup>3</load-on-startup>
                  	</servlet>
                  	<servlet-mapping>
                  		<servlet-name>myapp</servlet-name>
                  		<url-pattern>*.htm</url-pattern>
                  	</servlet-mapping>
                  	<servlet-mapping>
                  		<servlet-name>axis</servlet-name>
                  		<url-pattern>/axis/*</url-pattern>
                  	</servlet-mapping>
                  Whatever I try in the browser for url = .../myapp/axis/*
                  tomcat responds: HTTP Status 404 - Servlet axis is not available

                  What am I missing?

                  Thanks

                  Comment


                  • #10
                    My problem was due to a missing .jar, don't know exactly which.
                    With all .jars from jpetstore Axis now responds correctly.

                    Comment


                    • #12
                      I've been trying to work through this example and am stuck at figuring out what is supposted to go inside the applicationContext.xml (and dataAccessContets-local.xml).

                      I can get the wsdl from the url http://localhost:8080/springapp/axis...ctManager?WSDL
                      successfully.

                      I've added

                      <listener> <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
                      </listener>

                      to the web.xml

                      When i call the service from DynamicInvoker i get

                      Exception in thread "main" AxisFault
                      faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
                      faultSubcode:
                      faultString: org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'prodMan' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans []; root of BeanFactory hierarchy
                      faultActor:
                      faultNode:
                      faultDetail:
                      {http://xml.apache.org/axis/}hostname:MarkM

                      org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'prodMan' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans []; root of BeanFactory hierarchy

                      Can anybody tell me what's supposed to go inside the applicationContext.xml file?

                      Thanks,

                      Mark

                      Comment


                      • #13
                        also can someone tell how you configure a webapp client for the webservice?
                        jpetstore only uses a regular application, not a web app.

                        I tried deploying one on jboss but got an eexception from axis that there was no engine configuration file found (when deployong the client web app).
                        A regular client application seems to work fine to call the service

                        Comment

                        Working...
                        X