通过Java中的HttpAsyncClient发送SOAP消息对象

时间:2016-04-27 16:27:56

标签: java asynchronous soap nio apache-httpclient-4.x

我在Java中有一个SOAP Message对象attachments。现在我使用TransformerFactory将消息的SOAPPart转换为String并使用{{1}发送它post方法。到这里它工作正常。 但是当我尝试通过转换为String并附加到String writer来发送SOAPMessage中的附件时,我得到了一个异常。

附件是我要作为附件发送的文件。

以下是我的代码片段

HttpAsyncClient

我得到的例外

        final SOAPMessage message;
        final StringWriter sw = new StringWriter();

        try {
            TransformerFactory.newInstance().newTransformer().transform(new DOMSource(message.getSOAPPart()),
                    new StreamResult(sw));
            sw.append("\n");
            TransformerFactory.newInstance().newTransformer().transform(new StreamSource(attachment), new StreamResult(sw));
        } catch (TransformerException e) {
            throw new RuntimeException(e);
        }

        HttpPost post = new HttpPost(url.toString());
        HttpEntity entity = new StringEntity(sw.toString(), HTTP.UTF_8);

        post.addHeader("Content-Type", "text/xml; charset=utf-8");
        post.setConfig(params);
        post.setEntity(entity);
        client.execute(post, new AsyncResponseHandler<>(subscribedUsers, campaignId, path, isOnline,
                CommunicationConstants.EMAIL));

我的请求字符串是 我在第67行中遇到异常,其中另一个xml块正在启动,因为它们将它们作为单独的xml进行处理。

<< "<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server.userException</faultcode><faultstring>org.xml.sax.SAXParseException; lineNumber: 67; columnNumber: 6; The processing instruction target matching &quot;[xX][mM][lL]&quot; is not allowed.</faultstring><detail><ns1:stackTrace xmlns:ns1="http://xml.apache.org/axis/">org.xml.sax.SAXParseException; lineNumber: 67; columnNumber: 6; The processing instruction target matching &quot;[xX][mM][lL]&quot; is not allowed.[\n]"
21:34:48.614 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)[\n]"
21:34:48.614 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)[\n]"
21:34:48.614 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[\n]"
21:34:48.614 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[\n]"
21:34:48.614 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[\n]"
21:34:48.614 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)[\n]"
21:34:48.614 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLScanner.scanPIData(Unknown Source)[\n]"
21:34:48.614 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanPIData(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLScanner.scanPI(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)[\n]"
21:34:48.615 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x9]at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)[\n]"

0 个答案:

没有答案