@Override
 public void registerMethods() {
   Method.register(Method.ALL);
   Method.register(Method.CONNECT);
   Method.register(Method.DELETE);
   Method.register(Method.GET);
   Method.register(Method.HEAD);
   Method.register(Method.OPTIONS);
   Method.register(Method.POST);
   Method.register(Method.PUT);
   Method.register(Method.TRACE);
 }
  /**
   * Constructor.
   *
   * @param context The context of the parent connector.
   * @param connection The associated network connection.
   * @param methodName The protocol method name.
   * @param resourceUri The target resource URI.
   * @param protocol The protocol name and version.
   */
  public SipInboundRequest(
      Context context,
      Connection<Server> connection,
      String methodName,
      String resourceUri,
      String protocol) {
    super();
    this.context = context;
    this.cacheDirectivesAdded = false;
    this.clientAdded = false;
    this.conditionAdded = false;
    this.connection = connection;
    this.cookiesAdded = false;
    this.referrerAdded = false;
    this.securityAdded = false;
    this.userPrincipal = null;
    this.proxySecurityAdded = false;
    this.recipientsInfoAdded = false;
    this.resourceUri = resourceUri;
    this.protocol = protocol;
    this.warningsAdded = false;

    // SIP specific initialization
    this.alertInfoAdded = false;
    this.allowedEventTypesAdded = false;
    this.callerInfoAdded = false;
    this.contactAdded = false;
    this.eventAdded = false;
    this.inReplyToAdded = false;
    this.priorityAdded = false;

    // Set the properties
    setMethod(Method.valueOf(methodName));
  }
Пример #3
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);
 }
Пример #5
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);
  }
  /**
   * Returns the target method according to a list of properties.
   *
   * @param resolver The resolver.
   * @return The target method.
   */
  protected Method getTargetMethod(Resolver<String> resolver) {
    Method method = Method.valueOf(resolver.resolve("method"));
    if (method == null) {
      method = getTargetMethod();
    }

    return method;
  }
Пример #7
0
  /**
   * Effectively handles a call without content negotiation of the response entity. The default
   * behavior is to dispatch the call to one of the {@link #get()}, {@link #post(Representation)},
   * {@link #put(Representation)}, {@link #delete()}, {@link #head()} or {@link #options()} methods.
   *
   * @return The response entity.
   * @throws ResourceException
   */
  protected Representation doHandle() throws ResourceException {
    Representation result = null;
    Method method = getMethod();

    if (method == null) {
      setStatus(Status.CLIENT_ERROR_BAD_REQUEST, "No method specified");
    } else {
      if (method.equals(Method.PUT)) {
        result = put(getRequestEntity());
      } else if (isExisting()) {
        if (method.equals(Method.GET)) {
          result = get();
        } else if (method.equals(Method.POST)) {
          result = post(getRequestEntity());
        } else if (method.equals(Method.DELETE)) {
          result = delete();
        } else if (method.equals(Method.HEAD)) {
          result = head();
        } else if (method.equals(Method.OPTIONS)) {
          result = options();
        } else {
          result = doHandle(method, getRequestEntity());
        }
      } else {
        setStatus(Status.CLIENT_ERROR_NOT_FOUND);
      }
    }

    return result;
  }
Пример #8
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);
    }
Пример #9
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);
    }
  /**
   * Constructor.
   *
   * @param context The context of the HTTP server connector that issued the call.
   * @param httpCall The low-level HTTP server call.
   */
  public HttpRequest(Context context, ServerCall httpCall) {
    this.context = context;
    this.clientAdded = false;
    this.conditionAdded = false;
    this.cookiesAdded = false;
    this.entityAdded = false;
    this.referrerAdded = false;
    this.securityAdded = false;
    this.proxySecurityAdded = false;
    this.recipientsInfoAdded = false;
    this.warningsAdded = false;
    this.httpCall = httpCall;

    // Set the properties
    setMethod(Method.valueOf(httpCall.getMethod()));

    // Set the host reference
    StringBuilder sb = new StringBuilder();
    sb.append(httpCall.getProtocol().getSchemeName()).append("://");
    sb.append(httpCall.getHostDomain());
    if ((httpCall.getHostPort() != -1)
        && (httpCall.getHostPort() != httpCall.getProtocol().getDefaultPort())) {
      sb.append(':').append(httpCall.getHostPort());
    }
    setHostRef(sb.toString());

    // Set the resource reference
    if (httpCall.getRequestUri() != null) {
      setResourceRef(new Reference(getHostRef(), httpCall.getRequestUri()));

      if (getResourceRef().isRelative()) {
        // Take care of the "/" between the host part and the segments.
        if (!httpCall.getRequestUri().startsWith("/")) {
          setResourceRef(new Reference(getHostRef().toString() + "/" + httpCall.getRequestUri()));
        } else {
          setResourceRef(new Reference(getHostRef().toString() + httpCall.getRequestUri()));
        }
      }

      setOriginalRef(getResourceRef().getTargetRef());
    }

    // Set the request date
    String dateHeader = httpCall.getRequestHeaders().getFirstValue(HeaderConstants.HEADER_DATE);
    Date date = null;
    if (dateHeader != null) {
      date = DateUtils.parse(dateHeader);
    }

    if (date == null) {
      date = new Date();
    }

    setDate(date);
  }
Пример #11
0
 public void handle(Request request, Response response) {
   Method met = request.getMethod();
   try {
     if (met.equals(Method.GET)) {
       doGet(request, response);
     } else if (met.equals(Method.POST)) {
       doPost(request, response);
     } else {
       throw new RestletException("Method not allowed", Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
     }
   } catch (RestletException re) {
     response.setEntity(re.getRepresentation());
     response.setStatus(re.getStatus());
   } catch (IOException ioe) {
     StringBuilder strBld = new StringBuilder();
     strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
     strBld.append("\n<GeoWebCacheException>");
     strBld.append("\nEncountered IO error " + ioe.getMessage());
     strBld.append("\n</GeoWebCacheException>");
     response.setEntity(strBld.toString(), MediaType.TEXT_XML);
     response.setStatus(Status.SERVER_ERROR_INTERNAL);
   }
 }
Пример #12
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);
  }
Пример #13
0
  /**
   * Effectively handles a call with content negotiation of the response entity. The default
   * behavior is to dispatch the call to one of the {@link #get(Variant)}, {@link
   * #post(Representation,Variant)}, {@link #put(Representation,Variant)}, {@link #delete(Variant)},
   * {@link #head(Variant)} or {@link #options(Variant)} methods.
   *
   * @param variant The response variant expected.
   * @return The response entity.
   * @throws ResourceException
   */
  protected Representation doHandle(Variant variant) throws ResourceException {
    Representation result = null;
    Method method = getMethod();

    if (method == null) {
      setStatus(Status.CLIENT_ERROR_BAD_REQUEST, "No method specified");
    } else {
      if (method.equals(Method.PUT)) {
        result = put(getRequestEntity(), variant);
      } else if (isExisting()) {
        if (method.equals(Method.GET)) {
          if (variant instanceof Representation) {
            result = (Representation) variant;
          } else {
            result = get(variant);
          }
        } else if (method.equals(Method.POST)) {
          result = post(getRequestEntity(), variant);
        } else if (method.equals(Method.DELETE)) {
          result = delete(variant);
        } else if (method.equals(Method.HEAD)) {
          if (variant instanceof Representation) {
            result = (Representation) variant;
          } else {
            result = head(variant);
          }
        } else if (method.equals(Method.OPTIONS)) {
          if (variant instanceof Representation) {
            result = (Representation) variant;
          } else {
            result = options(variant);
          }
        } else if (variant instanceof VariantInfo) {
          result = doHandle(((VariantInfo) variant).getAnnotationInfo(), variant);
        } else {
          setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
        }
      } else {
        setStatus(Status.CLIENT_ERROR_NOT_FOUND);
      }
    }

    return result;
  }
 private static Operation getOperationFromMethod(Method method) {
   Operation operation = new Operation();
   operation.setMethod(method.getName());
   return operation;
 }