當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientRequest.putHeader方法代碼示例

本文整理匯總了Java中io.vertx.core.http.HttpClientRequest.putHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientRequest.putHeader方法的具體用法?Java HttpClientRequest.putHeader怎麽用?Java HttpClientRequest.putHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.http.HttpClientRequest的用法示例。


在下文中一共展示了HttpClientRequest.putHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: asyncPostStringWithData

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public static void asyncPostStringWithData(String url, String body, ContentType type, String encode, Handler<String> callback) {
        checkInitialized();
        HttpClientRequest req = client.requestAbs(HttpMethod.POST, url, resp -> {
            resp.bodyHandler(buf -> {
                callback.handle(buf.toString());
            });
        });
        switch (type) {
            case XML:
                req.putHeader("content-type", "application/xml;charset=" + encode);
                break;
            case JSON:
                req.putHeader("content-type", "application/json;charset=" + encode);
                break;
            case FORM:
                req.putHeader("content-type", "application/x-www-form-urlencoded" + encode);
                break;
        }
//        req.putHeader("content-length", String.valueOf(body.length()));
//        req.write(body);
        req.end(body, encode);
    }
 
開發者ID:Leibnizhu,項目名稱:AlipayWechatPlatform,代碼行數:23,代碼來源:NetworkUtils.java

示例2: execute

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public Observable<HttpClientResponse> execute(String url) {
    ObservableFuture<HttpClientResponse> handler = RxHelper.observableFuture();
    HttpClientRequest httpClientRequest =
            httpClient.requestAbs(method, url, httpClientResponse -> {
                httpClientResponse.pause();
                handler.complete(httpClientResponse);
            }).setChunked(chunked)
                    .setTimeout(timeoutMs)
                    .exceptionHandler(handler::fail);
    for (Map.Entry<String, String> entry : headers.entries()) {
        httpClientRequest.putHeader(entry.getKey(), entry.getValue());
    }

    long contentLength = contentLength();

    if (!chunked && contentLength >= 0 && !httpClientRequest.headers().contains(CONTENT_LENGTH)) {
        httpClientRequest.putHeader(CONTENT_LENGTH, valueOf(contentLength));
    }
    return writeEntity(httpClientRequest)
            .doOnNext(aVoid -> httpClientRequest.end())
            .flatMap(aVoid -> handler);
}
 
開發者ID:pitchpoint-solutions,項目名稱:sfs,代碼行數:23,代碼來源:ExecuteRequest.java

示例3: execute

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Override
public void execute() {
  final HttpClientRequest httpClientRequest = httpClient.request(method, uriEncoder.toString());
  httpClientRequest.handler(new AuthHttpHandler(this, responseHandler));
  httpClientRequest.putHeader(HttpHeaders.ACCEPT, Format.JSON.getDefaultMimetype());
  if (authorization == null && AuthScheme.Type.BASIC == realm.getSchemeType()) {
    authorize(uri, AuthSchemeFactory.newScheme(realm));
  }
  if (authorization != null) {
    httpClientRequest.putHeader(HttpHeaders.AUTHORIZATION, authorization);
  }
  if (body != null) {
    httpClientRequest.putHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(contentLength))
      .putHeader(HttpHeaders.CONTENT_TYPE, contentType)
      .write(body);
  }
  httpClientRequest.exceptionHandler(exception -> {
    responseHandler.handle(new ErrorResponse(exception));
  }).end();
}
 
開發者ID:etourdot,項目名稱:vertx-marklogic,代碼行數:21,代碼來源:DefaultMarklogicRequest.java

示例4: testOkFormDataArrayCsv

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test()
public void testOkFormDataArrayCsv(TestContext context) {
    Async async = context.async();
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/formdata/array/csv");
    req.handler(response -> {
        response.bodyHandler(body -> {
            context.assertEquals(response.statusCode(), 200);
            context.assertEquals("[\"1\",\"2\",\"3\"]", body.toString());
            async.complete();
        });
    });

    // Construct form
    StringBuffer payload = new StringBuffer().append("array_formdata=").append(esc.escape("1,2,3"));
    req.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
    req.end(payload.toString());
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:18,代碼來源:FormParameterExtractorTest.java

示例5: testOkFormDataArrayTsv

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test()
public void testOkFormDataArrayTsv(TestContext context) {
    Async async = context.async();
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/formdata/array/tsv");
    req.handler(response -> {
        response.bodyHandler(body -> {
            context.assertEquals(response.statusCode(), 200);
            context.assertEquals("[\"1\",\"2\",\"3\"]", body.toString());
            async.complete();
        });
    });

    // Construct form
    StringBuffer payload = new StringBuffer().append("array_formdata=").append(esc.escape("1\t2\t3"));
    req.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
    req.end(payload.toString());
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:18,代碼來源:FormParameterExtractorTest.java

示例6: doLogin

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public void doLogin(TestContext context) {
  String doc = "{" + LS
          + "  \"tenant\" : \"t1\"," + LS
          + "  \"username\" : \"peter\"," + LS
          + "  \"password\" : \"peter-password\"" + LS
          + "}";
  HttpClientRequest req = httpClient.post(port, "localhost", "/authn/login", response -> {
    context.assertEquals(200, response.statusCode());
    String headers = response.headers().entries().toString();
    okapiToken = response.getHeader("X-Okapi-Token");
    response.endHandler(x -> {
      useItWithGet(context);
    });
  });
  req.putHeader("X-Okapi-Tenant", okapiTenant);
  req.end(doc);
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:18,代碼來源:OkapiPerformance.java

示例7: testMainHeaderWithAnotherHeader

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test(timeout = 2000)
public void testMainHeaderWithAnotherHeader(TestContext context) {
    Async async = context.async();
    HttpClientRequest req = httpClient.get(TEST_PORT, TEST_HOST, "/v2/pet/1", response -> {
        context.assertEquals(response.statusCode(), 200);
        String header = response.getHeader("MainHeader");
        context.assertNotNull(header);
        context.assertEquals("MainValue", header);
        String customerHeader = response.getHeader("MyCustomerHeader");
        context.assertNotNull(customerHeader);
        context.assertEquals("MyCustomerValue", customerHeader);
        async.complete();
    });
    req.putHeader("MyCustomerHeader", "MyCustomerValue");
    req.end();
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:17,代碼來源:BuildRouterTest.java

示例8: setCseContext

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
protected void setCseContext(Invocation invocation, HttpClientRequest request) {
  try {
    String cseContext = JsonUtils.writeValueAsString(invocation.getContext());
    request.putHeader(org.apache.servicecomb.core.Const.CSE_CONTEXT, cseContext);
  } catch (Exception e) {
    LOGGER.debug(e.toString());
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:9,代碼來源:VertxHttpMethod.java

示例9: makeHttpClientRequest

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
/**
 * Creates {@link HttpClientRequest} (Vert.x) from {@link Request} (feign).
 *
 * @param request feign request
 * @param client vertx HTTP client
 *
 * @return fully formed HttpClientRequest
 */
private HttpClientRequest makeHttpClientRequest(
    final Request request,
    final HttpClient client) throws MalformedURLException {
  final URL url = new URL(request.url());
  final int port = url.getPort() > -1
      ? url.getPort()
      : HttpClientOptions.DEFAULT_DEFAULT_PORT;
  final String host = url.getHost();
  final String requestUri = url.getFile();

  HttpClientRequest httpClientRequest = client.request(
      httpMethodFromString(request.method()),
      port,
      host,
      requestUri);

  /* Put headers to request */
  for (Map.Entry<String, Collection<String>> header :
      request.headers().entrySet()) {
    httpClientRequest = httpClientRequest.putHeader(
        header.getKey(), header.getValue());
  }

  return httpClientRequest;
}
 
開發者ID:OpenFeign,項目名稱:feign-vertx,代碼行數:34,代碼來源:VertxHttpClient.java

示例10: testBasicAuthAllKoBadCredentials

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test(timeout = 2000)
public void testBasicAuthAllKoBadCredentials(TestContext context) {
    Async async = context.async();
    
    HttpClientRequest req = httpClient.get(TEST_PORT, TEST_HOST, "/test", response -> {
    	context.assertEquals(response.statusCode(), 401);
    	String header = response.getHeader("WWW-Authenticate");
        context.assertNotNull(header);
     	context.assertEquals("Basic realm=\"vertx-web\"", header);
        async.complete();
    });
    req.putHeader("Authorization", DUMMY_BASIC_AUTH);
    req.end();
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:15,代碼來源:BasicAuthTest.java

示例11: doDispatch

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
/**
 * Dispatch the request to the downstream REST layers.
 *
 * @param context routing context instance
 * @param path    relative path
 * @param client  relevant HTTP client
 */
private void doDispatch(RoutingContext context, String path, HttpClient client, Future<Object> cbFuture) {
  HttpClientRequest toReq = client
    .request(context.request().method(), path, response -> {
      response.bodyHandler(body -> {
        if (response.statusCode() >= 500) { // api endpoint server error, circuit breaker should fail
          cbFuture.fail(response.statusCode() + ": " + body.toString());
        } else {
          HttpServerResponse toRsp = context.response()
            .setStatusCode(response.statusCode());
          response.headers().forEach(header -> {
            toRsp.putHeader(header.getKey(), header.getValue());
          });
          // send response
          toRsp.end(body);
          cbFuture.complete();
        }
        ServiceDiscovery.releaseServiceObject(discovery, client);
      });
    });
  // set headers
  context.request().headers().forEach(header -> {
    toReq.putHeader(header.getKey(), header.getValue());
  });
  if (context.user() != null) {
    toReq.putHeader("user-principal", context.user().principal().encode());
  }
  // send request
  if (context.getBody() == null) {
    toReq.end();
  } else {
    toReq.end(context.getBody());
  }
}
 
開發者ID:sczyh30,項目名稱:vertx-blueprint-microservice,代碼行數:41,代碼來源:APIGatewayVerticle.java

示例12: testBasicAuthDummyKoBadCredentials

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test(timeout = 2000)
public void testBasicAuthDummyKoBadCredentials(TestContext context) {
    Async async = context.async();
    
    HttpClientRequest req = httpClient.get(TEST_PORT, TEST_HOST, "/dummy", response -> {
    	context.assertEquals(response.statusCode(), 401);
    	String header = response.getHeader("WWW-Authenticate");
        context.assertNotNull(header);
     	context.assertEquals("Basic realm=\"vertx-web\"", header);
        async.complete();
    });
    req.putHeader("Authorization", ALL_BASIC_AUTH);
    req.end();
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:15,代碼來源:BasicAuthTest.java

示例13: useItWithGet

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
public void useItWithGet(TestContext context) {
  HttpClientRequest req = httpClient.get(port, "localhost", "/testb", response -> {
    context.assertEquals(200, response.statusCode());
    String headers = response.headers().entries().toString();
    response.handler(x -> {
      context.assertEquals("It works", x.toString());
    });
    response.endHandler(x -> {
      useItWithPost(context);
    });
  });
  req.headers().add("X-Okapi-Token", okapiToken);
  req.putHeader("X-Okapi-Tenant", okapiTenant);
  req.end();
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:16,代碼來源:OkapiPerformance.java

示例14: testC

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test(timeout = 2000)
public void testC(TestContext context) {
    Async async = context.async();
    
    HttpClientRequest req = httpClient.get(TEST_PORT, TEST_HOST, "/test", response -> {
    	context.assertEquals(response.statusCode(), 401);
    	async.complete();
    });
    req.putHeader("Authorization", C_BASIC_AUTH);
    req.end();
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:12,代碼來源:ChainingAuthTest.java

示例15: testCD

import io.vertx.core.http.HttpClientRequest; //導入方法依賴的package包/類
@Test(timeout = 2000)
public void testCD(TestContext context) {
    Async async = context.async();
    
    HttpClientRequest req = httpClient.get(TEST_PORT, TEST_HOST, "/test", response -> {
    	context.assertEquals(response.statusCode(), 200);
    	async.complete();
    });
    req.putHeader("Authorization", C_D_BASIC_AUTH);
    req.end();
}
 
開發者ID:phiz71,項目名稱:vertx-swagger,代碼行數:12,代碼來源:ChainingAuthTest.java


注:本文中的io.vertx.core.http.HttpClientRequest.putHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。