各位好!我在写一个webService的测试桩(完善代码覆盖),调用端的请求方式和处理暂时不能做修改,现在是webservice服务能发布成功,但是请求过来出现Couldn't parse stream的错误。
1.服务端
webService发布 配置:web.xml, spring导入cxf文件
//web.xml
<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>/services/*</url-pattern>
</servlet-mapping>
<!-- 导入CXF为扩展Spring提供的几个XML配置文件 -->
<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="serviceImpl"
implementor="....ServiceImpl"
address="/NciicServices">
</jaxws:endpoint>
服务端代码:
@WebService(targetNamespace = "http://webservice.a.a.com/")
public interface IdentityWebService {
public String nciicCheck(String inLicense, String inConditions);
}
@WebService(serviceName = "NciicServices", targetNamespace = "http://webservice.a.a.com/")
public class IdentityWebServiceImpl implements IdentityWebService{
static Logger logger = LoggerFactory.getLogger(IdentityWebServiceImpl.class);
private static final String LOG_HEADER = "[identityAuth-nccicCheck-公安实名认证]";
@Override
public String nciicCheck(String inLicense, String inConditions){
logger.info("{},接收请求参数licence={},conditions={}", LOG_HEADER, inLicense , inConditions);
return "success connected";
}
}
服务发布启动后浏览器访问结果:发布信息如图

客户端访问结果则报错:(客户端代码使用中,不可改调用方式)
客户端代码:
String serviceUrl = "http://localhost:8464/services/NciicServices?wsdl";
String serviceName = "NciicServices";
ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory();
Protocol protocol = new Protocol("https", easy, 443);
Protocol.registerProtocol("https", protocol);
Service serviceModel = new ObjectServiceFactory().create(ServiceInf.class, serviceName, null, null);
ServiceInf service;
try {
service = (ServiceInf) new XFireProxyFactory().create(serviceModel, serviceUrl);
} catch (MalformedURLException e1) {
throw new RuntimeException(e1);
}
Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();
client.addOutHandler(new DOMOutHandler());
// 压缩传输
client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED, Boolean.TRUE);
client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "0");
client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "10*1000L");
String licensecode = "asdf";
String condition="asdfjklk";
try {
// 调用核查方法
result = service.nciicCheck(licensecode, condition);
} catch (Exception e) {
logger.error("{}发生异常:", HEADER, e);
}
return result;
public interface ServiceInf{
public String nciicCheck(String inLicense, String inConditions);
}
请求发起,服务端异常如下:
java.lang.RuntimeException: Couldn't parse stream.
at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1705) ~[cxf-api-2.7.16.jar:2.7.16]
at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:123) ~[cxf-api-2.7.16.jar:2.7.16]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) ~[cxf-api-2.7.16.jar:2.7.16]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [cxf-api-2.7.16.jar:2.7.16]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249) [cxf-rt-transports-http-2.7.16.jar:2.7.16]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248) [cxf-rt-transports-http-2.7.16.jar:2.7.16]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222) [cxf-rt-transports-http-2.7.16.jar:2.7.16]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153) [cxf-rt-transports-http-2.7.16.jar:2.7.16]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171) [cxf-rt-transports-http-2.7.16.jar:2.7.16]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289) [cxf-rt-transports-http-2.7.16.jar:2.7.16]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209) [cxf-rt-transports-http-2.7.16.jar:2.7.16]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [javax.servlet-api-3.1.0.jar:3.1.0]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265) [cxf-rt-transports-http-2.7.16.jar:2.7.16]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1667) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.0.RELEASE.jar:4.1.0.RELEASE]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.Server.handle(Server.java:497) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:610) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:539) [jetty-all-9.2.3.v20140905.jar:9.2.3.v20140905]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_141]
Caused by: com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 start byte 0x8b (at char #2, byte #-1)
at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:550) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:605) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:628) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFactory.java:331) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1703) ~[cxf-api-2.7.16.jar:2.7.16]
... 34 common frames omitted
Caused by: java.io.CharConversionException: Invalid UTF-8 start byte 0x8b (at char #2, byte #-1)
at com.ctc.wstx.io.UTF8Reader.reportInvalidInitial(UTF8Reader.java:303) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at com.ctc.wstx.io.UTF8Reader.read(UTF8Reader.java:189) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at com.ctc.wstx.io.ReaderBootstrapper.initialLoad(ReaderBootstrapper.java:250) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at com.ctc.wstx.io.ReaderBootstrapper.bootstrapInput(ReaderBootstrapper.java:133) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:545) ~[woodstox-core-asl-4.4.1.jar:4.4.1]
... 38 common frames omitted
这个utf-8貌似是编码问题,但是这套服务端程序也发布有别的webService服务,只不过调用端是直接new Client去invoke调用的,有中文且一直在用;这里的客户端调用的话使用的代理类过渡(客户端代码不可改,为服务方提供,改动可能造成正式环境不可用)
求解!!不知道是发布方式不对还是没做好处理。