Results 1 to 10 of 10

Thread: AXIS web-service - ServletEndpointSupport

  1. #1
    Join Date
    Oct 2005
    Location
    Manchester, UK
    Posts
    19

    Default AXIS web-service - ServletEndpointSupport

    Hi,

    I've been trying to get a web service up and running which uses Tomcat + Axis + Spring + Hibernate. The web service implementation extends ServletEndpointSupport, but I can't seem to get access to the application context. As far as I can see the onInit method is never called:

    Code:
    public class RepositorySoapBindingImpl extends ServletEndpointSupport implements Repository {
    
        private DataSetDAO dao;
        
        protected void onInit() {
            dao = (DataSetDAO)getWebApplicationContext().getBean("dataSetDAO");
        }
        
        public String getDataSetComplete(long dataSetId) throws RemoteException, RepositoryServiceFault {
    
            IDataSet ds = dao.getDataSetComplete(dataSetId);
    
            //etc
        }
    
    }
    However, I have been able to get it to work by not extending ServletEndpointSupport and using this code in the business method of the web service implementation to get the application context instead:

    Code:
            HttpServlet servlet = (HttpServlet) MessageContext.getCurrentContext().getProperty(
                    HTTPConstants.MC_HTTP_SERVLET);
            ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext());
    This seems like a bit of a hack though, and I'd really like to use ServletEndpointSupport - if anyone can tell me how to get it to work!!

    cheers, Rob


    web.xml:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <web-app xmlns="http&#58;//java.sun.com/xml/ns/j2ee"
        xmlns&#58;xsi="http&#58;//www.w3.org/2001/XMLSchema-instance"
        xsi&#58;schemaLocation="http&#58;//java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">
    
      	<display-name>Repository</display-name>
      
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	    
      	<servlet>
        	<servlet-name>AxisServlet</servlet-name>
        	<display-name>Apache-Axis Servlet</display-name>
        	<servlet-class>
            	org.apache.axis.transport.http.AxisServlet
        	</servlet-class>
            <load-on-startup>1</load-on-startup>
      	</servlet>
      
      	<servlet-mapping>
        	<servlet-name>AxisServlet</servlet-name>
        	<url-pattern>/services/*</url-pattern>
      	</servlet-mapping>
    
      	<session-config>
        	<session-timeout>60</session-timeout>
      	</session-config>
      
      	<welcome-file-list>
        	<welcome-file>index.jsp</welcome-file>
      	</welcome-file-list>
      	
    	<resource-ref> 
    		<description>Connection to my DB.</description> 
    		<res-ref-name>jdbc/Repository</res-ref-name> 
    		<res-type>javax.sql.DataSource </res-type> 
    		<res-auth>Container</res-auth> 
    	</resource-ref>   	
    
    </web-app>
    context.xml:
    Code:
    <Context path="/repository" docBase="repository" debug="1" reloadable="true" crossContext="true">
    
     	<Resource 
     		name="jdbc/Repository" 
     		auth="Container" 
     		scope="Shareable" 
     		type="javax.sql.DataSource"
     		maxActive="100" 
     		maxIdle="30" 
     		maxWait="10000"
    		username="root" 
    		password=""
    		driverClassName="com.mysql.jdbc.Driver"
    		url="jdbc&#58;mysql&#58;//localhost/test?autoReconnect=true"/>
    </Context>
    applicationContext.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
        "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
        <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="java&#58;comp/env/jdbc/Repository"/>
        </bean>
    
        <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource">
            	<ref local="dataSource"/>
            </property>
            <property name="mappingResources">
                <list>
                    <value>org/psygrid/data/model/hibernate/Persistent.hbm.xml</value>
                </list>
            </property>
            <property name="hibernateProperties">
            	<props>
                	<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
            	</props>
            </property>
        </bean>
    
    	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    	     <property name="sessionFactory">
                 <ref local="sessionFactory"/>
             </property>
        </bean>
        
        <bean id="dataSetDAO" class="org.psygrid.data.dao.hibernate.DataSetDAOHibernate">
        	<property name="sessionFactory">
            	<ref local="sessionFactory"/>
        	</property>
    	</bean>
    
    </beans>

  2. #2
    Join Date
    Jan 2005
    Location
    Austin, TX
    Posts
    9

    Default You might have an extra jaxrpc.jar included in a shared lib

    I ran into this problem with JBoss http://jira.jboss.org/jira/browse/JBWS-220

    Good luck

  3. #3
    Join Date
    Apr 2005
    Location
    Italy
    Posts
    95

    Default

    The original post didn't include the server-wsdd.xml file to configure Axis and tell it to use that class to implement the Service.

    My guess is the Service wasn't registered properly there.

  4. #4
    Join Date
    Oct 2005
    Location
    Manchester, UK
    Posts
    19

    Default Re. AXIS web-service - ServletEndpointSupport

    Hi,

    Thanks for the replies so far. My server-config.wsdd is shown below. I have just used org.apache.axis.utils.Admin to generate this, with the deploy.wsdd that was generated by wsdl2java as an argument.

    So, am I right in thinking that I need to add something to server-config.wsdd so that Axis knows that ServiceLifecycle is being used?

    cheers, Rob

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
     <globalConfiguration>
      <parameter name="adminPassword" value="admin"/>
      <parameter name="enableNamespacePrefixOptimization" value="false"/>
      <parameter name="dotNetSoapEncFix" value="true"/>
      <parameter name="disablePrettyXML" value="true"/>
      <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
      <parameter name="sendXsiTypes" value="true"/>
      <parameter name="sendMultiRefs" value="true"/>
      <parameter name="sendXMLDeclaration" value="true"/>
      <requestFlow>
       <handler type="java:org.apache.axis.handlers.JWSHandler">
        <parameter name="scope" value="session"/>
       </handler>
       <handler type="java:org.apache.axis.handlers.JWSHandler">
        <parameter name="scope" value="request"/>
        <parameter name="extension" value=".jwr"/>
       </handler>
      </requestFlow>
     </globalConfiguration>
     <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
     <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
     <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
     <service name="AdminService" provider="java:MSG">
      <parameter name="allowedMethods" value="AdminService"/>
      <parameter name="enableRemoteAdmin" value="false"/>
      <parameter name="className" value="org.apache.axis.utils.Admin"/>
      <namespace>http://xml.apache.org/axis/wsdd/</namespace>
     </service>
     <service name="Version" provider="java:RPC">
      <parameter name="allowedMethods" value="getVersion"/>
      <parameter name="className" value="org.apache.axis.Version"/>
     </service>
     <service name="repository" provider="java:RPC">
      <parameter name="allowedMethods" value="*"/>
      <parameter name="typeMappingVersion" value="1.2"/>
      <parameter name="wsdlPortType" value="Repository"/>
      <parameter name="className" value="org.psygrid.data.RepositorySoapBindingSkeleton"/>
      <parameter name="wsdlServicePort" value="repository"/>
      <parameter name="wsdlTargetNamespace" value="urn:data.psygrid.org"/>
      <parameter name="wsdlServiceElement" value="RepositoryService"/>
      <parameter name="schemaUnqualified" value="urn:data.psygrid.org"/>
      <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" qname="ns1:RepositoryServiceFault" serializer="org.apache.axis.encoding.ser.BeanSerializerFactory" type="java:org.psygrid.data.RepositoryServiceFault" xmlns:ns1="urn:data.psygrid.org"/>
      <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" qname="ns2:RepositoryOutOfDateFault" serializer="org.apache.axis.encoding.ser.BeanSerializerFactory" type="java:org.psygrid.data.RepositoryOutOfDateFault" xmlns:ns2="urn:data.psygrid.org"/>
     </service>
     <transport name="http">
      <requestFlow>
       <handler type="URLMapper"/>
       <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
      </requestFlow>
      <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>
      <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
      <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>
     </transport>
     <transport name="local">
      <responseFlow>
       <handler type="LocalResponder"/>
      </responseFlow>
     </transport>
    </deployment>

  5. #5
    Join Date
    Apr 2005
    Location
    Italy
    Posts
    95

    Default

    The error is here:

    Code:
     <service name="repository" provider="java:RPC">
       ...
      <parameter name="className" value="org.psygrid.data.RepositorySoapBindingSkeleton"/>
      ...
     </service>
    This class in your original post which extends ServletEndpointSupport was RepositorySoapBindingImpl not RepositorySoapBindingSkeleton.

    Hope that helps.

  6. #6
    Join Date
    Oct 2005
    Location
    Manchester, UK
    Posts
    19

    Default

    Thanks a lot Derek - you were spot on, and it's working now.

    That'll teach me for trusting auto-generated config files!

    cheers, Rob

  7. #7

    Default Integrate with listener context

    Hi,

    Is this still the best way to load the context for an Axis servlet? It would be nice if the code was able to interact with the context loaded with the web application context loaded via the listener ContextLoaderListener.

    The "issue" is that if these two contexts can't interact. I am writing a few components which have a web GUI interface and a SOAP interface which are deployed as one web application. We have two contexts loaded when there only need be one.... not that this is usually a pain with amount of memory available to most servers nowadays, but it is nice to not have to load the application context (in the exposed business method) when the first web service request arrives.

    Cheers,

    David L

  8. #8

    Default

    Hello!

    I run into the same probles like r0bh does.
    But this time using spring 2.0-rc3, jboss-4.0.4 and axis from spring distribution (not from jbossws project).
    className is pointed at the class implementing ServletEndpointSupport.
    Simptom is the same: init() is not called.

    Does anybody have same problem?

  9. #9

    Default

    Solved. The problem was in different classloaders loading spring.jar and axis. After using single classloader for both(either in shared libs or in WEB-INF/lib) - all works just fine

  10. #10
    Join Date
    Sep 2007
    Posts
    19

    Default Using a singleton ServletEndpointSupport

    i have more or less the same configuration as you.
    A class that extends ServletEndpointSupport, spring-2.0.4.
    I don't have this class that extends ServletEndpointSupport in the applicationContext.xml, so every times i call this throw the wsdl generated, it seems that the onInit method is called.
    How can i avoid this?
    I need to have a singleton, not one instance every time I call the wsdl.
    Spring by default use singleton objects, i think, and in applicationContext i'm not using any reference to say that the beans are singleton.

Similar Threads

  1. Replies: 1
    Last Post: Jun 3rd, 2008, 04:20 AM
  2. Replies: 2
    Last Post: Aug 2nd, 2005, 08:34 AM
  3. Replies: 3
    Last Post: Jul 4th, 2005, 07:13 AM
  4. Replies: 9
    Last Post: Feb 8th, 2005, 09:25 PM
  5. Creating a proper service layer?
    By infectedrhythms in forum Architecture
    Replies: 5
    Last Post: Jan 5th, 2005, 06:32 PM

Posting Permissions

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