简体   繁体   English

在Apache Axis中使用JAX-RPC创建简单的Web服务

[英]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. 我想使用Apache Axis在Jax-RPC中创建一个简单的Web服务。

I also want to implement spring nature to it. 我也想对其实施弹簧特性。

I am new to Jax-RPC, could some share some references. 我是Jax-RPC的新手,可以分享一些参考。

Thanks. 谢谢。

Apache Axis and JAX-RPC are to independent frameworks for creating web services. Apache AxisJAX-RPC是用于创建Web服务的独立框架。 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. 我所能做的就是为您提供一些入门指南,以便您可以更好地了解什么是JAX-RPC和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. 从您先前与此问题相关的所有问题中,我假设您需要支持rpc/encoded WSDL样式。 Well, JAX-RPC and Axis will do that. 好吧,JAX-RPC和Axis将做到这一点。 Don't know how to do this via JAX-RPC but this is some hints how to do this with Axis and Spring: 不知道如何通过JAX-RPC此操作,但这是一些如何使用Axis和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. 使它们成为.jar文件,并将其放入您的类路径中。 These classes are handlers that your Axis web service's implementation class could be exposed as a Spring bean. 这些类是Axis Web服务的实现类可以作为Spring bean公开的处理程序。

In Axis WSDD file configure java:SPRING provider for the web service which you want to expose as Spring bean. Axis WSDD文件中,为要作为Spring bean公开的Web服务配置java:SPRING提供程序。 Define unique value for parameter springBeanId . 为参数springBeanId定义唯一值。 For example (from WSDD file): 例如(来自WSDD文件):

<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: WEB-INF/applicationContext.xml中将您的Web服务实现定义为Spring bean,例如:

<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. 完成这些步骤之后,您就可以将Web服务实现类用作常见的Spring bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM