use of jakarta.xml.soap.MimeHeaders in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testRealSoapHeader.
@Test
public void testRealSoapHeader() throws Exception {
String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Header>" + "<auth>" + "<username>user</username>" + "<password>pass</password>" + "</auth>" + "<bar>BAR</bar>" + "<baz>BAZ</baz>" + "<qux>qux</qux>" + "</soapenv:Header>" + "<soapenv:Body>" + "<foo>foo</foo>" + "</soapenv:Body>" + "</soapenv:Envelope>";
SOAPMessage message = MessageFactory.newInstance().createMessage(new MimeHeaders(), new ByteArrayInputStream(soap.getBytes("UTF-8")));
SoapMessage soapMessage = new SaajSoapMessage(message);
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
String authHeader = "auth";
mapper.setRequestHeaderNames(authHeader, "ba*");
Map<String, Object> headers = mapper.toHeadersFromRequest(soapMessage);
assertThat(headers.get(authHeader)).isNotNull();
assertThat(headers.get(authHeader)).isInstanceOf(SoapHeaderElement.class);
SoapHeaderElement header = (SoapHeaderElement) headers.get(authHeader);
DOMSource source = (DOMSource) header.getSource();
NodeList nodeList = source.getNode().getChildNodes();
assertThat(nodeList.item(0).getNodeName()).isEqualTo("username");
assertThat(nodeList.item(0).getFirstChild().getNodeValue()).isEqualTo("user");
assertThat(nodeList.item(1).getNodeName()).isEqualTo("password");
assertThat(nodeList.item(1).getFirstChild().getNodeValue()).isEqualTo("pass");
header = (SoapHeaderElement) headers.get("bar");
assertThat(header).isNotNull();
source = (DOMSource) header.getSource();
nodeList = source.getNode().getChildNodes();
assertThat(nodeList.item(0).getNodeValue()).isEqualTo("BAR");
header = (SoapHeaderElement) headers.get("baz");
assertThat(header).isNotNull();
source = (DOMSource) header.getSource();
nodeList = source.getNode().getChildNodes();
assertThat(nodeList.item(0).getNodeValue()).isEqualTo("BAZ");
assertThat(headers.get("qux")).isNull();
}
use of jakarta.xml.soap.MimeHeaders in project openmq by eclipse-ee4j.
the class UMSServlet method getHeaders.
/**
* Returns a <code>MimeHeaders</code> object that contains the headers in the given <code>HttpServletRequest</code>
* object.
*
* @param req the <code>HttpServletRequest</code> object that a messaging provider sent to the servlet
* @return a new <code>MimeHeaders</code> object containing the headers in the message sent to the servlet
*/
protected static MimeHeaders getHeaders(HttpServletRequest req) {
Enumeration enum2 = req.getHeaderNames();
MimeHeaders headers = new MimeHeaders();
while (enum2.hasMoreElements()) {
String headerName = (String) enum2.nextElement();
String headerValue = req.getHeader(headerName);
StringTokenizer values = new StringTokenizer(headerValue, ",");
while (values.hasMoreTokens()) {
headers.addHeader(headerName, values.nextToken().trim());
}
}
return headers;
}
use of jakarta.xml.soap.MimeHeaders in project openmq by eclipse-ee4j.
the class UMSServlet method doXmlMessaging.
/**
* Http request services. HTTP requests are transformed into SOAP messages and dispated to the appropriate services.
*/
public void doXmlMessaging(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
SOAPMessage msg = null;
try {
// Get all the headers from the HTTP request.
MimeHeaders headers = getHeaders(req);
// Get the body of the HTTP request.
InputStream is = req.getInputStream();
// Now internalize the contents of a HTTP request and
// create a SOAPMessage
msg = mfactory.createMessage(headers, is);
SOAPMessage reply = null;
/**
* Dispatch message to mq soap service.
*/
reply = onMessage(msg);
if (reply != null) {
if (reply.saveRequired()) {
reply.saveChanges();
}
if (isSOAPFault(reply)) {
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} else {
resp.setStatus(HttpServletResponse.SC_OK);
}
// remove content-length header field
reply.getMimeHeaders().removeHeader(CONTENT_LENGTH);
putHeaders(reply.getMimeHeaders(), resp);
String[] sa = reply.getMimeHeaders().getHeader(CONTENT_TYPE);
if (sa == null || sa.length == 0) {
// XXX:
// int acount = reply.countAttachments();
resp.setHeader(CONTENT_TYPE, TEXT_XML);
}
// Write out the message on the response stream.
OutputStream os = resp.getOutputStream();
reply.writeTo(os);
os.flush();
} else {
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
} catch (Throwable ex) {
/**
* Log exception.
*/
logger.log(Level.WARNING, ex.getMessage(), ex);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.
the class StreamMessageTest method testWriteSwaToStreamClientRequest.
// Bug 17367334
public void testWriteSwaToStreamClientRequest() throws Exception {
String ctype = "multipart/related; boundary=MIME_Boundary; " + "start=\"<6232425701115978772--54bee05.140acdf4f8a.-7f3f>\"; " + "type=\"text/xml\"; start-info=\"text/xml\"";
MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
InputStream is = getClass().getClassLoader().getResourceAsStream("etc/bug17367334InputMsg.txt");
Packet packet = (Packet) mcf.createContext(is, ctype);
Message message = packet.getInternalMessage();
assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
packet.setState(State.ClientRequest);
// System.out.println("SWA packet.getContentType(): " + packet.getContentType().getContentType() );
ContentType contentType = packet.writeTo(baos);
// System.out.println("etc/bug17367334InputMsg.txt\r\n" + contentType.getContentType() + "\r\n" + new String(baos.toByteArray()));
ByteArrayInputStream 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);
}
use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.
the class Client method testUsingJaxwsMsg.
public void testUsingJaxwsMsg() throws IOException, SOAPException {
TestServiceService service = new TestServiceService();
Dispatch<SOAPMessage> disp = service.createDispatch(new QName("http://server.jaxws195.fromjava/", "TestServicePort"), SOAPMessage.class, Service.Mode.MESSAGE);
MimeHeaders mhs = new MimeHeaders();
mhs.addHeader("Content-Type", "text/xml");
SOAPMessage msg = SOAPVersion.SOAP_11.saajMessageFactory.createMessage(mhs, new ByteArrayInputStream(jaxwsMsg.getBytes()));
disp.invoke(msg);
}
Aggregations