use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class SOAPHandlerInterceptorTest method testChangeSOAPBodyOutBound.
// SAAJ tree is created from DOMXMLStreamWriter. Any changes to SOAPMessage should be streamed back to
// outputStream
@Test
public void testChangeSOAPBodyOutBound() throws Exception {
@SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
list.add(new SOAPHandler<SOAPMessageContext>() {
public boolean handleMessage(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
try {
smc.setMessage(prepareSOAPMessage("resources/greetMeRpcLitRespChanged.xml"));
} catch (Exception e) {
throw new Fault(e);
}
}
return true;
}
public boolean handleFault(SOAPMessageContext smc) {
return true;
}
public Set<QName> getHeaders() {
return null;
}
public void close(MessageContext messageContext) {
}
});
HandlerChainInvoker invoker = new HandlerChainInvoker(list);
IMocksControl control = createNiceControl();
Binding binding = control.createMock(Binding.class);
expect(binding.getHandlerChain()).andReturn(list).anyTimes();
Exchange exchange = control.createMock(Exchange.class);
expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
SoapMessage message = new SoapMessage(new MessageImpl());
message.setExchange(exchange);
// This is to set direction to outbound
expect(exchange.getOutMessage()).andReturn(message).anyTimes();
CachedStream originalEmptyOs = new CachedStream();
XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(originalEmptyOs);
message.setContent(XMLStreamWriter.class, writer);
InterceptorChain chain = new PhaseInterceptorChain((new PhaseManagerImpl()).getOutPhases());
// Interceptors after SOAPHandlerInterceptor DOMXMLStreamWriter to write
chain.add(new AbstractProtocolHandlerInterceptor<SoapMessage>(binding, Phase.MARSHAL) {
public void handleMessage(SoapMessage message) throws Fault {
try {
XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
SoapVersion soapVersion = Soap11.getInstance();
writer.setPrefix("soap", soapVersion.getNamespace());
writer.writeStartElement("soap", soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace());
writer.writeNamespace("soap", soapVersion.getNamespace());
writer.writeEndElement();
writer.flush();
} catch (Exception e) {
// do nothing
}
}
});
chain.add(new SOAPHandlerInterceptor(binding));
message.setInterceptorChain(chain);
control.replay();
chain.doIntercept(message);
control.verify();
writer.flush();
// Verify SOAPMessage
SOAPMessage resultedMessage = message.getContent(SOAPMessage.class);
assertNotNull(resultedMessage);
SOAPBody bodyNew = resultedMessage.getSOAPBody();
Iterator<?> itNew = bodyNew.getChildElements(new QName("http://apache.org/hello_world_rpclit", "sendReceiveDataResponse"));
SOAPBodyElement bodyElementNew = (SOAPBodyElement) itNew.next();
Iterator<?> outIt = bodyElementNew.getChildElements(new QName("http://apache.org/hello_world_rpclit/types", "out"));
Element outElement = (SOAPElement) outIt.next();
assertNotNull(outElement);
Element elem3Element = DOMUtils.findAllElementsByTagNameNS(outElement, "http://apache.org/hello_world_rpclit/types", "elem3").get(0);
assertEquals("100", elem3Element.getTextContent());
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class RMEndpoint method buildBindingInfo.
void buildBindingInfo(ServiceInfo si, ProtocolVariation protocol) {
// explicitly
if (null != applicationEndpoint) {
final QName bindingQName = new QName(protocol.getWSRMNamespace(), BINDING_NAME);
SoapBindingInfo sbi = (SoapBindingInfo) applicationEndpoint.getEndpointInfo().getBinding();
SoapVersion sv = sbi.getSoapVersion();
String bindingId = sbi.getBindingId();
SoapBindingInfo bi = new SoapBindingInfo(si, bindingId, sv);
bi.setName(bindingQName);
BindingOperationInfo boi = null;
RMConstants consts = protocol.getConstants();
boi = bi.buildOperation(consts.getCreateSequenceOperationName(), consts.getCreateSequenceOperationName().getLocalPart(), null);
addAction(boi, consts.getCreateSequenceAction(), consts.getCreateSequenceResponseAction());
bi.addOperation(boi);
boi = bi.buildOperation(consts.getTerminateSequenceOperationName(), consts.getTerminateSequenceOperationName().getLocalPart(), null);
if (RM11Constants.NAMESPACE_URI.equals(protocol.getWSRMNamespace())) {
addAction(boi, consts.getTerminateSequenceAction(), RM11Constants.INSTANCE.getTerminateSequenceResponseAction());
} else {
addAction(boi, consts.getTerminateSequenceAction());
}
bi.addOperation(boi);
boi = bi.buildOperation(consts.getTerminateSequenceAnonymousOperationName(), null, consts.getTerminateSequenceAnonymousOperationName().getLocalPart());
addAction(boi, consts.getTerminateSequenceAction());
bi.addOperation(boi);
boi = bi.buildOperation(consts.getSequenceAckOperationName(), null, null);
addAction(boi, consts.getSequenceAckAction());
bi.addOperation(boi);
boi = bi.buildOperation(consts.getCloseSequenceOperationName(), null, null);
if (RM11Constants.NAMESPACE_URI.equals(protocol.getWSRMNamespace())) {
addAction(boi, consts.getCloseSequenceAction(), RM11Constants.INSTANCE.getCloseSequenceResponseAction());
} else {
addAction(boi, consts.getCloseSequenceAction());
}
bi.addOperation(boi);
boi = bi.buildOperation(consts.getAckRequestedOperationName(), null, null);
addAction(boi, consts.getAckRequestedAction());
bi.addOperation(boi);
boi = bi.buildOperation(consts.getCreateSequenceOnewayOperationName(), consts.getCreateSequenceOnewayOperationName().getLocalPart(), null);
addAction(boi, consts.getCreateSequenceAction());
bi.addOperation(boi);
boi = bi.buildOperation(consts.getCreateSequenceResponseOnewayOperationName(), consts.getCreateSequenceResponseOnewayOperationName().getLocalPart(), null);
addAction(boi, consts.getCreateSequenceResponseAction());
bi.addOperation(boi);
si.addBinding(bi);
}
// TODO: BindingFaultInfo (SequenceFault)
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class MAPCodecTest method setUpMessage.
private SoapMessage setUpMessage(boolean requestor, boolean outbound, boolean invalidMAP, boolean preExistingSOAPAction, Boolean generateRelatesTo, String exposeAs) throws Exception {
SoapMessage message = new SoapMessage(new MessageImpl());
setUpOutbound(message, outbound);
expectRelatesTo = generateRelatesTo != null ? generateRelatesTo : (requestor && !outbound) || (!requestor && outbound);
message.put(REQUESTOR_ROLE, Boolean.valueOf(requestor));
String mapProperty = getMAPProperty(requestor, outbound);
AddressingProperties maps = getMAPs(requestor, outbound, exposeAs);
final Element header = control.createMock(Element.class);
codec.setHeaderFactory(new MAPCodec.HeaderFactory() {
public Element getHeader(SoapVersion version) {
return header;
}
});
List<Header> headers = message.getHeaders();
JAXBContext jaxbContext = control.createMock(JAXBContext.class);
ContextUtils.setJAXBContext(jaxbContext);
Names200408.setJAXBContext(jaxbContext);
Names200403.setJAXBContext(jaxbContext);
if (outbound) {
setUpEncode(requestor, message, header, maps, mapProperty, invalidMAP, preExistingSOAPAction);
} else {
setUpDecode(message, headers, maps, mapProperty, requestor);
}
control.replay();
return message;
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class RetransmissionQueueImpl method readHeaders.
private void readHeaders(XMLStreamReader xmlReader, SoapMessage message) throws XMLStreamException {
// read header portion of SOAP document into DOM
SoapVersion version = message.getVersion();
XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, version.getBody());
Node nd = message.getContent(Node.class);
W3CDOMStreamWriter writer = message.get(W3CDOMStreamWriter.class);
Document doc = null;
if (writer != null) {
StaxUtils.copy(filteredReader, writer);
doc = writer.getDocument();
} else if (nd instanceof Document) {
doc = (Document) nd;
StaxUtils.readDocElements(doc, doc, filteredReader, false, false);
} else {
doc = StaxUtils.read(filteredReader);
message.setContent(Node.class, doc);
}
// get the actual SOAP header
Element element = doc.getDocumentElement();
QName header = version.getHeader();
List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(element, header.getNamespaceURI(), header.getLocalPart());
for (Element elem : elemList) {
// set all child elements as headers for message transmission
Element hel = DOMUtils.getFirstElement(elem);
while (hel != null) {
SoapHeader sheader = new SoapHeader(DOMUtils.getElementQName(hel), hel);
message.getHeaders().add(sheader);
hel = DOMUtils.getNextElement(hel);
}
}
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class HeaderVerifier method addPartialResponseHeader.
private void addPartialResponseHeader(SoapMessage message) {
try {
// add piggybacked wsa:From header to partial response
List<Header> header = message.getHeaders();
Document doc = DOMUtils.getEmptyDocument();
SoapVersion ver = message.getVersion();
Element hdr = doc.createElementNS(ver.getHeader().getNamespaceURI(), ver.getHeader().getLocalPart());
hdr.setPrefix(ver.getHeader().getPrefix());
marshallFrom("urn:piggyback_responder", hdr, getMarshaller());
Element elem = DOMUtils.getFirstElement(hdr);
while (elem != null) {
Header holder = new Header(new QName(elem.getNamespaceURI(), elem.getLocalName()), elem, null);
header.add(holder);
elem = DOMUtils.getNextElement(elem);
}
} catch (Exception e) {
verificationCache.put("SOAP header addition failed: " + e);
e.printStackTrace();
}
}
Aggregations