javaweb-servicesspringaxisjax-rpc

Create a simple web services using JAX-RPC in Apache Axis


I want to create a simple web services in Jax-RPC using Apache Axis.

I also want to implement spring nature to it.

I am new to Jax-RPC, could some share some references.

Thanks.


Solution

  • Apache Axis and JAX-RPC are to independent frameworks for creating web services. Nobody could answer your question because there is no correct answer for it. What I can do is just give you some links to gets started with so that you could get better understanding what is JAX-RPC and Apache Axis.

    See:

    From all of your previous question related to this one, I am assuming that you need to support rpc/encoded WSDL style. Well, JAX-RPC and Axis will do that. Don't know how to do this via JAX-RPC but this is some hints how to do this with Axis and Spring:

    Create two classes:

    import org.apache.axis.EngineConfiguration;
    import org.apache.axis.Handler;
    import org.apache.axis.deployment.wsdd.WSDDProvider;
    import org.apache.axis.deployment.wsdd.WSDDService;
    
    public class WSDDSpringProvider extends WSDDProvider {
    
        public static final String PROVIDER_NAME = "SPRING";
        public static final String PARAM_SPRING_BEAN_ID = "springBeanId";
    
        public String getName(){
            return "SPRING";
        }
    
        public Handler newProviderInstance(WSDDService service, EngineConfiguration registry)
            throws Exception {
            return new SpringProvider(service.getParameter("springBeanId"));
        }
    
    }
    

    And another:

    import java.io.PrintStream;
    import java.lang.reflect.Method;
    import javax.servlet.Servlet;
    import javax.servlet.ServletConfig;
    import org.apache.axis.MessageContext;
    import org.apache.axis.providers.java.RPCProvider;
    import org.apache.axis.transport.http.HTTPConstants;
    import org.springframework.web.context.WebApplicationContext;
    import org.springframework.web.context.support.WebApplicationContextUtils;
    
    public class SpringProvider extends RPCProvider {
    
        private String springBeanId;
    
        public SpringProvider(String springBeanId) {
            this.springBeanId = springBeanId;
        }
    
        protected Object makeNewServiceObject(MessageContext msgContext, String clsName)
            throws Exception {
            Servlet servlet = (Servlet)msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLET);
            WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletConfig().getServletContext());
            return wac.getBean(springBeanId);
        }
    
        protected Object invokeMethod(MessageContext msgContext, Method method, Object obj, Object argValues[])
            throws Exception {
            Method proxyMethod = obj.getClass().getMethod(method.getName(), method.getParameterTypes());
            return proxyMethod.invoke(obj, argValues);
        }
    
    }
    

    Make them as a .jar file and put it into your classpath. These classes are handlers that your Axis web service's implementation class could be exposed as a Spring bean.

    In Axis WSDD file configure java:SPRING provider for the web service which you want to expose as Spring bean. Define unique value for parameter springBeanId. For example (from WSDD file):

    <ns:service name="TestService" provider="java:SPRING" use="literal">
       <ns:parameter name="springBeanId" value="webServiceImpl" />
       <!-- ... -->
    </ns:service>
    

    Define your web service implementation as Spring bean in WEB-INF/applicationContext.xml, for example:

    <bean id="webServiceImpl" class="your.pkg.WebServiceImpl">
    </bean>
    

    After these steps you are able to use your web service implementation class as common Spring bean.