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;
}
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);
}
}
}
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;
}
}
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);
}
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();
}
Aggregations