![](/img/trans.png)
[英]will Apache CXF supports JAX-RPC based web services(SOAP)
[英]Create a simple web services using JAX-RPC in Apache Axis
我想使用Apache Axis在Jax-RPC中創建一個簡單的Web服務。
我也想對其實施彈簧特性。
我是Jax-RPC的新手,可以分享一些參考。
謝謝。
Apache Axis
和JAX-RPC
是用於創建Web服務的獨立框架。 沒有人可以回答您的問題,因為沒有正確的答案。 我所能做的就是為您提供一些入門指南,以便您可以更好地了解什么是JAX-RPC和Apache Axis。
看到:
從您先前與此問題相關的所有問題中,我假設您需要支持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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.