Java Code Examples for org.apache.cxf.message.ExchangeImpl#put()

The following examples show how to use org.apache.cxf.message.ExchangeImpl#put() . 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: 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 2
Source File: SingletonResourceProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void init(Endpoint ep) {
    if (resourceInstance instanceof Constructor) {
        Constructor<?> c = (Constructor<?>)resourceInstance;
        Message m = new MessageImpl();
        ExchangeImpl exchange = new ExchangeImpl();
        exchange.put(Endpoint.class, ep);
        m.setExchange(exchange);
        Object[] values = 
            ResourceUtils.createConstructorArguments(c, m, false, Collections.emptyMap());
        try {
            resourceInstance = values.length > 0 ? c.newInstance(values) : c.newInstance(new Object[]{});
        } catch (Exception ex) {
            throw new ServiceConstructionException(ex);
        }
    }
    if (callPostConstruct) {
        InjectionUtils.invokeLifeCycleMethod(resourceInstance,
            ResourceUtils.findPostConstructMethod(ClassHelper.getRealClass(resourceInstance)));
    }    
}
 
Example 3
Source File: LoggingOutInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private CachedOutputStream handleAndGetCachedOutputStream(LoggingOutInterceptor interceptor) {
    interceptor.setPrintWriter(new PrintWriter(new ByteArrayOutputStream()));

    Endpoint endpoint = control.createMock(Endpoint.class);
    EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
    BindingInfo bindingInfo = control.createMock(BindingInfo.class);
    EasyMock.expect(endpointInfo.getBinding()).andReturn(bindingInfo).anyTimes();
    EasyMock.expect(endpointInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
    EasyMock.expect(bindingInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
    control.replay();

    Message message = new MessageImpl();
    ExchangeImpl exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.put(Endpoint.class, endpoint);

    message.put(Message.CONTENT_TYPE, "application/xml");
    message.setContent(OutputStream.class, new ByteArrayOutputStream());
    interceptor.handleMessage(message);
    OutputStream os = message.getContent(OutputStream.class);
    assertTrue(os instanceof CachedOutputStream);
    return (CachedOutputStream)os;
}
 
Example 4
Source File: SpringViewResolverProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    this.viewResolver = new SpringViewResolverProvider(viewResolverMock, localeResolverMock);
    ExchangeImpl exchange = new ExchangeImpl();
    Endpoint endpoint = new MockEndpoint();
    endpoint.put(ServerProviderFactory.class.getName(), ServerProviderFactory.getInstance());
    exchange.put(Endpoint.class, endpoint);
    exchange.put(ServerProviderFactory.class.getName(), ServerProviderFactory.getInstance());
    MessageImpl message = new MessageImpl();
    message.setExchange(exchange);
    message.put(AbstractHTTPDestination.HTTP_REQUEST, requestMock);
    message.put(AbstractHTTPDestination.HTTP_RESPONSE, responseMock);
    message.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
    viewResolver.setMessageContext(new MessageContextImpl(message));
}
 
Example 5
Source File: LocalConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void dispatchDirect(Message message) throws IOException {
    if (destination.getMessageObserver() == null) {
        throw new IllegalStateException("Local destination does not have a MessageObserver on address "
                                        + destination.getAddress().getAddress().getValue());
    }

    MessageImpl copy = new MessageImpl();
    copy.put(IN_CONDUIT, this);
    copy.setDestination(destination);

    transportFactory.copy(message, copy);
    MessageImpl.copyContent(message, copy);

    OutputStream out = message.getContent(OutputStream.class);
    out.flush();
    out.close();

    CachedOutputStream stream = message.get(CachedOutputStream.class);
    copy.setContent(InputStream.class, stream.getInputStream());
    copy.removeContent(CachedOutputStream.class);
    stream.releaseTempFileHold();

    // Create a new incoming exchange and store the original exchange for the response
    ExchangeImpl ex = new ExchangeImpl();
    ex.setInMessage(copy);
    ex.put(IN_EXCHANGE, message.getExchange());
    ex.put(LocalConduit.DIRECT_DISPATCH, true);
    ex.setDestination(destination);

    destination.getMessageObserver().onMessage(copy);
}