Search in sources :

Example 1 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project jbossws-cxf by jbossws.

the class EndpointImpl method echo.

public String echo(long time) {
    ContinuationProvider p = (ContinuationProvider) context.getMessageContext().get(ContinuationProvider.class.getName());
    Continuation c = p.getContinuation();
    if (c.isNew()) {
        if (time < 0) {
            c.suspend(-time);
        } else {
            c.suspend(2000 - (time % 1000));
        }
        return null;
    }
    return "Echo:" + time;
}
Also used : Continuation(org.apache.cxf.continuations.Continuation) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider)

Example 2 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class BinaryDataProvider method copyInputToOutput.

protected void copyInputToOutput(InputStream is, OutputStream os, Annotation[] anns, MultivaluedMap<String, Object> outHeaders) throws IOException {
    if (isRangeSupported()) {
        Message inMessage = PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage();
        handleRangeRequest(is, os, new HttpHeadersImpl(inMessage), outHeaders);
    } else {
        boolean nioWrite = AnnotationUtils.getAnnotation(anns, UseNio.class) != null;
        if (nioWrite) {
            ContinuationProvider provider = getContinuationProvider();
            if (provider != null) {
                copyUsingNio(is, os, provider.getContinuation());
            }
            return;
        }
        if (closeResponseInputStream) {
            IOUtils.copyAndCloseInput(is, os, bufferSize);
        } else {
            IOUtils.copy(is, os, bufferSize);
        }
    }
}
Also used : UseNio(org.apache.cxf.annotations.UseNio) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Message(org.apache.cxf.message.Message) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl)

Example 3 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class HWSoapMessageDocProvider method invoke.

public SOAPMessage invoke(SOAPMessage request) {
    try {
        final MessageContext messageContext = ctx.getMessageContext();
        ContinuationProvider contProvider = (ContinuationProvider) messageContext.get(ContinuationProvider.class.getName());
        final Continuation continuation = contProvider.getContinuation();
        if (continuation.isNew()) {
            continuation.suspend(5000);
            new Thread(new Runnable() {

                public void run() {
                    try {
                        continuation.resume();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            return null;
        } else if (!continuation.isResumed()) {
            continuation.reset();
            throw new RuntimeException("time out");
        } else {
            return resumeMessage(request);
        }
    } catch (SOAPFaultException e) {
        throw e;
    }
}
Also used : Continuation(org.apache.cxf.continuations.Continuation) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) MessageContext(javax.xml.ws.handler.MessageContext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Example 4 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class AsyncHTTPConduitTest method start.

@BeforeClass
public static void start() throws Exception {
    Bus b = createStaticBus();
    b.setProperty(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
    b.setProperty("org.apache.cxf.transport.http.async.MAX_CONNECTIONS", 501);
    BusFactory.setThreadDefaultBus(b);
    AsyncHTTPConduitFactory hcf = (AsyncHTTPConduitFactory) b.getExtension(HTTPConduitFactory.class);
    assertEquals(501, hcf.maxConnections);
    ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort", new org.apache.hello_world_soap_http.GreeterImpl() {

        public String greetMeLater(long cnt) {
            // use the continuations so the async client can
            // have a ton of connections, use less threads
            // 
            // mimic a slow server by delaying somewhere between
            // 1 and 2 seconds, with a preference of delaying the earlier
            // requests longer to create a sort of backlog/contention
            // with the later requests
            ContinuationProvider p = (ContinuationProvider) getContext().getMessageContext().get(ContinuationProvider.class.getName());
            Continuation c = p.getContinuation();
            if (c.isNew()) {
                if (cnt < 0) {
                    c.suspend(-cnt);
                } else {
                    c.suspend(2000 - (cnt % 1000));
                }
                return null;
            }
            return "Hello, finally! " + cnt;
        }

        public String greetMe(String me) {
            if (me.equals(FILL_BUFFER)) {
                return String.join("", Collections.nCopies(16093, " "));
            } else {
                return "Hello " + me;
            }
        }
    });
    StringBuilder builder = new StringBuilder("NaNaNa");
    for (int x = 0; x < 50; x++) {
        builder.append(" NaNaNa ");
    }
    request = builder.toString();
    URL wsdl = AsyncHTTPConduitTest.class.getResource("/wsdl/hello_world_services.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService();
    assertNotNull("Service is null", service);
    g = service.getSoapPort();
    assertNotNull("Port is null", g);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Bus(org.apache.cxf.Bus) Continuation(org.apache.cxf.continuations.Continuation) HTTPConduitFactory(org.apache.cxf.transport.http.HTTPConduitFactory) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Endpoint(javax.xml.ws.Endpoint) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 5 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class BookCxfContinuationStore method getContinuation.

private Continuation getContinuation(String name) {
    ContinuationProvider provider = (ContinuationProvider) context.get(ContinuationProvider.class.getName());
    if (provider == null) {
        Message m = PhaseInterceptorChain.getCurrentMessage();
        UriInfo uriInfo = new UriInfoImpl(m);
        if (uriInfo.getAbsolutePath().toString().contains("/books/subresources/")) {
            // when we suspend a CXF continuation from a sub-resource, the invocation will
            // return directly to that object - and sub-resources do not have contexts supported
            // by default - so we just need to depend on PhaseInterceptorChain
            provider = (ContinuationProvider) m.get(ContinuationProvider.class.getName());
        }
    }
    if (provider == null) {
        throw new WebApplicationException(500);
    }
    synchronized (suspended) {
        Continuation suspendedCont = suspended.remove(name);
        if (suspendedCont != null) {
            return suspendedCont;
        }
    }
    return provider.getContinuation();
}
Also used : Continuation(org.apache.cxf.continuations.Continuation) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Message(org.apache.cxf.message.Message) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) UriInfoImpl(org.apache.cxf.jaxrs.impl.UriInfoImpl)

Aggregations

ContinuationProvider (org.apache.cxf.continuations.ContinuationProvider)13 Continuation (org.apache.cxf.continuations.Continuation)9 URL (java.net.URL)3 Endpoint (javax.xml.ws.Endpoint)3 Bus (org.apache.cxf.Bus)3 SOAPService (org.apache.hello_world_soap_http.SOAPService)3 Message (org.apache.cxf.message.Message)2 HTTPConduitFactory (org.apache.cxf.transport.http.HTTPConduitFactory)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 Method (java.lang.reflect.Method)1 FutureTask (java.util.concurrent.FutureTask)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 UriInfo (javax.ws.rs.core.UriInfo)1 MessageContext (javax.xml.ws.handler.MessageContext)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 UseAsyncMethod (org.apache.cxf.annotations.UseAsyncMethod)1 UseNio (org.apache.cxf.annotations.UseNio)1 SuspendedInvocationException (org.apache.cxf.continuations.SuspendedInvocationException)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1