You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2009/12/23 11:07:32 UTC

svn commit: r893453 - in /incubator/clerezza/issues/CLEREZZA-48: ./ org.apache.clerezza.triaxrs/ org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/

Author: reto
Date: Wed Dec 23 10:07:31 2009
New Revision: 893453

URL: http://svn.apache.org/viewvc?rev=893453&view=rev
Log:
CLEREZZA-48: Agron's patch

Added:
    incubator/clerezza/issues/CLEREZZA-48/
    incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/
      - copied from r893434, incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/
Modified:
    incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java
    incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java
    incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/WebRequestImpl.java

Modified: incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java?rev=893453&r1=893434&r2=893453&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java (original)
+++ incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/ResponseProcessor.java Wed Dec 23 10:07:31 2009
@@ -43,6 +43,7 @@
 
 import javax.activation.UnsupportedDataTypeException;
 import javax.security.auth.Subject;
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.GenericEntity;
@@ -63,6 +64,7 @@
 import org.wymiwyg.wrhapi.HandlerException;
 import org.wymiwyg.wrhapi.HeaderName;
 import org.wymiwyg.wrhapi.MessageBody;
+import org.wymiwyg.wrhapi.Method;
 import org.wymiwyg.wrhapi.Response;
 import org.wymiwyg.wrhapi.ResponseStatus;
 import org.wymiwyg.wrhapi.util.MessageBody2Write;
@@ -106,6 +108,21 @@
 		if (entity == null) {
 			response.setHeader(HeaderName.CONTENT_LENGTH, 0);
 
+            String method = request.getMethod();
+            if (method != null && Method.OPTIONS.toString().contains(method)) {
+                List<String> allowed = new ArrayList<String>();
+                for (Annotation annotation : annotations) {
+                    HttpMethod httpMethod = annotation.annotationType().getAnnotation(HttpMethod.class);
+                    String annotationValue;
+                    if (httpMethod != null) {
+                        annotationValue = annotation.annotationType().getSimpleName();
+                        allowed.add(annotationValue);
+                    }
+                }
+                response.setHeader(HeaderName.ALLOW, allowed.toString()
+                        .replace("[", "").replace("]", "").replace(" ", ""));
+            }
+
 			if (responseStatus == ResponseStatus.SUCCESS.getCode()) {
 				response.setResponseStatus(ResponseStatus.NO_CONTENT);
 				flushHeaders(headerMap, response);

Modified: incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java?rev=893453&r1=893434&r2=893453&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java (original)
+++ incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java Wed Dec 23 10:07:31 2009
@@ -27,8 +27,10 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
@@ -525,7 +527,17 @@
 	
 	private ProcessableResponse responsDefaultOption(WebRequest request,
 			Set<Method> candidateMethods) {
-		throw new UnsupportedOperationException("Not yet implemented");
+        
+		List<Annotation> annotationList = new ArrayList<Annotation>();
+        Annotation[] annotations = {};
+        for (Method candidateMethod : candidateMethods){
+            Annotation[] declaredAnnotations = candidateMethod.getDeclaredAnnotations();
+            for (Annotation annotation : declaredAnnotations) {
+                annotationList.add(annotation);
+            }
+        }
+        return ProcessableResponse.createProcessableResponse(null,
+                annotationList.toArray(annotations), null, null, null);
 	}
 
 	private String templateUrlEncode(String value) {

Modified: incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/WebRequestImpl.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/WebRequestImpl.java?rev=893453&r1=893434&r2=893453&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/WebRequestImpl.java (original)
+++ incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/WebRequestImpl.java Wed Dec 23 10:07:31 2009
@@ -39,6 +39,7 @@
 import org.apache.clerezza.triaxrs.util.CaseInsensitiveMap;
 import org.wymiwyg.wrhapi.HandlerException;
 import org.wymiwyg.wrhapi.HeaderName;
+import org.wymiwyg.wrhapi.Method;
 import org.wymiwyg.wrhapi.Request;
 
 /**
@@ -228,7 +229,16 @@
 
 	@Override
 	public String getMethod() {
-		throw new UnsupportedOperationException("Not supported yet.");
+		try {
+            Method method = wrhapiRequest.getMethod();
+            if (method != null) {
+                return (method.toString()).substring(8);
+            } else {
+                return null;
+            }
+        } catch (HandlerException ex) {
+            throw new RuntimeException(ex);
+        }
 	}
 
 	@Override