使用Apache Axis中的JAX

编程入门 行业动态 更新时间:2024-10-25 11:18:59
使用Apache Axis中的JAX-RPC创建简单的Web服务(Create a simple web services using JAX-RPC in Apache Axis)

我想使用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-RPC

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.

更多推荐

本文发布于:2023-07-19 09:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1176906.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Apache   Axis   JAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!