org.eclipse.jetty.http.HttpMethod Java Examples
The following examples show how to use
org.eclipse.jetty.http.HttpMethod.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpIT.java From digdag with Apache License 2.0 | 6 votes |
private void verifyEphemeralErrorsAreRetried(HttpMethod[] methods, Map<String, String> params) throws IOException { proxy = TestUtils.startRequestFailingProxy(3, requests); String uri = "http://localhost:" + httpMockWebServer.getPort() + "/test"; for (HttpMethod method : methods) { runWorkflow(folder, "acceptance/http/http.dig", ImmutableMap.<String, String>builder() .putAll(params) .put("test_uri", uri) .put("http.method", method.asString()) .put("http.proxy.enabled", "true") .put("http.proxy.host", "localhost") .put("http.proxy.port", Integer.toString(proxy.getListenAddress().getPort())) .build(), ImmutableMap.of(), 0); assertThat(requests.keySet().stream().anyMatch(k -> k.startsWith(method.asString())), is(true)); } assertThat(requests.size(), is(methods.length)); assertThat(httpMockWebServer.getRequestCount(), is(methods.length)); }
Example #2
Source File: RemoteLRS.java From TinCanJava with Apache License 2.0 | 6 votes |
private LRSResponse updateDocument(String resource, Map<String, String> queryParams, Document document) { HTTPRequest request = new HTTPRequest(); request.setMethod(HttpMethod.POST.asString()); request.setResource(resource); request.setQueryParams(queryParams); request.setContentType(document.getContentType()); request.setContent(document.getContent()); if (document.getEtag() != null) { request.setHeaders(new HashMap<String, String>()); request.getHeaders().put("If-Match", document.getEtag()); } HTTPResponse response = makeSyncRequest(request); LRSResponse lrsResponse = new LRSResponse(request, response); if (response.getStatus() == 204) { lrsResponse.setSuccess(true); } else { lrsResponse.setSuccess(false); } return lrsResponse; }
Example #3
Source File: RemoteLRS.java From TinCanJava with Apache License 2.0 | 6 votes |
@Override public AboutLRSResponse about() { HTTPRequest request = new HTTPRequest(); request.setMethod(HttpMethod.GET.asString()); request.setResource("about"); HTTPResponse response = makeSyncRequest(request); int status = response.getStatus(); AboutLRSResponse lrsResponse = new AboutLRSResponse(request, response); if (status == 200) { lrsResponse.setSuccess(true); try { lrsResponse.setContent(new About(response.getContent())); } catch (Exception ex) { lrsResponse.setErrMsg("Exception: " + ex.toString()); lrsResponse.setSuccess(false); } } else { lrsResponse.setSuccess(false); } return lrsResponse; }
Example #4
Source File: DynRealmITCase.java From syncope with Apache License 2.0 | 6 votes |
private static ArrayNode fetchDynRealmsFromElasticsearch(final String userKey) throws Exception { String body = '{' + " \"query\": {" + " \"match\": {\"_id\": \"" + userKey + "\"}" + " }" + '}'; HttpClient httpClient = new HttpClient(); httpClient.start(); ContentResponse response = httpClient.newRequest("http://localhost:9200/master_user/_search"). method(HttpMethod.GET). header(HttpHeader.CONTENT_TYPE, MediaType.APPLICATION_JSON). content(new InputStreamContentProvider(IOUtils.toInputStream(body))). send(); assertEquals(HttpStatus.OK_200, response.getStatus()); return (ArrayNode) OBJECT_MAPPER.readTree(response.getContent()). get("hits").get("hits").get(0).get("_source").get("dynRealms"); }
Example #5
Source File: RemoteLRS.java From TinCanJava with Apache License 2.0 | 6 votes |
private LRSResponse deleteDocument(String resource, Map<String, String> queryParams) { HTTPRequest request = new HTTPRequest(); request.setMethod(HttpMethod.DELETE.asString()); request.setResource(resource); request.setQueryParams(queryParams); HTTPResponse response = makeSyncRequest(request); LRSResponse lrsResponse = new LRSResponse(request, response); if (response.getStatus() == 204) { lrsResponse.setSuccess(true); } else { lrsResponse.setSuccess(false); } return lrsResponse; }
Example #6
Source File: JwtAuthenticatorTest.java From cruise-control with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testRedirect() throws IOException, ServerAuthException { JwtAuthenticator authenticator = new JwtAuthenticator(TOKEN_PROVIDER, JWT_TOKEN); HttpServletRequest request = mock(HttpServletRequest.class); expect(request.getMethod()).andReturn(HttpMethod.GET.asString()); expect(request.getQueryString()).andReturn(null); expect(request.getHeader(HttpHeader.AUTHORIZATION.asString())).andReturn(null); expect(request.getCookies()).andReturn(new Cookie[] {}); expect(request.getRequestURL()).andReturn(new StringBuffer(CRUISE_CONTROL_ENDPOINT)); HttpServletResponse response = mock(HttpServletResponse.class); response.sendRedirect(TOKEN_PROVIDER.replace(JwtAuthenticator.REDIRECT_URL, CRUISE_CONTROL_ENDPOINT)); expectLastCall().andVoid(); replay(request, response); Authentication actualAuthentication = authenticator.validateRequest(request, response, true); verify(request, response); assertEquals(Authentication.SEND_CONTINUE, actualAuthentication); }
Example #7
Source File: HttpIT.java From digdag with Apache License 2.0 | 6 votes |
private void verifyEphemeralErrorsAreNotRetried(HttpMethod[] methods, Map<String, String> params) throws IOException { proxy = TestUtils.startRequestFailingProxy(3, requests); String uri = "http://localhost:" + httpMockWebServer.getPort() + "/test"; for (HttpMethod method : methods) { runWorkflow(folder, "acceptance/http/http.dig", ImmutableMap.<String, String>builder() .putAll(params) .put("test_uri", uri) .put("http.method", method.asString()) .put("http.proxy.enabled", "true") .put("http.proxy.host", "localhost") .put("http.proxy.port", Integer.toString(proxy.getListenAddress().getPort())) .build(), ImmutableMap.of(), 1); assertThat(requests.keySet().stream().anyMatch(k -> k.startsWith(method.asString())), is(true)); } assertThat(httpMockWebServer.getRequestCount(), is(0)); }
Example #8
Source File: JettyConfig.java From nakadi with MIT License | 6 votes |
@Bean public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory( @Value("${server.port:8080}") final String port, @Value("${jetty.threadPool.maxThreads:200}") final String maxThreads, @Value("${jetty.threadPool.minThreads:8}") final String minThreads, @Value("${jetty.threadPool.idleTimeout:60000}") final String idleTimeout) { final JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(Integer.valueOf(port)); factory.addServerCustomizers((JettyServerCustomizer) server -> { final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class); threadPool.setMaxThreads(Integer.valueOf(maxThreads)); threadPool.setMinThreads(Integer.valueOf(minThreads)); threadPool.setIdleTimeout(Integer.valueOf(idleTimeout)); final GzipHandler gzipHandler = new GzipHandler(); gzipHandler.addIncludedMethods(HttpMethod.POST.asString()); gzipHandler.setHandler(server.getHandler()); gzipHandler.setSyncFlush(true); server.setHandler(gzipHandler); }); return factory; }
Example #9
Source File: ZeppelinhubRestApiHandler.java From zeppelin with Apache License 2.0 | 5 votes |
public String get(String token, String argument) throws IOException { if (StringUtils.isBlank(token)) { return StringUtils.EMPTY; } String url = zepelinhubUrl + argument; if (PROXY_ON) { return sendToZeppelinHubViaProxy(new HttpGet(url), StringUtils.EMPTY, token, true); } else { return sendToZeppelinHub(HttpMethod.GET, url, StringUtils.EMPTY, token, true); } }
Example #10
Source File: HTTP.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Send out a POST-HTTP request. Errors will be logged, returned values just ignored. * * @param url the URL to be used for the POST request. * @param contentType the content type of the given <code>content</code> * @param content the content to be send to the given <code>url</code> or <code>null</code> if no content should be * send. * @param timeout timeout in ms * @return the response body or <code>NULL</code> when the request went wrong */ static public String sendHttpPostRequest(String url, String contentType, String content, int timeout) { String response = null; try { response = HttpUtil.executeUrl(HttpMethod.POST.name(), url, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), contentType, timeout); } catch (IOException e) { logger.error("Fatal transport error: {}", e.getMessage()); } return response; }
Example #11
Source File: HTTP.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Send out a POST-HTTP request. Errors will be logged, returned values just ignored. * * @param url the URL to be used for the POST request. * @param timeout timeout in ms * @return the response body or <code>NULL</code> when the request went wrong */ static public String sendHttpPostRequest(String url, int timeout) { String response = null; try { response = HttpUtil.executeUrl(HttpMethod.POST.name(), url, timeout); } catch (IOException e) { logger.error("Fatal transport error: {}", e.getMessage()); } return response; }
Example #12
Source File: Http2SolrClient.java From lucene-solr with Apache License 2.0 | 5 votes |
public OutStream initOutStream(String baseUrl, UpdateRequest updateRequest, String collection) throws IOException { String contentType = requestWriter.getUpdateContentType(); final ModifiableSolrParams origParams = new ModifiableSolrParams(updateRequest.getParams()); // The parser 'wt=' and 'version=' params are used instead of the // original params ModifiableSolrParams requestParams = new ModifiableSolrParams(origParams); requestParams.set(CommonParams.WT, parser.getWriterType()); requestParams.set(CommonParams.VERSION, parser.getVersion()); String basePath = baseUrl; if (collection != null) basePath += "/" + collection; if (!basePath.endsWith("/")) basePath += "/"; OutputStreamContentProvider provider = new OutputStreamContentProvider(); Request postRequest = httpClient .newRequest(basePath + "update" + requestParams.toQueryString()) .method(HttpMethod.POST) .header(HttpHeader.CONTENT_TYPE, contentType) .content(provider); decorateRequest(postRequest, updateRequest); InputStreamResponseListener responseListener = new InputStreamResponseListener(); postRequest.send(responseListener); boolean isXml = ClientUtils.TEXT_XML.equals(requestWriter.getUpdateContentType()); OutStream outStream = new OutStream(collection, origParams, provider, responseListener, isXml); if (isXml) { outStream.write("<stream>".getBytes(FALLBACK_CHARSET)); } return outStream; }
Example #13
Source File: ZeppelinhubRestApiHandler.java From zeppelin with Apache License 2.0 | 5 votes |
private String sendToZeppelinHub(HttpMethod method, String url, String json, String token, boolean withResponse) throws IOException { Request request = client.newRequest(url).method(method).header(ZEPPELIN_TOKEN_HEADER, token); if ((method.equals(HttpMethod.PUT) || method.equals(HttpMethod.POST)) && !StringUtils.isBlank(json)) { request.content(new StringContentProvider(json, "UTF-8"), "application/json;charset=UTF-8"); } return withResponse ? sendToZeppelinHub(request) : sendToZeppelinHubWithoutResponseBody(request); }
Example #14
Source File: HttpUtilTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void baseTest() throws Exception { mockResponse(HttpStatus.OK_200); String result = HttpUtil.executeUrl("GET", URL, 500); assertEquals("Some content", result); verify(httpClientMock).newRequest(URL); verify(requestMock).method(HttpMethod.GET); verify(requestMock).timeout(500, TimeUnit.MILLISECONDS); verify(requestMock).send(); }
Example #15
Source File: ZeppelinhubRestApiHandler.java From zeppelin with Apache License 2.0 | 5 votes |
public void del(String token, String argument) throws IOException { if (StringUtils.isBlank(argument)) { LOG.error("Cannot delete empty note from ZeppelinHub"); return; } if (PROXY_ON) { sendToZeppelinHubViaProxy(new HttpDelete(zepelinhubUrl + argument), StringUtils.EMPTY, token, false); } else { sendToZeppelinHub(HttpMethod.DELETE, zepelinhubUrl + argument, StringUtils.EMPTY, token, false); } }
Example #16
Source File: ZeppelinhubRestApiHandler.java From zeppelin with Apache License 2.0 | 5 votes |
public void put(String token, String jsonNote) throws IOException { if (StringUtils.isBlank(jsonNote)) { LOG.error("Cannot save empty note/string to ZeppelinHub"); return; } if (PROXY_ON) { sendToZeppelinHubViaProxy(new HttpPut(zepelinhubUrl), jsonNote, token, false); } else { sendToZeppelinHub(HttpMethod.PUT, zepelinhubUrl, jsonNote, token, false); } }
Example #17
Source File: ZeppelinhubRestApiHandler.java From zeppelin with Apache License 2.0 | 5 votes |
public String putWithResponseBody(String token, String url, String json) throws IOException { if (StringUtils.isBlank(url) || StringUtils.isBlank(json)) { LOG.error("Empty note, cannot send it to zeppelinHub"); throw new IOException("Cannot send emtpy note to zeppelinHub"); } if (PROXY_ON) { return sendToZeppelinHubViaProxy(new HttpPut(zepelinhubUrl + url), json, token, true); } else { return sendToZeppelinHub(HttpMethod.PUT, zepelinhubUrl + url, json, token, true); } }
Example #18
Source File: PipelineManagerServlet.java From baleen with Apache License 2.0 | 5 votes |
@Override public WebPermission[] getPermissions() { return new WebPermission[] { new WebPermission("Create " + getType(), HttpMethod.POST, getType() + ".create"), new WebPermission("Get/List " + getType(), HttpMethod.GET, getType() + ".list"), new WebPermission("Delete " + getType(), HttpMethod.DELETE, getType() + ".delete"), new WebPermission("Pause/unpause " + getType(), HttpMethod.POST, getType() + ".control"), }; }
Example #19
Source File: HTTP.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Send out a PUT-HTTP request. Errors will be logged, returned values just ignored. * * @param url the URL to be used for the PUT request. * @param contentType the content type of the given <code>content</code> * @param content the content to be send to the given <code>url</code> or <code>null</code> if no content should be * send. * @param timeout timeout in ms * @return the response body or <code>NULL</code> when the request went wrong */ static public String sendHttpPutRequest(String url, String contentType, String content, int timeout) { String response = null; try { response = HttpUtil.executeUrl(HttpMethod.PUT.name(), url, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), contentType, timeout); } catch (IOException e) { logger.error("Fatal transport error: {}", e.getMessage()); } return response; }
Example #20
Source File: HTTP.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Send out a PUT-HTTP request. Errors will be logged, returned values just ignored. * * @param url the URL to be used for the PUT request. * @param timeout timeout in ms * @return the response body or <code>NULL</code> when the request went wrong */ static public String sendHttpPutRequest(String url, int timeout) { String response = null; try { response = HttpUtil.executeUrl(HttpMethod.PUT.name(), url, timeout); } catch (IOException e) { logger.error("Fatal transport error: {}", e.getMessage()); } return response; }
Example #21
Source File: HTTP.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Send out a GET-HTTP request. Errors will be logged, returned values just ignored. * * @param url the URL to be used for the GET request. * @param headers the HTTP headers to be sent in the request. * @param timeout timeout in ms * @return the response body or <code>NULL</code> when the request went wrong */ public static String sendHttpGetRequest(String url, Map<String, String> headers, int timeout) { try { Properties headerProperties = new Properties(); headerProperties.putAll(headers); return HttpUtil.executeUrl(HttpMethod.GET.name(), url, headerProperties, null, null, timeout); } catch (IOException e) { logger.error("Fatal transport error: {}", e.getMessage()); } return null; }
Example #22
Source File: HTTP.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Send out a GET-HTTP request. Errors will be logged, success returns response * * @param url the URL to be used for the GET request. * @param timeout timeout in ms * @return the response body or <code>NULL</code> when the request went wrong */ static public String sendHttpGetRequest(String url, int timeout) { String response = null; try { return HttpUtil.executeUrl(HttpMethod.GET.name(), url, timeout); } catch (IOException e) { logger.error("Fatal transport error: {}", e.getMessage()); } return response; }
Example #23
Source File: BaseHttpUtilTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { initMocks(this); Field httpClientFactory = HttpUtil.class.getDeclaredField("httpClientFactory"); httpClientFactory.setAccessible(true); httpClientFactory.set(null, clientFactoryMock); when(clientFactoryMock.getCommonHttpClient()).thenReturn(httpClientMock); when(httpClientMock.newRequest(URL)).thenReturn(requestMock); when(requestMock.method(any(HttpMethod.class))).thenReturn(requestMock); when(requestMock.timeout(anyLong(), any(TimeUnit.class))).thenReturn(requestMock); when(requestMock.send()).thenReturn(contentResponseMock); }
Example #24
Source File: HttpUtilTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCreateHttpMethod() { assertEquals(HttpMethod.GET, HttpUtil.createHttpMethod("GET")); assertEquals(HttpMethod.PUT, HttpUtil.createHttpMethod("PUT")); assertEquals(HttpMethod.POST, HttpUtil.createHttpMethod("POST")); assertEquals(HttpMethod.DELETE, HttpUtil.createHttpMethod("DELETE")); }
Example #25
Source File: HttpUtilTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Test public void baseTest() throws Exception { mockResponse(HttpStatus.OK_200); String result = HttpUtil.executeUrl("GET", URL, 500); assertEquals("Some content", result); verify(httpClientMock).newRequest(URL); verify(requestMock).method(HttpMethod.GET); verify(requestMock).timeout(500, TimeUnit.MILLISECONDS); verify(requestMock).send(); }
Example #26
Source File: HttpRequestBuilderTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testPostWithContentType() throws Exception { ArgumentCaptor<ContentProvider> argumentCaptor = ArgumentCaptor.forClass(ContentProvider.class); mockResponse(HttpStatus.OK_200); String result = HttpRequestBuilder.postTo(URL).withContent("{json: true}", "application/json") .getContentAsString(); assertEquals("Some content", result); // verify just the content-type to be added to the request verify(requestMock).method(HttpMethod.POST); verify(requestMock).content(argumentCaptor.capture(), ArgumentMatchers.eq("application/json")); }
Example #27
Source File: HttpUtil.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Factory method to create a {@link HttpMethod}-object according to the given String <code>httpMethodString</code> * * @param httpMethodString the name of the {@link HttpMethod} to create * @throws IllegalArgumentException if <code>httpMethod</code> is none of <code>GET</code>, <code>PUT</code>, * <code>POST</POST> or <code>DELETE</code> */ public static HttpMethod createHttpMethod(String httpMethodString) { // @formatter:off return Optional.ofNullable(HttpMethod.fromString(httpMethodString)) .filter(m -> m == GET || m == POST || m == PUT || m == DELETE) .orElseThrow(() -> new IllegalArgumentException("Given HTTP Method '" + httpMethodString + "' is unknown")); // @formatter:on }
Example #28
Source File: HttpUtil.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Factory method to create a {@link HttpMethod}-object according to the given String <code>httpMethodString</code> * * @param httpMethodString the name of the {@link HttpMethod} to create * @throws IllegalArgumentException if <code>httpMethod</code> is none of <code>GET</code>, <code>PUT</code>, * <code>POST</POST> or <code>DELETE</code> */ public static HttpMethod createHttpMethod(String httpMethodString) { // @formatter:off return Optional.ofNullable(HttpMethod.fromString(httpMethodString)) .filter(m -> m == GET || m == POST || m == PUT || m == DELETE) .orElseThrow(() -> new IllegalArgumentException("Given HTTP Method '" + httpMethodString + "' is unknown")); // @formatter:on }
Example #29
Source File: BaseHttpUtilTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() throws Exception { initMocks(this); Field httpClientFactory = HttpUtil.class.getDeclaredField("httpClientFactory"); httpClientFactory.setAccessible(true); httpClientFactory.set(null, clientFactoryMock); when(clientFactoryMock.getCommonHttpClient()).thenReturn(httpClientMock); when(httpClientMock.newRequest(URL)).thenReturn(requestMock); when(requestMock.method(any(HttpMethod.class))).thenReturn(requestMock); when(requestMock.timeout(anyLong(), any(TimeUnit.class))).thenReturn(requestMock); when(requestMock.send()).thenReturn(contentResponseMock); }
Example #30
Source File: HTTP.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Send out a PUT-HTTP request. Errors will be logged, returned values just ignored. * * @param url the URL to be used for the PUT request. * @param contentType the content type of the given <code>content</code> * @param content the content to be send to the given <code>url</code> or <code>null</code> if no content should be * sent. * @param headers the HTTP headers to be sent in the request. * @param timeout timeout in ms * @return the response body or <code>NULL</code> when the request went wrong */ static public String sendHttpPutRequest(String url, String contentType, String content, Map<String, String> headers, int timeout) { try { Properties headerProperties = new Properties(); headerProperties.putAll(headers); return HttpUtil.executeUrl(HttpMethod.PUT.name(), url, headerProperties, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), contentType, timeout); } catch (IOException e) { logger.error("Fatal transport error: {}", e.getMessage()); } return null; }