http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java new file mode 100644 index 0000000..b76899b --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java @@ -0,0 +1,293 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.rest.RestServletContext.*; +import static org.apache.juneau.urlencoding.UrlEncodingContext.*; + +import java.util.*; + +import javax.servlet.http.*; + +import org.apache.juneau.*; +import org.apache.juneau.json.*; +import org.apache.juneau.plaintext.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.samples.addressbook.*; +import org.apache.juneau.transforms.*; +import org.apache.juneau.urlencoding.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testParams", + serializers=PlainTextSerializer.class, + properties={ + @Property(name=REST_allowMethodParam, value="*") + } +) +public class ParamsResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Basic tests + //==================================================================================================== + @RestMethod(name="GET", path="/") + public void doGet(RestResponse res) { + res.setOutput("GET"); + } + + @RestMethod(name="GET", path="/get1") + public String doGet1() { + return "GET /get1"; + } + + @RestMethod(name="GET", path="/get1/{foo}") + public void doGet1a(RestResponse res, String foo) { + res.setOutput("GET /get1a " + foo); + } + + @RestMethod(name="GET", path="/get1/{foo}/{bar}") + public void doGet1b(RestResponse res, String foo, String bar) { + res.setOutput("GET /get1b " + foo + "," + bar); + } + + @RestMethod(name="GET", path="/get3/{foo}/{bar}/*") + public void doGet3(HttpServletRequest reqx, HttpServletResponse resx, String foo, int bar) { + RestRequest req = (RestRequest)reqx; + RestResponse res = (RestResponse)resx; + res.setOutput("GET /get3/"+foo+"/"+bar+" remainder="+req.getPathRemainder()); + } + + // Test method name with overlapping name, remainder allowed. + @RestMethod(name="GET2") + public void get2(RestRequest req, RestResponse res) { + res.setOutput("GET2 remainder="+req.getPathRemainder()); + } + + // Default POST + @RestMethod(name="POST") + public void doPost(RestRequest req, RestResponse res) { + res.setOutput("POST remainder="+req.getPathRemainder()); + } + + // Bean parameter + @RestMethod(name="POST", path="/person/{person}") + public void doPost(RestRequest req, RestResponse res, Person p) { + res.setOutput("POST /person/{name="+p.name+",birthDate.year="+p.birthDate.get(Calendar.YEAR)+"} remainder="+req.getPathRemainder()); + } + + // Various primitive types + @RestMethod(name="PUT", path="/primitives/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}") + public void doPut1(RestResponse res, int xInt, short xShort, long xLong, char xChar, float xFloat, double xDouble, byte xByte, boolean xBoolean) { + res.setOutput("PUT /primitives/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean); + } + + // Various primitive objects + @RestMethod(name="PUT", path="/primitiveObjects/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}") + public void doPut2(RestResponse res, Integer xInt, Short xShort, Long xLong, Character xChar, Float xFloat, Double xDouble, Byte xByte, Boolean xBoolean) { + res.setOutput("PUT /primitiveObjects/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean); + } + + // Object with forString(String) method + @RestMethod(name="PUT", path="/uuid/{uuid}") + public void doPut1(RestResponse res, UUID uuid) { + res.setOutput("PUT /uuid/"+uuid); + } + + @Override /* RestServlet */ + public Class<?>[] createPojoSwaps() { + return new Class[]{CalendarSwap.DateMedium.class}; + } + + //==================================================================================================== + // @FormData annotation - GET + //==================================================================================================== + @RestMethod(name="GET", path="/testParamGet/*") + public String testParamGet(RestRequest req, @Query("p1") String p1, @Query("p2") int p2) throws Exception { + return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"],p2=["+p2+","+req.getQueryParameter("p2")+","+req.getQueryParameter("p2", int.class)+"]"; + } + + //==================================================================================================== + // @FormData annotation - POST + //==================================================================================================== + @RestMethod(name="POST", path="/testParamPost/*") + public String testParamPost(RestRequest req, @FormData("p1") String p1, @FormData("p2") int p2) throws Exception { + return "p1=["+p1+","+req.getFormDataParameter("p1")+","+req.getFormDataParameter("p1", String.class)+"],p2=["+p2+","+req.getFormDataParameter("p2")+","+req.getFormDataParameter("p2", int.class)+"]"; + } + + //==================================================================================================== + // @Query annotation - GET + //==================================================================================================== + @RestMethod(name="GET", path="/testQParamGet/*") + public String testQParamGet(RestRequest req, @Query("p1") String p1, @Query("p2") int p2) throws Exception { + return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"],p2=["+p2+","+req.getQueryParameter("p2")+","+req.getQueryParameter("p2", int.class)+"]"; + } + + //==================================================================================================== + // @Query annotation - POST + //==================================================================================================== + @RestMethod(name="POST", path="/testQParamPost/*") + public String testQParamPost(RestRequest req, @Query("p1") String p1, @Query("p2") int p2) throws Exception { + return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"],p2=["+p2+","+req.getQueryParameter("p2")+","+req.getQueryParameter("p2", int.class)+"]"; + } + + //==================================================================================================== + // @FormData(format=PLAIN) annotation - GET + //==================================================================================================== + @RestMethod(name="GET", path="/testPlainParamGet/*") + public String testPlainParamGet(RestRequest req, @Query(value="p1",format="PLAIN") String p1) throws Exception { + return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"]"; + } + + //==================================================================================================== + // @FormData(format=PLAIN) annotation - POST + //==================================================================================================== + @RestMethod(name="POST", path="/testPlainParamPost/*") + public String testPlainParamPost(RestRequest req, @FormData(value="p1",format="PLAIN") String p1) throws Exception { + return "p1=["+p1+","+req.getFormDataParameter("p1")+","+req.getFormDataParameter("p1", String.class)+"]"; + } + + //==================================================================================================== + // @Query(format=PLAIN) annotation - GET + //==================================================================================================== + @RestMethod(name="GET", path="/testPlainQParamGet/*") + public String testPlainQParamGet(RestRequest req, @Query(value="p1",format="PLAIN") String p1) throws Exception { + return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"]"; + } + + //==================================================================================================== + // @Query(format=PLAIN) annotation - POST + //==================================================================================================== + @RestMethod(name="POST", path="/testPlainQParamPost/*") + public String testPlainQParamPost(RestRequest req, @Query(value="p1",format="PLAIN") String p1) throws Exception { + return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"]"; + } + + //==================================================================================================== + // @HasQuery annotation - GET + //==================================================================================================== + @RestMethod(name="GET", path="/testHasParamGet/*") + public String testHasParamGet(RestRequest req, @HasQuery("p1") boolean p1, @HasQuery("p2") Boolean p2) throws Exception { + return "p1=["+p1+","+req.hasQueryParameter("p1")+"],p2=["+p2+","+req.hasQueryParameter("p2")+"]"; + } + + //==================================================================================================== + // @HasQuery annotation - POST + //==================================================================================================== + @RestMethod(name="POST", path="/testHasParamPost/*") + public String testHasParamPost(RestRequest req, @HasFormData("p1") boolean p1, @HasFormData("p2") Boolean p2) throws Exception { + return "p1=["+p1+","+req.hasFormDataParameter("p1")+"],p2=["+p2+","+req.hasFormDataParameter("p2")+"]"; + } + + //==================================================================================================== + // @HasQuery annotation - GET + //==================================================================================================== + @RestMethod(name="GET", path="/testHasQParamGet/*") + public String testHasQParamGet(RestRequest req, @HasQuery("p1") boolean p1, @HasQuery("p2") Boolean p2) throws Exception { + return "p1=["+p1+","+req.hasQueryParameter("p1")+"],p2=["+p2+","+req.hasQueryParameter("p2")+"]"; + } + + //==================================================================================================== + // @HasQuery annotation - POST + //==================================================================================================== + @RestMethod(name="POST", path="/testHasQParamPost/*") + public String testHasQParamPost_post(RestRequest req, @HasQuery("p1") boolean p1, @HasQuery("p2") Boolean p2) throws Exception { + return "p1=["+p1+","+req.hasQueryParameter("p1")+"],p2=["+p2+","+req.hasQueryParameter("p2")+"]"; + } + + //==================================================================================================== + // Form POSTS with @Body parameter + //==================================================================================================== + @RestMethod(name="POST", path="/testFormPostAsContent/*") + public String testFormPostAsContent(@Body Test6Bean bean, + @HasQuery("p1") boolean hqp1, @HasQuery("p2") boolean hqp2, + @Query("p1") String qp1, @Query("p2") int qp2) throws Exception { + return "bean=["+JsonSerializer.DEFAULT_LAX.toString(bean)+"],qp1=["+qp1+"],qp2=["+qp2+"],hqp1=["+hqp1+"],hqp2=["+hqp2+"]"; + } + + public static class Test6Bean { + public String p1; + public int p2; + } + + //==================================================================================================== + // Test @FormData and @Query annotations when using multi-part parameters (e.g. &key=val1,&key=val2). + //==================================================================================================== + @RestMethod(name="GET", path="/testMultiPartParams") + public String testMultiPartParams( + @Query(value="p1",multipart=true) String[] p1, + @Query(value="p2",multipart=true) int[] p2, + @Query(value="p3",multipart=true) List<String> p3, + @Query(value="p4",multipart=true) List<Integer> p4, + @Query(value="p5",multipart=true) String[] p5, + @Query(value="p6",multipart=true) int[] p6, + @Query(value="p7",multipart=true) List<String> p7, + @Query(value="p8",multipart=true) List<Integer> p8, + @Query(value="p9",multipart=true) A[] p9, + @Query(value="p10",multipart=true) List<A> p10, + @Query(value="p11",multipart=true) A[] p11, + @Query(value="p12",multipart=true) List<A> p12) throws Exception { + ObjectMap m = new ObjectMap() + .append("p1", p1) + .append("p2", p2) + .append("p3", p3) + .append("p4", p4) + .append("p5", p5) + .append("p6", p6) + .append("p7", p7) + .append("p8", p8) + .append("p9", p9) + .append("p10", p10) + .append("p11", p11) + .append("p12", p12); + return JsonSerializer.DEFAULT_LAX.toString(m); + } + + public static class A { + public String a; + public int b; + public boolean c; + } + + //==================================================================================================== + // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2) + // using URLENC_expandedParams property. + // A simple round-trip test to verify that both serializing and parsing works. + //==================================================================================================== + @RestMethod(name="POST", path="/testFormPostsWithMultiParamsUsingProperty", + properties={ + @Property(name=URLENC_expandedParams, value="true"), + @Property(name=UonSerializerContext.UON_simpleMode, value="true") + } + ) + public DTO2s.B testFormPostsWithMultiParamsViaProperty(@Body DTO2s.B content) throws Exception { + return content; + } + + //==================================================================================================== + // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2) + // using @UrlEncoding(expandedParams=true) annotation. + // A simple round-trip test to verify that both serializing and parsing works. + //==================================================================================================== + @RestMethod(name="POST", path="/testFormPostsWithMultiParamsUsingAnnotation", + properties={ + @Property(name=UonSerializerContext.UON_simpleMode, value="true") + } + ) + public DTO2s.C testFormPostsWithMultiParamsUsingAnnotation(@Body DTO2s.C content) throws Exception { + return content; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java new file mode 100644 index 0000000..c32c44b --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java @@ -0,0 +1,112 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.rest.annotation.Inherit.*; + +import org.apache.juneau.*; +import org.apache.juneau.annotation.*; +import org.apache.juneau.internal.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.plaintext.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + * Validates correct parser is used. + */ +@RestResource( + path="/testParsers", + parsers=ParsersResource.TestParserA.class, + serializers=PlainTextSerializer.class +) +public class ParsersResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + @Consumes("text/a") + public static class TestParserA extends ReaderParser { + @SuppressWarnings("unchecked") + @Override /* Parser */ + protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { + return (T)("text/a - " + IOUtils.read(session.getReader()).trim()); + } + } + + //==================================================================================================== + // Parser defined on class. + //==================================================================================================== + @RestMethod(name="PUT", path="/testParserOnClass") + public String testParserOnClass(@Body String in) { + return in; + } + + //==================================================================================================== + // Parser defined on method. + //==================================================================================================== + @RestMethod(name="PUT", path="/testParserOnMethod", parsers=TestParserB.class) + public String testParserOnMethod(@Body String in) { + return in; + } + + @Consumes("text/b") + public static class TestParserB extends ReaderParser { + @SuppressWarnings("unchecked") + @Override /* Parser */ + protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { + return (T)("text/b - " + IOUtils.read(session.getReader()).trim()); + } + } + + //==================================================================================================== + // Parser overridden on method. + //==================================================================================================== + @RestMethod(name="PUT", path="/testParserOverriddenOnMethod", parsers={TestParserB.class,TestParserC.class}, parsersInherit=PARSERS) + public String testParserOverriddenOnMethod(@Body String in) { + return in; + } + + @Consumes("text/c") + public static class TestParserC extends ReaderParser { + @SuppressWarnings("unchecked") + @Override /* Parser */ + protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { + return (T)("text/c - " + IOUtils.read(session.getReader()).trim()); + } + } + + //==================================================================================================== + // Parser with different Accept than Content-Type. + //==================================================================================================== + @RestMethod(name="PUT", path="/testParserWithDifferentMediaTypes", parsers={TestParserD.class}, parsersInherit=PARSERS) + public String testParserWithDifferentMediaTypes(@Body String in) { + return in; + } + + @Consumes("text/a,text/d") + public static class TestParserD extends ReaderParser { + @SuppressWarnings("unchecked") + @Override /* Parser */ + protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { + return (T)("text/d - " + IOUtils.read(session.getReader()).trim()); + } + } + + //==================================================================================================== + // Check for valid error response. + //==================================================================================================== + @RestMethod(name="PUT", path="/testValidErrorResponse") + public String testValidErrorResponse(@Body String in) { + return in; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathResource.java new file mode 100644 index 0000000..a38cb68 --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathResource.java @@ -0,0 +1,69 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + * Tests the RestServlet.getPath() method. + */ +@RestResource( + path="/testPath", + children={ + PathResource.TestPath2.class + } +) +public class PathResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Basic tests + //==================================================================================================== + @RestMethod(name="GET", path="/") + public String doGet() { + return getPath(); + } + + @RestResource( + path="/testPath2", + children={ + PathResource.TestPath3.class + } + ) + public static class TestPath2 extends RestServletDefault { + private static final long serialVersionUID = 1L; + // Basic tests + @RestMethod(name="GET", path="/") + public String doGet() { + return getPath(); + } + } + + @RestResource( + path="/testPath3" + ) + public static class TestPath3a extends RestServletDefault { + private static final long serialVersionUID = 1L; + // Basic tests + @RestMethod(name="GET", path="/") + public String doGet() { + return getPath(); + } + } + + public static class TestPath3 extends TestPath3a { + private static final long serialVersionUID = 1L; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathsResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathsResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathsResource.java new file mode 100644 index 0000000..c0fc94f --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathsResource.java @@ -0,0 +1,73 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + * Tests the URL-related methods on RestRequest. + */ +@RestResource( + path="/testPaths", + children={ + PathsResource.A.class + } +) +public class PathsResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + @RestMethod(name="GET", path="/*") + public ObjectMap doGet1(RestRequest req, @PathRemainder String r) { + return getPaths(req).append("pathRemainder2", r).append("method",1); + } + + @RestMethod(name="GET", path="/test2/*") + public ObjectMap doGet2(RestRequest req, @PathRemainder String r) { + return getPaths(req).append("pathRemainder2", r).append("method",2); + } + + @RestResource( + path="/a" + ) + public static class A extends RestServletDefault { + private static final long serialVersionUID = 1L; + @RestMethod(name="GET", path="/*") + public ObjectMap doGet1(RestRequest req, @PathRemainder String r) { + return getPaths(req).append("pathRemainder2", r).append("method",3); + } + @RestMethod(name="GET", path="/test2/*") + public ObjectMap doGet2(RestRequest req, @PathRemainder String r) { + return getPaths(req).append("pathRemainder2", r).append("method",4); + } + } + + private static ObjectMap getPaths(RestRequest req) { + return new ObjectMap() + .append("pathInfo", req.getPathInfo()) + .append("pathInfoUndecoded", req.getPathInfoUndecoded()) + .append("pathInfoParts", req.getPathInfoParts()) + .append("pathRemainder", req.getPathRemainder()) + .append("pathRemainderUndecoded", req.getPathRemainderUndecoded()) + .append("requestURI", req.getRequestURI()) + .append("requestParentURI", req.getRequestParentURI()) + .append("requestURL", req.getRequestURL()) + .append("servletPath", req.getServletPath()) + .append("servletURI", req.getServletURI()) + .append("servletParentURI", req.getServletParentURI()) + .append("relativeServletURI", req.getRelativeServletURI()); + + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PropertiesResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PropertiesResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PropertiesResource.java new file mode 100644 index 0000000..ad60f37 --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PropertiesResource.java @@ -0,0 +1,89 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static java.lang.String.*; + +import org.apache.juneau.*; +import org.apache.juneau.annotation.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testProperties", + properties={ + @Property(name="A1",value="a1"), + @Property(name="A2",value="a2"), + @Property(name="foo",value="bar"), + @Property(name="bar",value="baz"), + @Property(name="R1a",value="$R{requestURI}"), + @Property(name="R1b",value="$R{requestParentURI}"), + @Property(name="R2",value="$R{foo}"), + @Property(name="R3",value="$R{$R{foo}}"), + @Property(name="R4",value="$R{A1}"), + @Property(name="R5",value="$R{A2}"), + @Property(name="R6",value="$R{C}"), + } +) +public class PropertiesResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Properties defined on method. + //==================================================================================================== + @RestMethod(name="GET", path="/testPropertiesDefinedOnMethod", + properties={ + @Property(name="B1",value="b1"), + @Property(name="B2",value="b2") + }, + serializers=PropertySerializer1.class + ) + public void testPropertiesDefinedOnMethod(RestResponse res) { + res.setProperty("A2", "c"); + res.setProperty("B2", "c"); + res.setProperty("C", "c"); + res.setOutput(null); + } + + @Produces("application/json,text/json") + public static class PropertySerializer1 extends WriterSerializer { + @Override /* Serializer */ + protected void doSerialize(SerializerSession session, Object output) throws Exception { + ObjectMap p = session.getProperties(); + session.getWriter().write(format("A1=%s,A2=%s,B1=%s,B2=%s,C=%s,R1a=%s,R1b=%s,R2=%s,R3=%s,R4=%s,R5=%s,R6=%s", + p.get("A1"), p.get("A2"), p.get("B1"), p.get("B2"), p.get("C"), + p.get("R1a"), p.get("R1b"), p.get("R2"), p.get("R3"), p.get("R4"), p.get("R5"), p.get("R6"))); + } + } + + //==================================================================================================== + // Make sure attributes/parameters/headers are available through ctx.getProperties(). + //==================================================================================================== + @RestMethod(name="GET", path="/testProperties/{A}", serializers=PropertySerializer2.class) + public void testProperties(RestResponse res) { + res.setOutput(null); + } + + @Produces("application/json,text/json") + public static class PropertySerializer2 extends WriterSerializer { + @Override /* Serializer */ + protected void doSerialize(SerializerSession session, Object output) throws Exception { + ObjectMap p = session.getProperties(); + session.getWriter().write(format("A=%s,P=%s,H=%s", p.get("A"), p.get("P"), p.get("h"))); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestClient2Resource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestClient2Resource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestClient2Resource.java new file mode 100644 index 0000000..671f12c --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestClient2Resource.java @@ -0,0 +1,36 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import java.io.*; + +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testRestClient" +) +public class RestClient2Resource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Echo response + //==================================================================================================== + @RestMethod(name="POST", path="/") + public Reader test1(RestRequest req) throws Exception { + return new StringReader(req.getBodyAsString()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/Root.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/Root.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/Root.java new file mode 100644 index 0000000..67634e4 --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/Root.java @@ -0,0 +1,71 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.microservice.resources.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.rest.labels.*; + +@RestResource( + path="/", + children={ + AcceptCharsetResource.class, + BeanContextPropertiesResource.class, + CallbackStringsResource.class, + CharsetEncodingsResource.class, + ClientVersionResource.class, + ConfigResource.class, + ContentResource.class, + DefaultContentTypesResource.class, + ErrorConditionsResource.class, + TransformsResource.class, + GroupsResource.class, + GzipResource.TestGzipOff.class, + GzipResource.TestGzipOn.class, + InheritanceResource.TestEncoders.class, + InheritanceResource.TestTransforms.class, + InheritanceResource.TestParsers.class, + InheritanceResource.TestProperties.class, + InheritanceResource.TestSerializers.class, + LargePojosResource.class, + MessagesResource.Messages2Resource.class, + MessagesResource.class, + NlsResource.class, + NlsPropertyResource.class, + NoParserInputResource.class, + OnPostCallResource.class, + OnPreCallResource.class, + OptionsWithoutNlsResource.class, + OverlappingMethodsResource.class, + ParamsResource.class, + ParsersResource.class, + PathResource.class, + PathsResource.class, + PropertiesResource.class, + RestClient2Resource.class, + SerializersResource.class, + StaticFilesResource.class, + UrisResource.class, + UrlContentResource.class, + ShutdownResource.class + } +) +public class Root extends RestServletDefault { + private static final long serialVersionUID = 1L; + + @RestMethod(name="GET", path="/") + public ChildResourceDescriptions doGet(RestRequest req) { + return new ChildResourceDescriptions(this, req); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java new file mode 100644 index 0000000..d08c0cf --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java @@ -0,0 +1,103 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import static org.apache.juneau.rest.annotation.Inherit.*; + +import org.apache.juneau.annotation.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testSerializers", + serializers=SerializersResource.TestSerializerA.class +) +public class SerializersResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + @Produces("text/a") + public static class TestSerializerA extends WriterSerializer { + @Override /* Serializer */ + protected void doSerialize(SerializerSession session, Object o) throws Exception { + session.getWriter().write("text/a - " + o); + } + } + + @Produces("text/b") + public static class TestSerializerB extends WriterSerializer { + @Override /* Serializer */ + protected void doSerialize(SerializerSession session, Object o) throws Exception { + session.getWriter().write("text/b - " + o); + } + } + + //==================================================================================================== + // Serializer defined on class. + //==================================================================================================== + @RestMethod(name="GET", path="/testSerializerOnClass") + public String testSerializerOnClass() { + return "test1"; + } + + //==================================================================================================== + // Serializer defined on method. + //==================================================================================================== + @RestMethod(name="GET", path="/testSerializerOnMethod", serializers=TestSerializerB.class) + public String testSerializerOnMethod() { + return "test2"; + } + + //==================================================================================================== + // Serializer overridden on method. + //==================================================================================================== + @RestMethod(name="GET", path="/testSerializerOverriddenOnMethod", serializers={TestSerializerB.class,TestSerializerC.class}, serializersInherit=SERIALIZERS) + public String testSerializerOverriddenOnMethod() { + return "test3"; + } + + @Produces("text/a") + public static class TestSerializerC extends WriterSerializer { + @Override /* Serializer */ + protected void doSerialize(SerializerSession session, Object o) throws Exception { + session.getWriter().write("text/c - " + o); + } + } + + //==================================================================================================== + // Serializer with different Accept than Content-Type. + //==================================================================================================== + @RestMethod(name="GET", path="/testSerializerWithDifferentMediaTypes", serializers={TestSerializerD.class}, serializersInherit=SERIALIZERS) + public String testSerializerWithDifferentMediaTypes() { + return "test4"; + } + + @Produces(value="text/a,text/d",contentType="text/d") + public static class TestSerializerD extends WriterSerializer { + @Override /* Serializer */ + protected void doSerialize(SerializerSession session, Object o) throws Exception { + session.getWriter().write("text/d - " + o); + } + } + + //==================================================================================================== + // Check for valid 406 error response. + //==================================================================================================== + @RestMethod(name="GET", path="/test406") + public String test406() { + return "test406"; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java new file mode 100644 index 0000000..ba9d895 --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java @@ -0,0 +1,36 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.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/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/TransformsParentResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/TransformsParentResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/TransformsParentResource.java new file mode 100644 index 0000000..eb52d29 --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/TransformsParentResource.java @@ -0,0 +1,26 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.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/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/TransformsResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/TransformsResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/TransformsResource.java new file mode 100644 index 0000000..1b52c13 --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/TransformsResource.java @@ -0,0 +1,114 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.*; +import org.apache.juneau.parser.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.serializer.*; +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(@Body A a) { + return a; + } + @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform/{a}") + public A test1c(@Path 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(@Body A a) { + return a; + } + @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform/{a}", pojoSwaps={SwapA3.class}) + public A test2c(@Path A a) { + return a; + } + + + public static class A { + public int f1; + } + + public static class SwapA1 extends StringSwap<A> { + @Override /* PojoSwap */ + public String swap(BeanSession session, A a) throws SerializeException { + return "A1-" + a.f1; + } + @Override /* PojoSwap */ + public A unswap(BeanSession session, String in, ClassMeta<?> hint) 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 StringSwap<A> { + @Override /* PojoSwap */ + public String swap(BeanSession session, A a) throws SerializeException { + return "A2-" + a.f1; + } + @Override /* PojoSwap */ + public A unswap(BeanSession session, String in, ClassMeta<?> hint) 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 StringSwap<A> { + @Override /* PojoSwap */ + public String swap(BeanSession session, A a) throws SerializeException { + return "A3-" + a.f1; + } + @Override /* PojoSwap */ + public A unswap(BeanSession session, String in, ClassMeta<?> hint) 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/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/UrisResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/UrisResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/UrisResource.java new file mode 100644 index 0000000..8de0852 --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/UrisResource.java @@ -0,0 +1,121 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.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/91a388d0/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/UrlContentResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/UrlContentResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/UrlContentResource.java new file mode 100644 index 0000000..3719c49 --- /dev/null +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/UrlContentResource.java @@ -0,0 +1,59 @@ +// *************************************************************************************************************************** +// * 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.rest.test; + +import org.apache.juneau.json.*; +import org.apache.juneau.plaintext.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.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(@Body String content) { + return String.format("class=%s, value=%s", content.getClass().getName(), content.toString()); + } + + @RestMethod(name="GET", path="/testEnum") + public String testEnum(@Body 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(@Body 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(@Body 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/91a388d0/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/Messages2Resource.properties ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/Messages2Resource.properties b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/Messages2Resource.properties new file mode 100644 index 0000000..9a5fe73 --- /dev/null +++ b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/Messages2Resource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +key2 = value2b +key3 = value3b \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/MessagesResource.properties ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/MessagesResource.properties b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/MessagesResource.properties new file mode 100644 index 0000000..d107ee8 --- /dev/null +++ b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/MessagesResource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +key1 = value1a +key2 = value2a \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/NlsPropertyResource.properties ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/NlsPropertyResource.properties b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/NlsPropertyResource.properties new file mode 100644 index 0000000..a833256 --- /dev/null +++ b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/NlsPropertyResource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +key1 = value1 +key2 = value2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties new file mode 100644 index 0000000..d461923 --- /dev/null +++ b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/NlsResource.properties @@ -0,0 +1,71 @@ +# *************************************************************************************************************************** +# * 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. * +# * * +# *************************************************************************************************************************** + +title = Test2.a +description = Test2.b +test2.summary = Test2.c +test2.req.path.a.description = Test2.d +test2.req.query.b.description = Test2.e +test2.req.body.description = Test2.f +test2.req.header.D.description = Test2.g +test2.req.path.a2.description = Test2.h +test2.req.query.b2.description = Test2.i +test2.req.header.D2.description = Test2.j +test2.res.200.description = OK2 +test2.res.201.description = Test2.l + +Test3.title = Test3.a +Test3.description = Test3.b +Test3.test3.summary = Test3.c +Test3.test3.req.path.a.description = Test3.d +Test3.test3.req.query.b.description = Test3.e +Test3.test3.req.body.description = Test3.f +Test3.test3.req.header.D.description = Test3.g +Test3.test3.req.path.a2.description = Test3.h +Test3.test3.req.query.b2.description = Test3.i +Test3.test3.req.header.D2.description = Test3.j +Test3.test3.res.200.description = OK3 +Test3.test3.res.201.description = Test3.l + +Test4.title = $L{foo} +Test4.description = $L{foo} +Test4.test4.summary = $L{foo} +Test4.test4.req.path.a.description = $L{foo} +Test4.test4.req.query.b.description = $L{foo} +Test4.test4.req.body.description = $L{foo} +Test4.test4.req.header.D.description = $L{foo} +Test4.test4.req.path.a2.description = $L{foo} +Test4.test4.req.query.b2.description = $L{foo} +Test4.test4.req.header.D2.description = $L{foo} +Test4.test4.res.200.description = foo$L{foo}foo$L{foo}foo +Test4.test4.res.201.description = $L{foo} + +foo = $L{bar} +bar = baz + +Test5.title = $L{foo2} +Test5.description = $R{servletTitle} +Test5.test5.summary = $R{servletTitle} +Test5.test5.req.path.a.description = $R{servletTitle} +Test5.test5.req.query.b.description = $R{servletTitle} +Test5.test5.req.body.description = $R{servletTitle} +Test5.test5.req.header.D.description = $R{servletTitle} +Test5.test5.req.path.a2.description = $R{servletTitle} +Test5.test5.req.query.b2.description = $R{servletTitle} +Test5.test5.req.header.D2.description = $R{servletTitle} +Test5.test5.res.200.description = foo$R{servletTitle}foo$R{servletTitle}foo +Test5.test5.res.201.description = $R{servletTitle} +Test5.foo2 = $L{bar2} +Test5.bar2 = baz2 + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt new file mode 100644 index 0000000..b4ea91c --- /dev/null +++ b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/xdocs/test.txt @@ -0,0 +1,13 @@ + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** + OK-1 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xdocs/test.txt ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xdocs/test.txt b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xdocs/test.txt new file mode 100644 index 0000000..e3db156 --- /dev/null +++ b/juneau-rest-test/src/main/resources/org/apache/juneau/rest/test/xdocs/xdocs/test.txt @@ -0,0 +1,13 @@ + *************************************************************************************************************************** + * 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. * + *************************************************************************************************************************** + OK-2 \ No newline at end of file