You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by am...@apache.org on 2018/08/01 22:06:18 UTC
[cxf] 07/08: Remove unnecessary changes for InvocationCallback
This is an automated email from the ASF dual-hosted git repository.
amccright pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit a1693399ff7635f90b029308073d143adf8b450a
Author: Andy McCright <j....@gmail.com>
AuthorDate: Tue Jul 17 20:22:12 2018 -0500
Remove unnecessary changes for InvocationCallback
---
.../apache/cxf/jaxrs/client/ClientProxyImpl.java | 24 +++---
.../cxf/jaxrs/client/JaxrsClientCallback.java | 5 +-
.../microprofile/client/MPRestClientCallback.java} | 87 +++++-----------------
.../client/proxy/MicroProfileClientProxyImpl.java | 8 ++
4 files changed, 41 insertions(+), 83 deletions(-)
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index cc5dfea..7993aae 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -767,10 +767,6 @@ public class ClientProxyImpl extends AbstractClient implements
}
outMessage.getInterceptorChain().add(bodyWriter);
- int invocationCallbackIdx = Arrays.asList(ori.getInParameterTypes()).indexOf(InvocationCallback.class);
- if (invocationCallbackIdx > -1) {
- outMessage.setContent(InvocationCallback.class, methodParams[invocationCallbackIdx]);
- }
Map<String, Object> reqContext = getRequestContext(outMessage);
reqContext.put(OperationResourceInfo.class.getName(), ori);
reqContext.put(PROXY_METHOD_PARAM_BODY_INDEX, bodyIndex);
@@ -805,8 +801,8 @@ public class ClientProxyImpl extends AbstractClient implements
}
protected InvocationCallback<Object> checkAsyncCallback(OperationResourceInfo ori,
- Map<String, Object> reqContext,
- Message outMessage) {
+ Map<String, Object> reqContext,
+ Message outMessage) {
Object callbackProp = reqContext.get(InvocationCallback.class.getName());
if (callbackProp != null) {
if (callbackProp instanceof Collection) {
@@ -840,11 +836,12 @@ public class ClientProxyImpl extends AbstractClient implements
return null;
}
- protected Object doInvokeAsync(OperationResourceInfo ori, Message outMessage,
- InvocationCallback<Object> asyncCallback) {
+ protected Object doInvokeAsync(OperationResourceInfo ori,
+ Message outMessage,
+ InvocationCallback<Object> asyncCallback) {
outMessage.getExchange().setSynchronous(false);
setAsyncMessageObserverIfNeeded(outMessage.getExchange());
- JaxrsClientCallback<?> cb = new JaxrsClientCallback<Object>(asyncCallback,
+ JaxrsClientCallback<?> cb = newJaxrsClientCallback(asyncCallback,
ori.getMethodToInvoke().getReturnType(), ori.getMethodToInvoke().getGenericReturnType());
outMessage.getExchange().put(JaxrsClientCallback.class, cb);
doRunInterceptorChain(outMessage);
@@ -852,6 +849,12 @@ public class ClientProxyImpl extends AbstractClient implements
return null;
}
+ protected JaxrsClientCallback<?> newJaxrsClientCallback(InvocationCallback<Object> asyncCallback,
+ Class<?> responseClass,
+ Type outGenericType) {
+ return new JaxrsClientCallback<Object>(asyncCallback, responseClass, outGenericType);
+ }
+
@Override
protected Object retryInvoke(URI newRequestURI,
MultivaluedMap<String, String> headers,
@@ -876,8 +879,7 @@ public class ClientProxyImpl extends AbstractClient implements
Method method = outMessage.getExchange().get(Method.class);
checkResponse(method, r, outMessage);
- if (outMessage.getExchange().isSynchronous() && (method.getReturnType() == Void.class
- || method.getReturnType() == Void.TYPE)) {
+ if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE) {
return null;
}
if (method.getReturnType() == Response.class
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
index 227242f..98443c5 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
@@ -22,7 +22,6 @@ package org.apache.cxf.jaxrs.client;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -65,7 +64,7 @@ public class JaxrsClientCallback<T> extends ClientCallback {
return result;
}
- public CompletableFuture<T> createFuture() {
+ public Future<T> createFuture() {
return new JaxrsResponseFuture<T>(this);
}
@@ -97,7 +96,7 @@ public class JaxrsClientCallback<T> extends ClientCallback {
- static class JaxrsResponseFuture<T> extends CompletableFuture<T> implements Future<T> {
+ static class JaxrsResponseFuture<T> implements Future<T> {
JaxrsClientCallback<T> callback;
JaxrsResponseFuture(JaxrsClientCallback<T> cb) {
callback = cb;
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MPRestClientCallback.java
similarity index 52%
copy from rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
copy to rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MPRestClientCallback.java
index 227242f..a6863a3 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
+++ b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MPRestClientCallback.java
@@ -17,11 +17,10 @@
* under the License.
*/
-package org.apache.cxf.jaxrs.client;
+package org.apache.cxf.microprofile.client;
import java.lang.reflect.Type;
import java.util.Map;
-import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -30,76 +29,24 @@ import java.util.concurrent.TimeoutException;
import javax.ws.rs.client.InvocationCallback;
-import org.apache.cxf.endpoint.ClientCallback;
+import org.apache.cxf.jaxrs.client.JaxrsClientCallback;
-public class JaxrsClientCallback<T> extends ClientCallback {
- private final InvocationCallback<T> handler;
- private final Type outType;
- private final Class<?> responseClass;
+public class MPRestClientCallback<T> extends JaxrsClientCallback {
- public JaxrsClientCallback(final InvocationCallback<T> handler,
- Class<?> responseClass,
- Type outGenericType) {
- this.handler = handler;
- this.outType = outGenericType;
- this.responseClass = responseClass;
- }
-
- public InvocationCallback<T> getHandler() {
- return handler;
- }
-
- public Type getOutGenericType() {
- return outType;
- }
- public Class<?> getResponseClass() {
- return responseClass;
+ public MPRestClientCallback(InvocationCallback<T> handler,
+ Class<?> responseClass,
+ Type outGenericType) {
+ super(handler, responseClass, outGenericType);
}
@Override
- public boolean cancel(boolean mayInterruptIfRunning) {
- boolean result = super.cancel(mayInterruptIfRunning);
- if (result && handler != null) {
- handler.failed(new CancellationException());
- }
- return result;
- }
-
- public CompletableFuture<T> createFuture() {
- return new JaxrsResponseFuture<T>(this);
+ public Future<T> createFuture() {
+ return new MPRestClientResponseFuture<T>(this);
}
- @SuppressWarnings("unchecked")
- public void handleResponse(Map<String, Object> ctx, Object[] res) {
- context = ctx;
- result = res;
- if (handler != null) {
- handler.completed((T)res[0]);
- }
- done = true;
- synchronized (this) {
- notifyAll();
- }
- }
-
- @Override
- public void handleException(Map<String, Object> ctx, final Throwable ex) {
- context = ctx;
- exception = ex;
- if (handler != null) {
- handler.failed(exception);
- }
- done = true;
- synchronized (this) {
- notifyAll();
- }
- }
-
-
-
- static class JaxrsResponseFuture<T> extends CompletableFuture<T> implements Future<T> {
- JaxrsClientCallback<T> callback;
- JaxrsResponseFuture(JaxrsClientCallback<T> cb) {
+ static class MPRestClientResponseFuture<T> extends CompletableFuture<T> implements Future<T> {
+ MPRestClientCallback<T> callback;
+ MPRestClientResponseFuture(MPRestClientCallback<T> cb) {
callback = cb;
}
@@ -118,8 +65,9 @@ public class JaxrsClientCallback<T> extends ClientCallback {
try {
return getObject(callback.get()[0]);
} catch (InterruptedException ex) {
- if (callback.handler != null) {
- callback.handler.failed(ex);
+ InvocationCallback<T> handler = callback.getHandler();
+ if (handler != null) {
+ handler.failed(ex);
}
throw ex;
}
@@ -129,8 +77,9 @@ public class JaxrsClientCallback<T> extends ClientCallback {
try {
return getObject(callback.get(timeout, unit)[0]);
} catch (InterruptedException ex) {
- if (callback.handler != null) {
- callback.handler.failed(ex);
+ InvocationCallback<T> handler = callback.getHandler();
+ if (handler != null) {
+ handler.failed(ex);
}
throw ex;
}
diff --git a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
index 384b188..9038f2b 100644
--- a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
+++ b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
@@ -37,6 +37,7 @@ import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
import org.apache.cxf.message.Message;
+import org.apache.cxf.microprofile.client.MPRestClientCallback;
import org.apache.cxf.microprofile.client.MicroProfileClientProviderFactory;
import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;
@@ -100,6 +101,13 @@ public class MicroProfileClientProxyImpl extends ClientProxyImpl {
}
@Override
+ protected JaxrsClientCallback<?> newJaxrsClientCallback(InvocationCallback<Object> asyncCallback,
+ Class<?> responseClass,
+ Type outGenericType) {
+ return new MPRestClientCallback<Object>(asyncCallback, responseClass, outGenericType);
+ }
+
+ @Override
protected void checkResponse(Method m, Response r, Message inMessage) throws Throwable {
MicroProfileClientProviderFactory factory = MicroProfileClientProviderFactory.getInstance(inMessage);
List<ResponseExceptionMapper<?>> mappers = factory.createResponseExceptionMapper(inMessage,