Java Code Examples for org.eclipse.jetty.http.HttpMethod

Following code examples demonstrate how to use org.eclipse.jetty.http.HttpMethod from jetty. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.eclipse.jetty.http.HttpMethod and various code implementation of this class.
Example 1
Project : jetty Source File : SymphonyWarehouseRestApiClient.java View Source Code on GitHub

	private <T> T doApiRequest(Class apiResponseClass, String endpoint, WarehouseApiInfo apiInfo, String clientRef, HttpMethod method, String requestJson) {
		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.setDateFormat(dateFormat);
		String username = apiInfo.getUsername();
		String password = apiInfo.getPassword();
		Map<String, String> customHeaders = Maps.newHashMap();
		customHeaders.put("WarehouseKey", apiInfo.getWarehouseKey());
		customHeaders.put("ClientRef", clientRef);

		try {
			Future<ContentResponse> response;
			switch(method) {
				case POST:
					response = httpClientWrapper.postJSON(endpoint, requestJson, username, password, customHeaders);
					break;
				case DELETE:
					response = httpClientWrapper.delete(endpoint, username, password, customHeaders);
					break;
				case GET:
					response = httpClientWrapper.getJSON(endpoint, username, password, customHeaders);
					break;
				default:
					throw new RequestTypeNotImplementedException("HTTP {} Type Not Implemented");
			}
			String respString = response.get().getContentAsString();
			T responseObj = (T) objectMapper.readValue(respString, apiResponseClass);
			logger.info("{}: {} with username: {} \n" +
					"response {}", method, endpoint, username, prettyPrintGson.toJson(responseObj));
			return responseObj;
		} catch (IOException | InterruptedException | ExecutionException e) {
			throw new WarehouseNetworkException(format("HTTP {} Error: endpoint : %s, username : %s, ",
					method, endpoint, username));
		}
	}
			
Example 2
Project : jetty Source File : RestTest.java View Source Code on GitHub

    public static void main(String[] args) {
        RestResponse response = new RestRequest()
                .setRequestType(HttpMethod.GET)
                .setHost("httpbin.org")
                .setPath("/get")
                .setProtocol("https")
                .build();
        response.getResponseCode();
        response.getresponseMessage();
        response.isJson();
    }
			
Example 3
Project : jetty Source File : FritzAhaReauthCallback.java View Source Code on GitHub

    
    public FritzAhaReauthCallback(String path, String args, FritzAhaWebInterface webIface, HttpMethod httpMethod,
            int retries) {
        this.path = path;
        this.args = args;
        this.webIface = webIface;
        this.httpMethod = httpMethod;
        this.retries = retries;
        retryCallback = this;
    }
			
Example 4
Project : jetty Source File : HttpValidator.java View Source Code on GitHub

	public static boolean isPostOrPutRequest(String httpMethod) {

	    boolean isPostOrPut = false;
	    
	    if (!StringUtils.isBlank(httpMethod)) {
	        
	        isPostOrPut = httpMethod.equalsIgnoreCase(HttpMethod.POST.name()) || httpMethod.equalsIgnoreCase(HttpMethod.PUT.name());
	    }
	    
		return isPostOrPut;
	}
			
Example 5
Project : jetty Source File : ThirdParty.java View Source Code on GitHub

    public static void post(String uri, String content) throws Exception {
        HttpClient httpClient = new HttpClient();
        httpClient.start();
        httpClient
            .newRequest(uri)
            .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
            .content(new StringContentProvider(content))
            .method(HttpMethod.POST)
            .send();
    }
			
Example 6
Project : jetty Source File : ApiHandler.java View Source Code on GitHub

  private <T extends ApiResponse> T doRequest(String requestUri, Class<T> expectedResponseType, HttpMethod method) {
    if (StringUtils.isEmpty(config.getApiAccessKey())) return null;

    try {
      Request request = httpClient.newRequest(requestUri);
      request.method(method);
      ContentResponse get = request.send();
      String content = get.getContentAsString();
      String mediaType = get.getMediaType();

      try {
        int limit = Integer.parseInt(get.getHeaders().get("X-Ratelimit-Limit"));
        int remaining = Integer.parseInt(get.getHeaders().get("X-Ratelimit-Remaining"));
        apiLimits.setTotalLimit(limit);
        apiLimits.setCallCount(limit - remaining);
        apiLimits.setRemainingCount(remaining);
      } catch (NumberFormatException e) {
        apiLimits.setTotalLimit(0);
        apiLimits.setCallCount(apiLimits.getCallCount() + 1);
        apiLimits.setRemainingCount(0);
      }

      if (expectedResponseType != null) {
        if (get.getStatus() == 200) {
          return new ModelMarshaller<>(expectedResponseType).unMarshal(content, mediaType);
        } else {
          PinterestApiError error = new ModelMarshaller<>(PinterestApiError.class).unMarshal(content, mediaType);
          System.err.println("The Api returned an error: " + error.getMessage() + " (" + error.getType() + ")");
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }