You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2013/09/30 13:11:02 UTC

svn commit: r1527513 - in /tomee/tomee/trunk/server: openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/OptionsTest.java openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java

Author: rmannibucau
Date: Mon Sep 30 11:11:02 2013
New Revision: 1527513

URL: http://svn.apache.org/r1527513
Log:
adding a test on OPTIONS request method

Added:
    tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/OptionsTest.java
Modified:
    tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java

Added: tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/OptionsTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/OptionsTest.java?rev=1527513&view=auto
==============================================================================
--- tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/OptionsTest.java (added)
+++ tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/OptionsTest.java Mon Sep 30 11:11:02 2013
@@ -0,0 +1,62 @@
+/*
+ *     Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+package org.apache.openejb.server.cxf.rs;
+
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.Singleton;
+import javax.ws.rs.OPTIONS;
+import javax.ws.rs.Path;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@EnableServices("jax-rs")
+@RunWith(ApplicationComposer.class)
+public class OptionsTest {
+    @Module
+    @Classes(OptionsBean.class)
+    public static WebApp service() throws Exception {
+        return new WebApp().contextRoot("app");
+    }
+
+    @Test
+    public void check() throws Exception {
+        final HttpURLConnection conn = HttpURLConnection.class.cast(new URL("http://127.0.0.1:4204/app/options").openConnection());
+        conn.setRequestMethod("OPTIONS");
+        assertEquals("ok", IO.slurp(conn.getInputStream()));
+        conn.getInputStream().close();
+    }
+
+    @Singleton
+    @Path("options")
+    public static class OptionsBean {
+        @OPTIONS
+        public String providers() {
+            return "ok";
+        }
+
+    }
+}

Modified: tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java?rev=1527513&r1=1527512&r2=1527513&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java (original)
+++ tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java Mon Sep 30 11:11:02 2013
@@ -582,7 +582,8 @@ public class HttpRequestImpl implements 
     }
 
     private boolean hasBody() {
-        return !method.equals(Method.GET.name()) && !method.equals(Method.DELETE.name()) && !method.equals(Method.HEAD.name());
+        return !method.equals(Method.GET.name()) && !method.equals(Method.DELETE.name())
+            && !method.equals(Method.HEAD.name()) && !method.equals(Method.OPTIONS.name());
     }
     /**
      * reads the body from the data input passed in
@@ -598,7 +599,8 @@ public class HttpRequestImpl implements 
 
         contentType = getHeader(HttpRequest.HEADER_CONTENT_TYPE);
 
-        if (hasBody() && FORM_URL_ENCODED.equals(contentType)) {
+        final boolean hasBody = hasBody();
+        if (hasBody && FORM_URL_ENCODED.equals(contentType)) {
             String rawParams;
 
             try {
@@ -634,7 +636,7 @@ public class HttpRequestImpl implements 
                 formParams.put(name, value);
                     //System.out.println(name + ": " + value);
             }
-        } else if (hasBody() && CHUNKED.equals(headers.get(TRANSFER_ENCODING))) {
+        } else if (hasBody && CHUNKED.equals(headers.get(TRANSFER_ENCODING))) {
             try {
                 ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
                 for (String line = in.readLine(); line != null; line = in.readLine()) {
@@ -658,7 +660,7 @@ public class HttpRequestImpl implements 
             } catch (Exception e) {
                 throw (IOException)new IOException("Unable to read chunked body").initCause(e);
             }
-        } else if (hasBody()){
+        } else if (hasBody){
             // TODO This really is terrible
             body = readContent(in);
             this.in = new ServletByteArrayIntputStream(body);