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

时间:2011-12-29 22:21:11

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

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

错误是:

  

由于异常而无法创建SOAP消息:XML reader错误:   com.ctc.wstx.exc.WstxUnexpectedCharException:意外字符'['   (代码91)prolog;预期'<'在[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;
} 

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

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