0

私はWebサービスの使用を開始したばかりで、クラ​​イアントアプリが別のwsdl Webサービスに接続されており、soapは私のものとは異なるプレフィックスを使用しています。ハンドラーで確認して、soap rawメッセージを出力しました。彼らは「S」と私の「env」を使用しました。Netbeans 6.5 から JAX WS 2.1 を使用しました。

確かなことはわかりませんが、この違いが失敗の原因だと思います。これは私のスタックトレースです:

    14:01:56,817 ERROR [CommonClient] Exception caught while (preparing for) performing the invocation: 
javax.xml.ws.soap.SOAPFaultException: Couldn't create SOAP message due to exception: XML reader error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
    at org.jboss.ws.core.jaxws.SOAPFaultHelperJAXWS.getSOAPFaultException(SOAPFaultHelperJAXWS.java:84)
    at org.jboss.ws.core.jaxws.binding.SOAP11BindingJAXWS.throwFaultException(SOAP11BindingJAXWS.java:107)
    at org.jboss.ws.core.CommonSOAPBinding.unbindResponseMessage(CommonSOAPBinding.java:579)
    at org.jboss.ws.core.CommonClient.invoke(CommonClient.java:381)
    at org.jboss.ws.core.jaxws.client.ClientImpl.invoke(ClientImpl.java:290)
    at org.jboss.ws.core.jaxws.client.ClientProxy.invoke(ClientProxy.java:170)
    at org.jboss.ws.core.jaxws.client.ClientProxy.invoke(ClientProxy.java:150)
    at $Proxy1792.doService(Unknown Source)
    at com.pckg.web.services.MyWebServiceImpl.service(MyWebServiceImpl.java:143)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:662)

ハンドラーも使用して見つけたいくつかの方法に基づいて、プレフィックスの石鹸メッセージを変更しようとしました。残念ながら、石鹸ハンドラーが機能していないか、何かを見逃している可能性があります。

これは私のハンドラーのようなものです:

public class CustomSOAPHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public Set<QName> getHeaders() {
    return null;
}
@Override
public void close(MessageContext context) {
}
@Override
public boolean handleFault(SOAPMessageContext context) {
    WebUtils.log("CustomSOAPHandler.handleFault");
    try {
        boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (outbound) {
            WebUtils.log("Direction : outbound (handleFault)");
        } else {
            WebUtils.log("Direction : inbound (handleFault)");
        }
        if (!outbound) {
            try {
                SOAPMessage msg = ((SOAPMessageContext) context).getMessage();
                logToSystemOut(context);
                if (context.getMessage().getSOAPBody().getFault() != null) {
                    String detailName = null;
                    try {
                        detailName = context.getMessage().getSOAPBody().getFault().getDetail().getFirstChild().getLocalName();
                        WebUtils.log("detailName : " + detailName);
                    } catch (Exception e) {
                    }
                }
            } catch (SOAPException e) {
            WebUtils.log("SOAP Exception : " + e);
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        WebUtils.log("Exception in handler: " + e);
    }
    return true;
}
@Override
public boolean handleMessage(SOAPMessageContext context) {
    WebUtils.log("CustomSOAPHandler.handleMessage");
    try {
        SOAPMessage message = context.getMessage();
        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPHeader header = message.getSOAPHeader();
        SOAPBody body = message.getSOAPBody();
        WebUtils.log("Configure SOAP Message prefix from [" + envelope.getPrefix() + "] into [S]");
        envelope.setPrefix("S");
        header.setPrefix("S");
        body.setPrefix("S");
        context.setMessage(message);
        Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (outboundProperty.booleanValue()) {
            // outbound
            WebUtils.log("Direction : outbound (handleMessage)");
            logToSystemOut(context);
        } else {
            // inbound
            WebUtils.log("Direction : inbound (handleMessage)");
            logToSystemOut(context);
        }
    } catch (Exception e) {
        WebUtils.log("Exception in handler: " + e);
    }
    return true;
}
private void logToSystemOut(SOAPMessageContext smc) {
    SOAPMessage msg = smc.getMessage();
    if (msg == null) {
        WebUtils.log("SOAP Message is null");
        return;
    }
    WebUtils.log("");
    WebUtils.log("--------------------");
    WebUtils.log("DUMP OF SOAP MESSAGE");
    WebUtils.log("--------------------");
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        msg.writeTo(baos);
        WebUtils.log(baos.toString(getMessageEncoding(msg)));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
private String getMessageEncoding(SOAPMessage msg) throws SOAPException {
    String encoding = "utf-8";
    if (msg.getProperty(SOAPMessage.CHARACTER_SET_ENCODING) != null) {
        encoding = msg.getProperty(SOAPMessage.CHARACTER_SET_ENCODING).toString();
    }
    return encoding;
}  

}

私のクラスでは、サービス オブジェクトを作成した後、次のコードを使用します。

com.gateway.ws.WebServiceCustomService service = new 
com.gateway.ws.WebServiceCustomService();
    service.setHandlerResolver(new HandlerResolver() {
                    @Override
                    public List<Handler> getHandlerChain(PortInfo portInfo) {
                        List<Handler> handlerChain = new ArrayList<Handler>();
                        Handler soapHandler = new CustomSOAPHandler();
                        handlerChain.add(soapHandler);
                        return handlerChain;
                    }
                });
com.gateway.ws.WebServicePort port = service.getWebServicePort();
            BindingProvider bindingProvider = (BindingProvider) port;
Binding binding = bindingProvider.getBinding();
            List handlerList = binding.getHandlerChain();
            System.out.println("LIST OF HANDLER " + handlerList.size());

前に言ったように、ログを確認したところ、プレフィックスが「S」に変更されたことはありませんでした

11:46:06,145 INFO  [STDOUT] LIST OF HANDLER 1
11:46:06,147 INFO  [STDOUT] SOAPHandler.handleMessage
11:46:06,148 INFO  [STDOUT] Configure SOAP Message prefix from [env] into [S]
11:46:06,149 INFO  [STDOUT] Outgoing message:
11:46:06,149 INFO  [STDOUT] --------------------
11:46:06,149 INFO  [STDOUT] DUMP OF SOAP MESSAGE
11:46:06,149 INFO  [STDOUT] --------------------
11:46:06,155 INFO  [STDOUT] <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><ns1:doService xmlns:ns1="http://ws.gateway.xl/"><request>content</request></ns1:doService></env:Body></env:Envelope>

どんなアドバイスもとても役に立ちます。ありがとうございました。

4

0 に答える 0