use of javax.xml.ws.Response in project uavstack by uavorg.
the class CXFClientE2ETest method doGet.
/**
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest request,
* javax.servlet.http.HttpServletResponse response)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String test = request.getParameter("test");
if (test == null || "good".equals(test)) {
TestService_Service service = new TestService_Service();
TestService ts = service.getPort(TestService.class);
ts.echo();
} else if ("fault".equals(test)) {
TestService_Service service = new TestService_Service();
TestService ts = service.getPort(TestService.class);
ts.echoFault();
} else if ("async1".equals(test)) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(TestService_Service.WSDL_LOCATION);
try {
client.invokeWrapped(new ClientCallback() {
@Override
public void handleResponse(Map<String, Object> ctx, Object[] res) {
super.handleResponse(ctx, res);
}
@Override
public void handleException(Map<String, Object> ctx, Throwable ex) {
super.handleException(ctx, ex);
}
}, "echo");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if ("async0".equals(test)) {
Service sr = Service.create(TestService_Service.WSDL_LOCATION, TestService_Service.SERVICE);
JAXBContext jc = null;
try {
jc = JAXBContext.newInstance("com.creditease.monitorframework.fat.client");
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Dispatch d = sr.createDispatch(TestService_Service.TestServicePort, jc, Mode.PAYLOAD);
d.invokeAsync(null, new AsyncHandler() {
@Override
public void handleResponse(Response res) {
if (res.isDone()) {
try {
System.out.println(res.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
});
}
}
use of javax.xml.ws.Response in project cxf by apache.
the class ClientServerTest method testAsyncSynchronousPolling.
@Test
public void testAsyncSynchronousPolling() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull(service);
final String expectedString = new String("Hello, finally!");
class Poller extends Thread {
Response<GreetMeLaterResponse> response;
int tid;
Poller(Response<GreetMeLaterResponse> r, int t) {
response = r;
tid = t;
}
public void run() {
if (tid % 2 > 0) {
while (!response.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
// ignore
}
}
}
GreetMeLaterResponse reply = null;
try {
reply = response.get();
} catch (Exception ex) {
fail("Poller " + tid + " failed with " + ex);
}
assertNotNull("Poller " + tid + ": no response received from service", reply);
String s = reply.getResponseType();
assertEquals(expectedString, s);
}
}
Greeter greeter = service.getPort(portName, Greeter.class);
updateAddressPort(greeter, PORT);
long before = System.currentTimeMillis();
long delay = 3000;
Response<GreetMeLaterResponse> response = greeter.greetMeLaterAsync(delay);
long after = System.currentTimeMillis();
assertTrue("Duration of calls exceeded " + delay + " ms", after - before < delay);
// first time round, responses should not be available yet
assertFalse("Response already available.", response.isDone());
Poller[] pollers = new Poller[4];
for (int i = 0; i < pollers.length; i++) {
pollers[i] = new Poller(response, i);
}
for (Poller p : pollers) {
p.start();
}
for (Poller p : pollers) {
p.join();
}
}
use of javax.xml.ws.Response in project cxf by apache.
the class AsyncHTTPConduitTest method testCallAsync.
@Test
public void testCallAsync() throws Exception {
updateAddressPort(g, PORT);
GreetMeResponse resp = (GreetMeResponse) g.greetMeAsync(request, new AsyncHandler<GreetMeResponse>() {
public void handleResponse(Response<GreetMeResponse> res) {
try {
res.get().getResponseType();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}).get();
assertEquals("Hello " + request, resp.getResponseType());
g.greetMeLaterAsync(1000, new AsyncHandler<GreetMeLaterResponse>() {
public void handleResponse(Response<GreetMeLaterResponse> res) {
}
}).get();
}
use of javax.xml.ws.Response in project cxf by apache.
the class AsyncHTTPConduitTest method testCallAsyncCallbackInvokedOnlyOnce.
@Test
public void testCallAsyncCallbackInvokedOnlyOnce() throws Exception {
// This test is especially targeted for RHEL 6.8
updateAddressPort(g, PORT_INV);
int repeat = 100;
final AtomicInteger count = new AtomicInteger(0);
for (int i = 0; i < repeat; i++) {
try {
g.greetMeAsync(request, new AsyncHandler<GreetMeResponse>() {
public void handleResponse(Response<GreetMeResponse> res) {
count.incrementAndGet();
}
}).get();
} catch (Exception e) {
}
}
Thread.sleep(1000);
assertEquals("Callback should be invoked only once per request", repeat, count.intValue());
}
use of javax.xml.ws.Response in project cxf by apache.
the class AsyncHTTPConduitTest method testRetransmitAsync.
@Test
public void testRetransmitAsync() throws Exception {
updateAddressPort(g, PORT);
HTTPConduit c = (HTTPConduit) ClientProxy.getClient(g).getConduit();
HTTPClientPolicy cp = new HTTPClientPolicy();
cp.setMaxRetransmits(2);
cp.setChunkLength(20);
c.setClient(cp);
GreetMeResponse resp = (GreetMeResponse) g.greetMeAsync(request, new AsyncHandler<GreetMeResponse>() {
public void handleResponse(Response<GreetMeResponse> res) {
try {
res.get().getResponseType();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}).get();
assertEquals("Hello " + request, resp.getResponseType());
g.greetMeLaterAsync(1000, new AsyncHandler<GreetMeLaterResponse>() {
public void handleResponse(Response<GreetMeLaterResponse> res) {
}
}).get();
}
Aggregations