use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class XMLMessage method getDataSource.
public static DataSource getDataSource(Message msg, WSFeatureList f) {
if (msg == null)
return null;
if (msg instanceof MessageDataSource) {
return ((MessageDataSource) msg).getDataSource();
} else {
AttachmentSet atts = msg.getAttachments();
if (atts != null && !atts.isEmpty()) {
final ByteArrayBuffer bos = new ByteArrayBuffer();
try {
Codec codec = new XMLHTTPBindingCodec(f);
Packet packet = new Packet(msg);
com.sun.xml.ws.api.pipe.ContentType ct = codec.getStaticContentType(packet);
codec.encode(packet, bos);
return createDataSource(ct.getContentType(), bos.newInputStream());
} catch (IOException ioe) {
throw new WebServiceException(ioe);
}
} else {
final ByteArrayBuffer bos = new ByteArrayBuffer();
XMLStreamWriter writer = XMLStreamWriterFactory.create(bos);
try {
msg.writePayloadTo(writer);
writer.flush();
} catch (XMLStreamException e) {
throw new WebServiceException(e);
}
return XMLMessage.createDataSource("text/xml", bos.newInputStream());
}
}
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class ReferenceParametersTest method testFaultToReferenceParametersStreamMessage1.
/**
* See if the ReferenceParamaters get added proeprly from FaultToEPR to fault response
* @throws Exception
*/
public void testFaultToReferenceParametersStreamMessage1() throws Exception {
String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:user=\"http://foo.bar\" " + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "<S:Header>" + "<wsa:Action>http://example.org/action/echoIn</wsa:Action>" + "<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "<wsa:MessageID>urn:uuid:1234567890</wsa:MessageID>" + "<wsa:FaultTo>" + "<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>" + "<wsa:ReferenceParameters>" + "<user:foo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user:bar xmlns:user=\"http://foo.bar\">" + "<user:foobar>barfoo</user:foobar>" + "</user:bar>" + "</wsa:ReferenceParameters>" + "</wsa:FaultTo>" + "</S:Header>" + "<S:Body><DataType xmlns=\"http://foo.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
Message message = useStreamCodec(requestStr);
WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.W3C, SOAPVersion.SOAP_11);
String responseStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body><S:Fault>" + "<faultcode>echo:EmptyEchoString</faultcode>" + "<faultstring>The echo string was empty.</faultstring>" + "</S:Fault></S:Body></S:Envelope>";
Message m2 = useStreamCodec(responseStr);
wsepr.addReferenceParametersToList(m2.getHeaders());
ByteArrayBuffer baos = new ByteArrayBuffer();
XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
m2.writeTo(writer);
writer.flush();
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
Message sm = Messages.create(reader);
Packet sm_packet = new Packet(sm);
List<Element> refParams = sm_packet.getReferenceParameters();
assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
for (Element e : refParams) {
assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
assertEquals("NS Decl did not match", "http://foo.bar", e.getNamespaceURI());
}
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class GlobalNsDeclTest method testNsDecl.
public void testNsDecl() throws Exception {
String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" " + "xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:user=\"http://foo.bar\">" + "<S:Header>" + "<user:foo>bar</user:foo>" + "</S:Header>" + "<S:Body>" + "<addNumbers xmlns=\"http://example.com/\">" + "<number1>10</number1>" + "<number2>10</number2>" + "</addNumbers>" + "</S:Body></S:Envelope>";
Message message = useStreamCodec(requestStr);
MessageHeaders hl = message.getHeaders();
ByteArrayBuffer baos = new ByteArrayBuffer();
XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
writer.writeStartDocument();
for (Header h : hl.asList()) {
h.writeTo(writer);
}
writer.writeEndDocument();
writer.flush();
// baos.writeTo(System.out);
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
// go to start element
reader.next();
Header h = Headers.create(SOAPVersion.SOAP_11, reader);
assertEquals(h.getNamespaceURI(), "http://foo.bar");
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class ReferenceParametersTest method testFaultToReferenceParametersStreamMessage1.
/**
* See if the ReferenceParamaters get added proeprly from FaultToEPR to fault response
* @throws Exception
*/
public void testFaultToReferenceParametersStreamMessage1() throws Exception {
String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:user=\"http://foo.bar\" " + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "<S:Header>" + "<wsa:Action>http://example.org/action/echoIn</wsa:Action>" + "<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "<wsa:MessageID>urn:uuid:1234567890</wsa:MessageID>" + "<wsa:FaultTo>" + "<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>" + "<wsa:ReferenceParameters>" + "<user:foo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user:bar xmlns:user=\"http://foo.bar\">" + "<user:foobar>barfoo</user:foobar>" + "</user:bar>" + "</wsa:ReferenceParameters>" + "</wsa:FaultTo>" + "</S:Header>" + "<S:Body><DataType xmlns=\"http://foo.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
Message message = useStreamCodec(requestStr);
WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.W3C, SOAPVersion.SOAP_11);
String responseStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body><S:Fault>" + "<faultcode>echo:EmptyEchoString</faultcode>" + "<faultstring>The echo string was empty.</faultstring>" + "</S:Fault></S:Body></S:Envelope>";
Message m2 = useStreamCodec(responseStr);
wsepr.addReferenceParametersToList(m2.getHeaders());
ByteArrayBuffer baos = new ByteArrayBuffer();
XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
m2.writeTo(writer);
writer.flush();
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
Message sm = Messages.create(reader);
Packet sm_packet = new Packet(sm);
List<Element> refParams = sm_packet.getReferenceParameters();
assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
for (Element e : refParams) {
assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
assertEquals("NS Decl did not match", "http://foo.bar", e.getNamespaceURI());
}
}
use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.
the class ReferenceParametersTest method testFaultToReferenceParametersJAXBMessage1.
public void testFaultToReferenceParametersJAXBMessage1() throws Exception {
String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:user=\"http://foo.bar\" " + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "<S:Header>" + "<wsa:Action>http://example.org/action/echoIn</wsa:Action>" + "<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "<wsa:MessageID>urn:uuid:1234567890</wsa:MessageID>" + "<wsa:FaultTo>" + "<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>" + "<wsa:ReferenceParameters>" + "<user:foo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user:bar xmlns:user=\"http://foo.bar\">" + "<user:foobar>barfoo</user:foobar>" + "</user:bar>" + "</wsa:ReferenceParameters>" + "</wsa:FaultTo>" + "</S:Header>" + "<S:Body><DataType xmlns=\"http://foo.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
Message message = useStreamCodec(requestStr);
WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.W3C, SOAPVersion.SOAP_11);
Message m2 = Messages.create("Test Unsupported", AddressingVersion.W3C, SOAPVersion.SOAP_11);
wsepr.addReferenceParametersToList(m2.getHeaders());
ByteArrayBuffer baos = new ByteArrayBuffer();
XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
m2.writeTo(writer);
writer.flush();
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
Message sm = Messages.create(reader);
Packet sm_packet = new Packet(sm);
List<Element> refParams = sm_packet.getReferenceParameters();
assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
for (Element e : refParams) {
assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
assertEquals("NS Decl did not match", "http://foo.bar", e.getNamespaceURI());
}
}
Aggregations