当前位置: 首页>>代码示例>>Java>>正文


Java HttpHeaders类代码示例

本文整理汇总了Java中io.vertx.core.http.HttpHeaders的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders类的具体用法?Java HttpHeaders怎么用?Java HttpHeaders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpHeaders类属于io.vertx.core.http包,在下文中一共展示了HttpHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: genBodyBuffer

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
private void genBodyBuffer() throws Exception {
  if (bodyBuffer != null) {
    return;
  }

  if (formMap == null) {
    return;
  }

  request.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
  try (BufferOutputStream output = new BufferOutputStream()) {
    for (Entry<String, Object> entry : formMap.entrySet()) {
      output.write(entry.getKey().getBytes(StandardCharsets.UTF_8));
      output.write('=');
      if (entry.getValue() != null) {
        String value = RestObjectMapper.INSTANCE.convertToString(entry.getValue());
        value = URLEncoder.encode(value, StandardCharsets.UTF_8.name());
        output.write(value.getBytes(StandardCharsets.UTF_8));
      }
      output.write('&');
    }
    bodyBuffer = output.getBuffer();
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:RestClientRequestImpl.java

示例2: end

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Override
public void end(Buffer chunk) {
    checkWritten();
    if (!chunked && !contentLengthSet()) {
        headers().set(HttpHeaders.CONTENT_LENGTH, String.valueOf(chunk.length()));
    }
    body().appendBuffer(chunk);
    if (!headWritten) {
        prepareHeaders();
    }

    outputResponse();

    closed = true;
    written = true;

    if (bodyEndHandler != null) {
        bodyEndHandler.handle(null);
    }
    if (endHandler != null) {
        endHandler.handle(null);
    }
}
 
开发者ID:noseka1,项目名称:vertx-aws-lambda,代码行数:24,代码来源:HttpServerResponseImpl.java

示例3: addResponseHeaders

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
default void addResponseHeaders(RouteDefinition definition, HttpServerResponse response) {

		if (!response.ended() &&
			!response.headers().contains(HttpHeaders.CONTENT_TYPE)) {

			if (definition != null &&
			    definition.getProduces() != null) {
				for (MediaType produces : definition.getProduces()) {
					response.putHeader(HttpHeaders.CONTENT_TYPE, MediaTypeHelper.toString(produces));
				}
			}
			else {
				response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD);
			}
		}
	}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:17,代码来源:HttpResponseWriter.java

示例4: handle

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Override
public void handle(final RoutingContext context) {

    if (LOG.isErrorEnabled()) {
        LOG.error("Unhandled server exception statusCode={} responseEnded={} uri={}", context.statusCode(), context.response().ended(), context.request().uri(), context.failure());
    }
    if (!context.response().ended()) {
        if (context.failure() instanceof ConnectException) {
            context.response().setStatusCode(504)
                .setStatusMessage(GATEWAY_TIMEOUT)
                .putHeader(CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
                .end(Errors.serverError(GATEWAY_TIMEOUT).toBuffer());
        } else if (context.failure() instanceof UnknownHostException) {
            context.response().setStatusCode(503)
                .setStatusMessage(GATEWAY_ERROR)
                .putHeader(CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
                .end(Errors.serverError(GATEWAY_ERROR).toBuffer());
        } else {
            context.response().setStatusCode(context.statusCode() == -1 ? 500 : context.statusCode())
                .setStatusMessage(INTERNAL_SERVER_ERROR)
                .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
                .end(Errors.serverError(INTERNAL_SERVER_ERROR).toBuffer());
        }
    }

}
 
开发者ID:trajano,项目名称:app-ms,代码行数:27,代码来源:GlobalFailureHandler.java

示例5: reply

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
public static void reply(
        final RoutingContext context,
        final Envelop envelop) {
    // 1. Get response reference
    final HttpServerResponse response
            = context.response();
    // 2. Set response status
    final HttpStatusCode code = envelop.status();
    response.setStatusCode(code.code());
    response.setStatusMessage(code.message());
    response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    // 3. Response process
    if (!response.ended()) {
        response.end(envelop.response());
    }
    response.close();
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:18,代码来源:Answer.java

示例6: callback_path_responds_with_302_when_no_auth_code_param_is_present

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Test
public void callback_path_responds_with_302_when_no_auth_code_param_is_present(final TestContext ctx) {
    final Async async = ctx.async();

    vertx.createHttpClient().get(PORT, HOST, "/oauth/callback", res -> {
        assertEquals(302, res.statusCode());
        final URL redirectUrl = buildUrl(res.headers().get(HttpHeaders.LOCATION));
        assertEquals("accounts.google.com", redirectUrl.getHost());
        final Map<String, String> params = parseQuery(redirectUrl);
        assertEquals("offline", params.get("access_type"));
        assertEquals("force", params.get("approval_prompt"));
        assertEquals(System.getenv("CLIENT_ID"), params.get("client_id"));
        assertEquals(System.getenv("REDIRECT_URL"), params.get("redirect_uri"));
        assertEquals("code", params.get("response_type"));
        async.complete();
    }).putHeader(HttpHeaders.USER_AGENT, "SomeUserAgent/1.0").end();
}
 
开发者ID:travelaudience,项目名称:nexus-proxy,代码行数:18,代码来源:CloudIamAuthNexusProxyVerticleTests.java

示例7: ask

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
public static void ask(
	HttpServerResponse httpServerResponse, String conversationToken,
	String initialPrompt, String[] noInputPrompts) {

	httpServerResponse.putHeader(
		HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8");
	httpServerResponse.putHeader("Google-Assistant-API-Version", "v1");

	JsonObject responseJSON = new JsonObject();

	if (conversationToken != null) {
		responseJSON.put("conversation_token", conversationToken);
	}

	responseJSON.put("expect_user_response", true);
	responseJSON.put(
		"expected_inputs",
		JsonUtil.getArray(
			_getExpectedInputJSON(initialPrompt, noInputPrompts)));

	httpServerResponse.end(responseJSON.encode());
}
 
开发者ID:Ithildir,项目名称:actions-on-google-vertx-sample,代码行数:23,代码来源:ConversationUtil.java

示例8: apply

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Override
public JsonObject apply(RoutingContext context) throws Throwable {

    if (context.request().method() == HttpMethod.GET) {
        throw new RequestConvertersionException("Invalid HttpRequestMethod 'GET'");
    }

    checkContentType(context.request().headers().get(HttpHeaders.CONTENT_TYPE));

    final JsonObject jsonObject = context.getBodyAsJson();

    checkJsonObject(jsonObject);

    return new JsonObject(
        ImmutableMap.<String, Object>builder()
            .putAll(jsonObject.getMap())
            .putAll(pathParams(context.pathParams(), jsonObject))
            .build()
    );
}
 
开发者ID:codefacts,项目名称:Elastic-Components,代码行数:21,代码来源:JsonObjectRequestConverterImpl.java

示例9: handle

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Override
public void handle(RoutingContext rc) {
  HttpServerResponse response = rc.response();
  response
    .setChunked(true)
    .putHeader(HttpHeaders.CONTENT_TYPE, "text/event-stream")
    .putHeader(HttpHeaders.CACHE_CONTROL, "no-cache")
    .putHeader(HttpHeaders.CONNECTION, HttpHeaders.KEEP_ALIVE);

  rc.request().connection()
    .closeHandler(v -> {
      connections.remove(response);
      endQuietly(response);
    })
    .exceptionHandler(t -> {
      connections.remove(response);
      rc.fail(t);
    });

  connections.add(response);
}
 
开发者ID:vert-x3,项目名称:vertx-circuit-breaker,代码行数:22,代码来源:HystrixMetricEventStream.java

示例10: createSuccessResponse

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
private KnotContext createSuccessResponse(KnotContext inputContext, String renderedContent) {
  ClientResponse clientResponse = inputContext.getClientResponse();
  if (StringUtils.isBlank(renderedContent)) {
    clientResponse.setStatusCode(HttpResponseStatus.NO_CONTENT.code());
  } else {
    MultiMap headers = clientResponse.getHeaders();
    headers.add(HttpHeaders.CONTENT_LENGTH.toString().toLowerCase(),
        Integer.toString(renderedContent.length()));

    clientResponse.setBody(Buffer.buffer(renderedContent)).setHeaders(headers);
    clientResponse.setStatusCode(HttpResponseStatus.OK.code());
  }

  return new KnotContext()
      .setClientRequest(inputContext.getClientRequest())
      .setClientResponse(clientResponse);
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:18,代码来源:FragmentAssemblerKnotProxyImpl.java

示例11: testOkAddBodyRequiredWithXML

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Test
public void testOkAddBodyRequiredWithXML(TestContext context) {
    Async async = context.async();
    String bodyReqXml = "<BodyType><id>1</id><name>body 1</name></BodyType>";
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/body/required");
    req.handler(response -> {
        context.assertEquals(response.statusCode(), 200);
        response.bodyHandler(body -> {
            context.assertEquals(bodyReqXml, body.toString());
            async.complete();
        });

    })
    .putHeader(HttpHeaders.CONTENT_TYPE, "application/xml")
    .end(bodyReqXml);
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:17,代码来源:BodyParameterExtractorTest.java

示例12: testOkAddArrayBodyWithXML

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Test
public void testOkAddArrayBodyWithXML(TestContext context) {
    Async async = context.async();
    String bodyReqXml = "<BodyType><id>1</id><name>body 1</name></BodyType><BodyType><id>2</id><name>body 2</name></BodyType>";
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/body/array");
    req.handler(response -> {
        context.assertEquals(response.statusCode(), 200);
        response.bodyHandler(body -> {
            context.assertEquals(bodyReqXml, body.toString());
            async.complete();
        });

    })
    .putHeader(HttpHeaders.CONTENT_TYPE, "application/xml")
    .end(bodyReqXml);
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:17,代码来源:BodyParameterExtractorTest.java

示例13: testOkFormDataSimpleRequired

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Test()
public void testOkFormDataSimpleRequired(TestContext context) {
    Async async = context.async();
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/formdata/simple/required");
    req.handler(response -> {
        response.bodyHandler(body -> {
            context.assertEquals(response.statusCode(), 200);
            context.assertEquals("toto", body.toString());
            async.complete();
        });
    });

    // Construct form
    StringBuffer payload = new StringBuffer().append("formDataRequired=").append(esc.escape("toto"));
    req.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
    req.end(payload.toString());
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:18,代码来源:FormParameterExtractorTest.java

示例14: testOkFormDataSimpleRequiredAllowEmpty

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Test()
public void testOkFormDataSimpleRequiredAllowEmpty(TestContext context) {
    Async async = context.async();
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/formdata/simple/required/allowempty");
    req.handler(response -> {
        response.bodyHandler(body -> {
            context.assertEquals(response.statusCode(), 200);
            context.assertEquals("", body.toString());
            async.complete();
        });
    });
    // Construct form
    StringBuffer payload = new StringBuffer().append("formDataRequired=");
    req.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
    req.end(payload.toString());
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:17,代码来源:FormParameterExtractorTest.java

示例15: testOkFormDataSimpleNotRequiredWithParam

import io.vertx.core.http.HttpHeaders; //导入依赖的package包/类
@Test()
public void testOkFormDataSimpleNotRequiredWithParam(TestContext context) {
    Async async = context.async();
    HttpClientRequest req = httpClient.post(TEST_PORT, TEST_HOST, "/formdata/simple/not/required");
    req.handler(response -> {
        response.bodyHandler(body -> {
            context.assertEquals(response.statusCode(), 200);
            context.assertEquals("toto", body.toString());
            async.complete();
        });
    });

    // Construct form
    StringBuffer payload = new StringBuffer().append("formDataNotRequired=").append(esc.escape("toto"));
    req.putHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
    req.end(payload.toString());
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:18,代码来源:FormParameterExtractorTest.java


注:本文中的io.vertx.core.http.HttpHeaders类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。