protected <T> Future<T> doInvokeAsync(String httpMethod, Object body, Class<?> requestClass, Type inType, Class<?> respClass, Type outType, InvocationCallback<T> callback) { JaxrsClientCallback<T> cb = new JaxrsClientCallback<>(callback, respClass, outType); prepareAsyncClient(httpMethod, body, requestClass, inType, respClass, outType, cb); return cb.createFuture(); }
public boolean cancel(boolean mayInterruptIfRunning) { return callback.cancel(mayInterruptIfRunning); }
public Map<String, Object> getContext() { try { return callback.getResponseContext(); } catch (Exception ex) { return null; } } public boolean cancel(boolean mayInterruptIfRunning) {
@Override protected void doHandleAsyncResponse(Message message, Response r, JaxrsClientCallback<?> cb) { if (r == null) { try { r = handleResponse(message.getExchange().getOutMessage(), cb.getResponseClass(), cb.getOutGenericType()); } catch (Throwable t) { cb.handleException(message, t); return; } finally { completeExchange(message.getExchange(), false); } } if (cb.getResponseClass() == null || Response.class.equals(cb.getResponseClass())) { cb.handleResponse(message, new Object[] {r}); } else if (r.getStatus() >= 300) { cb.handleException(message, convertToWebApplicationException(r)); } else { cb.handleResponse(message, new Object[] {r.getEntity()}); closeAsyncResponseIfPossible(r, message, cb); } } }
JaxrsClientCallback<T> cb = new JaxrsClientCallback<T>(callback, respClass, outType); m.getExchange().put(JaxrsClientCallback.class, cb); Future<T> future = cb.createFuture(); if (m.getExchange().get(Exception.class) != null) { Throwable ex = m.getExchange().get(Exception.class); ex = ex.getCause(); cb.handleException(m, ex);
@Override protected void doHandleAsyncResponse(Message message, Response r, JaxrsClientCallback<?> cb) { try { Object entity = handleResponse(message.getExchange().getOutMessage(), cb.getResponseClass()); cb.handleResponse(message, new Object[] {entity}); } catch (Throwable t) { cb.handleException(message, t); } finally { completeExchange(message.getExchange(), false); closeAsyncResponseIfPossible(r, message, cb); } } }
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { try { return getObject(callback.get(timeout, unit)[0]); } catch (InterruptedException ex) { if (callback.handler != null) { callback.handler.failed(ex); } throw ex; } }
@Override protected Object doInvokeAsync(OperationResourceInfo ori, Message outMessage, InvocationCallback<Object> asyncCallback) { MPAsyncInvocationInterceptorImpl aiiImpl = new MPAsyncInvocationInterceptorImpl(outMessage); outMessage.getInterceptorChain().add(aiiImpl); List<Interceptor<? extends Message>>inboundChain = cfg.getInInterceptors(); inboundChain.add(new MPAsyncInvocationInterceptorPostAsyncImpl(aiiImpl.getInterceptors())); inboundChain.add(new MPAsyncInvocationInterceptorRemoveContextImpl(aiiImpl.getInterceptors())); setTimeouts(cfg.getRequestContext()); super.doInvokeAsync(ori, outMessage, asyncCallback); JaxrsClientCallback<?> cb = outMessage.getExchange().get(JaxrsClientCallback.class); return cb.createFuture(); }
@Override public void handleMessage(Message message) throws Fault { if (!message.getExchange().isSynchronous()) { Throwable ex = message.getContent(Exception.class); if (ex == null) { ex = message.getExchange().get(Exception.class); } if (ex != null) { JaxrsClientCallback<?> cb = message.getExchange().get(JaxrsClientCallback.class); if (ex instanceof Fault) { ex = ex.getCause(); } ex = ex instanceof ProcessingException ? ex : new ProcessingException(ex); cb.handleException(message, ex); } } } }
protected void closeAsyncResponseIfPossible(Response r, Message outMessage, JaxrsClientCallback<?> cb) { if (responseStreamCanBeClosed(outMessage, cb.getResponseClass())) { r.close(); } }
public boolean isCancelled() { return callback.isCancelled(); } public boolean isDone() {
protected JaxrsClientCallback<?> newJaxrsClientCallback(InvocationCallback<Object> asyncCallback, Class<?> responseClass, Type outGenericType) { return new JaxrsClientCallback<>(asyncCallback, responseClass, outGenericType); }
@Override protected void doHandleAsyncResponse(Message message, Response r, JaxrsClientCallback<?> cb) { if (r == null) { try { r = handleResponse(message.getExchange().getOutMessage(), cb.getResponseClass(), cb.getOutGenericType()); } catch (Throwable t) { cb.handleException(message, t); return; } finally { completeExchange(message.getExchange(), false); } } if (cb.getResponseClass() == null || Response.class.equals(cb.getResponseClass())) { cb.handleResponse(message, new Object[] {r}); } else if (r.getStatus() >= 300) { cb.handleException(message, convertToWebApplicationException(r)); } else { cb.handleResponse(message, new Object[] {r.getEntity()}); closeAsyncResponseIfPossible(r, message, cb); } } }
@Override protected void doHandleAsyncResponse(Message message, Response r, JaxrsClientCallback<?> cb) { try { Object entity = handleResponse(message.getExchange().getOutMessage(), cb.getResponseClass()); cb.handleResponse(message, new Object[] {entity}); } catch (Throwable t) { cb.handleException(message, t); } finally { completeExchange(message.getExchange(), false); closeAsyncResponseIfPossible(r, message, cb); } } }
public T get() throws InterruptedException, ExecutionException { try { return getObject(callback.get()[0]); } catch (InterruptedException ex) { if (callback.handler != null) { callback.handler.failed(ex); } throw ex; } } public T get(long timeout, TimeUnit unit) throws InterruptedException,
@Override protected Object doInvokeAsync(OperationResourceInfo ori, Message outMessage, InvocationCallback<Object> asyncCallback) { MPAsyncInvocationInterceptorImpl aiiImpl = new MPAsyncInvocationInterceptorImpl(outMessage); outMessage.getInterceptorChain().add(aiiImpl); List<Interceptor<? extends Message>>inboundChain = cfg.getInInterceptors(); inboundChain.add(new MPAsyncInvocationInterceptorPostAsyncImpl(aiiImpl.getInterceptors())); inboundChain.add(new MPAsyncInvocationInterceptorRemoveContextImpl(aiiImpl.getInterceptors())); setTimeouts(cfg.getRequestContext()); super.doInvokeAsync(ori, outMessage, asyncCallback); JaxrsClientCallback<?> cb = outMessage.getExchange().get(JaxrsClientCallback.class); return cb.createFuture(); }
private void handleAsyncResponse(Message message) { JaxrsClientCallback<?> cb = message.getExchange().get(JaxrsClientCallback.class); Response r = null; try { Object[] results = preProcessResult(message); if (results != null && results.length == 1) { r = (Response)results[0]; } } catch (Exception ex) { Throwable t = ex instanceof WebApplicationException ? (WebApplicationException)ex : ex instanceof ProcessingException ? (ProcessingException)ex : new ProcessingException(ex); cb.handleException(message, t); return; } doHandleAsyncResponse(message, r, cb); }
private void closeAsyncResponseIfPossible(Response r, Message outMessage, JaxrsClientCallback<?> cb) { if (responseStreamCanBeClosed(outMessage, cb.getResponseClass())) { r.close(); } }
public boolean isCancelled() { return callback.isCancelled(); } public boolean isDone() {
protected JaxrsClientCallback<?> newJaxrsClientCallback(InvocationCallback<Object> asyncCallback, Class<?> responseClass, Type outGenericType) { return new JaxrsClientCallback<>(asyncCallback, responseClass, outGenericType); }