org.apache.cxf.message.ExchangeImpl Java Examples

The following examples show how to use org.apache.cxf.message.ExchangeImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TruncatedTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void truncatedInboundInterceptorInputStream() throws IOException {

    Message message = new MessageImpl();
    ByteArrayInputStream inputStream = new ByteArrayInputStream("TestMessage".getBytes(StandardCharsets.UTF_8));
    message.setContent(InputStream.class, inputStream);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    LogEventSenderMock logEventSender = new LogEventSenderMock();
    LoggingInInterceptor interceptor = new LoggingInInterceptor(logEventSender);
    interceptor.setLimit(1); // set limit to 1 byte in order to get a truncated message!

    Collection<PhaseInterceptor<? extends Message>> interceptors = interceptor.getAdditionalInterceptors();
    for (PhaseInterceptor intercept : interceptors) {
        intercept.handleMessage(message);
    }

    interceptor.handleMessage(message);

    LogEvent event = logEventSender.getLogEvent();
    assertNotNull(event);
    assertEquals("T", event.getPayload()); // only the first byte is read!
    assertTrue(event.isTruncated());
}
 
Example #2
Source File: MessageContextImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testContextResolver() {
    ContextResolver<JAXBContext> resolver = new CustomContextResolver();
    ProviderFactory factory = ServerProviderFactory.getInstance();
    factory.registerUserProvider(resolver);

    Message m = new MessageImpl();
    Exchange ex = new ExchangeImpl();
    m.setExchange(ex);
    ex.setInMessage(m);
    Endpoint e = EasyMock.createMock(Endpoint.class);
    EasyMock.expect(e.get(ServerProviderFactory.class.getName())).andReturn(factory);
    EasyMock.replay(e);
    ex.put(Endpoint.class, e);
    MessageContext mc = new MessageContextImpl(m);
    ContextResolver<JAXBContext> resolver2 =
        mc.getResolver(ContextResolver.class, JAXBContext.class);
    assertNotNull(resolver2);
    assertSame(resolver2, resolver);
}
 
Example #3
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignature() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myAlias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/ds:Signature", doc);
}
 
Example #4
Source File: DOM4JProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message createMessage(ProviderFactory factory) {
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    e.setInMessage(m);
    Endpoint endpoint = EasyMock.createMock(Endpoint.class);
    endpoint.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    endpoint.get(Application.class.getName());
    EasyMock.expectLastCall().andReturn(null);
    endpoint.size();
    EasyMock.expectLastCall().andReturn(0).anyTimes();
    endpoint.isEmpty();
    EasyMock.expectLastCall().andReturn(true).anyTimes();
    endpoint.get(ServerProviderFactory.class.getName());
    EasyMock.expectLastCall().andReturn(factory).anyTimes();
    EasyMock.replay(endpoint);
    e.put(Endpoint.class, endpoint);
    return m;
}
 
Example #5
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test(expected = SoapFault.class)
public void testTwoWayRequestWithReplyToNone() throws Exception {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    exchange.setOutMessage(message);
    message.setExchange(exchange);
    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.FALSE);
    AddressingProperties maps = new AddressingProperties();
    EndpointReferenceType replyTo = new EndpointReferenceType();
    replyTo.setAddress(ContextUtils.getAttributedURI(Names.WSA_NONE_ADDRESS));
    maps.setReplyTo(replyTo);
    AttributedURIType id =
        ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(""));
    setUpMessageProperty(message,
                         ADDRESSING_PROPERTIES_OUTBOUND,
                         maps);
    setUpMessageProperty(message,
                         "org.apache.cxf.ws.addressing.map.fault.name",
                         "NoneAddress");

    aggregator.mediate(message, false);
}
 
Example #6
Source File: AsyncResponseImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Test that creatinging an AsyncResponse with a null continuation throws
 * an IllegalArgumentException instead of a NullPointer Exception.
 */
@Test
public void testNullContinutaion() {
    HttpServletRequest req = control.createMock(HttpServletRequest.class);
    AsyncContext asyncCtx = control.createMock(AsyncContext.class);
    Message msg = new MessageImpl();
    msg.setExchange(new ExchangeImpl());

    req.startAsync();
    EasyMock.expectLastCall().andReturn(asyncCtx);
    control.replay();

    AsyncResponse impl;
    try {
        impl = new AsyncResponseImpl(msg);
    } catch (IllegalArgumentException e) {
        assertEquals("Continuation not supported. " 
                         + "Please ensure that all servlets and servlet filters support async operations",
                     e.getMessage());
        return;
    }
    Assert.fail("Expected IllegalArgumentException, but instead got valid AsyncResponse, " + impl);
}
 
Example #7
Source File: AbstractSTSTokenTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
static MessageImpl prepareMessage(Bus bus, STSClient stsClient, String serviceAddress) throws EndpointException {
    MessageImpl message = new MessageImpl();
    message.put(SecurityConstants.STS_CLIENT, stsClient);
    message.put(Message.ENDPOINT_ADDRESS, serviceAddress);

    Exchange exchange = new ExchangeImpl();
    ServiceInfo si = new ServiceInfo();
    si.setName(new QName("http://www.apache.org", "ServiceName"));
    Service s = new ServiceImpl(si);
    EndpointInfo ei = new EndpointInfo();
    ei.setName(new QName("http://www.apache.org", "EndpointName"));
    Endpoint ep = new EndpointImpl(bus, s, ei);
    ei.setBinding(new BindingInfo(si, null));
    message.setExchange(exchange);
    exchange.put(Endpoint.class, ep);
    return message;
}
 
Example #8
Source File: TestBase.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    SortedSet<Phase> phases = new TreeSet<>();
    Phase phase1 = new Phase("phase1", 1);
    Phase phase2 = new Phase("phase2", 2);
    Phase phase3 = new Phase("phase3", 3);
    phases.add(phase1);
    phases.add(phase2);
    phases.add(phase3);
    chain = new PhaseInterceptorChain(phases);

    Exchange exchange = new ExchangeImpl();
    MessageImpl messageImpl = new MessageImpl();
    messageImpl.setInterceptorChain(chain);
    messageImpl.setExchange(exchange);
    xmlMessage = messageImpl;
}
 
Example #9
Source File: DocLiteralInInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setUpUsingHelloWorld() throws Exception {
    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass()
        .getResource("/wsdl/jaxb/hello_world.wsdl").toString(), new QName(ns, "SOAPService"));

    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] {GreetMe.class, GreetMeResponse.class}));
    service.setDataBinding(db);

    operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);

    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);

    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
 
Example #10
Source File: SOAPLoggingTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSoap() {
    DefaultLogEventMapper mapper = new DefaultLogEventMapper();
    Message message = new MessageImpl();
    ExchangeImpl exchange = new ExchangeImpl();
    ServiceInfo service = new ServiceInfo();
    BindingInfo info = new BindingInfo(service, "bindingId");
    SoapBinding value = new SoapBinding(info);
    exchange.put(Binding.class, value);
    OperationInfo opInfo = new OperationInfo();
    opInfo.setName(new QName("http://my", "Operation"));
    BindingOperationInfo boi = new BindingOperationInfo(info, opInfo);
    exchange.put(BindingOperationInfo.class, boi);
    message.setExchange(exchange);
    LogEvent event = mapper.map(message);
    Assert.assertEquals("{http://my}Operation", event.getOperationName());
}
 
Example #11
Source File: JAXWSMethodInvokerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuspendedException() throws Throwable {
    Exception originalException = new RuntimeException();
    ContinuationService serviceObject =
        new ContinuationService(originalException);
    Method serviceMethod = ContinuationService.class.getMethod("invoke", new Class[]{});

    Exchange ex = new ExchangeImpl();
    Message inMessage = new MessageImpl();
    ex.setInMessage(inMessage);
    inMessage.setExchange(ex);
    inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);

    JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
    try {
        jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
        fail("Suspended invocation swallowed");
    } catch (SuspendedInvocationException suspendedEx) {
        assertSame(suspendedEx, serviceObject.getSuspendedException());
        assertSame(originalException, suspendedEx.getRuntimeException());
    }
}
 
Example #12
Source File: JAXWSMethodInvokerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testFaultAvoidHeadersCopy() throws Throwable {
    ExceptionService serviceObject = new ExceptionService();
    Method serviceMethod = ExceptionService.class.getMethod("invoke", new Class[]{});

    Exchange ex = new ExchangeImpl();
    prepareInMessage(ex, false);


    JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
    try {
        jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
        fail("Expected fault");
    } catch (Fault fault) {
        Message outMsg = ex.getOutMessage();
        assertNull(outMsg);
    }
}
 
Example #13
Source File: ProviderFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message prepareFaultMessage(String contentType, String acceptType) {
    Message message = new MessageImpl();
    Map<String, List<String>> headers = new MetadataMap<String, String>();
    message.put(Message.PROTOCOL_HEADERS, headers);
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(null);
    exchange.setInFaultMessage(message);
    if (acceptType != null) {
        headers.put("Accept", Collections.singletonList(acceptType));
        exchange.setOutMessage(new MessageImpl());
    } else {
        headers.put("Content-Type", Collections.singletonList(contentType));
    }
    message.put("Content-Type", contentType);
    message.setExchange(exchange);
    return message;
}
 
Example #14
Source File: XSLTJaxbProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message createMessage() {
    ProviderFactory factory = ServerProviderFactory.getInstance();
    Message m = new MessageImpl();
    m.put(Message.ENDPOINT_ADDRESS, "http://localhost:8080/bar");
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    e.setInMessage(m);
    Endpoint endpoint = EasyMock.mock(Endpoint.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(null).anyTimes();
    EasyMock.expect(endpoint.get(Application.class.getName())).andReturn(null);
    EasyMock.expect(endpoint.size()).andReturn(0).anyTimes();
    EasyMock.expect(endpoint.isEmpty()).andReturn(true).anyTimes();
    EasyMock.expect(endpoint.get(ServerProviderFactory.class.getName())).andReturn(factory).anyTimes();
    EasyMock.replay(endpoint);
    e.put(Endpoint.class, endpoint);
    return m;
}
 
Example #15
Source File: ResponseImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message createMessage() {
    ProviderFactory factory = ServerProviderFactory.getInstance();
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    e.setInMessage(m);
    e.setOutMessage(new MessageImpl());
    Endpoint endpoint = EasyMock.createMock(Endpoint.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(null).anyTimes();
    EasyMock.expect(endpoint.get(Application.class.getName())).andReturn(null);
    EasyMock.expect(endpoint.size()).andReturn(0).anyTimes();
    EasyMock.expect(endpoint.isEmpty()).andReturn(true).anyTimes();
    EasyMock.expect(endpoint.get(ServerProviderFactory.class.getName())).andReturn(factory).anyTimes();
    EasyMock.replay(endpoint);
    e.put(Endpoint.class, endpoint);
    return m;
}
 
Example #16
Source File: SoapPreProtocolOutInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private SoapMessage setUpMessage() throws Exception {

        SoapMessage message = new SoapMessage(new MessageImpl());
        Exchange exchange = new ExchangeImpl();
        BindingOperationInfo bop = setUpBindingOperationInfo("http://foo/bar",
                                                             "opReq",
                                                             "opResp",
                                                             SEI.class.getMethod("op", new Class[0]));
        SoapOperationInfo sop = new SoapOperationInfo();
        sop.setAction("http://foo/bar/SEI/opReq");
        bop.addExtensor(sop);
        exchange.put(BindingOperationInfo.class, bop);
        message.setExchange(exchange);
        message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);

        control.replay();
        return message;
    }
 
Example #17
Source File: TransformTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void transformInboundInterceptorInputStream() {
    // Arrange
    Message message = new MessageImpl();
    ByteArrayInputStream inputStream =
            new ByteArrayInputStream(ORIG_LOGGING_CONTENT.getBytes(StandardCharsets.UTF_8));
    message.setContent(InputStream.class, inputStream);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    LogEventSenderMock logEventSender = new LogEventSenderMock();
    LoggingInInterceptor interceptor = new TransformLoggingInInterceptor(logEventSender);

    // Act
    Collection<PhaseInterceptor<? extends Message>> interceptors = interceptor.getAdditionalInterceptors();
    for (PhaseInterceptor intercept : interceptors) {
        intercept.handleMessage(message);
    }
    interceptor.handleMessage(message);

    // Verify
    LogEvent event = logEventSender.getLogEvent();
    assertNotNull(event);
    assertEquals(TRANSFORMED_LOGGING_CONTENT, event.getPayload()); // only the first byte is read!
}
 
Example #18
Source File: ProviderFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message prepareMessage(String contentType, String acceptType) {
    Message message = new MessageImpl();
    Map<String, List<String>> headers = new MetadataMap<>();
    message.put(Message.PROTOCOL_HEADERS, headers);
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(message);
    if (acceptType != null) {
        headers.put("Accept", Collections.singletonList(acceptType));
        exchange.setOutMessage(new MessageImpl());
    } else {
        headers.put("Content-Type", Collections.singletonList(contentType));
    }
    message.put("Content-Type", contentType);
    message.setExchange(exchange);
    return message;
}
 
Example #19
Source File: DOM4JProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message createMessage(boolean suppress) {
    ProviderFactory factory = ServerProviderFactory.getInstance();
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    Exchange e = new ExchangeImpl();
    e.put(DOM4JProvider.SUPPRESS_XML_DECLARATION, suppress);
    m.setExchange(e);
    e.setInMessage(m);
    Endpoint endpoint = EasyMock.createMock(Endpoint.class);
    endpoint.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    endpoint.get(Application.class.getName());
    EasyMock.expectLastCall().andReturn(null);
    endpoint.size();
    EasyMock.expectLastCall().andReturn(0).anyTimes();
    endpoint.isEmpty();
    EasyMock.expectLastCall().andReturn(true).anyTimes();
    endpoint.get(ServerProviderFactory.class.getName());
    EasyMock.expectLastCall().andReturn(factory).anyTimes();
    EasyMock.replay(endpoint);
    e.put(Endpoint.class, endpoint);
    return m;
}
 
Example #20
Source File: TruncatedTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void truncatedOutboundInterceptorOutputStream() throws IOException {

    Message message = new MessageImpl();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    message.setContent(OutputStream.class, outputStream);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    LogEventSenderMock logEventSender = new LogEventSenderMock();
    LoggingOutInterceptor interceptor = new LoggingOutInterceptor(logEventSender);
    interceptor.setLimit(1); // set limit to 1 byte in order to get a truncated message!
    interceptor.handleMessage(message);
    byte[] payload = "TestMessage".getBytes(StandardCharsets.UTF_8);

    OutputStream out = message.getContent(OutputStream.class);
    out.write(payload);
    out.close();
    LogEvent event = logEventSender.getLogEvent();
    assertNotNull(event);
    assertEquals("T", event.getPayload()); // only the first byte is read!
    assertTrue(event.isTruncated());
}
 
Example #21
Source File: TransformTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void transformOutboundInterceptorWriter() throws IOException {
    // Arrange
    Message message = new MessageImpl();
    StringWriter stringWriter = new StringWriter();
    message.setContent(Writer.class, stringWriter);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    LogEventSenderMock logEventSender = new LogEventSenderMock();
    LoggingOutInterceptor interceptor = new TransformLoggingOutInterceptor(logEventSender);

    // Act
    interceptor.handleMessage(message);
    Writer out = message.getContent(Writer.class);
    out.write(ORIG_LOGGING_CONTENT);
    out.close();

    // Assert
    LogEvent event = logEventSender.getLogEvent();
    assertNotNull(event);
    assertEquals(TRANSFORMED_LOGGING_CONTENT, event.getPayload()); // only the first byte is read!
}
 
Example #22
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncrypt() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//s:Body/xenc:EncryptedData", doc);
}
 
Example #23
Source File: TruncatedTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void truncatedInboundInterceptorReader() throws IOException {

    Message message = new MessageImpl();
    StringReader stringReader = new StringReader("TestMessage");
    message.setContent(Reader.class, stringReader);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    LogEventSenderMock logEventSender = new LogEventSenderMock();
    LoggingInInterceptor interceptor = new LoggingInInterceptor(logEventSender);
    interceptor.setLimit(1); // set limit to 1 byte in order to get a truncated message!

    Collection<PhaseInterceptor<? extends Message>> interceptors = interceptor.getAdditionalInterceptors();
    for (PhaseInterceptor intercept : interceptors) {
        intercept.handleMessage(message);
    }

    interceptor.handleMessage(message);

    LogEvent event = logEventSender.getLogEvent();
    assertNotNull(event);
    assertEquals("T", event.getPayload()); // only the first byte is read!
    assertTrue(event.isTruncated());
}
 
Example #24
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplyToWithAnonymousAddressRetained() throws Exception {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.setOutMessage(message);
    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.TRUE);
    AddressingProperties maps = new AddressingProperties();
    EndpointReferenceType replyTo = new EndpointReferenceType();
    replyTo.setAddress(ContextUtils.getAttributedURI(Names.WSA_ANONYMOUS_ADDRESS));
    maps.setReplyTo(replyTo);
    AttributedURIType id =
        ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(""));
    setUpMessageProperty(message,
                         CLIENT_ADDRESSING_PROPERTIES,
                         maps);
    aggregator.mediate(message, false);
    AddressingProperties props =
        (AddressingProperties)message.get(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND);
    assertSame(replyTo, props.getReplyTo());
}
 
Example #25
Source File: TruncatedTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void truncatedOutboundInterceptorWriter() throws IOException {

    Message message = new MessageImpl();
    StringWriter stringWriter = new StringWriter();
    message.setContent(Writer.class, stringWriter);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    LogEventSenderMock logEventSender = new LogEventSenderMock();
    LoggingOutInterceptor interceptor = new LoggingOutInterceptor(logEventSender);
    interceptor.setLimit(1); // set limit to 1 byte in order to get a truncated message!
    interceptor.handleMessage(message);

    Writer out = message.getContent(Writer.class);
    out.write("TestMessage");
    out.close();
    LogEvent event = logEventSender.getLogEvent();
    assertNotNull(event);
    assertEquals("T", event.getPayload()); // only the first byte is read!
    assertTrue(event.isTruncated());
}
 
Example #26
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimestamp() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    ohandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    ohandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/wsu:Timestamp", doc);
}
 
Example #27
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignature() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myAlias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/ds:Signature", doc);
}
 
Example #28
Source File: WSS4JOutInterceptorTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncrypt() throws Exception {
    SOAPMessage saaj = readSAAJDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    msg.setContent(SOAPMessage.class, saaj);
    
    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");

    handler.handleMessage(msg);

    SOAPPart doc = saaj.getSOAPPart();
    assertValid("//wsse:Security", doc);
    assertValid("//s:Body/xenc:EncryptedData", doc);
}
 
Example #29
Source File: ContextPropertiesMappingTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateWebServiceContext() {
    Exchange exchange = new ExchangeImpl();
    Message inMessage = new MessageImpl();
    Message outMessage = new MessageImpl();

    inMessage.putAll(message);

    exchange.setInMessage(inMessage);
    exchange.setOutMessage(outMessage);

    MessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION);

    Object requestHeader = ctx.get(MessageContext.HTTP_REQUEST_HEADERS);
    assertNotNull("the request header should not be null", requestHeader);
    assertEquals("we should get the request header", requestHeader, HEADER);
    Object responseHeader = ctx.get(MessageContext.HTTP_RESPONSE_HEADERS);
    assertNull("the response header should be null", responseHeader);
    Object outMessageHeader = outMessage.get(Message.PROTOCOL_HEADERS);
    assertEquals("the outMessage PROTOCOL_HEADERS should be update", responseHeader, outMessageHeader);

    Object inAttachments = ctx.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
    assertNotNull("inbound attachments object must be initialized", inAttachments);
    assertTrue("inbound attachments must be in a Map", inAttachments instanceof Map);
    assertTrue("no inbound attachments expected", ((Map<?, ?>)inAttachments).isEmpty());
}
 
Example #30
Source File: SoapActionInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSoapAction() throws Exception {
    SoapPreProtocolOutInterceptor i = new SoapPreProtocolOutInterceptor();

    Message message = new MessageImpl();
    message.setExchange(new ExchangeImpl());
    message.getExchange().setOutMessage(message);
    SoapBinding sb = new SoapBinding(null);
    message = sb.createMessage(message);
    assertNotNull(message);
    assertTrue(message instanceof SoapMessage);
    SoapMessage soapMessage = (SoapMessage) message;
    soapMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    assertEquals(Soap11.getInstance(), soapMessage.getVersion());
    (new SoapPreProtocolOutInterceptor()).handleMessage(soapMessage);
    Map<String, List<String>> reqHeaders
        = CastUtils.cast((Map<?, ?>)soapMessage.get(Message.PROTOCOL_HEADERS));
    assertNotNull(reqHeaders);
    assertEquals("\"\"", reqHeaders.get(SoapBindingConstants.SOAP_ACTION).get(0));

    sb.setSoapVersion(Soap12.getInstance());
    soapMessage.clear();
    soapMessage = (SoapMessage) sb.createMessage(soapMessage);
    soapMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    i.handleMessage(soapMessage);
    String ct = (String) soapMessage.get(Message.CONTENT_TYPE);
    assertEquals("application/soap+xml", ct);

    BindingOperationInfo bop = createBindingOperation();

    soapMessage.getExchange().put(BindingOperationInfo.class, bop);
    SoapOperationInfo soapInfo = new SoapOperationInfo();
    soapInfo.setAction("foo");
    bop.addExtensor(soapInfo);

    i.handleMessage(soapMessage);
    ct = (String) soapMessage.get(Message.CONTENT_TYPE);
    assertEquals("application/soap+xml; action=\"foo\"", ct);
}