use of com.sun.xml.ws.message.stream.StreamMessage in project metro-jax-ws by eclipse-ee4j.
the class SAAJFactoryTest method testNullNamespacePrefix.
/**
* Test whether SAAJFactory.readAsSOAPMessage can handle null namespace prefixes if the
* appropriate flag is set on Woodstox
*/
public void testNullNamespacePrefix() throws Exception {
XMLInputFactory infact = XMLInputFactory.newFactory();
try {
// for Woodstox, set property that ensures it will return null prefixes for default namespace
infact.setProperty("com.ctc.wstx.returnNullForDefaultNamespace", Boolean.TRUE);
} catch (Throwable t) {
// is unreliable
return;
}
String soap = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body>" + "<sendMessage xmlns=\"http://www.foo.bar/schema/\" xmlns:ns2=\"http://www.foo.bar/types/\">;" + " <message xsi:type=\"ns2:someType\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "</message>" + "</sendMessage></soap:Body></soap:Envelope>";
XMLStreamReader envelope = infact.createXMLStreamReader(new StringReader(soap));
StreamMessage smsg = new StreamMessage(SOAPVersion.SOAP_11, envelope, null);
SAAJFactory saajFac = new SAAJFactory();
try {
// Previously this line failed with NPE - should be fixed now.
SOAPMessage msg = saajFac.readAsSOAPMessage(SOAPVersion.SOAP_11, smsg);
} catch (NullPointerException npe) {
fail("NPE for null namespace prefix is not fixed!");
npe.printStackTrace();
}
}
use of com.sun.xml.ws.message.stream.StreamMessage in project metro-jax-ws by eclipse-ee4j.
the class SAAJFactoryTest method testResetDefaultNamespaceToGlobalWithWoodstax.
/**
* Test whether SAAJFactory.readAsSOAPMessage can handle default namespace reset correctly.
*
* <p>
* This test emulates JDK-8159058 issue. The issue is that the default namespace reset was not respected
* with built-in JDK XML input factory (it worked well with woodstax).
* </p>
*
* <p>
* This test operates against woodstax.
* </p>
*/
public void testResetDefaultNamespaceToGlobalWithWoodstax() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newFactory();
XMLStreamReader envelope = inputFactory.createXMLStreamReader(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<s:Body>" + "<SampleServiceRequest xmlns=\"http://sample.ex.org/\">" + "<RequestParams xmlns=\"\">" + "<Param1>hogehoge</Param1>" + "<Param2>fugafuga</Param2>" + "</RequestParams>" + "</SampleServiceRequest>" + "</s:Body>" + "</s:Envelope>"));
StreamMessage streamMessage = new StreamMessage(SOAPVersion.SOAP_11, envelope, null);
SAAJFactory saajFac = new SAAJFactory();
SOAPMessage soapMessage = saajFac.readAsSOAPMessage(SOAPVersion.SOAP_11, streamMessage);
// check object model
SOAPElement request = (SOAPElement) soapMessage.getSOAPBody().getFirstChild();
assertEquals("SampleServiceRequest", request.getLocalName());
assertEquals("http://sample.ex.org/", request.getNamespaceURI());
SOAPElement params = (SOAPElement) request.getFirstChild();
assertEquals("RequestParams", params.getLocalName());
assertNull(params.getNamespaceURI());
SOAPElement param1 = (SOAPElement) params.getFirstChild();
assertEquals("Param1", param1.getLocalName());
assertNull(param1.getNamespaceURI());
Element param2 = (Element) params.getChildNodes().item(1);
assertEquals("Param2", param2.getLocalName());
assertNull(param2.getNamespaceURI());
// check the message as string
assertEquals("<SampleServiceRequest xmlns=\"http://sample.ex.org/\">" + "<RequestParams xmlns=\"\">" + "<Param1>hogehoge</Param1>" + "<Param2>fugafuga</Param2>" + "</RequestParams>" + "</SampleServiceRequest>", nodeToText(request));
}
use of com.sun.xml.ws.message.stream.StreamMessage in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageCopyTest method createSOAP11StreamMessage.
private StreamMessage createSOAP11StreamMessage(String msg) throws IOException {
Codec codec = Codecs.createSOAPEnvelopeXmlCodec(SOAPVersion.SOAP_11);
Packet packet = new Packet();
ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes("utf-8"));
codec.decode(in, "text/xml", packet);
return (StreamMessage) packet.getMessage();
}
use of com.sun.xml.ws.message.stream.StreamMessage in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageCopyTest method testMessageForestCopy.
private void testMessageForestCopy(int i) throws Exception {
String soapMsgStart = "<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'><S:Body>";
String soapMsgEnd = "</S:Body></S:Envelope>";
StringBuilder sb = new StringBuilder(soapMsgStart);
while (i-- > 0) {
sb.append("<a/>");
}
sb.append(soapMsgEnd);
StreamMessage msg = createSOAP11StreamMessage(sb.toString());
Message msg1 = msg.copy();
msg1.copy();
}
use of com.sun.xml.ws.message.stream.StreamMessage in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageCopyTest method testMessageCopy.
private void testMessageCopy(int i) throws Exception {
String str = getMessage(i);
StreamMessage msg = createSOAP11StreamMessage(str);
Message msg1 = msg.copy();
Message msg2 = msg.copy();
Message msg3 = msg1.copy();
Message msg4 = msg2.copy();
compareXmlStrings(str, writeMsgEnvelope(msg));
compareXmlStrings(str, writeMsgEnvelope(msg1));
compareXmlStrings(str, writeMsgEnvelope(msg2));
compareXmlStrings(str, writeMsgEnvelope(msg3));
compareXmlStrings(str, writeMsgEnvelope(msg4));
}
Aggregations