Package org.jboss.netty.handler.codec.http

Examples of org.jboss.netty.handler.codec.http.HttpMethod


                throw new NoTypeConversionAvailableException(body, ChannelBuffer.class);
            }
        }

        // update HTTP method accordingly as we know if we have a body or not
        HttpMethod method = NettyHttpHelper.createMethod(message, body != null);
        request.setMethod(method);

        // set the content type in the response.
        String contentType = MessageHelper.getContentType(message);
        if (contentType != null) {
View Full Code Here


     * @param message  the Camel message
     * @return the created method
     */
    public static HttpMethod createMethod(Message message, boolean hasPayload) {
        // use header first
        HttpMethod m = message.getHeader(Exchange.HTTP_METHOD, HttpMethod.class);
        if (m != null) {
            return m;
        }
        String name = message.getHeader(Exchange.HTTP_METHOD, String.class);
        if (name != null) {
View Full Code Here

                throw new NoTypeConversionAvailableException(body, ChannelBuffer.class);
            }
        }

        // update HTTP method accordingly as we know if we have a body or not
        HttpMethod method = NettyHttpHelper.createMethod(message, body != null);
        request.setMethod(method);

        // set the content type in the response.
        String contentType = MessageHelper.getContentType(message);
        if (contentType != null) {
View Full Code Here

        return id;
    }
   
    public boolean isPut(MessageEvent e) {
      HttpRequest request = (HttpRequest) e.getMessage();
    HttpMethod method = request.getMethod();
    return method == HttpMethod.PUT;
    }
View Full Code Here

    return method == HttpMethod.PUT;
    }
   
    public boolean isPost(MessageEvent e) {
      HttpRequest request = (HttpRequest) e.getMessage();
    HttpMethod method = request.getMethod();
    return method == HttpMethod.POST;
    }
View Full Code Here

    return method == HttpMethod.POST;
    }
   
    public boolean isGet(MessageEvent e) {
      HttpRequest request = (HttpRequest) e.getMessage();
    HttpMethod method = request.getMethod();
    return method == HttpMethod.GET;
    }
View Full Code Here

    return method == HttpMethod.GET;
    }
   
    public boolean isDelete(MessageEvent e) {
      HttpRequest request = (HttpRequest) e.getMessage();
    HttpMethod method = request.getMethod();
    return method == HttpMethod.DELETE;
    }
View Full Code Here

   * Performs CRUD methods on individual annotation objects.
   * @param tsdb The TSD to which we belong
   * @param query The query to parse and respond to
   */
  public void execute(final TSDB tsdb, HttpQuery query) throws IOException {
    final HttpMethod method = query.getAPIMethod();
   
    final Annotation note;
    if (query.hasContent()) {
      note = query.serializer().parseAnnotationV1();
    } else {
      note = parseQS(query);
    }
   
    // GET
    if (method == HttpMethod.GET) {
      try {
        final Annotation stored_annotation =
          Annotation.getAnnotation(tsdb, note.getTSUID(), note.getStartTime())
            .joinUninterruptibly();
        if (stored_annotation == null) {
          throw new BadRequestException(HttpResponseStatus.NOT_FOUND,
              "Unable to locate annotation in storage");
        }
        query.sendReply(query.serializer().formatAnnotationV1(stored_annotation));
      } catch (BadRequestException e) {
        throw e;
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    // POST
    } else if (method == HttpMethod.POST || method == HttpMethod.PUT) {
     
      /**
       * Storage callback used to determine if the storage call was successful
       * or not. Also returns the updated object from storage.
       */
      class SyncCB implements Callback<Deferred<Annotation>, Boolean> {
       
        @Override
        public Deferred<Annotation> call(Boolean success) throws Exception {
          if (!success) {
            throw new BadRequestException(
                HttpResponseStatus.INTERNAL_SERVER_ERROR,
                "Failed to save the Annotation to storage",
                "This may be caused by another process modifying storage data");
          }
         
          return Annotation.getAnnotation(tsdb, note.getTSUID(),
              note.getStartTime());
        }
       
      }
     
      try {
        final Deferred<Annotation> process_meta = note.syncToStorage(tsdb,
            method == HttpMethod.PUT).addCallbackDeferring(new SyncCB());
        final Annotation updated_meta = process_meta.joinUninterruptibly();
        tsdb.indexAnnotation(note);
        query.sendReply(query.serializer().formatAnnotationV1(updated_meta));
      } catch (IllegalStateException e) {
        query.sendStatusOnly(HttpResponseStatus.NOT_MODIFIED);
      } catch (IllegalArgumentException e) {
        throw new BadRequestException(e);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    // DELETE   
    } else if (method == HttpMethod.DELETE) {

      try {
        note.delete(tsdb).joinUninterruptibly();
        tsdb.deleteAnnotation(note);
      } catch (IllegalArgumentException e) {
        throw new BadRequestException(
            "Unable to delete Annotation information", e);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
      query.sendStatusOnly(HttpResponseStatus.NO_CONTENT);
     
    } else {
      throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED,
          "Method not allowed", "The HTTP method [" + method.getName() +
          "] is not permitted for this endpoint");
    }
  }
View Full Code Here

    }

    private static HttpRequest createHttpRequest(int spdyVersion, SpdyHeadersFrame requestFrame)
            throws Exception {
        // Create the first line of the request from the name/value pairs
        HttpMethod  method      = SpdyHeaders.getMethod(spdyVersion, requestFrame);
        String      url         = SpdyHeaders.getUrl(spdyVersion, requestFrame);
        HttpVersion httpVersion = SpdyHeaders.getVersion(spdyVersion, requestFrame);
        SpdyHeaders.removeMethod(spdyVersion, requestFrame);
        SpdyHeaders.removeUrl(spdyVersion, requestFrame);
        SpdyHeaders.removeVersion(spdyVersion, requestFrame);
View Full Code Here

        }
        if (charset == null) {
            throw new NullPointerException("charset");
        }
        this.request = request;
        HttpMethod method = request.getMethod();
        if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH)) {
            bodyToDecode = true;
        }
        this.charset = charset;
        this.factory = factory;
        // Fill default values
View Full Code Here

TOP

Related Classes of org.jboss.netty.handler.codec.http.HttpMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.