use of javax.xml.ws.Response in project cxf by apache.
the class WSAPureWsdlTest method testBasicInvocationTimeouts.
@Test
public void testBasicInvocationTimeouts() throws Exception {
AddNumbersPortType port = getPort();
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/add");
HTTPConduit conduit = (HTTPConduit) ((Client) port).getConduit();
conduit.getClient().setConnectionTimeout(25);
conduit.getClient().setReceiveTimeout(10);
try {
// read timeout
port.addNumbersAsync(5092, 25).get();
fail("should have failed");
} catch (Exception t) {
// expected
assertTrue(t.getCause().toString(), t.getCause() instanceof java.net.SocketTimeoutException);
}
AsyncHandler<AddNumbersResponse> handler = new AsyncHandler<AddNumbersResponse>() {
public void handleResponse(Response<AddNumbersResponse> res) {
// System.out.println("in handle response");
synchronized (this) {
notifyAll();
}
}
};
synchronized (handler) {
port.addNumbersAsync(5092, 25, handler);
handler.wait(1000);
}
try {
// connection timeout
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT2 + "/jaxws/add");
port.addNumbersAsync(25, 25).get();
fail("should have failed");
} catch (Exception t) {
// expected
assertTrue(t.getCause().getCause().toString(), t.getCause().getCause() instanceof java.net.ConnectException || t.getCause().getCause() instanceof java.net.SocketTimeoutException);
}
synchronized (handler) {
port.addNumbersAsync(25, 25, handler);
handler.wait(1000);
}
MAPCodec mp = getMAPCodec((Client) port);
assertEquals(0, mp.getUncorrelatedExchanges().size());
}
use of javax.xml.ws.Response in project cxf by apache.
the class WSDiscoveryClient method resolve.
public ResolveMatchType resolve(W3CEndpointReference ref, int timeout) {
Dispatch<Object> disp = this.getDispatchInternal(false, version.getResolveAction());
ResolveType rt = new ResolveType();
rt.setEndpointReference(ref);
if (adHoc) {
disp.getRequestContext().put("udp.multi.response.timeout", timeout);
final Holder<ResolveMatchesType> response = new Holder<ResolveMatchesType>();
AsyncHandler<Object> handler = new AsyncHandler<Object>() {
public void handleResponse(Response<Object> res) {
try {
Object o = res.get();
while (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
if (o instanceof ResolveMatchesType) {
response.value = (ResolveMatchesType) o;
} else if (o instanceof HelloType) {
HelloType h = (HelloType) o;
QName sn = version.getServiceName();
if (h.getTypes().contains(sn) || h.getTypes().contains(new QName("", sn.getLocalPart()))) {
// A DiscoveryProxy wants us to flip to managed mode
uncache();
resetDispatch(h.getXAddrs().get(0));
}
}
} catch (InterruptedException e) {
// ?
} catch (ExecutionException e) {
// ?
}
}
};
disp.invokeAsync(new ObjectFactory().createResolve(rt), handler);
return response.value == null ? null : response.value.getResolveMatch();
}
Object o = disp.invoke(new ObjectFactory().createResolve(rt));
while (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
return o == null ? null : ((ResolveMatchesType) o).getResolveMatch();
}
use of javax.xml.ws.Response in project cxf by apache.
the class ClientServerTest method testAsyncCallUseProperAssignedExecutor.
@Test
public void testAsyncCallUseProperAssignedExecutor() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
class TestExecutor implements Executor {
private AtomicInteger count = new AtomicInteger();
public void execute(Runnable command) {
int c = count.incrementAndGet();
LOG.info("asyn call time " + c);
command.run();
}
public int getCount() {
return count.get();
}
}
Executor executor = new TestExecutor();
service.setExecutor(executor);
assertNotNull(service);
assertSame(executor, service.getExecutor());
assertEquals(((TestExecutor) executor).getCount(), 0);
Greeter greeter = service.getPort(portName, Greeter.class);
updateAddressPort(greeter, PORT);
List<Response<GreetMeResponse>> responses = new ArrayList<Response<GreetMeResponse>>();
for (int i = 0; i < 5; i++) {
responses.add(greeter.greetMeAsync("asyn call" + i));
}
// wait for all the responses
for (Response<GreetMeResponse> resp : responses) {
resp.get();
}
assertEquals(5, ((TestExecutor) executor).getCount());
}
use of javax.xml.ws.Response in project cxf by apache.
the class DispatchClientServerTest method testSOAPMessageInvokeToOneWay.
@Test
public void testSOAPMessageInvokeToOneWay() throws Exception {
SOAPService service = new SOAPService(null, SERVICE_NAME);
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
// message is "one way", but there really isn't a way for us to know that
// as we don't have a wsdl or other source of operation information to
// compare the payload to.
InputStream is1 = getClass().getResourceAsStream("resources/GreetMe1WDocLiteralReq2.xml");
SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
assertNotNull(soapReqMsg1);
// Version 1:
// we'll just call invoke
disp.invoke(soapReqMsg1);
// Version 2:
// We want to handle things asynchronously
AsyncHandler<SOAPMessage> callback = new AsyncHandler<SOAPMessage>() {
public void handleResponse(Response<SOAPMessage> res) {
synchronized (this) {
notifyAll();
}
}
};
synchronized (callback) {
disp.invokeAsync(soapReqMsg1, callback);
callback.wait();
}
}
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 e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}).get();
assertEquals("Hello " + request, resp.getResponseType());
g.greetMeLaterAsync(1000, new AsyncHandler<GreetMeLaterResponse>() {
public void handleResponse(Response<GreetMeLaterResponse> res) {
}
}).get();
}
Aggregations