Search in sources :

Example 1 with WrappedOutputStream

use of org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream in project cxf by apache.

the class HTTPConduitTest method testHandleResponseOnWorkqueueAllowCurrentThread.

@Test
public void testHandleResponseOnWorkqueueAllowCurrentThread() throws Exception {
    Message m = getNewMessage();
    Exchange exchange = new ExchangeImpl();
    Bus bus = new ExtensionManagerBus();
    exchange.put(Bus.class, bus);
    EndpointInfo endpointInfo = new EndpointInfo();
    Endpoint endpoint = new EndpointImpl(null, null, endpointInfo);
    exchange.put(Endpoint.class, endpoint);
    m.setExchange(exchange);
    HTTPClientPolicy policy = new HTTPClientPolicy();
    policy.setAsyncExecuteTimeoutRejection(true);
    m.put(HTTPClientPolicy.class, policy);
    exchange.put(Executor.class, new Executor() {

        @Override
        public void execute(Runnable command) {
            // forces us to use current thread
            throw new RejectedExecutionException("expected");
        }
    });
    HTTPConduit conduit = new MockHTTPConduit(bus, endpointInfo, policy);
    OutputStream os = conduit.createOutputStream(m, false, false, 0);
    assertTrue(os instanceof WrappedOutputStream);
    WrappedOutputStream wos = (WrappedOutputStream) os;
    try {
        wos.handleResponseOnWorkqueue(true, false);
        assertEquals(Thread.currentThread(), m.get(Thread.class));
        try {
            wos.handleResponseOnWorkqueue(false, false);
            fail("Expected RejectedExecutionException not thrown");
        } catch (RejectedExecutionException ex) {
            assertEquals("expected", ex.getMessage());
        }
    } catch (Exception ex) {
        throw ex;
    }
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Message(org.apache.cxf.message.Message) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) WrappedOutputStream(org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream) OutputStream(java.io.OutputStream) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Executor(java.util.concurrent.Executor) Endpoint(org.apache.cxf.endpoint.Endpoint) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) WrappedOutputStream(org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

OutputStream (java.io.OutputStream)1 Executor (java.util.concurrent.Executor)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Bus (org.apache.cxf.Bus)1 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)1 Exchange (org.apache.cxf.message.Exchange)1 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)1 Message (org.apache.cxf.message.Message)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 WrappedOutputStream (org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream)1 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)1 Test (org.junit.Test)1