Example #1
0
    /**
     * Issue a request with the given {@link Method} to the provided resource URI.
     *
     * @param method the http method to use
     * @param resourceUri the uri to issue the request to
     * @return the response to the request
     */
    public MockHttpServletResponse callInternal(Method method, String resourceUri)
        throws Exception {
      MockHttpServletRequest request = super.createRequest(resourceUri);
      request.setMethod(method.getName());

      return dispatch(request, null);
    }
 public MethodNotAllowedException(Reference uri, Method method) {
   super(
       Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.getCode(),
       String.format("Method %s not allowed", method),
       String.format("Method %s not allowed to %s", method.getName(), uri),
       null);
 }
Example #3
0
    public MockHttpServletResponse callInternal(Method method, String resourceUri, Form form)
        throws Exception {
      MockHttpServletRequest request = super.createRequest(resourceUri);
      request.setMethod(method.getName());
      // set the JSON payload
      request.setContent(form.encode().getBytes());
      request.setContentType("application/x-www-form-urlencoded");

      return dispatch(request, null);
    }
Example #4
0
    public MockHttpServletResponse callInternal(
        Method method, String resourceUri, JSONObject payload) throws Exception {
      MockHttpServletRequest request = super.createRequest(resourceUri);
      request.setMethod(method.getName());
      // set the JSON payload
      request.setContent(payload.toString().getBytes());
      request.setContentType("application/json");

      return dispatch(request, null);
    }
Example #5
0
  public Response sendRequest(Method method, String url, Representation representation) {
    this.logger.debug("Method: " + method.getName() + " url: " + url);

    Request request = new Request();
    request.setResourceRef(url);
    request.setMethod(method);

    if (!Method.GET.equals(method) && !Method.DELETE.equals(method)) {
      request.setEntity(representation);
    }

    request.setChallengeResponse(this.challenge);

    return this.restClient.handle(request);
  }
Example #6
0
  // Update the endpointUri with the restlet method information
  protected void updateEndpointUri() {
    String endpointUri = getEndpointUri();
    CollectionStringBuffer methods = new CollectionStringBuffer(",");
    if (getRestletMethods() != null && getRestletMethods().length > 0) {
      // list the method(s) as a comma seperated list
      for (Method method : getRestletMethods()) {
        methods.append(method.getName());
      }
    } else {
      // otherwise consider the single method we own
      methods.append(getRestletMethod());
    }

    // update the uri
    endpointUri = endpointUri + "?restletMethods=" + methods;
    setEndpointUri(endpointUri);
  }
 private static Operation getOperationFromMethod(Method method) {
   Operation operation = new Operation();
   operation.setMethod(method.getName());
   return operation;
 }