com.ctc.wstx.exc.WstxEOFException:仅在错误捕获

时间:2015-12-03 07:34:29

标签: java web-services soap cxf

所以我的Java / Spring / CXF / MySQL webservice启动并运行,完成了bean验证,在出错时会抛出自定义异常。这一切都很有效。

但是服务可能抛出的未经证实的错误(错误)呢?就像this page调用"未建模的故障" ,就像连接到后端数据库失败一样。为此,我故意在我的hibernate.properties文件中输入了一个不正确的密码。

所以我创建了一个自定义CXF拦截器以阻止soapfault:

公共类MyOutSoapFaultInterceptor扩展了AbstractSoapInterceptor {     private static Logger logger = Logger.getLogger(MyOutSoapFaultInterceptor.class);

public MyOutSoapFaultInterceptor()
{
    super(Phase.MARSHAL);
}

@Override
public void handleMessage( SoapMessage message) throws Fault
{
    logger.debug("entering");

    Exception e = message.getContent( Exception.class);
    if( e == null) {
        logger.debug("e is null");
    } else {
        logger.debug("e is not null");
        logger.debug("e.getCause:" + e.getCause());
        logger.debug("e.getMessage:" + e.getMessage());
        if( e instanceof Fault) {
            logger.debug("e is instanceOf Fault");
            SoapFault sf = SoapFault.createFault((Fault) e, message.getVersion());
            logger.debug("sf is not null");
            logger.debug("sf.getCause:" + sf.getCause());
            logger.debug("sf.getMessage:" + sf.getMessage());
            logger.debug("sf.getStatusCode:" + sf.getStatusCode());
            logger.debug("sf.getCode:" + sf.getCode());
            Fault newwFault = new Fault( new Exception("dammit"), Fault.FAULT_CODE_SERVER);
            newwFault.setMessage("argh");
            throw newwFault;
        }
    }
}

appclient.xml的相关部分:

<bean id="formsWebServicePortProxy" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
    <property name="wsdlDocumentUrl"  value="http://localhost:8080/dept_forms_webservice/formsService?wsdl"/>
    <property name="serviceInterface" value="mycom.dept.forms.web.endpoint.FormsEndpoint"/>
    <property name="serviceName"      value="FormsEndpointImplService"/>
    <property name="portName"         value="FormsEndpointImplPort"/>
    <property name="namespaceUri"     value="http://endpoint.web.forms.dept.mycom/"/>
</bean> 

我测试我的服务的非网络客户端应用程序包含以下代码段:

ApplicationContext ctx = new ClassPathXmlApplicationContext("appclient.xml");
theApp.formsWebServicePortProxy = (FormsEndpoint)      ctx.getBean("formsWebServicePortProxy");

logger.debug("entering");
System.out.println("entering testFindAllPermits");

java.util.List<mycom.dept.forms.web.endpoint.Permit> list_permit;

try {
    System.out.println("inside try block");
    list_permit = formsWebServicePortProxy.findAllPermit(); // <-- error thrown
    ListIterator<Permit> iter = list_permit.listIterator();
    while( iter.hasNext()) {
        System.out.println( iter.next().toString());
    }  
} catch ( org.springframework.remoting.jaxws.JaxWsSoapFaultException f) {
    System.out.println("caught JaxWsSoapFaultException");
    f.printStackTrace();    // <-- error thrown here
} catch ( Exception e) {
    System.out.println("caught Exception");
    System.out.println("e.getCause:" + e.getCause());
    System.out.println("e.getMessage:" + e.getMessage());
    if( e instanceof FormsEndpointException) {
        System.out.println("caught FEE");
    }
    e.printStackTrace();
}

logger.debug("exiting");
尝试在Web服务上调用方法时,

产生以下结果:

inside try block
caught JaxWsSoapFaultException
org.springframework.remoting.jaxws.JaxWsSoapFaultException: Error reading XMLStreamReader.; nested exception is javax.xml.ws.soap.SOAPFaultException: Error reading XMLStreamReader.
    at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:557)
    at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.invoke(JaxWsPortClientInterceptor.java:541)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy36.findAllPermit(Unknown Source)
    at mycom.dept.forms.app.FormsWebServiceClient.testFindAllPermits(FormsWebServiceClient.java:434)
    at mycom.dept.forms.app.FormsWebServiceClient.main(FormsWebServiceClient.java:480)
2015-12-02 23:58:55 DEBUG [dept.forms.app.FormsWebServiceClient-testFindAllPermits] - exiting
exiting
Caused by: javax.xml.ws.soap.SOAPFaultException: Error reading XMLStreamReader.
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)
    at com.sun.proxy.$Proxy35.findAllPermit(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:580)
    at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:554)
    ... 6 more
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
    at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
    at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2119)
    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2025)
    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1117)
    at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1140)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:139)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:61)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:798)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1667)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1520)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1428)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:658)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:532)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:464)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:367)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:89)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
    ... 13 more

所有人的根似乎是

Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog

at [row,col {unknown-source}]:[1,0 ....

此错误会导致this page之类的一些点击,表明我从网络服务获得空响应。或者更准确地说,是一个空肥皂体。但谷歌搜索引发了很多例子,并且引发了新的错误(新的例外(&#34; foo&#34;));&#34;也许我没有在客户端正确处理事情?

TIA,

Still-learning Stev

0 个答案:

没有答案