You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2016/09/15 21:25:39 UTC
[14/20] incubator-juneau git commit: Clean up Javadocs
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/StaticFilesResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/StaticFilesResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/StaticFilesResource.java
deleted file mode 100755
index 6eac65b..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/StaticFilesResource.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// ***************************************************************************************************************************
-// * 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.juneau.server;
-
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testStaticFiles",
- staticFiles="{xdocs:'xdocs'}"
-)
-public class StaticFilesResource extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Tests the @RestResource(staticFiles) annotation.
- //====================================================================================================
- @RestMethod(name="GET", path="/*")
- public String testXdocs() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java
deleted file mode 100755
index de06b18..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// ***************************************************************************************************************************
-// * 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.juneau.server;
-
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- pojoSwaps={TransformsResource.SwapA1.class}
-)
-public class TransformsParentResource extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java
deleted file mode 100755
index ca47d95..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java
+++ /dev/null
@@ -1,113 +0,0 @@
-// ***************************************************************************************************************************
-// * 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.juneau.server;
-
-import org.apache.juneau.parser.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.transform.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testTransforms",
- pojoSwaps={TransformsResource.SwapA2.class}
-)
-public class TransformsResource extends TransformsParentResource {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Test class transform overrides parent class transform
- // Should return "A2-1".
- //====================================================================================================
- @RestMethod(name="GET", path="/testClassTransformOverridesParentClassTransform")
- public A testClassTransformOverridesParentClassTransform() {
- return new A();
- }
- @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform")
- public A test1b(@Content A a) {
- return a;
- }
- @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform/{a}")
- public A test1c(@Attr A a) {
- return a;
- }
-
- //====================================================================================================
- // Test method transform overrides class transform
- // Should return "A3-1".
- //====================================================================================================
- @RestMethod(name="GET", path="/testMethodTransformOverridesClassTransform", pojoSwaps={SwapA3.class})
- public A test2a() {
- return new A();
- }
- @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform", pojoSwaps={SwapA3.class})
- public A test2b(@Content A a) {
- return a;
- }
- @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform/{a}", pojoSwaps={SwapA3.class})
- public A test2c(@Attr A a) {
- return a;
- }
-
-
- public static class A {
- public int f1;
- }
-
- public static class SwapA1 extends PojoSwap<A,String> {
- @Override /* PojoSwap */
- public String swap(A a) throws SerializeException {
- return "A1-" + a.f1;
- }
- @Override /* PojoSwap */
- public A unswap(String in) throws ParseException {
- if (! in.startsWith("A1"))
- throw new RuntimeException("Invalid input for SwapA1!");
- A a = new A();
- a.f1 = Integer.parseInt(in.substring(3));
- return a;
- }
- }
-
- public static class SwapA2 extends PojoSwap<A,String> {
- @Override /* PojoSwap */
- public String swap(A a) throws SerializeException {
- return "A2-" + a.f1;
- }
- @Override /* PojoSwap */
- public A unswap(String in) throws ParseException {
- if (! in.startsWith("A2"))
- throw new RuntimeException("Invalid input for SwapA2!");
- A a = new A();
- a.f1 = Integer.parseInt(in.substring(3));
- return a;
- }
- }
-
- public static class SwapA3 extends PojoSwap<A,String> {
- @Override /* PojoSwap */
- public String swap(A a) throws SerializeException {
- return "A3-" + a.f1;
- }
- @Override /* PojoSwap */
- public A unswap(String in) throws ParseException {
- if (! in.startsWith("A3"))
- throw new RuntimeException("Invalid input for SwapA3!");
- A a = new A();
- a.f1 = Integer.parseInt(in.substring(3));
- return a;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java
deleted file mode 100755
index bdd586a..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java
+++ /dev/null
@@ -1,120 +0,0 @@
-// ***************************************************************************************************************************
-// * 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.juneau.server;
-
-import org.apache.juneau.*;
-import org.apache.juneau.server.annotation.*;
-
-@RestResource(
- path="/testuris",
- children={
- UrisResource.Child.class
- }
-)
-public class UrisResource extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/*")
- public ObjectMap test1(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "root.test1");
- }
-
- @RestMethod(name="GET", path="/test2/*")
- public ObjectMap test2(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "root.test2");
- }
-
- @RestMethod(name="GET", path="/test3%2Ftest3/*")
- public ObjectMap test3(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "root.test3");
- }
-
- @RestMethod(name="GET", path="/test4/test4/*")
- public ObjectMap test4(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "root.test4");
- }
-
- @RestResource(
- path="/child",
- children={
- GrandChild.class
- }
- )
- public static class Child extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/*")
- public ObjectMap test1(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "child.test1");
- }
-
- @RestMethod(name="GET", path="/test2/*")
- public ObjectMap test2(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "child.test2");
- }
-
- @RestMethod(name="GET", path="/test3%2Ftest3/*")
- public ObjectMap test3(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "child.test3");
- }
-
- @RestMethod(name="GET", path="/test4/test4/*")
- public ObjectMap test4(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "child.test4");
- }
- }
-
- @RestResource(
- path="/grandchild"
- )
- public static class GrandChild extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/*")
- public ObjectMap test1(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "grandchild.test1");
- }
-
- @RestMethod(name="GET", path="/test2/*")
- public ObjectMap test2(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "grandchild.test2");
- }
-
- @RestMethod(name="GET", path="/test3%2Ftest3/*")
- public ObjectMap test3(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "grandchild.test3");
- }
-
- @RestMethod(name="GET", path="/test4/test4/*")
- public ObjectMap test4(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "grandchild.test4");
- }
- }
-
- static ObjectMap getPathInfoObject(RestRequest req) throws Exception {
- ObjectMap m = new ObjectMap();
- m.put("contextPath", req.getContextPath());
- m.put("pathInfo", req.getPathInfo());
- m.put("pathRemainder", req.getPathRemainder());
- m.put("pathTranslated", req.getPathTranslated());
- m.put("requestParentURI", req.getRequestParentURI());
- m.put("requestURI", req.getRequestURI());
- m.put("requestURL", req.getRequestURL());
- m.put("servletPath", req.getServletPath());
- m.put("servletURI", req.getServletURI());
- m.put("testURL1", req.getURL("testURL"));
- m.put("testURL2", req.getURL("/testURL"));
- m.put("testURL3", req.getURL("http://testURL"));
- return m;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java
deleted file mode 100755
index c3b9f39..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// ***************************************************************************************************************************
-// * 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.juneau.server;
-
-import org.apache.juneau.json.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testUrlContent",
- serializers={PlainTextSerializer.class},
- parsers={JsonParser.class}
-)
-public class UrlContentResource extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/testString")
- public String testString(@Content String content) {
- return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
- }
-
- @RestMethod(name="GET", path="/testEnum")
- public String testEnum(@Content TestEnum content) {
- return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
- }
-
- public static enum TestEnum {
- X1
- }
-
- @RestMethod(name="GET", path="/testBean")
- public String testBean(@Content TestBean content) throws Exception {
- return String.format("class=%s, value=%s", content.getClass().getName(), JsonSerializer.DEFAULT_LAX.serialize(content));
- }
-
- public static class TestBean {
- public int f1;
- public String f2;
- }
-
- @RestMethod(name="GET", path="/testInt")
- public String testString(@Content Integer content) {
- return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/AcceptCharsetResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/AcceptCharsetResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/AcceptCharsetResource.java
new file mode 100755
index 0000000..bc43ad4
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/AcceptCharsetResource.java
@@ -0,0 +1,76 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import static org.apache.juneau.server.RestServletContext.*;
+
+import java.io.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testAcceptCharset",
+ serializers={PlainTextSerializer.class},
+ properties={
+ // Some versions of Jetty default to ISO8601, so specify UTF-8 for test consistency.
+ @Property(name=REST_defaultCharset,value="utf-8")
+ }
+)
+public class AcceptCharsetResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Test that Q-values are being resolved correctly.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testQValues")
+ public String testQValues() {
+ return "foo";
+ }
+
+ //====================================================================================================
+ // Validate various Accept-Charset variations.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testCharsetOnResponse", parsers=TestParser.class, serializers=TestSerializer.class)
+ public String testCharsetOnResponse(@Content String in) {
+ return in;
+ }
+
+ @Consumes("text/plain")
+ public static class TestParser extends InputStreamParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)session.getProperties().getString("characterEncoding");
+ }
+ }
+
+ @Produces("text/plain")
+ public static class TestSerializer extends OutputStreamSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ Writer w = new OutputStreamWriter(session.getOutputStream());
+ w.append(o.toString()).append('/').append(session.getProperties().getString("characterEncoding"));
+ w.flush();
+ w.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/BeanContextPropertiesResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/BeanContextPropertiesResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/BeanContextPropertiesResource.java
new file mode 100755
index 0000000..872c774
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/BeanContextPropertiesResource.java
@@ -0,0 +1,42 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.transforms.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testBeanContext",
+ pojoSwaps=DateSwap.ISO8601DTZ.class
+)
+public class BeanContextPropertiesResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Validate that transforms defined on class transform to underlying bean context.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testClassTransforms/{d1}")
+ public Reader testClassTransforms(@Attr("d1") Date d1, @Param("d2") Date d2, @Header("X-D3") Date d3) throws Exception {
+ DateSwap df = DateSwap.ISO8601DTZ.class.newInstance();
+ return new StringReader(
+ "d1="+df.swap(d1)+",d2="+df.swap(d2)+",d3="+df.swap(d3)+""
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/CallbackStringsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/CallbackStringsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/CallbackStringsResource.java
new file mode 100755
index 0000000..8b8ee45
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/CallbackStringsResource.java
@@ -0,0 +1,53 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import java.util.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testCallback"
+)
+public class CallbackStringsResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Test GET
+ //====================================================================================================
+ @RestMethod(name="GET", path="/")
+ public ObjectMap test1(RestRequest req) throws Exception {
+ return new ObjectMap().append("method","GET").append("headers", getFooHeaders(req)).append("content", req.getInputAsString());
+ }
+
+ //====================================================================================================
+ // Test PUT
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/")
+ public ObjectMap testCharsetOnResponse(RestRequest req) throws Exception {
+ return new ObjectMap().append("method","PUT").append("headers", getFooHeaders(req)).append("content", req.getInputAsString());
+ }
+
+ private Map<String,Object> getFooHeaders(RestRequest req) {
+ Map<String,Object> m = new TreeMap<String,Object>();
+ for (Map.Entry<String,Object> e : req.getHeaders().entrySet())
+ if (e.getKey().startsWith("Foo-"))
+ m.put(e.getKey(), e.getValue());
+ return m;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/CharsetEncodingsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/CharsetEncodingsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/CharsetEncodingsResource.java
new file mode 100755
index 0000000..814455a
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/CharsetEncodingsResource.java
@@ -0,0 +1,55 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testCharsetEncodings",
+ defaultRequestHeaders={"Accept: text/s", "Content-Type: text/p"},
+ parsers={CharsetEncodingsResource.CtParser.class}, serializers={CharsetEncodingsResource.ASerializer.class}
+)
+public class CharsetEncodingsResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Consumes("text/p")
+ public static class CtParser extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)IOUtils.read(session.getReader());
+ }
+ }
+
+ @Produces("text/s")
+ public static class ASerializer extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ session.getWriter().write(o.toString());
+ }
+ }
+
+ @RestMethod(name="PUT", path="/")
+ public String test1(RestRequest req, @Content String in) {
+ return req.getCharacterEncoding() + "/" + in + "/" + req.getCharacterEncoding();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/ClientVersionResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/ClientVersionResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/ClientVersionResource.java
new file mode 100644
index 0000000..f3a10cb
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/ClientVersionResource.java
@@ -0,0 +1,93 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import org.apache.juneau.microservice.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testClientVersion",
+ children={
+ ClientVersionResource.DefaultHeader.class,
+ ClientVersionResource.CustomHeader.class
+ }
+)
+@SuppressWarnings("serial")
+public class ClientVersionResource extends Resource {
+
+ @RestResource(
+ path="/defaultHeader"
+ )
+ public static class DefaultHeader extends Resource {
+
+ @RestMethod(name="GET", path="/")
+ public String test0() {
+ return "no-version";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[0.0,1.0)")
+ public String test1() {
+ return "[0.0,1.0)";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[1.0,1.0]")
+ public String test2() {
+ return "[1.0,1.0]";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[1.1,2)")
+ public String test3() {
+ return "[1.1,2)";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="2")
+ public String test4() {
+ return "2";
+ }
+ }
+
+ @RestResource(
+ path="/customHeader",
+ clientVersionHeader="Custom-Client-Version"
+ )
+ public static class CustomHeader extends Resource {
+
+ @RestMethod(name="GET", path="/")
+ public String test0() {
+ return "no-version";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[0.0,1.0)")
+ public String test1() {
+ return "[0.0,1.0)";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[1.0,1.0]")
+ public String test2() {
+ return "[1.0,1.0]";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[1.1,2)")
+ public String test3() {
+ return "[1.1,2)";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="2")
+ public String test4() {
+ return "2";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/ConfigResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/ConfigResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/ConfigResource.java
new file mode 100755
index 0000000..bace723
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/ConfigResource.java
@@ -0,0 +1,38 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import org.apache.juneau.ini.*;
+import org.apache.juneau.microservice.*;
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testConfig"
+)
+@SuppressWarnings("serial")
+public class ConfigResource extends Resource {
+
+ @RestMethod(name="GET", path="/")
+ public ConfigFile test1(RestRequest req) {
+ return req.getConfig();
+ }
+
+ @RestMethod(name="GET", path="/{key}/{class}")
+ public Object test2(RestRequest req, @Attr("key") String key, @Attr("class") Class<?> c) throws Exception {
+ return req.getConfig().getObject(c, key);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/ContentResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/ContentResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/ContentResource.java
new file mode 100755
index 0000000..02e925d
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/ContentResource.java
@@ -0,0 +1,81 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import static org.apache.juneau.server.RestServletContext.*;
+
+import java.util.*;
+
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testContent",
+ properties={
+ @Property(name=REST_allowMethodParam, value="*")
+ }
+)
+public class ContentResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @RestMethod(name="POST", path="/boolean")
+ public boolean testBool(@Content boolean b) {
+ return b;
+ }
+
+ @RestMethod(name="POST", path="/Boolean")
+ public Boolean testBoolean(@Content Boolean b) {
+ return b;
+ }
+
+ @RestMethod(name="POST", path="/int")
+ public int testInt(@Content int i) {
+ return i;
+ }
+
+ @RestMethod(name="POST", path="/Integer")
+ public Integer testInteger(@Content Integer i) {
+ return i;
+ }
+
+ @RestMethod(name="POST", path="/float")
+ public float testFloat(@Content float f) {
+ return f;
+ }
+
+ @RestMethod(name="POST", path="/Float")
+ public Float testFloat2(@Content Float f) {
+ return f;
+ }
+
+ @RestMethod(name="POST", path="/Map")
+ public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
+ return m;
+ }
+
+ @RestMethod(name="POST", path="/B")
+ public DTO2s.B testPojo1(@Content DTO2s.B b) {
+ return b;
+ }
+
+ @RestMethod(name="POST", path="/C")
+ public DTO2s.C testPojo2(@Content DTO2s.C c) {
+ return c;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/DTO2s.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/DTO2s.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/DTO2s.java
new file mode 100755
index 0000000..ad33642
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/DTO2s.java
@@ -0,0 +1,139 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import java.util.*;
+
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.urlencoding.annotation.*;
+
+public class DTO2s {
+
+ @Bean(sort=true)
+ public static class A {
+ public String a;
+ public int b;
+ public boolean c;
+
+ public static A create() {
+ A t = new A();
+ t.a = "a";
+ t.b = 1;
+ t.c = true;
+ return t;
+ }
+
+ }
+
+ @SuppressWarnings("serial")
+ @Bean(sort=true)
+ public static class B {
+ public String[] f01;
+ public List<String> f02;
+ public int[] f03;
+ public List<Integer> f04;
+ public String[][] f05;
+ public List<String[]> f06;
+ public A[] f07;
+ public List<A> f08;
+ public A[][] f09;
+ public List<List<A>> f10;
+
+ private String[] f11;
+ private List<String> f12;
+ private int[] f13;
+ private List<Integer> f14;
+ private String[][] f15;
+ private List<String[]> f16;
+ private A[] f17;
+ private List<A> f18;
+ private A[][] f19;
+ private List<List<A>> f20;
+
+ public String[] getF11() { return f11; }
+ public List<String> getF12() { return f12; }
+ public int[] getF13() { return f13; }
+ public List<Integer> getF14() { return f14; }
+ public String[][] getF15() { return f15; }
+ public List<String[]> getF16() { return f16; }
+ public A[] getF17() { return f17; }
+ public List<A> getF18() { return f18; }
+ public A[][] getF19() { return f19; }
+ public List<List<A>> getF20() { return f20; }
+
+ public void setF11(String[] f11) { this.f11 = f11; }
+ public void setF12(List<String> f12) { this.f12 = f12; }
+ public void setF13(int[] f13) { this.f13 = f13; }
+ public void setF14(List<Integer> f14) { this.f14 = f14; }
+ public void setF15(String[][] f15) { this.f15 = f15; }
+ public void setF16(List<String[]> f16) { this.f16 = f16; }
+ public void setF17(A[] f17) { this.f17 = f17; }
+ public void setF18(List<A> f18) { this.f18 = f18; }
+ public void setF19(A[][] f19) { this.f19 = f19; }
+ public void setF20(List<List<A>> f20) { this.f20 = f20; }
+
+ static B create() {
+ B t = new B();
+ t.f01 = new String[]{"a","b"};
+ t.f02 = new ArrayList<String>(){{add("c");add("d");}};
+ t.f03 = new int[]{1,2};
+ t.f04 = new ArrayList<Integer>(){{add(3);add(4);}};
+ t.f05 = new String[][]{{"e","f"},{"g","h"}};
+ t.f06 = new ArrayList<String[]>(){{add(new String[]{"i","j"});add(new String[]{"k","l"});}};
+ t.f07 = new A[]{A.create(),A.create()};
+ t.f08 = new ArrayList<A>(){{add(A.create());add(A.create());}};
+ t.f09 = new A[][]{{A.create()},{A.create()}};
+ t.f10 = new ArrayList<List<A>>(){{add(Arrays.asList(A.create()));add(Arrays.asList(A.create()));}};
+ t.setF11(new String[]{"a","b"});
+ t.setF12(new ArrayList<String>(){{add("c");add("d");}});
+ t.setF13(new int[]{1,2});
+ t.setF14(new ArrayList<Integer>(){{add(3);add(4);}});
+ t.setF15(new String[][]{{"e","f"},{"g","h"}});
+ t.setF16(new ArrayList<String[]>(){{add(new String[]{"i","j"});add(new String[]{"k","l"});}});
+ t.setF17(new A[]{A.create(),A.create()});
+ t.setF18(new ArrayList<A>(){{add(A.create());add(A.create());}});
+ t.setF19(new A[][]{{A.create()},{A.create()}});
+ t.setF20(new ArrayList<List<A>>(){{add(Arrays.asList(A.create()));add(Arrays.asList(A.create()));}});
+ return t;
+ }
+ }
+
+ @UrlEncoding(expandedParams=true)
+ public static class C extends B {
+ @SuppressWarnings("serial")
+ static C create() {
+ C t = new C();
+ t.f01 = new String[]{"a","b"};
+ t.f02 = new ArrayList<String>(){{add("c");add("d");}};
+ t.f03 = new int[]{1,2};
+ t.f04 = new ArrayList<Integer>(){{add(3);add(4);}};
+ t.f05 = new String[][]{{"e","f"},{"g","h"}};
+ t.f06 = new ArrayList<String[]>(){{add(new String[]{"i","j"});add(new String[]{"k","l"});}};
+ t.f07 = new A[]{A.create(),A.create()};
+ t.f08 = new ArrayList<A>(){{add(A.create());add(A.create());}};
+ t.f09 = new A[][]{{A.create()},{A.create()}};
+ t.f10 = new ArrayList<List<A>>(){{add(Arrays.asList(A.create()));add(Arrays.asList(A.create()));}};
+ t.setF11(new String[]{"a","b"});
+ t.setF12(new ArrayList<String>(){{add("c");add("d");}});
+ t.setF13(new int[]{1,2});
+ t.setF14(new ArrayList<Integer>(){{add(3);add(4);}});
+ t.setF15(new String[][]{{"e","f"},{"g","h"}});
+ t.setF16(new ArrayList<String[]>(){{add(new String[]{"i","j"});add(new String[]{"k","l"});}});
+ t.setF17(new A[]{A.create(),A.create()});
+ t.setF18(new ArrayList<A>(){{add(A.create());add(A.create());}});
+ t.setF19(new A[][]{{A.create()},{A.create()}});
+ t.setF20(new ArrayList<List<A>>(){{add(Arrays.asList(A.create()));add(Arrays.asList(A.create()));}});
+ return t;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/DefaultContentTypesResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/DefaultContentTypesResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/DefaultContentTypesResource.java
new file mode 100755
index 0000000..a35a9f3
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/DefaultContentTypesResource.java
@@ -0,0 +1,128 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import static org.apache.juneau.server.annotation.Inherit.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testDefaultContentTypes",
+ defaultRequestHeaders={" Accept : text/s2 "," Content-Type : text/p2 "},
+ parsers={DefaultContentTypesResource.P1.class,DefaultContentTypesResource.P2.class}, serializers={DefaultContentTypesResource.S1.class,DefaultContentTypesResource.S2.class}
+)
+@SuppressWarnings("synthetic-access")
+public class DefaultContentTypesResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Consumes("text/p1")
+ public static class P1 extends DummyParser { public P1() {super("p1");}}
+
+ @Consumes("text/p2")
+ public static class P2 extends DummyParser { public P2() {super("p2");}}
+
+ @Consumes("text/p3")
+ public static class P3 extends DummyParser { public P3() {super("p3");}}
+
+ @Produces("text/s1")
+ public static class S1 extends DummySerializer { public S1() {super("s1");}}
+
+ @Produces("text/s2")
+ public static class S2 extends DummySerializer { public S2() {super("s2");}}
+
+ @Produces("text/s3")
+ public static class S3 extends DummySerializer { public S3() {super("s3");}}
+
+ /**
+ * Test that default Accept and Content-Type headers on servlet annotation are picked up.
+ */
+ @RestMethod(name="PUT", path="/testDefaultHeadersOnServletAnnotation")
+ public String testDefaultHeadersOnServletAnnotation(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on servlet annotation are picked up
+ // when @RestMethod.parsers/serializers annotations are used.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testRestMethodParsersSerializers", parsers=P3.class, serializers=S3.class)
+ public String testRestMethodParsersSerializers(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on servlet annotation are picked up
+ // when @RestMethod.addParsers/addSerializers annotations are used.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testRestMethodAddParsersSerializers", parsers=P3.class, parsersInherit=PARSERS, serializers=S3.class, serializersInherit=SERIALIZERS)
+ public String testRestMethodAddParsersSerializers(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Various Accept incantations.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testAccept")
+ public String testAccept(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on method annotation are picked up
+ // when @RestMethod.parsers/serializers annotations are used.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testRestMethodParserSerializerAnnotations", defaultRequestHeaders={"Accept: text/s3","Content-Type: text/p3"}, parsers=P3.class, serializers=S3.class)
+ public String testRestMethodParserSerializerAnnotations(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on method annotation are picked up
+ // when @RestMethod.addParsers/addSerializers annotations are used.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testRestMethodAddParsersSerializersAnnotations", defaultRequestHeaders={"Accept: text/s3","Content-Type: text/p3"}, parsers=P3.class, parsersInherit=PARSERS, serializers=S3.class, serializersInherit=SERIALIZERS)
+ public String testRestMethodAddParsersSerializersAnnotations(@Content String in) {
+ return in;
+ }
+
+ public static class DummyParser extends ReaderParser {
+ private String name;
+ private DummyParser(String name) {
+ this.name = name;
+ }
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)name;
+ }
+ }
+
+ public static class DummySerializer extends WriterSerializer {
+ private String name;
+ private DummySerializer(String name) {
+ this.name = name;
+ }
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object output) throws Exception {
+ session.getWriter().write(name + "/" + output);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/ErrorConditionsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/ErrorConditionsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/ErrorConditionsResource.java
new file mode 100755
index 0000000..45f9d2c
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/ErrorConditionsResource.java
@@ -0,0 +1,135 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ * Validates correct parser is used.
+ */
+@RestResource(
+ path="/testErrorConditions"
+)
+public class ErrorConditionsResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Test non-existent properties
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testNonExistentBeanProperties")
+ public String testNonExistentBeanProperties(@Content Test1 in) {
+ return "OK";
+ }
+
+ public static class Test1 {
+ public String f1;
+ }
+
+ //====================================================================================================
+ // Test trying to set properties to wrong data type
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testWrongDataType")
+ public String testWrongDataType(@Content Test2 in) {
+ return "OK";
+ }
+
+ public static class Test2 {
+ public int f1;
+ }
+
+ //====================================================================================================
+ // Test trying to parse into class with non-public no-arg constructor.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParseIntoNonConstructableBean")
+ public String testParseIntoNonConstructableBean(@Content Test3a in) {
+ return "OK";
+ }
+
+ public static class Test3a {
+ public int f1;
+ private Test3a(){}
+ }
+
+ //====================================================================================================
+ // Test trying to parse into non-static inner class
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParseIntoNonStaticInnerClass")
+ public String testParseIntoNonStaticInnerClass(@Content Test3b in) {
+ return "OK";
+ }
+
+ public class Test3b {
+ public Test3b(){}
+ }
+
+ //====================================================================================================
+ // Test trying to parse into non-public inner class
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParseIntoNonPublicInnerClass")
+ public String testParseIntoNonPublicInnerClass(@Content Test3b1 in) {
+ return "OK";
+ }
+
+ static class Test3b1 {
+ public Test3b1(){}
+ }
+
+ //====================================================================================================
+ // Test exception thrown during bean construction.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testThrownConstructorException")
+ public String testThrownConstructorException(@Content Test3c in) {
+ return "OK";
+ }
+
+ public static class Test3c {
+ public int f1;
+ private Test3c(){}
+ public static Test3c valueOf(String s) {
+ throw new RuntimeException("Test error");
+ }
+ }
+
+ //====================================================================================================
+ // Test trying to set parameters to invalid types.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testSetParameterToInvalidTypes/{a1}")
+ public String testSetParameterToInvalidTypes(@Param("p1") int t1, @Attr int a1, @Header("h1") int h1) {
+ return "OK";
+ }
+
+ //====================================================================================================
+ // Test SC_NOT_FOUND & SC_METHOD_NOT_ALLOWED
+ //====================================================================================================
+ @RestMethod(name="GET", path="/test404and405")
+ public String test404and405() {
+ return "OK";
+ }
+
+ //====================================================================================================
+ // Test SC_PRECONDITION_FAILED
+ //====================================================================================================
+ @RestMethod(name="GET", path="/test412", matchers=NeverMatcher.class)
+ public String test412() {
+ return "OK";
+ }
+
+ public static class NeverMatcher extends RestMatcher {
+ @Override /* RestMatcher */
+ public boolean matches(RestRequest req) {
+ return false;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/GroupsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/GroupsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/GroupsResource.java
new file mode 100755
index 0000000..4f335bf
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/GroupsResource.java
@@ -0,0 +1,72 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testGroups"
+)
+public class GroupsResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Produces({"text/s1","text/s2"})
+ public static class SSerializer extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object output) throws Exception {
+ session.getWriter().write("text/s," + output);
+ }
+ }
+
+ @Consumes({"text/p1","text/p2"})
+ public static class PParser extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)IOUtils.read(session.getReader());
+ }
+ }
+
+
+ @Override /* RestServlet */
+ public SerializerGroup createSerializers(ObjectMap properties, Class<?>[] beanFilters, Class<?>[] pojoSwaps) throws Exception {
+ return new SerializerGroup().append(SSerializer.class).setProperties(properties).addBeanFilters(beanFilters).addPojoSwaps(pojoSwaps);
+ }
+
+ @Override /* RestServlet */
+ public ParserGroup createParsers(ObjectMap properties, Class<?>[] beanFilters, Class<?>[] pojoSwaps) throws Exception {
+ return new ParserGroup().append(PParser.class).setProperties(properties).addBeanFilters(beanFilters).addPojoSwaps(pojoSwaps);
+ }
+
+ //====================================================================================================
+ // Serializer defined on class.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testSerializerDefinedOnClass")
+ public String testSerializerDefinedOnClass_get() {
+ return "GET";
+ }
+
+ @RestMethod(name="PUT", path="/testSerializerDefinedOnClass")
+ public String testSerializerDefinedOnClass_put(@Content String in) {
+ return in;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/main/java/org/apache/juneau/server/test/GzipResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/test/GzipResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/test/GzipResource.java
new file mode 100755
index 0000000..3810209
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/test/GzipResource.java
@@ -0,0 +1,111 @@
+// ***************************************************************************************************************************
+// * 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.juneau.server.test;
+
+import java.io.*;
+
+import org.apache.juneau.encoders.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.server.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+public class GzipResource {
+
+ //================================================================================
+ // Encoder for "myencoding" encoding
+ //================================================================================
+ public static class MyEncoder extends GzipEncoder {
+ @Override /* Encoder */
+ public String[] getCodings() {
+ return new String[]{"mycoding"};
+ }
+ }
+
+ //====================================================================================================
+ // Test with no compression enabled.
+ //====================================================================================================
+ @RestResource(
+ path="/testGzipOff",
+ serializers=PlainTextSerializer.class,
+ parsers=PlainTextParser.class
+ )
+ public static class TestGzipOff extends RestServlet {
+ private static final long serialVersionUID = 1L;
+ @RestMethod(name="GET", path="/")
+ public String test1get() {
+ return "foo";
+ }
+ @RestMethod(name="PUT", path="/")
+ public String test1put(@Content String in) {
+ return in;
+ }
+ }
+
+ //====================================================================================================
+ // Test with compression enabled.
+ //====================================================================================================
+ @RestResource(
+ path="/testGzipOn",
+ serializers=PlainTextSerializer.class,
+ parsers=PlainTextParser.class,
+ encoders=MyEncoder.class
+ )
+ public static class TestGzipOn extends RestServlet {
+ private static final long serialVersionUID = 1L;
+ @RestMethod(name="GET", path="/")
+ public String test1() {
+ return "foo";
+ }
+ @RestMethod(name="PUT", path="/")
+ public String test1put(@Content String in) {
+ return in;
+ }
+ // This method bypasses the content type and encoding from
+ // the serializers and encoders when calling getOutputStream() directly.
+ @RestMethod(name="GET", path="/direct")
+ public void direct(RestResponse res) throws Exception {
+ res.setContentType("text/direct");
+ OutputStream os = res.getOutputStream();
+ os.write("test".getBytes());
+ os.flush();
+ }
+
+ // This method bypasses the content type and encoding from
+ // the serializers and encoders when calling getWriter() directly.
+ @RestMethod(name="GET", path="/direct2")
+ public void direct2(RestResponse res) throws Exception {
+ Writer w = res.getWriter();
+ w.append("test");
+ w.flush();
+ }
+
+ // This method uses getNegotiatedWriter() which should use GZip encoding.
+ @RestMethod(name="GET", path="/direct3")
+ public void direct3(RestResponse res) throws Exception {
+ Writer w = res.getNegotiatedWriter();
+ w.append("test");
+ w.flush();
+ }
+
+ // This method overrides the set of encoders at the method level and so shouldn't use GZip encoding.
+ @RestMethod(name="GET", path="/direct4", inheritEncoders=false)
+ public void direct4(RestResponse res) throws Exception {
+ Writer w = res.getNegotiatedWriter();
+ w.append("test");
+ w.flush();
+ }
+ }
+}