1.所需的依赖的包:
commons-logging-1.1.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)
geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)
geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
jaxb-api-2.1.jar
jaxb-impl-2.1.6.jar
jaxws-api-2.1.jar
jetty-6.1.5.jar
jetty-util-6.1.5.jar
neethi-2.0.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
XmlSchema-1.2.jar
xml-resolver-1.2.jar
spring jar 包, 用来支持xml配置:
aopalliance-1.0.jar
spring-core-2.0.4.jar
spring-beans-2.0.4.jar
spring-context-2.0.4.jar
spring-web-2.0.4.jar
CXF jar包:
cxf-2.1.jar
以上jar 包 可从apache官方网站下载 apache-cxf-2.1.2.zip, 然后从apache-cxf-2.1.2/lib 目录中获得
2. web.xml中配置:
<!--hyt 20170720 -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
3.使用的applicationContext-shiro-nocas.xml中暴露setvlet
<bean id="chainDefinitionSectionMetaSource" class="ins.policy.**.ChainDefinitionSectionMetaSource">
<property name="filterChainDefinitions">
<value>
<!-- 静态资源区 -->
/devjs/** = anon
/js/** = anon
/dist/** = anon
/css/** = anon
/img/** = anon
/plugins/** = anon
/favicon.ico = anon
/verification/** = anon
/webservice/** = anon
/**/app/** = anon
/logout=logout
/** =user
</value>
</property>
</bean>
在applicationContext-cxf.xml下配置
<jaxws:server id="pacgServiceSoap"
serviceClass="ins.com.application.*.*.service.facade.PacgService"
address="/pacgService">
<jaxws:serviceBean>
<!-- 要暴露的 bean 的引用 -->
<!-- <ref bean="pacgService" /> -->
<bean class="ins.com.application.*.*.service.impl.PacgServiceImpl"></bean>
</jaxws:serviceBean>
<jaxws:inInterceptors>
<ref bean="inMessageInterceptor" />
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="outLoggingInterceptor" />
</jaxws:outInterceptors>
</jaxws:server>
4.新建接口:如下
package ins.com.application.*.*.service.facade;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(targetNamespace="http://localhost:8080/webservice/pacgService")
public interface PacgService {
@WebMethod()
public String newService(@WebParam(name="xml") String xml);
}
实现类如下:
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class PacgServiceImpl implements PacgService {
public String newService( String xml) {
System.out.println("1");
}
}
5.发布成功,查看
http://localhost:8080/webservice
6.客户端调用
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(wsdlmed);
//new javax.xml.namespace.QName
//第一个参数:发布的wsdl里的targetNamespace里的url
//第二个参数:方法名
call.setOperationName(new javax.xml.namespace.QName("http://localhost:8080/webservice/pacgService",
"newService"));
call.setSOAPActionURI(soapuri);
call.setEncodingStyle(null);
/ /addParameter :@WebParam(name="xml") 参数名
call.addParameter("xml",org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN) ;
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setTimeout(300000);
String xml="123";
String result = (String) call.invoke(new Object[] { xml });