summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java74
1 files changed, 39 insertions, 35 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
index f66ecfdbb5..c47473b3ee 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.util.List;
@@ -81,51 +82,54 @@ public class JAXRSOperationSelectorInterceptor implements Interceptor {
}
public Message invoke(Message msg) {
- try {
- HTTPContext bindingContext = (HTTPContext)msg.getBindingContext();
-
- // By-pass the operation selector
- if (bindingContext == null) {
- return getNext().invoke(msg);
- }
- String path = URLDecoder.decode(HTTPUtils.getRequestPath(bindingContext.getHttpRequest()), "UTF-8");
+ HTTPContext bindingContext = (HTTPContext)msg.getBindingContext();
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
+ // By-pass the operation selector
+ if (bindingContext == null) {
+ return getNext().invoke(msg);
+ }
- List<Operation> operations =
- filterOperationsByHttpMethod(interfaceContract, bindingContext.getHttpRequest().getMethod());
+ String path = null;
+ try {
+ path = URLDecoder.decode(HTTPUtils.getRequestPath(bindingContext.getHttpRequest()), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException(e);
+ }
- Operation operation = findOperation(path, operations);
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
- final JavaOperation javaOperation = (JavaOperation)operation;
- final Method method = javaOperation.getJavaMethod();
+ List<Operation> operations =
+ filterOperationsByHttpMethod(interfaceContract, bindingContext.getHttpRequest().getMethod());
- if (path != null && path.length() > 0) {
- if (method.getAnnotation(Path.class) != null) {
- msg.setBody(new Object[] {path});
- }
- }
+ Operation operation = findOperation(path, operations);
- // FIXME: [rfeng] We should follow JAX-RS rules to identify the entity parameter
- Class<?>[] paramTypes = method.getParameterTypes();
- if (paramTypes.length == 1) {
- Class<?> type = paramTypes[0];
- InputStream is = (InputStream)((Object[])msg.getBody())[0];
- Object target = convert(is, bindingContext.getHttpRequest().getContentType(), type);
- msg.setBody(new Object[] {target});
- } else if (paramTypes.length == 0) {
- msg.setBody(null);
- }
+ final JavaOperation javaOperation = (JavaOperation)operation;
+ final Method method = javaOperation.getJavaMethod();
- msg.setOperation(operation);
+ if (path != null && path.length() > 0) {
+ if (method.getAnnotation(Path.class) != null) {
+ msg.setBody(new Object[] {path});
+ }
+ }
- return getNext().invoke(msg);
- } catch (Exception e) {
- throw new RuntimeException(e);
+ // FIXME: [rfeng] We should follow JAX-RS rules to identify the entity parameter
+ Class<?>[] paramTypes = method.getParameterTypes();
+ if (paramTypes.length == 1) {
+ Class<?> type = paramTypes[0];
+ InputStream is = (InputStream)((Object[])msg.getBody())[0];
+ Object target = convert(is, bindingContext.getHttpRequest().getContentType(), type);
+ msg.setBody(new Object[] {target});
+ } else if (paramTypes.length == 0) {
+ msg.setBody(null);
}
+
+ msg.setOperation(operation);
+
+ return getNext().invoke(msg);
+
}
private Object convert(InputStream content, String contentType, Class<?> type) {