【问题标题】:Error with JAX-WS Couldn't create SOAP message due to exception: XML reader error: WstxUnexpectedCharException: Unexpected character '['由于异常,JAX-WS 出错无法创建 SOAP 消息:XML 阅读器错误:WstxUnexpectedCharException:意外字符“[”
【发布时间】:2012-01-30 05:52:01
【问题描述】:

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

错误是:

由于异常,无法创建 SOAP 消息:XML 阅读器错误: com.ctc.wstx.exc.WstxUnexpectedCharException:意外字符“[” (代码 91)在序言中; [row,col {unknown-source}] 处的预期“

我正在调用的函数是:

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;
} 

【问题讨论】:

    标签: java web-services jax-ws webservice-client


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        最后我不得不使用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);
                }
            });
        

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-08-15
          • 2015-11-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-06-15
          • 1970-01-01
          • 2013-02-27
          相关资源
          最近更新 更多