/trunk/org.mwc.asset.comms/docs/restlet_src/org.restlet.test/org/restlet/test/jaxrs/services/resources/PathParamTestService.java

https://bitbucket.org/haris_peco/debrief · Java · 108 lines · 62 code · 12 blank · 34 comment · 0 complexity · 1e92f29e6af537e611fdae6d7bd7139a MD5 · raw file

  1. /**
  2. * Copyright 2005-2010 Noelios Technologies.
  3. *
  4. * The contents of this file are subject to the terms of one of the following
  5. * open source licenses: LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL 1.0 (the
  6. * "Licenses"). You can select the license that you prefer but you may not use
  7. * this file except in compliance with one of these Licenses.
  8. *
  9. * You can obtain a copy of the LGPL 3.0 license at
  10. * http://www.opensource.org/licenses/lgpl-3.0.html
  11. *
  12. * You can obtain a copy of the LGPL 2.1 license at
  13. * http://www.opensource.org/licenses/lgpl-2.1.php
  14. *
  15. * You can obtain a copy of the CDDL 1.0 license at
  16. * http://www.opensource.org/licenses/cddl1.php
  17. *
  18. * You can obtain a copy of the EPL 1.0 license at
  19. * http://www.opensource.org/licenses/eclipse-1.0.php
  20. *
  21. * See the Licenses for the specific language governing permissions and
  22. * limitations under the Licenses.
  23. *
  24. * Alternatively, you can obtain a royalty free commercial license with less
  25. * limitations, transferable or non-transferable, directly at
  26. * http://www.noelios.com/products/restlet-engine
  27. *
  28. * Restlet is a registered trademark of Noelios Technologies.
  29. */
  30. package org.restlet.test.jaxrs.services.resources;
  31. import java.util.List;
  32. import javax.ws.rs.GET;
  33. import javax.ws.rs.Path;
  34. import javax.ws.rs.PathParam;
  35. import javax.ws.rs.Produces;
  36. import javax.ws.rs.WebApplicationException;
  37. import javax.ws.rs.core.MediaType;
  38. import javax.ws.rs.core.PathSegment;
  39. import javax.ws.rs.core.Response;
  40. import org.restlet.test.jaxrs.services.tests.PathParamTest;
  41. /**
  42. * @author Stephan Koops
  43. * @see PathParamTest
  44. * @see PathParam
  45. */
  46. @Path("pathParamTest/{var1}")
  47. public class PathParamTestService {
  48. @Path("checkUnmodifiable/{var1}")
  49. @GET
  50. @Produces("text/plain")
  51. public Object checkUnmodifiable(@PathParam("var1") List<PathSegment> var1s) {
  52. try {
  53. var1s.clear();
  54. throw new WebApplicationException(Response.serverError().entity(
  55. "the List must be unmodifiable").build());
  56. } catch (UnsupportedOperationException uoe) {
  57. return null;
  58. }
  59. }
  60. @GET
  61. @Produces("text/plain")
  62. public String get(@PathParam("var1") String var1) {
  63. return var1;
  64. }
  65. @Path("abc/{var2}/def")
  66. @GET
  67. @Produces("text/plain")
  68. public String get(@PathParam("var1") String var1,
  69. @PathParam("var2") String var2) {
  70. return var1 + "\n" + var2;
  71. }
  72. @GET
  73. @Path("regExp/{buchstabe:[a-zA-Z]}")
  74. @Produces(MediaType.TEXT_PLAIN)
  75. public String getRegExpEinBuchstabe(@PathParam("buchstabe") String buchstabe) {
  76. return "ein Buchstabe: "+buchstabe;
  77. }
  78. @GET
  79. @Path("regExp/{string}")
  80. @Produces(MediaType.TEXT_PLAIN)
  81. public String getRegExpSonstwas(@PathParam("string") String string) {
  82. return "anderes: "+string;
  83. }
  84. @GET
  85. @Path("regExp/{zahl:[-]?[0-9]+}")
  86. @Produces(MediaType.TEXT_PLAIN)
  87. public String getRegExpZahl(@PathParam("zahl") int zahl) {
  88. return "Zahl: "+zahl;
  89. }
  90. @Path("st/{var1}")
  91. @GET
  92. @Produces(MediaType.TEXT_PLAIN)
  93. public String getVar1(@PathParam("var1") String var1) {
  94. return var1;
  95. }
  96. }