SoapUI可以发送soap请求,java xml不能

时间:2017-03-28 10:39:01

标签: java soap

我有一个项目,我必须向端点发出soap请求。使用SOAPUI,请求进行得很顺利,我收到了响应,但是当我使用Java时,收到以下错误:

com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post SEVERE: SAAJ0010: Unable to read response
java.lang.NullPointerException

任何人都知道为什么会这样吗?以下是调用发生的部分:

InputStream is = new ByteArrayInputStream(message.getBytes("UTF-8"));
                MessageFactory factory = MessageFactory.newInstance();
                SOAPMessage soapMsg = factory.createMessage(null, is);
                SOAPConnectionFactory connFactory = SOAPConnectionFactory.newInstance();
                SOAPConnection conn = connFactory.createConnection();
                URL endpoint = new URL(Main.SOAP_END_POINT_TESTING);
                System.out.println(endpoint);

                SOAPMessage response = conn.call(soapMsg, endpoint); //right here is where the error is thrown

连接是通过纯HTTP

1 个答案:

答案 0 :(得分:0)

试试这个:

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();

SOAPEnvelope envelope = soapPart.getEnvelope();

您必须在此处创建正文,然后保存更改。

soapMessage.saveChanges();

打印请求消息

ByteArrayOutputStream outRequest = new ByteArrayOutputStream();
soapMessage.writeTo(outRequest);
String request=outRequest.toString();

SOAPMessage soapResponse = soapConnection.call(soapMessage,url);