用于 Microsoft WCF 服务的 Apache CXF 客户端,MTOM 返回 400

Apache CXF Client for Microsoft WCF service with MTOM returning 400

提问人:cloudwalker 提问时间:10/13/2017 更新时间:10/18/2017 访问量:893

问:

我有一个用于 Microsoft WCF 服务的 apache CXF 客户端,并且我正在尝试通过 MTOM 发送文件。但是,我不断收到 400,根据合作伙伴的说法,WCF 端的错误是创建 MTOM 读取器时出错

我已经跟踪了出站消息,它看起来像这样:

INFO: Outbound Message
---------------------------
ID: 1
Address: https://someserver.com/ImportService.svc?wsdl
Encoding: UTF-8
Http-Method: POST
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:1d46d7c9-047b-440d-928b-ab8689ab5e6f"; start="<[email protected]>"; start-info="application/soap+xml; action=\"http://tempuri.org/IImportService/UploadFile\""
Headers: {Accept=[*/*], Accept-Encoding=[gzip;q=1.0, identity; q=0.5, *;q=0], Content-Encoding=[gzip]}
Payload: --uuid:1d46d7c9-047b-440d-928b-ab8689ab5e6f
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml; action=\"http://tempuri.org/IImportService/UploadFile\""
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>

    <?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="true">
            <wsse:UsernameToken wsu:Id="UsernameToken-e51a6fdd-5053-4aae-a9fb-363dde7d9e77">
                <wsse:Username>[email protected]</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mypassword</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
        <ns2:letterOptions xmlns="http://schemas.datacontract.org/2004/07/PublicServices.Import" xmlns:ns2="http://tempuri.org/">
            <EnableQBPlanConsolidation>false</EnableQBPlanConsolidation>
            <MASKSSN>true</MASKSSN>
            <SRPrintedNumberofDays>2</SRPrintedNumberofDays>
            <SuppressAllLetters>false</SuppressAllLetters>
            <SuppressNewMemberLoginLetter>false</SuppressNewMemberLoginLetter>
            <SuppressTakeOverLetterForTermed>false</SuppressTakeOverLetterForTermed>
            <SuppressTerminationLetter>false</SuppressTerminationLetter>
        </ns2:letterOptions>
        <ns2:JobQueueType xmlns="http://schemas.datacontract.org/2004/07/PublicServices.Import" xmlns:ns2="http://tempuri.org/">Import</ns2:JobQueueType>
        <Filename xmlns="http://tempuri.org/">testImport.csv</Filename>
        <Action xmlns="http://www.w3.org/2005/08/addressing">http://tempuri.org/IImportService/UploadFile</Action>
        <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:f380e4cc-225f-4b7d-bd46-6b5d607a59ca</MessageID>
        <To xmlns="http://www.w3.org/2005/08/addressing">https://someserver.com/ImportService.svc?wsdl</To>
        <ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
            <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
        </ReplyTo>
    </soap:Header>
    <soap:Body>
        <FileUploadMessage xmlns="http://tempuri.org/" xmlns:ns2="http://schemas.datacontract.org/2004/07/PublicServices.Import" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/">
            <FileByteStream>
                <xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:[email protected]"/>
            </FileByteStream>
        </FileUploadMessage>
    </soap:Body>
</soap:Envelope>
--uuid:1d46d7c9-047b-440d-928b-ab8689ab5e6f
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <6[email protected]>

[VERSION],1.0
[NPM],552652222,1,Basic Client,Basic Client,Bob,Z,Jones,MR,[email protected],402444555,,1234 Some street,,Omaha,NE,68123,,M,T,F,F

--uuid:1d46d7c9-047b-440d-928b-ab8689ab5e6f--

我发现还有很多其他人也有同样问题的其他例子:https://coderanch.com/t/224995/java/Apache-CXF-MTOM-enabled-WCF

请求 WCF 服务协定时出现 HTTP 错误请求错误

http://mail-archives.apache.org/mod_mbox/cxf-users/201211.mbox/%3CCAPXL[email protected]%3E

这些都无法解决我的问题。我尝试了多个不同版本的 CXF,但所有这些版本都出现了相同的错误。

这是调用服务的代码的合并版本:

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setBindingId(SOAPBinding.SOAP12HTTP_MTOM_BINDING);
    proxyFactory.setServiceClass(IImportService.class);
    proxyFactory.setAddress(proxyEndpoint);
    proxyFactory.getFeatures().add(new WSAddressingFeature());

    IImportService importService = (IImportService) proxyFactory.create();

    Client client = (Client) importService;

    LetterOptions letterOptions = new LetterOptions();
    letterOptions.setSRPrintedNumberofDays(2);
    letterOptions.setMASKSSN(true);
    letterOptions.setEnableQBPlanConsolidation(false);

    List<Object> headerList = new ArrayList<>();

    headerList.add(new Header(new QName("http://tempuri.org/", "letterOptions"),
            letterOptions, new JAXBDataBinding(LetterOptions.class)));
    headerList.add(new Header(new QName("http://tempuri.org/", "JobQueueType"), JobQueueType.IMPORT, new JAXBDataBinding(JobQueueType.class)));
    headerList.add(new Header(new QName("http://tempuri.org/", "Filename"), "testImport.csv", new JAXBDataBinding(String.class)));

    client.getRequestContext().put(Header.HEADER_LIST, headerList);
    client.getEndpoint().getActiveFeatures().add(new LoggingFeature());

    client.getInInterceptors().add(new GZIPInInterceptor());
    client.getInInterceptors().add(new LogResponseInterceptor());

    GZIPOutInterceptor outInterceptor = new GZIPOutInterceptor();
    outInterceptor.setForce(true);
    client.getOutInterceptors().add(outInterceptor);

    Map props = new HashMap();
    props.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    props.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    props.put(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordCallbackHandler.class.getName());
    props.put(WSHandlerConstants.USER, "[email protected]");
    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(props);
    client.getOutInterceptors().add(wssOut);

    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy policy = conduit.getClient();
    if(policy == null) {
        policy = new HTTPClientPolicy();
    }
    policy.setAllowChunking(false);

    FileUploadMessageReponse response = importService.uploadFile(fileUploadMessage);

一个有趣的花絮是,我可以复制登录到 SoapUI 中的相同请求,并且它工作正常。

Java Web 服务 WCF CXF

评论


答: 暂无答案