我想使用Apache Axis在Jax-RPC中创建一个简单的Web服务。
我也想实现它的春天性。
我是Jax-RPC的新手,可能会分享一些参考资料。
谢谢。
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.
最满意答案
Apache Axis和JAX-RPC用于创建Web服务的独立框架。 没人能回答你的问题,因为没有正确答案。 我能做的就是给你一些入门链接,这样你就可以更好地理解什么是JAX-RPC和Apache Axis。
看到:
Web服务 - Apache Axis JAX-RPC从您之前与之相关的所有问题,我假设您需要支持rpc/encoded WSDL样式。 好吧,JAX-RPC和Axis会做到这一点。 不知道如何通过JAX-RPC执行此操作,但这是一些提示如何使用Axis和Spring执行此操作:
创建两个类:
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")); } }而另一个:
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); } }将它们作为.jar文件并将其放入类路径中。 这些类是处理程序,您的Axis Web服务的实现类可以作为Spring bean公开。
在Axis WSDD文件中,为要作为Spring bean公开的Web服务配置java:SPRING提供程序。 为参数springBeanId定义唯一值。 例如(来自WSDD文件):
<ns:service name="TestService" provider="java:SPRING" use="literal"> <ns:parameter name="springBeanId" value="webServiceImpl" /> <!-- ... --> </ns:service>在WEB-INF/applicationContext.xml中将Web服务实现定义为Spring bean,例如:
<bean id="webServiceImpl" class="your.pkg.WebServiceImpl"> </bean>完成这些步骤后,您可以将Web服务实现类用作常见的Spring bean。
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:
Web Services - Apache Axis JAX-RPCFrom 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.
更多推荐
发布评论