use of org.apache.cxf.message.MessageImpl in project tomee by apache.
the class OneWayProcessorInterceptor method createMessage.
private static Message createMessage(Exchange exchange) {
Endpoint ep = exchange.getEndpoint();
Message msg = null;
if (ep != null) {
msg = new MessageImpl();
msg.setExchange(exchange);
msg = ep.getBinding().createMessage(msg);
}
return msg;
}
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());
final String testHeaderKey = "X-Test-Header";
final String correctHeaderToBeForwarded = "correct header that needs to be forwarded";
final String listOfIntsHeaderKey = "X-Test-IntList-Header";
final List<Object> listOfIntsHeader = ImmutableList.of(1, 2, 3);
message.put(Message.CONTENT_TYPE, "application/vnd.paos+xml");
HashMap<String, List<String>> messageHeaders = new HashMap<>();
messageHeaders.put(testHeaderKey, ImmutableList.of("original, incorrect header value"));
message.put(Message.PROTOCOL_HEADERS, messageHeaders);
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, new SamlSecurity()) {
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());
httpResponseWrapper.headers = ImmutableMap.of(testHeaderKey, (Object) ImmutableList.of(correctHeaderToBeForwarded), listOfIntsHeaderKey, listOfIntsHeader).entrySet();
} 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"));
Map<String, List<String>> headers = (Map) message.get(Message.PROTOCOL_HEADERS);
assertThat(headers.get(testHeaderKey), hasItem(correctHeaderToBeForwarded));
assertThat(headers.get(listOfIntsHeaderKey), hasItems("1", "2", "3"));
}
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 cxf by apache.
the class AbstractFaultChainInitiatorObserver method onMessage.
public void onMessage(Message message) {
assert null != message;
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
Exchange exchange = message.getExchange();
Message faultMessage;
if (isOutboundObserver()) {
Exception ex = message.getContent(Exception.class);
if (!(ex instanceof Fault)) {
ex = new Fault(ex);
}
FaultMode mode = message.get(FaultMode.class);
faultMessage = exchange.getOutMessage();
if (null == faultMessage) {
faultMessage = new MessageImpl();
faultMessage.setExchange(exchange);
faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
}
faultMessage.setContent(Exception.class, ex);
if (null != mode) {
faultMessage.put(FaultMode.class, mode);
}
// CXF-3981
if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
faultMessage.put("javax.xml.ws.addressing.context.inbound", message.get("javax.xml.ws.addressing.context.inbound"));
}
exchange.setOutMessage(null);
exchange.setOutFaultMessage(faultMessage);
if (message.get(BindingFaultInfo.class) != null) {
faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
}
} else {
faultMessage = message;
exchange.setInMessage(null);
exchange.setInFaultMessage(faultMessage);
}
// setup chain
PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
initializeInterceptors(faultMessage.getExchange(), chain);
faultMessage.setInterceptorChain(chain);
try {
chain.doIntercept(faultMessage);
} catch (RuntimeException exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw exc;
} catch (Exception exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw new RuntimeException(exc);
}
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class SoapBindingTest method testCreateMessage.
@Test
public void testCreateMessage() throws Exception {
Message message = new MessageImpl();
SoapBinding sb = new SoapBinding(null);
message = sb.createMessage(message);
assertNotNull(message);
assertTrue(message instanceof SoapMessage);
SoapMessage soapMessage = (SoapMessage) message;
assertEquals(Soap11.getInstance(), soapMessage.getVersion());
assertEquals("text/xml", soapMessage.get(Message.CONTENT_TYPE));
soapMessage.remove(Message.CONTENT_TYPE);
sb.setSoapVersion(Soap12.getInstance());
soapMessage = (SoapMessage) sb.createMessage(soapMessage);
assertEquals(Soap12.getInstance(), soapMessage.getVersion());
assertEquals("application/soap+xml", soapMessage.get(Message.CONTENT_TYPE));
}
Aggregations