繁体   English   中英

JAX-WS出错由于异常而无法创建SOAP消息:XML reader错误:WstxUnexpectedCharException:意外字符'['

[英]Error with JAX-WS Couldn't create SOAP message due to exception: XML reader error: WstxUnexpectedCharException: Unexpected character '['

它显示以下错误,我不明白为什么,有人可以帮助我吗?

错误是:

由于异常而无法创建SOAP消息:XML reader error:com.ctc.wstx.exc.WstxUnexpectedCharException:prolog中的意外字符'['(代码91); 在[row,col {unknown-source}]预期'<':[1,1]

我打电话的功能是:

private static ContractTermsDownloadReply contractTermsDownloadOperation(
        ContractTermsDownloadRequest body) {
    ContractTermsDownload service = null;
    try {
        URI uri = new URI("https://companyname.com/ContractTermsDownload");
        service = new ContractTermsDownload(uri.toURL());
    } catch (Exception ex) {
        Logger.getLogger(JavaApplication1.class.getName()).log(
                Level.SEVERE, null, ex);
    }

    ariba.sourcing.vrealm_1461.ContractTermsDownloadPortType port = service
            .getContractTermsDownloadPortType();
    BindingProvider prov = (BindingProvider) port;
    prov.getRequestContext().put("authorization",
            "Basic User2011:Password2011");

    try {
        ContractTermsDownloadReply reply = port
                .contractTermsDownloadOperation(body);
        return reply;
    } catch (Exception exc) {
        System.out.println(exc.getMessage());
    }
    return null;
} 

如果您使用的是BasicAuth,则凭据通常为Base64编码。 请关注这一行,包括语法:

prov.getRequestContext().put("authorization", "Basic User2011:Password2011");

当我遇到这样的问题时,我需要看到发送到服务器的SOAP消息。 我运行tcpmon并设置我的客户端将请求发送到tcpmon。 你可以这样做检查客户端创建的SOAP消息吗?

最后我不得不使用CFX库并且工作正常,代码如下:

Client client = ClientProxy.getClient(contractTermsDownloadPortType);
client.getOutInterceptors().add(new AbstractOutDatabindingInterceptor(Phase.MARSHAL) {

        public void handleFault(Message message) {
        }

        public void handleMessage(Message message) throws Fault {
            MetadataMap<String, Object> headers = new MetadataMap<String, Object>();
            headers.putSingle("authorization", "Basic User:Password2012");
            message.put(Message.PROTOCOL_HEADERS, headers);
        }
    });

希望这会对某人有所帮助,因为这是一场噩梦。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM