Search in sources :

Example 21 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project ddf by codice.

the class PaosInInterceptorTest method handleMessagePaosResponseBasicBadAcsUrl.

@Test
public void handleMessagePaosResponseBasicBadAcsUrl() 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("error content".getBytes());
            } else if (responseConsumerURL.equals("https://idp.example.org/saml2/sso")) {
                httpResponseWrapper.statusCode = 200;
                httpResponseWrapper.content = new ByteArrayInputStream(IOUtils.toString(PaosInInterceptorTest.class.getClassLoader().getResource("idpresponse.xml").openStream()).replace("https://sp.example.org/PAOSConsumer", "badurl").getBytes());
            }
            return httpResponseWrapper;
        }
    };
    paosInInterceptor.handleMessage(message);
    assertThat(IOUtils.toString(message.getContent(InputStream.class)), is("error content"));
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 22 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project ddf by codice.

the class PaosInInterceptorTest method handleMessagePaosResponseBasicNoIdp.

@Test(expected = Fault.class)
public void handleMessagePaosResponseBasicNoIdp() throws IOException {
    Message message = new MessageImpl();
    message.setContent(InputStream.class, PaosInInterceptorTest.class.getClassLoader().getResource("ecprequest_noidp.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);
    paosInInterceptor.handleMessage(message);
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)22 Message (org.apache.cxf.message.Message)17 Test (org.junit.Test)16 Exchange (org.apache.cxf.message.Exchange)14 Bus (org.apache.cxf.Bus)9 MessageImpl (org.apache.cxf.message.MessageImpl)7 HashMap (java.util.HashMap)6 List (java.util.List)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 RuntimeCamelException (org.apache.camel.RuntimeCamelException)3 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 MessageObserver (org.apache.cxf.transport.MessageObserver)3 WebServiceException (javax.xml.ws.WebServiceException)2 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)2 Conduit (org.apache.cxf.transport.Conduit)2 InputStream (java.io.InputStream)1