CXF
CXF 定义服务端传递List参数报错,最好写一个类来封装List。
spring集成cxf
1.web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>(Spring Application)</display-name>
<context-param>
<description>log4j 配置文件位置</description>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<description>Spring配置文件位置</description>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext*.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<session-config>
<session-timeout>43200</session-timeout>
</session-config>
<!-- 集成cxf(webservice)-->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<!-- end booking ticket -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/index.jsp</location>
</error-page>
</web-app>
2.applicationContext-ws.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="userService" implementor="org.apache.cxf.ws.service.ComplexUserService"
address="/userService" />
</beans>
IComplexUserService.java
package org.apache.cxf.ws.service;
import javax.jws.WebService;
import org.apache.cxf.pojo.User;
@WebService
public interface IComplexUserService {
String validateUser(User user);
}
ComplexUserService.java
package org.apache.cxf.ws.service;
import javax.jws.WebService;
import org.apache.cxf.pojo.User;
@WebService(endpointInterface="org.apache.cxf.ws.service.IComplexUserService")
public class ComplexUserService implements IComplexUserService {
@Override
public String validateUser(User user) {
return user.validate(user);
}
}
Exception in thread "main" java.lang.UnsatisfiedLinkError: java.util.zip.ZipFile.open(Ljava/lang/String;IJZ)J
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:127)
at java.util.jar.JarFile.<init>(JarFile.java:135)
at java.util.jar.JarFile.<init>(JarFile.java:72)
at sun.misc.URLClassPath$JarLoader.getJarFile(URLClassPath.java:646)
at sun.misc.URLClassPath$JarLoader.access$600(URLClassPath.java:540)
at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:607)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:599)
at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:583)
at sun.misc.URLClassPath$3.run(URLClassPath.java:333)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:322)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:299)
at sun.misc.URLClassPath.findResource(URLClassPath.java:145)
at java.net.URLClassLoader$2.run(URLClassLoader.java:385)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(URLClassLoader.java:382)
at java.lang.ClassLoader.getResource(ClassLoader.java:1002)
at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1192)
at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:78)
at javax.xml.ws.spi.Provider.provider(Provider.java:83)
at javax.xml.ws.Endpoint.publish(Endpoint.java:170)
at org.apache.cxf.logInter.ServiceMain.main(ServiceMain.java:25)
weblogic自带了很多jar包 当工程中的jar和weblogic自带jar版本不一致时 往往会出现错误。
为了解决在weblogic中jar包冲突的问题 你可以在web-inf下创建一个weblogic.xml
内容如:
<?xml version="1.0"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>//优先加载web工程中的jar包
</container-descriptor>
</weblogic-web-app>
转载请注明地址:http://www.cnblogs.com/likehua/
package org.apache.cxf.logInter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.xml.ws.Endpoint;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.ws.service.ComplexUserService;
import org.apache.cxf.ws.service.IComplexUserService;
public class ServiceMain {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
IComplexUserService userService = new ComplexUserService();
EndpointImpl ep = (EndpointImpl)Endpoint.publish("http://localhost:7001/spring/services/userService",userService);
//添加in拦截器
ep.getInInterceptors().add(new LoggingInInterceptor(new PrintWriter(new FileWriter("in.txt"))));
//添加out拦截器
ep.getOutInterceptors().add(new LoggingOutInterceptor(new PrintWriter(new FileWriter("out.txt"))));
System.out.println("web service 暴露接口");
}
}
今天用cxf生成内控的客户端遇到问题 全部生成了jaxbelement元素的了 网上找了下命令 找了好久 贴出来以便忘记了 :
H:\apache-cxf-2.7.3\bin>wsdl2java.bat -b "1.xml" -p com.tempus.b2gs.tsa.outInter
face.innercontroller.osbservice -client -frontend jaxws21 http://172.16.3.158:8
085/osbServicewsdl
1.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:globalBindings generateElementProperty="false" />
</jaxb:bindings>