示例#1
0
 public UsageMessage getUsageMessage(Application application, UriInfo uriInfo, Request request)
     throws ClassNotFoundException, IOException {
   UsageMessage usage = new UsageMessage();
   usage.setMessage(RESPONSE);
   usage.setDetailedLink(findUsage(getRSDL(application), uriInfo, request.getMethod()));
   return usage;
 }
示例#2
0
 @Path("")
 @DELETE
 public Response resetBank() {
   log.debug("{} {}", request.getMethod(), uriInfo.getRequestUri());
   service.resetBank();
   return Response.noContent().build();
 }
示例#3
0
  protected ResourceState getCurrentState(ResourceState serviceDocument, String resourcePath) {
    ResourceState state = null;
    if (resourcePath != null) {
      /*
       * add a leading '/' if it needs it (when defining resources we must use a
       * full path, but requests can be relative, i.e. without a '/'
       */
      if (!resourcePath.startsWith("/")) {
        resourcePath = "/" + resourcePath;
      }
      // add service document path to resource path
      String serviceDocumentPath = serviceDocument.getPath();
      if (serviceDocumentPath.endsWith("/")) {
        serviceDocumentPath =
            serviceDocumentPath.substring(0, serviceDocumentPath.lastIndexOf("/"));
      }
      resourcePath = serviceDocumentPath + resourcePath;
      // turn the uri back into a template uri
      MultivaluedMap<String, String> pathParameters = uriInfo.getPathParameters();
      if (pathParameters != null) {
        for (String key : pathParameters.keySet()) {
          List<String> values = pathParameters.get(key);
          for (String value : values) {
            resourcePath = resourcePath.replace(value, "{" + key + "}");
          }
        }
      }
      String httpMethod = requestContext.getMethod();
      Event event = new Event(httpMethod, httpMethod);
      state = resourceStateProvider.determineState(event, resourcePath);

      if (state == null) {
        logger.warn("No state found, dropping back to path matching " + resourcePath);
        // escape the braces in the regex
        resourcePath = Pattern.quote(resourcePath);
        Map<String, Set<String>> pathToResourceStates =
            resourceStateProvider.getResourceStatesByPath();
        for (String path : pathToResourceStates.keySet()) {
          for (String name : pathToResourceStates.get(path)) {
            ResourceState s = resourceStateProvider.getResourceState(name);
            String pattern = null;
            if (s instanceof CollectionResourceState) {
              pattern = resourcePath + "(|\\(\\))";
              Matcher matcher = Pattern.compile(pattern).matcher(path);
              if (matcher.matches()) {
                state = s;
              }
            }
          }
        }
      }
    }
    return state;
  }
示例#4
0
 @Path("")
 @GET
 @Produces(MediaType.APPLICATION_XML)
 @Formatted
 public Response getBank() {
   log.debug("{} {}", request.getMethod(), uriInfo.getRequestUri());
   Bank bank = service.getBank();
   URI self = new BankRefs(uriInfo).setHRefs(bank);
   log.debug("returning bank:\n{}", bank.toXML());
   return Response.ok(bank, MediaType.APPLICATION_XML)
       .contentLocation(self)
       .lastModified(bank.getUpdated())
       .build();
 }
示例#5
0
 @Path("")
 @PUT
 @Consumes(MediaType.APPLICATION_XML)
 public Response updateBank(Bank bank) {
   log.debug("{} {}", request.getMethod(), uriInfo.getRequestUri());
   if (service.updateBank(bank) == 0) {
     log.debug("updated bank:\n{}", bank.toXML());
     return Response.noContent().build();
   } else {
     return Response.status(Status.BAD_REQUEST)
         .entity(String.format("cannot update bank"))
         .type(MediaType.TEXT_PLAIN)
         .build();
   }
 }
示例#6
0
  @GET
  @Path("/{id}")
  public Response getWebLogon(@PathParam("id") Long id) throws Exception {
    String method = request.getMethod();
    System.out.printf("method: %s%n", method);

    WebLogon webLogon = new WebLogon();
    webLogon.setUsername("johndoe");
    webLogon.setEmail("*****@*****.**");
    webLogon.setPassword("password");
    webLogon.setNotes("notes");
    webLogon.setUrl(new URI("http://www.yahoo.com"));

    URI self = uriInfo.getRequestUri();
    webLogon.setSelf(self);
    return Response.ok(webLogon).build();
  }
 @Test
 public void testMethod() {
   MutableRequest r = new MutableRequest("", "http://example.org/app/resource", "GET");
   Request v = r.toJaxrsRequest();
   assertEquals(v.getMethod(), "GET");
 }