use of javax.xml.soap.SOAPPart in project jbossws-cxf by jbossws.
the class JBossWSClientAuthConfig method getAuthContextID.
@SuppressWarnings("rawtypes")
public String getAuthContextID(MessageInfo messageInfo) {
SOAPMessage request = (SOAPMessage) messageInfo.getRequestMessage();
if (request == null) {
return null;
}
String authContext = null;
MimeHeaders headers = request.getMimeHeaders();
if (headers != null) {
String[] soapActions = headers.getHeader("SOAPAction");
if (soapActions != null && soapActions.length > 0) {
authContext = soapActions[0];
if (!StringUtils.isEmpty(authContext)) {
return authContext;
}
}
}
SOAPPart soapMessage = request.getSOAPPart();
if (soapMessage != null) {
try {
SOAPEnvelope envelope = soapMessage.getEnvelope();
if (envelope != null) {
SOAPBody body = envelope.getBody();
if (body != null) {
Iterator it = body.getChildElements();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof SOAPElement) {
QName name = ((SOAPElement) o).getElementQName();
return name.getLocalPart();
}
}
}
}
} catch (SOAPException se) {
// ignore;
Logger.getLogger(JBossWSClientAuthConfig.class).trace(se);
}
}
return null;
}
use of javax.xml.soap.SOAPPart in project jbossws-cxf by jbossws.
the class JBossWSServerAuthConfig method getAuthContextID.
@SuppressWarnings("rawtypes")
public String getAuthContextID(MessageInfo messageInfo) {
SOAPMessage request = (SOAPMessage) messageInfo.getRequestMessage();
if (request == null) {
return null;
}
String authContext = null;
MimeHeaders headers = request.getMimeHeaders();
if (headers != null) {
String[] soapActions = headers.getHeader("SOAPAction");
if (soapActions != null && soapActions.length > 0) {
authContext = soapActions[0];
if (!StringUtils.isEmpty(authContext)) {
return authContext;
}
}
}
SOAPPart soapMessage = request.getSOAPPart();
if (soapMessage != null) {
try {
SOAPEnvelope envelope = soapMessage.getEnvelope();
if (envelope != null) {
SOAPBody body = envelope.getBody();
if (body != null) {
Iterator it = body.getChildElements();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof SOAPElement) {
QName name = ((SOAPElement) o).getElementQName();
return name.getLocalPart();
}
}
}
}
} catch (SOAPException se) {
// ignore;
Logger.getLogger(JBossWSServerAuthConfig.class).trace(se);
}
}
return null;
}
use of javax.xml.soap.SOAPPart in project jbossws-cxf by jbossws.
the class TestHandler method checkEnvelope.
private void checkEnvelope(SOAPMessage soapMessage) throws SOAPException {
SOAPPart part = soapMessage.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
String namespace = envelope.getNamespaceURI();
if (envelopeNamespace.equals(namespace) == false) {
throw new RuntimeException("Expected '" + envelopeNamespace + "' namespace, actual '" + namespace + "'");
}
}
use of javax.xml.soap.SOAPPart in project jbossws-cxf by jbossws.
the class ProviderMessageTestCase method testProviderMessageNullResponse.
@Test
@RunAsClient
public void testProviderMessageNullResponse() throws Exception {
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgStringForNullResponse.getBytes()));
URL epURL = baseURL;
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage resMsg = con.call(reqMsg, epURL);
if (resMsg != null) {
SOAPPart soapPart = resMsg.getSOAPPart();
// verify there's either nothing in the reply or at least the response body is empty
if (soapPart != null && soapPart.getEnvelope() != null && soapPart.getEnvelope().getBody() != null) {
SOAPBody soapBody = soapPart.getEnvelope().getBody();
assertFalse(soapBody.getChildElements().hasNext());
}
}
}
use of javax.xml.soap.SOAPPart in project iaf by ibissource.
the class SOAPProviderBase method invoke.
@Override
public SOAPMessage invoke(SOAPMessage request) {
String result;
try (PipeLineSession pipelineSession = new PipeLineSession()) {
String correlationId = Misc.createSimpleUUID();
log.debug(getLogPrefix(correlationId) + "received message");
String soapProtocol = SOAPConstants.SOAP_1_1_PROTOCOL;
if (request == null) {
String faultcode = "soap:Server";
String faultstring = "SOAPMessage is null";
String httpRequestMethod = (String) webServiceContext.getMessageContext().get(MessageContext.HTTP_REQUEST_METHOD);
if (!"POST".equals(httpRequestMethod)) {
faultcode = "soap:Client";
faultstring = "Request was send using '" + httpRequestMethod + "' instead of 'POST'";
}
result = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body><soap:Fault>" + "<faultcode>" + faultcode + "</faultcode>" + "<faultstring>" + faultstring + "</faultstring>" + "</soap:Fault></soap:Body></soap:Envelope>";
} else {
// Make mime headers in request available as session key
@SuppressWarnings("unchecked") Iterator<MimeHeader> mimeHeaders = request.getMimeHeaders().getAllHeaders();
String mimeHeadersXml = getMimeHeadersXml(mimeHeaders).toXML();
pipelineSession.put("mimeHeaders", mimeHeadersXml);
// Make attachments in request (when present) available as session keys
int i = 1;
XmlBuilder attachments = new XmlBuilder("attachments");
@SuppressWarnings("unchecked") Iterator<AttachmentPart> attachmentParts = request.getAttachments();
while (attachmentParts.hasNext()) {
try {
AttachmentPart attachmentPart = attachmentParts.next();
XmlBuilder attachment = new XmlBuilder("attachment");
attachments.addSubElement(attachment);
XmlBuilder sessionKey = new XmlBuilder("sessionKey");
sessionKey.setValue("attachment" + i);
attachment.addSubElement(sessionKey);
Message rawContent = new Message(attachmentPart.getRawContentBytes());
pipelineSession.put("attachment" + i, rawContent);
log.debug(getLogPrefix(correlationId) + "adding attachment [attachment" + i + "] to session");
@SuppressWarnings("unchecked") Iterator<MimeHeader> attachmentMimeHeaders = attachmentPart.getAllMimeHeaders();
attachment.addSubElement(getMimeHeadersXml(attachmentMimeHeaders));
} catch (SOAPException e) {
log.warn("Could not store attachment in session key", e);
}
i++;
}
pipelineSession.put("attachments", attachments.toXML());
// Transform SOAP message to string
String message;
try {
SOAPPart part = request.getSOAPPart();
try {
if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(part.getEnvelope().getNamespaceURI()))
soapProtocol = SOAPConstants.SOAP_1_2_PROTOCOL;
} catch (SOAPException e) {
log.error("unable to determine SOAP URI NS type, falling back to SOAP 1.1", e);
}
message = XmlUtils.nodeToString(part);
log.debug(getLogPrefix(correlationId) + "transforming from SOAP message");
} catch (TransformerException e) {
String m = "Could not transform SOAP message to string";
log.error(m, e);
throw new WebServiceException(m, e);
}
pipelineSession.put("soapProtocol", soapProtocol);
if (soapProtocol.equals(SOAPConstants.SOAP_1_1_PROTOCOL)) {
String soapAction = (String) webServiceContext.getMessageContext().get(SoapBindingConstants.SOAP_ACTION);
pipelineSession.put(SoapBindingConstants.SOAP_ACTION, soapAction);
} else if (soapProtocol.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
String contentType = (String) webServiceContext.getMessageContext().get("Content-Type");
if (StringUtils.isNotEmpty(contentType) && contentType.contains("action=")) {
String action = findAction(contentType);
if (StringUtils.isNotEmpty(action)) {
pipelineSession.put(SoapBindingConstants.SOAP_ACTION, action);
} else {
log.warn(getLogPrefix(correlationId) + "no SOAPAction found!");
}
}
}
// Process message via WebServiceListener
ISecurityHandler securityHandler = new WebServiceContextSecurityHandler(webServiceContext);
pipelineSession.setSecurityHandler(securityHandler);
pipelineSession.put(PipeLineSession.HTTP_REQUEST_KEY, webServiceContext.getMessageContext().get(MessageContext.SERVLET_REQUEST));
pipelineSession.put(PipeLineSession.HTTP_RESPONSE_KEY, webServiceContext.getMessageContext().get(MessageContext.SERVLET_RESPONSE));
try {
log.debug(getLogPrefix(correlationId) + "processing message");
result = processRequest(correlationId, new Message(message), pipelineSession).asString();
} catch (ListenerException | IOException e) {
String m = "Could not process SOAP message: " + e.getMessage();
log.error(m);
throw new WebServiceException(m, e);
}
}
// Transform result string to SOAP message
SOAPMessage soapMessage = null;
try {
log.debug(getLogPrefix(correlationId) + "transforming to SOAP message");
soapMessage = getMessageFactory(soapProtocol).createMessage();
StreamSource streamSource = new StreamSource(new StringReader(result));
soapMessage.getSOAPPart().setContent(streamSource);
} catch (SOAPException e) {
String m = "Could not transform string to SOAP message";
log.error(m);
throw new WebServiceException(m, e);
}
try {
String multipartXml = pipelineSession.getMessage(attachmentXmlSessionKey).asString();
log.debug(getLogPrefix(correlationId) + "building multipart message with MultipartXmlSessionKey [" + multipartXml + "]");
if (StringUtils.isNotEmpty(multipartXml)) {
Element partsElement;
try {
partsElement = XmlUtils.buildElement(multipartXml);
} catch (DomBuilderException e) {
String m = "error building multipart xml";
log.error(m, e);
throw new WebServiceException(m, e);
}
Collection<Node> parts = XmlUtils.getChildTags(partsElement, "part");
if (parts == null || parts.size() == 0) {
log.warn(getLogPrefix(correlationId) + "no part(s) in multipart xml [" + multipartXml + "]");
} else {
Iterator<Node> iter = parts.iterator();
while (iter.hasNext()) {
Element partElement = (Element) iter.next();
// String partType = partElement.getAttribute("type");
String partName = partElement.getAttribute("name");
String partSessionKey = partElement.getAttribute("sessionKey");
String partMimeType = partElement.getAttribute("mimeType");
Message partObject = pipelineSession.getMessage(partSessionKey);
DataHandler dataHander;
try {
if (partObject.isBinary()) {
dataHander = new DataHandler(new ByteArrayDataSource(partObject.asByteArray(), partMimeType));
} else {
dataHander = new DataHandler(new ByteArrayDataSource(partObject.asString(), partMimeType));
}
} catch (IOException e) {
String m = "Unable to add session key '" + partSessionKey + "' as attachment";
log.error(m, e);
throw new WebServiceException(m, e);
}
AttachmentPart attachmentPart = soapMessage.createAttachmentPart(dataHander);
attachmentPart.setContentId(partName);
soapMessage.addAttachmentPart(attachmentPart);
log.debug(getLogPrefix(correlationId) + "appended filepart [" + partSessionKey + "] name [" + partName + "]");
}
}
}
} catch (IOException e) {
String m = "Could not transform attachment";
log.error(m);
throw new WebServiceException(m, e);
}
return soapMessage;
}
}
Aggregations