use of javax.xml.soap.SOAPMessage in project camel by apache.
the class TesterBean method processSOAP.
public SOAPMessage processSOAP(Exchange exchange) {
// Since the Camel-CXF endpoint uses a list to store the parameters
// and bean component uses the bodyAs expression to get the value
// we'll need to deal with the parameters ourself
SOAPMessage soapMessage = (SOAPMessage) exchange.getIn().getBody(List.class).get(0);
if (soapMessage == null) {
System.out.println("Incoming null message detected...");
return createDefaultSoapMessage("Greetings from Apache Camel!!!!", "null");
}
try {
SOAPPart sp = soapMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
String requestText = sb.getFirstChild().getTextContent();
System.out.println(requestText);
return createDefaultSoapMessage("Greetings from Apache Camel!!!!", requestText);
} catch (Exception e) {
e.printStackTrace();
return createDefaultSoapMessage("Greetings from Apache Camel!!!!", e.getClass().getName());
}
}
use of javax.xml.soap.SOAPMessage in project camel by apache.
the class TesterBean method createDefaultSoapMessage.
public static SOAPMessage createDefaultSoapMessage(String responseMessage, String requestMessage) {
try {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1");
SOAPBodyElement payload = body.addBodyElement(payloadName);
SOAPElement message = payload.addChildElement("responseType");
message.addTextNode(responseMessage + " Request was " + requestMessage);
return soapMessage;
} catch (SOAPException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of javax.xml.soap.SOAPMessage in project camel by apache.
the class CXFMessageProcessor method process.
public void process(Exchange exchange) throws Exception {
// just print out the request message
Message in = exchange.getIn();
String request = in.getBody(String.class);
// just make sure the request is greetme
assertTrue("It should be GreetMe request.", request.indexOf("<greetMe") > 0);
InputStream is = new ByteArrayInputStream(RESPONSE.getBytes());
SOAPMessage message = MessageFactory.newInstance().createMessage(null, is);
exchange.getOut().setBody(message);
}
use of javax.xml.soap.SOAPMessage in project camel by apache.
the class SpringWebserviceConsumer method populateExchangeWithBreadcrumbFromMessageContext.
private void populateExchangeWithBreadcrumbFromMessageContext(MessageContext messageContext, Exchange exchange) {
SaajSoapMessage saajSoap = (SaajSoapMessage) messageContext.getRequest();
SOAPMessage soapMessageRequest = null;
if (saajSoap != null) {
soapMessageRequest = saajSoap.getSaajMessage();
if (soapMessageRequest != null) {
MimeHeaders mimeHeaders = soapMessageRequest.getMimeHeaders();
if (mimeHeaders != null) {
String[] breadcrumbIdHeaderValues = mimeHeaders.getHeader(Exchange.BREADCRUMB_ID);
// may be required to implement
if (breadcrumbIdHeaderValues != null && breadcrumbIdHeaderValues.length >= 1) {
exchange.getIn().setHeader(Exchange.BREADCRUMB_ID, breadcrumbIdHeaderValues[0]);
}
}
}
}
}
use of javax.xml.soap.SOAPMessage in project midpoint by Evolveum.
the class WsFaultListener method faultOccurred.
@Override
public boolean faultOccurred(Exception exception, String description, Message message) {
LOGGER.trace("Handling fault: {}: {} - {}", new Object[] { exception, description, message, exception });
Object audited = message.getContextualProperty(SecurityHelper.CONTEXTUAL_PROPERTY_AUDITED_NAME);
if (audited != null && ((Boolean) audited)) {
return true;
}
if (exception instanceof PasswordCallbackException) {
return true;
}
if (exception.getCause() instanceof PasswordCallbackException) {
return true;
}
if (exception.getCause() != null && exception.getCause().getCause() instanceof PasswordCallbackException) {
return true;
}
try {
String auditMessage = exception.getMessage();
if (exception.getClass() != null) {
// Exception cause has much better message because CXF masks real messages in the SOAP faults.
auditMessage = exception.getCause().getMessage();
}
SOAPMessage saajSoapMessage = message.getContent(SOAPMessage.class);
String username = securityHelper.getUsernameFromMessage(saajSoapMessage);
ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
securityHelper.auditLoginFailure(username, null, connEnv, auditMessage);
} catch (WSSecurityException e) {
// Ignore
LOGGER.trace("Exception getting username from soap message (probably safe to ignore)", e);
} catch (Exception e) {
LOGGER.error("Error auditing SOAP fault: " + e.getMessage(), e);
// but otherwise ignore it
}
return true;
}
Aggregations