Я пытаюсь вызвать SOAP Запрос с использованием вложения (Использование JAVA) и получение Обнаружен недопустимый символ как ошибка SOAP, но тот же запрос отлично работает из SOAP UI, Не уверен, в чем проблема, любая помощь приветствуется. Спасибо!
package com.myCompany.myRequests;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.*;
private static void createSoapEnvelope(SOAPMessage soapMessage) throws SOAPException, IOException {
//Update namespace and naming prefix for SOAP-ENV
String PREFERRED_PREFIX = "soapenv";
String SOAP_ENV_NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/";
SOAPPart soapPart = soapMessage.getSOAPPart();
// add wsdl namespaces
String ser = "ser";
String serURI = "http://serv.myRequests.myCompany.com";
String xsd = "xsd";
String xsdURI = "http://mod.myRequests.myCompany.com/xsd";
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration( ser,serURI);
envelope.addNamespaceDeclaration( xsd,xsdURI);
//Update namespace and naming prefix for SOAP-ENV
SOAPHeader header = soapMessage.getSOAPHeader();
SOAPBody body = soapMessage.getSOAPBody();
SOAPFault fault = body.getFault();
envelope.removeNamespaceDeclaration(envelope.getPrefix());
envelope.addNamespaceDeclaration(PREFERRED_PREFIX, SOAP_ENV_NAMESPACE);
envelope.setPrefix(PREFERRED_PREFIX);
header.setPrefix(PREFERRED_PREFIX);
body.setPrefix(PREFERRED_PREFIX);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("testRequests", ser);
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("request", ser);
SOAPElement soapBodyElem2 = soapBodyElem1.addChildElement("refExt", xsd);
soapBodyElem2.addTextNode("test10000019");
SOAPElement soapBodyElem3 = soapBodyElem1.addChildElement("refExtSys", xsd);
soapBodyElem3.addTextNode("MYEXTSYSTEM");
SOAPElement soapBodyElem4 = soapBodyElem1.addChildElement("xReqNumber", xsd);
soapBodyElem4.addTextNode("1288563");
SOAPElement soapBodyElem5 = soapBodyElem1.addChildElement("attachments", xsd);
SOAPElement soapBodyElem6 = soapBodyElem5.addChildElement("attachmentData", xsd);
SOAPElement soapBodyElem7 = soapBodyElem5.addChildElement("fileName", xsd);
soapBodyElem7.addTextNode("test.pdf");
//MIME
DataHandler dh = new DataHandler(new FileDataSource("C:/test.pdf"));
AttachmentPart attachment = soapMessage.createAttachmentPart(dh);
attachment.addMimeHeader("Content-ID", "123456");
attachment.setContentType("application/octet-stream");
soapBodyElem6.addTextNode("cid:" + attachment.getContentId());
soapMessage.addAttachmentPart(attachment);
}
private static void callSoapWebService(String soapEndpointUrl, String soapAction) {
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(soapAction), soapEndpointUrl);
// Print the SOAP Response
System.out.println("Response SOAP Message:");
soapResponse.writeTo(System.out);
System.out.println();
soapConnection.close();
} catch (Exception e) {
System.err.println("\nError occurred while sending SOAP Request to Server!\nMake sure you have the correct endpoint URL and SOAPAction!\n");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest(String soapAction) throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
createSoapEnvelope(soapMessage);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
soapMessage.saveChanges();
/* Print the request message, just for debugging purposes */
System.out.println("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println("\n");
return soapMessage;
}
Запрос SOAP Сообщение: ------ = _ Part_0_398715379.1583071650097 Тип содержимого: text / xml; charset = utf-8
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns: ser = "http://serv.myRequests.myCompany.com" xmlns: xsd = "http://mod.myRequests.myCompany.com/xsd"> test10000019MYEXTSYSTEM1288563cid: 123456test.pdf
------ = _Part_0_398715379.1583071650097 Тип содержимого: application / octet-stream Идентификатор содержимого: 123456 ContentID: 123456 Часть: 123456
------ = _ Part_0_398715379.1583071650097 -
Ответ SOAP Сообщение: ------ = _ Part_2_1162798614.1583071650310 Тип содержимого: application / xop + xml; кодировка = UTF-8; type = "text / xml" Content-Transfer-Encoding: двоичный Content-ID: <0. 45578b72c7453219f9258fc41d80c38ff29e46b4edc1cf0e@apache.org>
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>Invalid
встреченный символorg. apache .axis2.AxisFault: обнаружен недопустимый символ в орг. apache .axis2.AxisFault.makeFault (AxisFault. java: 430) в орг. apache .axis2.rp c .receivers.RPCMessageReceiver.invokeBusinessLogi c (RPCMessageReceiver. java: 220) в орг. apache .axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogi c (AbstractInOutMessageReceiver. java: 40) в орг. ) в орг. apache .axis2.engine.AxisEngine.receive (AxisEngine. java: 169) в орг. apache .axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest (HTTPTransportUtils. java: 178) org. apache .axis2.transport.http.AxisServlet.doPost (AxisServlet. java: 163) в javax.servlet.http.HttpServlet.service (HttpServlet. java: 660) в javax.servlet.http. HttpServlet.service (HttpServlet. java: 741) в орг. apache .catalina.core.App licationFilterChain.internalDoFilter (ApplicationFilterChain. java: 231) в орг. apache .catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain. java: 166) в орг. apache .tomcat.websocket. doFilter (WsFilter. java: 53) в орг. apache .catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain. java: 193) в орг. apache .catalina.core.ApplicationFilterChain .doil java: 166) в орг. apache .catalina.core.StandardWrapperValve.invoke (StandardWrapperValve. java: 199) в орг. apache .catalina.core.StandardContextValve.invoke (StandardContextValve. * 1066 96) в орг. apache .catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase. java: 611) в орг. apache .catalina.core.StandardHostValve.invoke (StandardHostValve. java: 137) в орг. . apache .catalina.valves.ErrorReportValve.invoke (ErrorReportValve. java: 92) в org. apache .catalina.valves.AbstractAccessLogValve.invoke (AbstractAccessLogValve. java: 651) в org. apache .catal ina.core.StandardEngineValve.invoke (StandardEngineValve. java: 87) в орг. apache .catalina.connector.CoyoteAdapter.service (CoyoteAdapter. java: 343) в орг. apache .coyote.http11. Http11Processor.service (Http11Processor. java: 407) в орг. apache .coyote.AbstractProcessorLight.process (AbstractProcessorLight. java: 66) в орг. apache .coyote.AbstractProtocol $ ConnectionHandler.process (AbstractProtocol. java: 754) в орг. apache .tomcat.util. net .NioEndpoint $ SocketProcessor.doRun (NioEndpoint. java: 1376) в орг. apache .tomcat.util. net. SocketProcessorBase.run (SocketProcessorBase. java: 49) в java .util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor. java: 1149) в java .util.concurrent.ThreadPoolExcecutor. Worker $ java 624) в орг. apache .tomcat.util.threads.TaskThread $ WrappingRunnable.run (TaskThread. java: 61) в java .lang.Thread.run (Thread. java: 748) Причина: java .lang.IllegalArgumentException: недопустимый символ, встречающийся в org. apache .axiom.util.base64.Base64Utils.decode (Base64Utils. java: 162) в org. apache .axis2.databinding.typemapping.SimpleTypeMapper. getDataHandler (SimpleTypeMapper. java: 204) в орг. apache .axis2.databinding.utils.BeanUtil.deserialize (BeanUtil. java: 611) в орг. apache .axis2.databinding.utils.BeanUtil. десериализовать (BeanUtil. java: 523) в орг. apache .axis2.databinding.utils.BeanUtil.deserialize (BeanUtil. java: 613) в орг. apache .axis2.databinding.utils.BeanUtil. processObject (BeanUtil. java: 1077) в орг. apache .axis2.databinding.utils.BeanUtil.processElement (BeanUtil. java: 956) в орг. apache .axis2.databinding.utils.BeanUtil. десериализовать (BeanUtil. java: 826) в орг. apache .axis2.rp c .receivers.RPCUtil.processRequest (RPCUtil. java: 197) в орг. apache .axis2.rp c .receivers.RPCUtil.invokeServiceClass (RPCUtil. java: 250) в орг. apache .axis2.rp c .receivers.RPCMessageReceiver.invokeBusinessLogi c (RPCMessageReceiver. java: 121) ... 29 больше
------ = _ Part_2_1162798614.1583071650310 -