use of org.apache.cxf.message.MessageImpl in project camel by apache.
the class RawMessageWSDLGetInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
String method = (String) message.get(Message.HTTP_REQUEST_METHOD);
String query = (String) message.get(Message.QUERY_STRING);
if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
return;
}
String baseUri = (String) message.get(Message.REQUEST_URL);
String ctx = (String) message.get(Message.PATH_INFO);
Map<String, String> map = UrlUtils.parseQueryString(query);
if (isRecognizedQuery(map, baseUri, ctx, message.getExchange().getEndpoint().getEndpointInfo())) {
Document doc = getDocument(message, baseUri, map, ctx);
Endpoint e = message.getExchange().get(Endpoint.class);
Message mout = new MessageImpl();
mout.setExchange(message.getExchange());
mout = e.getBinding().createMessage(mout);
mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
message.getExchange().setOutMessage(mout);
mout.put(DOCUMENT_HOLDER, doc);
Iterator<Interceptor<? extends Message>> iterator = mout.getInterceptorChain().iterator();
while (iterator.hasNext()) {
Interceptor<? extends Message> inInterceptor = iterator.next();
if (inInterceptor instanceof AbstractPhaseInterceptor) {
AbstractPhaseInterceptor<?> interceptor = (AbstractPhaseInterceptor<?>) inInterceptor;
if (interceptor.getPhase().equals(Phase.PREPARE_SEND) || interceptor.getPhase().equals(Phase.PRE_STREAM)) {
// just make sure we keep the right interceptors
continue;
}
}
mout.getInterceptorChain().remove(inInterceptor);
}
// notice this is being added after the purge above, don't swap the order!
mout.getInterceptorChain().add(RawMessageWSDLGetOutInterceptor.INSTANCE);
// skip the service executor and goto the end of the chain.
message.getInterceptorChain().doInterceptStartingAt(message, OutgoingChainInterceptor.class.getName());
}
}
use of org.apache.cxf.message.MessageImpl in project camel by apache.
the class DefaultCxfBindingTest method testPayloadBodyNamespace.
@Test
public void testPayloadBodyNamespace() throws Exception {
MessageImpl message = new MessageImpl();
Map<String, String> nsMap = new HashMap<String, String>();
Document document = getDocument(SOAP_MESSAGE_1);
message.setContent(Node.class, document);
DefaultCxfBinding.getPayloadBodyElements(message, nsMap);
assertEquals(2, nsMap.size());
assertEquals("http://www.mycompany.com/test/", nsMap.get("xmlns"));
Element element = document.createElement("tag");
DefaultCxfBinding.addNamespace(element, nsMap);
assertEquals("http://www.mycompany.com/test/", element.getAttribute("xmlns"));
assertEquals("http://www.mycompany.com/test/1/", element.getAttribute("xmlns:ns1"));
}
use of org.apache.cxf.message.MessageImpl in project camel by apache.
the class DefaultCxfRsBindingTest method testCopyProtocolHeader.
@Test
public void testCopyProtocolHeader() {
DefaultCxfRsBinding cxfRsBinding = new DefaultCxfRsBinding();
cxfRsBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy());
Exchange exchange = new DefaultExchange(context);
Message camelMessage = new DefaultMessage();
org.apache.cxf.message.Message cxfMessage = new MessageImpl();
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("emptyList", Collections.EMPTY_LIST);
headers.put("zeroSizeList", new ArrayList<String>(0));
cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);
cxfRsBinding.copyProtocolHeader(cxfMessage, camelMessage, exchange);
assertNull("We should get nothing here", camelMessage.getHeader("emptyList"));
assertNull("We should get nothing here", camelMessage.getHeader("zeroSizeList"));
}
use of org.apache.cxf.message.MessageImpl in project ddf by codice.
the class PaosOutInterceptorTest method testHandleMessageNoAccept.
@Test
public void testHandleMessageNoAccept() {
Message message = new MessageImpl();
message.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
PaosOutInterceptor paosOutInterceptor = new PaosOutInterceptor(Phase.POST_LOGICAL);
paosOutInterceptor.handleMessage(message);
assertThat(((Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS)).get(HttpHeaders.ACCEPT), contains("application/vnd.paos+xml", "*/*"));
assertTrue(((Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS)).get("PAOS").contains("ver=\"urn:liberty:paos:2003-08\""));
assertTrue(((Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS)).get("PAOS").contains("\"urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp\",\"urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp:2.0:WantAuthnRequestsSigned\""));
}
use of org.apache.cxf.message.MessageImpl in project ddf by codice.
the class PaosInInterceptorTest method handleMessagePaosResponseBasicGood.
@Test
public void handleMessagePaosResponseBasicGood() throws IOException {
Message message = new MessageImpl();
message.setContent(InputStream.class, PaosInInterceptorTest.class.getClassLoader().getResource("ecprequest.xml").openStream());
message.put(Message.CONTENT_TYPE, "application/vnd.paos+xml");
Message outMessage = new MessageImpl();
HashMap<String, List> protocolHeaders = new HashMap<>();
outMessage.put(Message.PROTOCOL_HEADERS, protocolHeaders);
outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
protocolHeaders.put("Authorization", Collections.singletonList("BASIC dGVzdDp0ZXN0"));
ExchangeImpl exchange = new ExchangeImpl();
exchange.setOutMessage(outMessage);
message.setExchange(exchange);
PaosInInterceptor paosInInterceptor = new PaosInInterceptor(Phase.RECEIVE) {
HttpResponseWrapper getHttpResponse(String responseConsumerURL, String soapResponse, Message message) throws IOException {
HttpResponseWrapper httpResponseWrapper = new HttpResponseWrapper();
if (responseConsumerURL.equals("https://sp.example.org/PAOSConsumer")) {
httpResponseWrapper.statusCode = 200;
httpResponseWrapper.content = new ByteArrayInputStream("actual content".getBytes());
} else if (responseConsumerURL.equals("https://idp.example.org/saml2/sso")) {
httpResponseWrapper.statusCode = 200;
httpResponseWrapper.content = PaosInInterceptorTest.class.getClassLoader().getResource("idpresponse.xml").openStream();
}
return httpResponseWrapper;
}
};
paosInInterceptor.handleMessage(message);
assertThat(IOUtils.toString(message.getContent(InputStream.class)), is("actual content"));
}
Aggregations