Refine search
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, @Nullable String body) { Request httpRequest = this.httpClient.newRequest(url).method(method); addHttpHeaders(httpRequest, headers); if (body != null) { httpRequest.content(new StringContentProvider(body)); } ContentResponse response; try { response = httpRequest.send(); } catch (Exception ex) { throw new SockJsTransportFailureException("Failed to execute request to " + url, ex); } HttpStatus status = HttpStatus.valueOf(response.getStatus()); HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders()); return (response.getContent() != null ? new ResponseEntity<>(response.getContentAsString(), responseHeaders, status) : new ResponseEntity<>(responseHeaders, status)); }
Request req; if(graphId != null && graphId.length() > 0) { //ensure this is a 'real' graphId req = client.POST(restUrl + "graph/" + graphId + "?create=true"); req = client.POST(restUrl + "graph/"); req.content(new StringContentProvider(metaWrapper.toString()), "application/json"); res = req.send(); lgr.parseContentResponse(res);
client = new HttpClient(SSLUtils.createSslContextFactory(config, true)); } else { client = new HttpClient(); client.setFollowRedirects(false); Request req = client.newRequest(url); req.method(method); req.accept("application/json"); req.agent("kafka-connect"); if (serializedBody != null) { req.content(new StringContentProvider(serializedBody, StandardCharsets.UTF_8), "application/json");
@Override public void requestOnce(org.eclipse.jetty.client.HttpClient client, org.eclipse.jetty.client.api.Response.Listener responseListener) { org.eclipse.jetty.client.api.Request request = client .newRequest(uri) .accept("application/json") .timeout(task.getTimeoutMills(), TimeUnit.MILLISECONDS) .method(method); if (method == HttpMethod.POST) { request.content(new StringContentProvider(content), "application/json"); } if (!authorizationHeader.isEmpty()) { request.header("Authorization", authorizationHeader); } request.send(responseListener); }
private void normalizeRequest(Request request) if (request.getMethod() == null) request.method(HttpMethod.GET); if (request.getVersion() == null) request.version(HttpVersion.HTTP_1_1); if (request.getIdleTimeout() <= 0) request.idleTimeout(client.getIdleTimeout(), TimeUnit.MILLISECONDS); HttpMethod method = request.getMethod(); if (request.getAgent() == null) headers.put(client.getUserAgentField()); request.header(HttpHeader.CONTENT_TYPE.asString(), MimeTypes.Type.FORM_ENCODED.asString()); request.content(new StringContentProvider(params.toString())); break; List<HttpCookie> cookies = client.getCookieStore().get(request.getURI()); StringBuilder cookieString = null; for (int i = 0; i < cookies.size(); ++i)
final Request request = _httpClient.newRequest(url).method(HttpMethod.POST); request.header(HttpHeader.CONTENT_TYPE.asString(), "application/json;charset=UTF-8"); request.header(HttpHeader.COOKIE.asString(), value.toString()); request.content(new StringContentProvider(generateJSON(messages)));
/*配置sslcontextfactory处理https请求*/ SslContextFactory sslContextFactory = new SslContextFactory(); HttpClient httpClient = new HttpClient(sslContextFactory); httpClient.setFollowRedirects(false); httpClient.start(); /*配置post请求的url、body、以及请求头*/ Request request = httpClient.POST("https://a1.easemob.com/yinshenxia/yinshenxia/users"); request.header(HttpHeader.CONTENT_TYPE, "application/json"); request.content(new StringContentProvider("{\"username\":\"jliu\",\"password\":\"123456\"}","utf-8")); // request.param("username", "jliu"); // request.param("password", "123456"); ContentResponse response = request.send(); String res = new String(response.getContent()); System.out.println(res); httpClient.stop();
public void setRequestContent(String data, String charset) throws UnsupportedEncodingException { StringContentProvider cp = charset != null ? new StringContentProvider(data, charset) : new StringContentProvider(data); this.request.content(cp, this.requestContentType); }
public String callSynchronous(JsonArray params, OrangeContext orangeContext) throws RpcCallException { HttpClientWrapper clientWrapper = loadBalancer.getHttpClientWrapper(); HttpRequestWrapper balancedPost = clientWrapper.createHttpPost(this); //set custom headers if (orangeContext != null) { orangeContext.getProperties().forEach(balancedPost::setHeader); } balancedPost.setHeader("Content-type", TYPE_JSON); //TODO: fix: Temporary workaround below until go services are more http compliant balancedPost.setHeader("Connection", "close"); JsonRpcRequest jsonRequest = new JsonRpcRequest(null, methodName, params); String json = jsonRequest.toString(); balancedPost.setContentProvider(new StringContentProvider(json)); logger.debug("Sending request of size {}", json.length()); ContentResponse rpcResponse = clientWrapper.execute(balancedPost, new JsonRpcCallExceptionDecoder(), orangeContext); String rawResponse = rpcResponse.getContentAsString(); logger.debug("Json response from the service: {}", rawResponse); return JsonRpcResponse.fromString(rawResponse).getResult().getAsString(); }
/** * @param graphId String for graph ID * @param graph LemonGraphObject * @return LemonGraphResponse * @throws InvalidGraphException thrown when failing to connect and hit graph/ */ public static LemonGraphResponse postToGraph(String graphId, LemonGraphObject graph) throws InvalidGraphException { LemonGraphResponse lgr = new LemonGraphResponse(); ContentResponse res = null; try { openConnection(); String url = restUrl + "graph/" + graphId; Request req = client.POST(url); JSONObject graphContent = graph.get(); req.content(new StringContentProvider(graphContent.toString()), "application/json"); res = req.send(); lgr.parseContentResponse(res); // TODO: check responseCode to be 204? } catch (Exception e) { log.error("Error trying to postToGraph "+e.getMessage()); lgr.setSuccess(false); } return lgr; }
private void normalizeRequest(Request request) if (request.getMethod() == null) request.method(HttpMethod.GET); if (request.getVersion() == null) request.version(HttpVersion.HTTP_1_1); if (request.getIdleTimeout() <= 0) request.idleTimeout(client.getIdleTimeout(), TimeUnit.MILLISECONDS); HttpMethod method = request.getMethod(); if (request.getAgent() == null) headers.put(client.getUserAgentField()); request.header(HttpHeader.CONTENT_TYPE.asString(), MimeTypes.Type.FORM_ENCODED.asString()); request.content(new StringContentProvider(params.toString())); break; List<HttpCookie> cookies = client.getCookieStore().get(request.getURI()); StringBuilder cookieString = null; for (int i = 0; i < cookies.size(); ++i)
@Override public IRequest setBodyEntity(String content, String encoding, String contentType) { request.content(new StringContentProvider(content, encoding), contentType); return this; }
ContentResponse contentResponse = client.POST(endpoint) .content(new StringContentProvider("XML envelope")) .cookie(new HttpCookie("JSESSIONID", jSessionIdCookieValue)) .cookie(new HttpCookie("ZM_AUTH_TOKEN", authToken)) .cookie(new HttpCookie("ZM_TEST", "true")) .send();
private boolean sendRegistration(JsonObject request) { try { ContentResponse httpResponse = httpClient.newRequest(getRegistrationUri()). content(new StringContentProvider(request.toString())). method(HttpMethod.PUT).header(HttpHeader.CONTENT_TYPE, "application/json").send(); if (httpResponse.getStatus() == 200) { return true; } } catch (Exception ex) { logger.warn("Caught exception sending registration {}", request.toString(), ex); } return false; }
@Test public void shouldConflictWhenTryingToReplaceExistingEntryUsingPost() throws Exception { //given putStringValueInCache("default", "test", "test"); //when ContentResponse response = client .POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "default", "test")) .content(new StringContentProvider("Hey!")) .header("Content-type", "text/plain;charset=UTF-8") .send(); //then ResponseAssertion.assertThat(response).isConflicted(); }
protected Request getRequestWithoutSessionId(HttpServletRequest clientRequest, Request proxyRequest) throws IOException { String content = IOUtils.toString(clientRequest.getInputStream(), UTF_8); if (!content.isEmpty()) { String remoteHost = getRemoteHost(clientRequest); content = removeSessionIdSafe(content, remoteHost); } return proxyRequest.content( new StringContentProvider(clientRequest.getContentType(), content, UTF_8)); }
switch (format) { case "json": return new StringContentProvider(contentType.or("application/json"), resolveSecrets(content, secrets).toString(), UTF_8); case "form": if (content.isArray()) { switch (format) { case "text": return new StringContentProvider(contentType.or("plain/text"), resolveSecrets(content, secrets).asText(), UTF_8); case "json": return new StringContentProvider(contentType.or("application/json"), resolveSecrets(content, secrets).toString(), UTF_8); default: throw invalidContentFormat(format, nodeType);
protected String sendRequest(String path, String data, HttpMethod method) throws Exception { String url = getServiceUrl(path); Request request = httpClient.newRequest(url).method(method). header(HttpHeader.CONTENT_TYPE, "application/json"); if (data != null) { request.content(new StringContentProvider(data)); } ContentResponse response = request.send(); return response.getContentAsString(); }
@Test public void shouldPutImmortalEntryWithZeroTtlAndIdleTime() throws Exception { //when ContentResponse response = client .POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "expiration", "test")) .content(new StringContentProvider("test")) .header("timeToLiveSeconds", "0") .header("maxIdleTimeSeconds", "0") .send(); InternalCacheEntry<String, byte[]> cacheEntry = getCacheEntry("expiration", "test".getBytes()); Metadata metadata = cacheEntry.getMetadata(); //then ResponseAssertion.assertThat(response).isOk(); Assertions.assertThat(metadata.lifespan()).isEqualTo(DEFAULT_LIFESPAN); Assertions.assertThat(metadata.maxIdle()).isEqualTo(DEFAULT_MAX_IDLE); }
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, @Nullable String body) { Request httpRequest = this.httpClient.newRequest(url).method(method); addHttpHeaders(httpRequest, headers); if (body != null) { httpRequest.content(new StringContentProvider(body)); } ContentResponse response; try { response = httpRequest.send(); } catch (Exception ex) { throw new SockJsTransportFailureException("Failed to execute request to " + url, ex); } HttpStatus status = HttpStatus.valueOf(response.getStatus()); HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders()); return (response.getContent() != null ? new ResponseEntity<>(response.getContentAsString(), responseHeaders, status) : new ResponseEntity<>(responseHeaders, status)); }