use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class SOAPHandlerInterceptor method handleMessage.
public void handleMessage(SoapMessage message) {
if (binding.getHandlerChain().isEmpty()) {
return;
}
if (getInvoker(message).getProtocolHandlers().isEmpty()) {
return;
}
checkUnderstoodHeaders(message);
if (getInvoker(message).isOutbound()) {
if (!chainAlreadyContainsSAAJ(message)) {
SAAJ_OUT.handleMessage(message);
}
message.getInterceptorChain().add(ending);
} else {
boolean isFault = handleMessageInternal(message);
SOAPMessage msg = message.getContent(SOAPMessage.class);
if (msg != null) {
XMLStreamReader xmlReader = createXMLStreamReaderFromSOAPMessage(msg);
message.setContent(XMLStreamReader.class, xmlReader);
// replace headers
try {
SAAJInInterceptor.replaceHeaders(msg, message);
} catch (SOAPException e) {
e.printStackTrace();
}
}
if (isFault) {
Endpoint ep = message.getExchange().getEndpoint();
message.getInterceptorChain().abort();
if (ep.getInFaultObserver() != null) {
ep.getInFaultObserver().onMessage(message);
}
}
}
}
use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class SOAPHandlerInterceptor method createProtocolMessageContext.
@Override
protected MessageContext createProtocolMessageContext(SoapMessage message) {
SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message);
Exchange exch = message.getExchange();
setupBindingOperationInfo(exch, sm);
SOAPMessage msg = sm.getMessage();
if (msg != null) {
try {
List<SOAPElement> params = new ArrayList<>();
message.put(MessageContext.REFERENCE_PARAMETERS, params);
SOAPHeader head = SAAJUtils.getHeader(msg);
if (head != null) {
Iterator<Node> it = CastUtils.cast(head.getChildElements());
while (it != null && it.hasNext()) {
Node nd = it.next();
if (nd instanceof SOAPElement) {
SOAPElement el = (SOAPElement) nd;
if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter") && ("1".equals(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")) || Boolean.parseBoolean(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")))) {
params.add(el);
}
}
}
}
if (isRequestor(message) && msg.getSOAPPart().getEnvelope().getBody() != null && msg.getSOAPPart().getEnvelope().getBody().hasFault()) {
return null;
}
} catch (SOAPException e) {
throw new Fault(e);
}
}
return sm;
}
use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class SOAPHandlerInterceptor method getOpQName.
protected QName getOpQName(Exchange ex, Object data) {
SOAPMessageContextImpl sm = (SOAPMessageContextImpl) data;
try {
SOAPMessage msg = sm.getMessage();
if (msg == null) {
return null;
}
SOAPBody body = SAAJUtils.getBody(msg);
if (body == null) {
return null;
}
org.w3c.dom.Node nd = body.getFirstChild();
while (nd != null && !(nd instanceof org.w3c.dom.Element)) {
nd = nd.getNextSibling();
}
if (nd != null) {
return new QName(nd.getNamespaceURI(), nd.getLocalName());
}
} catch (SOAPException e) {
// ignore, nothing we can do
}
return null;
}
use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class GreeterDOMSourceMessageProvider method invoke.
public DOMSource invoke(DOMSource request) {
DOMSource response = new DOMSource();
try {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapReq = factory.createMessage();
soapReq.getSOAPPart().setContent(request);
System.out.println("Incoming Client Request as a DOMSource data in MESSAGE Mode");
soapReq.writeTo(System.out);
System.out.println("\n");
InputStream is = getClass().getResourceAsStream("/GreetMeDocLiteralResp2.xml");
SOAPMessage greetMeResponse = factory.createMessage(null, is);
is.close();
response.setNode(greetMeResponse.getSOAPPart());
} catch (Exception ex) {
ex.printStackTrace();
}
return response;
}
use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class GreeterSoapMessageProvider method invoke.
public SOAPMessage invoke(SOAPMessage request) {
SOAPMessage response = null;
try {
System.out.println("Incoming Client Request as a SOAPMessage");
MessageFactory factory = MessageFactory.newInstance();
InputStream is = getClass().getResourceAsStream("/GreetMeDocLiteralResp1.xml");
response = factory.createMessage(null, is);
is.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return response;
}
Aggregations