use of com.oracle.webservices.api.message.MessageContext in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageTest method testMtomAttachmentCid.
public void testMtomAttachmentCid() throws Exception {
String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
Packet packet = (Packet) m1;
Message riMsg = packet.getInternalMessage();
// This will cause all the attachments to be created ...
// Iterator<Attachment> as = packet.getInternalMessage().getAttachments().iterator();
// SAAJFactory:
SOAPVersion soapVersion = packet.getMessage().getSOAPVersion();
SOAPMessage saajMsg = soapVersion.getMessageFactory().createMessage();
SaajStaxWriterEx writer = new SaajStaxWriterEx(saajMsg, soapVersion.nsUri);
try {
riMsg.writeTo(writer);
} catch (XMLStreamException e) {
throw (e.getCause() instanceof SOAPException) ? (SOAPException) e.getCause() : new SOAPException(e);
}
saajMsg = writer.getSOAPMessage();
int counter = 0;
String hredCid = null;
for (Attachment a : riMsg.getAttachments()) {
hredCid = ((StreamingDataHandler) a.asDataHandler()).getHrefCid();
counter++;
}
assertTrue(writer.ma.size() == counter);
AttachmentPart ap = null;
// for (Iterator<AttachmentPart> itr = saajMsg.getAttachments(); itr.hasNext(); ) {
// System.out.println("\r\n itr.next().getContentId() " + itr.next().getContentId() );
// }
StreamingDataHandler sdh = (StreamingDataHandler) writer.ma.get(0);
assertEquals(hredCid, sdh.getHrefCid());
}
use of com.oracle.webservices.api.message.MessageContext in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageTest method testMtomAttachment.
public void testMtomAttachment() throws Exception {
String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
Packet packet = (Packet) m1;
Message message = packet.getInternalMessage();
Iterator<Attachment> as = packet.getInternalMessage().getAttachments().iterator();
Attachment att = null;
int counter = 0;
String cid1 = null;
while (as.hasNext()) {
att = as.next();
cid1 = att.getContentId();
counter++;
}
assertTrue(counter == 1);
// SAAJFactory:
SOAPVersion soapVersion = packet.getMessage().getSOAPVersion();
SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
SaajStaxWriterEx writer = new SaajStaxWriterEx(msg, soapVersion.nsUri);
try {
message.writeTo(writer);
} catch (XMLStreamException e) {
throw (e.getCause() instanceof SOAPException) ? (SOAPException) e.getCause() : new SOAPException(e);
}
msg = writer.getSOAPMessage();
counter = 0;
String cid2 = null;
for (Attachment a : message.getAttachments()) {
counter++;
cid2 = a.getContentId();
}
assertTrue(writer.ma.size() == counter);
StreamingDataHandler sdh = (StreamingDataHandler) writer.ma.get(0);
assertEquals(cid1, sdh.getHrefCid());
assertEquals(cid2, sdh.getHrefCid());
}
use of com.oracle.webservices.api.message.MessageContext in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageWrapperTest method testMTOM_riSaaj.
public void testMTOM_riSaaj() throws Exception {
// client creates request
MessageContext clientRequest = databinding.serializeRequest(clientCall);
// client writes request to OutputStream
ByteArrayOutputStream clientOut = new ByteArrayOutputStream();
ContentType cliCt = clientRequest.writeTo(clientOut);
// com.sun.xml.ws.api.pipe.ContentType cliCt = ((com.sun.xml.ws.api.databinding.Databinding)databinding).
// encode((Packet)clientRequest, clientOut);
// System.out.println("==== Client Request " + cliCt.getContentType() + " " + cliCt.getSOAPActionHeader() );
// System.out.println(new String(clientOut.toByteArray()) + "\r\n\r\n");
// client sends request to server
ByteArrayInputStream serverIn = new ByteArrayInputStream(clientOut.toByteArray());
// server decodes request to Packet
MessageContext serverRequest = mcf.createContext(serverIn, cliCt.getContentType());
// deprecated way to create/decode MC/Packet from inputStream
// com.sun.xml.ws.api.message.Packet serverRequest = new com.sun.xml.ws.api.message.Packet();
// ((com.sun.xml.ws.api.databinding.Databinding)databinding).decode(serverIn, cliCt.getContentType(), serverRequest);
// setup JRF env ...
// ContainerResolver.setInstance(new JRFContainerResolver());
// server coverts request to saaj SOAPMessage
SOAPMessage saajReq1 = serverRequest.getAsSOAPMessage();
assertEquals("wrong attachment count", 1, saajReq1.countAttachments());
// System.out.println("==== serverRequest.getSOAPMessage() 1 " + saajReq1);
// Write the SOAPMessage multiple times result in different message boundary -
// {
// saajReq1 = serverRequest.getSOAPMessage();
// System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + saajReq1);
// ByteArrayOutputStream saajReq1Out = new ByteArrayOutputStream();
// saajReq1.writeTo(saajReq1Out);
// System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + new String(saajReq1Out.toByteArray()));
// }
// {
// saajReq1 = serverRequest.getSOAPMessage();
// System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + saajReq1);
// ByteArrayOutputStream saajReq1Out = new ByteArrayOutputStream();
// saajReq1.writeTo(saajReq1Out);
// System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + new String(saajReq1Out.toByteArray()));
// }
// {
// saajReq1 = serverRequest.getSOAPMessage();
// System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + saajReq1);
// ByteArrayOutputStream saajReq1Out = new ByteArrayOutputStream();
// saajReq1.writeTo(saajReq1Out);
// System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + new String(saajReq1Out.toByteArray()));
// }
// !! NPE if the following line of serverRequest.setMessage(...) is removed
// ((Packet)serverRequest).setMessage(new com.sun.xml.ws.message.saaj.SAAJMessage(saajReq1));
SOAPMessage saajReq2 = ((Packet) serverRequest).getMessage().readAsSOAPMessage();
SOAPMessage saajReq3 = serverRequest.getAsSOAPMessage();
SOAPMessage saajReq4 = ((Packet) serverRequest).getMessage().readAsSOAPMessage();
// System.out.println("==== serverRequest.getSOAPMessage() 2 " + saajReq2);
assertTrue(saajReq1 == saajReq2);
assertTrue(saajReq3 == saajReq2);
assertTrue(saajReq4 == saajReq3);
// !! Do we need orassaj-XMLStreamReaderEx if the databinding can descerialize orasaaj SOAPMessagae as inline?
JavaCallInfo serverCall = databinding.deserializeRequest(serverRequest);
serverCall.setReturnValue(serverCall.getParameters()[0]);
// server creates response
MessageContext serverResponse = databinding.serializeResponse(serverCall);
// server coverts response to saaj SOAPMessage
SOAPMessage saajRes1 = serverResponse.getAsSOAPMessage();
// System.out.println("==== serverResponse.getSOAPMessage() 1 " + saajRes1);
// !! server coverts response to saaj SOAPMessage again but get another new saaj SOAPMessage
SOAPMessage saajRes2 = ((Packet) serverResponse).getMessage().readAsSOAPMessage();
SOAPMessage saajRes3 = serverResponse.getAsSOAPMessage();
SOAPMessage saajRes4 = ((Packet) serverResponse).getMessage().readAsSOAPMessage();
// System.out.println("==== serverResponse.getSOAPMessage() 2 " + saajRes2);
assertTrue(saajRes1 == saajRes2);
// !! Following line keeps the same saaj message but removes mtom effect on response
// ((Packet)serverResponse).setMessage(new com.sun.xml.ws.message.saaj.SAAJMessage(saajRes1));
SOAPMessage saajRes5 = serverResponse.getAsSOAPMessage();
assertTrue(saajRes3 == saajRes2);
assertTrue(saajRes3 == saajRes4);
assertTrue(saajRes4 == saajRes5);
// System.out.println("==== serverResponse.getSOAPMessage() 3 " + saajRes3);
// {
// ByteArrayOutputStream serverOut = new ByteArrayOutputStream();
// //TODO serverResponse.writeTo(serverOut);
// com.sun.xml.ws.api.pipe.ContentType resCt = ((com.sun.xml.ws.api.databinding.Databinding)databinding).
// encode((com.sun.xml.ws.api.message.Packet)serverResponse, serverOut);
// System.out.println("==== Server Response 1 " + resCt.getContentType() + " " + resCt.getSOAPActionHeader() );
// System.out.println(new String(serverOut.toByteArray()) + "\r\n\r\n");
// }
// {
// ByteArrayOutputStream serverOut = new ByteArrayOutputStream();
// //TODO serverResponse.writeTo(serverOut);
// com.sun.xml.ws.api.pipe.ContentType resCt = ((com.sun.xml.ws.api.databinding.Databinding)databinding).
// encode((com.sun.xml.ws.api.message.Packet)serverResponse, serverOut);
// System.out.println("==== Server Response 2 " + resCt.getContentType() + " " + resCt.getSOAPActionHeader() );
// System.out.println(new String(serverOut.toByteArray()) + "\r\n\r\n");
// }
ByteArrayOutputStream serverOut = new ByteArrayOutputStream();
ContentType resCt = serverResponse.writeTo(serverOut);
// com.sun.xml.ws.api.pipe.ContentType resCt = ((com.sun.xml.ws.api.databinding.Databinding)databinding).
// encode((com.sun.xml.ws.api.message.Packet)serverResponse, serverOut);
// System.out.println("==== Server Response x " + resCt.getContentType() + " " + resCt.getSOAPActionHeader() );
// System.out.println(new String(serverOut.toByteArray()) + "\r\n\r\n");
// server sends response to client
ByteArrayInputStream clientIn = new ByteArrayInputStream(serverOut.toByteArray());
MessageContext clientResponse = mcf.createContext(clientIn, resCt.getContentType());
// com.sun.xml.ws.api.message.Packet clientResponse = new com.sun.xml.ws.api.message.Packet();
// ((com.sun.xml.ws.api.databinding.Databinding)databinding).decode(clientIn, resCt.getContentType(), clientResponse);
clientCall = databinding.deserializeResponse(clientResponse, clientCall);
String res = new String((byte[]) clientCall.getReturnValue());
// System.out.println("response " + res);
assertEquals(res, reqStr);
}
use of com.oracle.webservices.api.message.MessageContext in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageTest method testWriteMtomToStreamClientRequest.
public void testWriteMtomToStreamClientRequest() throws Exception {
// DISI may set the packet.state to State.ClientRequest
// ((Packet)mc).setState(State.ClientRequest)
InputStream is = null;
ByteArrayOutputStream baos = null;
ByteArrayInputStream bais = null;
try {
String ctype = "multipart/related; boundary=MIME_Boundary; " + "start=\"<ff2b0fb4-9bcf-4ff5-ba16-d3436c78c3fd>\"; " + "type=\"application/xop+xml\"; start-info=\"text/xml\"";
MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
is = getClass().getClassLoader().getResourceAsStream("etc/testMtomMessage_osb_disi.msg");
MessageContext mc = mcf.createContext(is, ctype);
Packet packet = (Packet) mc;
Message message = packet.getInternalMessage();
assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
baos = new ByteArrayOutputStream();
((Packet) mc).setState(State.ClientRequest);
mc.writeTo(baos);
bais = new ByteArrayInputStream(baos.toByteArray());
MessageFactory mf = MessageFactory.newInstance();
MimeHeaders mh = new MimeHeaders();
mh.addHeader("Content-Type", ctype);
SOAPMessage sm = mf.createMessage(mh, bais);
assertEquals("wrong attachment count", 1, sm.countAttachments());
AttachmentPart ap = (AttachmentPart) sm.getAttachments().next();
assertEquals("wrong attachemnt Content-Id", "<testAttachmentContentId>", ap.getContentId());
NodeList nl = sm.getSOAPBody().getElementsByTagNameNS(MtomCodec.XOP_NAMESPACEURI, MtomCodec.XOP_LOCALNAME);
assertEquals(MtomCodec.XOP_NAMESPACEURI + ":" + MtomCodec.XOP_LOCALNAME + " not found", 1, nl.getLength());
Element elt = (Element) nl.item(0);
assertEquals("wrong href value", "cid:testAttachmentContentId", elt.getAttribute("href"));
} finally {
Exception e = null;
try {
if (is != null)
is.close();
} catch (IOException e1) {
e = e1;
}
try {
if (baos != null)
baos.close();
} catch (IOException e2) {
e = e2;
}
try {
if (bais != null)
bais.close();
} catch (Exception e3) {
e = e3;
}
if (e != null)
throw e;
}
}
use of com.oracle.webservices.api.message.MessageContext in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageTest method testWriteMtomToStream.
public void testWriteMtomToStream() throws Exception {
// Ensure writing StreamMessage to OutputputStream preserves CID and
// does not create duplicate attachment. We check this by re-parsing
// as a SOAP message and verifying the contents.
InputStream is = null;
ByteArrayOutputStream baos = null;
ByteArrayInputStream bais = null;
try {
String ctype = "multipart/related;type=\"application/xop+xml\";" + "boundary=\"----=_Part_0_1145105632.1353005695468\";" + "start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
is = getClass().getClassLoader().getResourceAsStream("etc/testMtomMessageReload_01.msg");
MessageContext mc = mcf.createContext(is, ctype);
Packet packet = (Packet) mc;
Message message = packet.getInternalMessage();
assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
baos = new ByteArrayOutputStream();
mc.writeTo(baos);
bais = new ByteArrayInputStream(baos.toByteArray());
MessageFactory mf = MessageFactory.newInstance();
MimeHeaders mh = new MimeHeaders();
mh.addHeader("Content-Type", ctype);
SOAPMessage sm = mf.createMessage(mh, bais);
assertEquals("wrong attachment count", 1, sm.countAttachments());
AttachmentPart ap = (AttachmentPart) sm.getAttachments().next();
assertEquals("wrong attachemnt Content-Id", "<534475ae-bdab-4594-9f97-c09908bacfbd>", ap.getContentId());
NodeList nl = sm.getSOAPBody().getElementsByTagNameNS(MtomCodec.XOP_NAMESPACEURI, MtomCodec.XOP_LOCALNAME);
assertEquals(MtomCodec.XOP_NAMESPACEURI + ":" + MtomCodec.XOP_LOCALNAME + " not found", 1, nl.getLength());
Element elt = (Element) nl.item(0);
assertEquals("wrong href value", "cid:534475ae-bdab-4594-9f97-c09908bacfbd", elt.getAttribute("href"));
} finally {
Exception e = null;
try {
if (is != null)
is.close();
} catch (IOException e1) {
e = e1;
}
try {
if (baos != null)
baos.close();
} catch (IOException e2) {
e = e2;
}
try {
if (bais != null)
bais.close();
} catch (Exception e3) {
e = e3;
}
if (e != null)
throw e;
}
}
Aggregations