Java Code Examples for io.vertx.core.http.HttpServerResponse#putHeader()
The following examples show how to use
io.vertx.core.http.HttpServerResponse#putHeader() .
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: PgUtil.java From raml-module-builder with Apache License 2.0 | 6 votes |
/** * Streaming GET with query. This produces a HTTP with JSON content with * properties {@code totalRecords}, {@code resultInfo} and custom element. * The custom element is array type which POJO that is of type clazz. * * @param <T> * @param table * @param clazz * @param cql * @param offset * @param limit * @param facets * @param element * @param queryTimeout query timeout in milliseconds, or 0 for no timeout * @param okapiHeaders * @param vertxContext * @param routingContext */ @SuppressWarnings({"squid:S107"}) // Method has >7 parameters public static <T> void streamGet(String table, Class<T> clazz, String cql, int offset, int limit, List<String> facets, String element, int queryTimeout, RoutingContext routingContext, Map<String, String> okapiHeaders, Context vertxContext) { HttpServerResponse response = routingContext.response(); try { List<FacetField> facetList = FacetManager.convertFacetStrings2FacetFields(facets, JSON_COLUMN); CQLWrapper wrapper = new CQLWrapper(new CQL2PgJSON(table + "." + JSON_COLUMN), cql, limit, offset); streamGet(table, clazz, wrapper, facetList, element, queryTimeout, routingContext, okapiHeaders, vertxContext); } catch (Exception e) { logger.error(e.getMessage(), e); response.setStatusCode(500); response.putHeader(HttpHeaders.CONTENT_TYPE, "text/plain"); response.end(e.toString()); } }
Example 2
Source File: ApiKeyHandler.java From gravitee-gateway with Apache License 2.0 | 6 votes |
@Override public void handle(RoutingContext ctx) { HttpServerResponse response = ctx.response(); try { String sApi = ctx.request().getParam("apiId"); ApiKeyRefresher apiKeyRefresher = apiKeyRefreshers.get(sApi); if (apiKeyRefresher == null) { response.setStatusCode(HttpStatusCode.NOT_FOUND_404); } else { response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); response.setStatusCode(HttpStatusCode.OK_200); response.setChunked(true); Json.prettyMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); response.write(Json.prettyMapper.writeValueAsString(new RefresherStatistics(apiKeyRefresher))); } } catch (JsonProcessingException jpe) { response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500); LOGGER.error("Unable to transform data object to JSON", jpe); } response.end(); }
Example 3
Source File: ApisManagementEndpoint.java From gravitee-gateway with Apache License 2.0 | 6 votes |
@Override public void handle(RoutingContext ctx) { HttpServerResponse response = ctx.response(); response.setStatusCode(HttpStatusCode.OK_200); response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); response.setChunked(true); try { Collection<ListApiEntity> apis = apiManager.apis().stream().map(api -> { ListApiEntity entity = new ListApiEntity(); entity.setId(api.getId()); entity.setName(api.getName()); entity.setVersion(api.getVersion()); return entity; }).collect(Collectors.toList()); Json.prettyMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); response.write(Json.prettyMapper.writeValueAsString(apis)); } catch (JsonProcessingException jpe) { response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500); LOGGER.error("Unable to transform data object to JSON", jpe); } response.end(); }
Example 4
Source File: AliPayApi.java From AlipayWechatPlatform with GNU General Public License v3.0 | 6 votes |
/** * 该方法实现了支付宝手机网页的支付功能; * 方法将调用支付宝支付页面需要用到的数据拼接和设置好,然后,写到响应中,前台会自动弹出支付宝支付页面; * 其中,支付金额要求大于0.01,并且小于100000000,需要调用者自己检查该值再传进来,否则页面会报获取不到订单信息错误; * * @param aliAccountInfo 保存了支付宝账户的信息,包括appId、用户私钥、支付宝公钥和回调地址等,具体参考AliAccountInfo类的属性说明 * @param payBizContent 保存了订单信息,包括本地订单号、金额等,具体参考BizContent类的属性说明 * Create by quandong */ public static void wapPay(AliAccountInfo aliAccountInfo, PayBizContent payBizContent, HttpServerResponse httpResponse) throws IOException { AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 从客户端工厂中获取AlipayClient AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest(); // 创建API对应的request String form = ""; alipayRequest.setReturnUrl(aliAccountInfo.getReturnUrl()); // 设置回跳地址 alipayRequest.setNotifyUrl(aliAccountInfo.getNotifyUrl()); // 设置通知地址 alipayRequest.setBizContent(payBizContent.toString()); // 填充业务参数 try { form = alipayClient.pageExecute(alipayRequest).getBody(); // 调用SDK生成表单 } catch (AlipayApiException e) { e.printStackTrace(); } httpResponse.putHeader("Content-Type", "text/html;charset=" + AlipayConstants.CHARSET_UTF8); // 设置文本类型及编码 httpResponse.end(form); // 直接将完整的表单html输出到页面 }
Example 5
Source File: ApiSubscriptionsHandler.java From gravitee-gateway with Apache License 2.0 | 6 votes |
@Override public void handle(RoutingContext ctx) { HttpServerResponse response = ctx.response(); try { String sApi = ctx.request().getParam("apiId"); SubscriptionRefresher apiKeyRefresher = subscriptionRefreshers.get(sApi); if (apiKeyRefresher == null) { response.setStatusCode(HttpStatusCode.NOT_FOUND_404); } else { response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); response.setStatusCode(HttpStatusCode.OK_200); response.setChunked(true); Json.prettyMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); response.write(Json.prettyMapper.writeValueAsString(new RefresherStatistics(apiKeyRefresher))); } } catch (JsonProcessingException jpe) { response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500); LOGGER.error("Unable to transform data object to JSON", jpe); } response.end(); }
Example 6
Source File: ApiManagementEndpoint.java From gravitee-gateway with Apache License 2.0 | 6 votes |
@Override public void handle(RoutingContext ctx) { HttpServerResponse response = ctx.response(); try { String sApi = ctx.request().getParam("apiId"); Api api = apiManager.get(sApi); if (api == null) { response.setStatusCode(HttpStatusCode.NOT_FOUND_404); } else { response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); response.setStatusCode(HttpStatusCode.OK_200); response.setChunked(true); Json.prettyMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); response.write(Json.prettyMapper.writeValueAsString(api)); } } catch (JsonProcessingException jpe) { response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500); LOGGER.error("Unable to transform data object to JSON", jpe); } response.end(); }
Example 7
Source File: WriteHandler.java From nassh-relay with GNU General Public License v2.0 | 5 votes |
@Override public void handle(final RoutingContext context) { final HttpServerRequest request = context.request(); final HttpServerResponse response = context.response(); response.putHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.putHeader("Pragma", "no-cache"); if (request.params().contains("sid") && request.params().contains("wcnt") && request.params().contains("data")) { final UUID sid = UUID.fromString(request.params().get("sid")); final byte[] data = Base64.getUrlDecoder().decode(request.params().get("data")); response.setStatusCode(200); final LocalMap<String, Session> map = vertx.sharedData().getLocalMap(Constants.SESSIONS); final Session session = map.get(sid.toString()); if (session == null) { response.setStatusCode(410); response.end(); return; } session.setWrite_count(Integer.parseInt(request.params().get("wcnt"))); final Buffer message = Buffer.buffer(); message.appendBytes(data); vertx.eventBus().publish(session.getHandler(), message); response.end(); } else { response.setStatusCode(410); response.end(); } }
Example 8
Source File: WriteReadStreamBlobAsHttpResponseHeaders.java From sfs with Apache License 2.0 | 5 votes |
@Override public Holder2<SfsRequest, Optional<A>> call(Holder2<SfsRequest, Optional<A>> input) { HttpServerResponse httpServerResponse = input.value0().response(); Optional<A> oBlob = input.value1(); if (oBlob.isPresent()) { A blob = oBlob.get(); long offset = blob.getOffset(); httpServerResponse .putHeader(X_CONTENT_OFFSET, valueOf(offset)); } return input; }
Example 9
Source File: Main.java From DocBleach with MIT License | 5 votes |
private void sendFile(RoutingContext routingContext, String fileName, File saneFile) { HttpServerResponse response = routingContext.response(); response.putHeader("Content-Description", "File Transfer"); response.putHeader("Content-Type", "application/octet-stream"); response.putHeader( "Content-Disposition", "attachment; filename=" + fileName); // @TODO: don't trust this name? response.putHeader("Content-Transfer-Encoding", "binary"); response.putHeader("Expires", "0"); response.putHeader("Pragma", "Public"); response.putHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.putHeader("Content-Length", "" + saneFile.length()); response.sendFile(saneFile.getAbsolutePath()); }
Example 10
Source File: JaxResponseWriter.java From rest.vertx with Apache License 2.0 | 5 votes |
private static void addHeaders(Response jaxrsResponse, HttpServerResponse response) { if (jaxrsResponse.getMetadata() != null) { List<Object> cookies = jaxrsResponse.getMetadata().get(HttpHeaders.SET_COOKIE.toString()); if (cookies != null) { Iterator<Object> it = cookies.iterator(); while (it.hasNext()) { Object next = it.next(); if (next instanceof NewCookie) { NewCookie cookie = (NewCookie) next; response.putHeader(HttpHeaders.SET_COOKIE, cookie.toString()); } } if (cookies.size() < 1) { jaxrsResponse.getMetadata().remove(HttpHeaders.SET_COOKIE.toString()); } } } if (jaxrsResponse.getMetadata() != null && jaxrsResponse.getMetadata().size() > 0) { for (String name : jaxrsResponse.getMetadata().keySet()) { List<Object> meta = jaxrsResponse.getMetadata().get(name); if (meta != null && meta.size() > 0) { for (Object item : meta) { if (item != null) { response.putHeader(name, item.toString()); } } } } } }
Example 11
Source File: AbstractEdgeDispatcher.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
protected void onFailure(RoutingContext context) { LOGGER.error("edge server failed.", context.failure()); HttpServerResponse response = context.response(); if (response.closed() || response.ended()) { return; } if (context.failure() instanceof InvocationException) { InvocationException exception = (InvocationException) context.failure(); response.setStatusCode(exception.getStatusCode()); response.setStatusMessage(exception.getReasonPhrase()); if (null == exception.getErrorData()) { response.end(); return; } String responseBody; try { responseBody = RestObjectMapperFactory.getRestObjectMapper().writeValueAsString(exception.getErrorData()); response.putHeader("Content-Type", MediaType.APPLICATION_JSON); } catch (JsonProcessingException e) { responseBody = exception.getErrorData().toString(); response.putHeader("Content-Type", MediaType.TEXT_PLAIN); } response.end(responseBody); } else { response.setStatusCode(Status.BAD_GATEWAY.getStatusCode()); response.setStatusMessage(Status.BAD_GATEWAY.getReasonPhrase()); response.end(); } }
Example 12
Source File: ReadHandler.java From nassh-relay with GNU General Public License v2.0 | 5 votes |
@Override public void handle(final RoutingContext context) { final HttpServerRequest request = context.request(); final HttpServerResponse response = context.response(); response.putHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.putHeader("Pragma", "no-cache"); if (request.params().contains("sid") && request.params().contains("rcnt")) { final UUID sid = UUID.fromString(request.params().get("sid")); final LocalMap<String, Session> map = vertx.sharedData().getLocalMap(Constants.SESSIONS); final Session session = map.get(sid.toString()); if (session == null) { logger.warn("could not find valid session for " + sid); response.setStatusCode(410); response.end(); return; } session.setRead_count(Integer.parseInt(request.params().get("rcnt"))); final TransferQueue queue; try { queue = QueueFactory.getQueue(sid.toString()); } catch (NoSuchQueueException ex) { logger.warn(ex, ex.fillInStackTrace()); response.setStatusCode(410); response.end(); return; } final Buffer buffer = queue.poll(); if (buffer == null) { queue.addObserver(new TransferObserver(session, request)); } else { final String encodedBytes = Base64.getUrlEncoder().encodeToString(buffer.getBytes()); response.setStatusCode(200); response.end(encodedBytes); } } else { response.setStatusCode(410); response.end(); } }
Example 13
Source File: CorsHandlerImpl.java From vertx-web with Apache License 2.0 | 5 votes |
private void addCredentialsAndOriginHeader(HttpServerResponse response, String origin) { if (allowCredentials) { response.putHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); // Must be exact origin (not '*') in case of credentials response.putHeader(ACCESS_CONTROL_ALLOW_ORIGIN, origin); } else { // Can be '*' too response.putHeader(ACCESS_CONTROL_ALLOW_ORIGIN, getAllowedOrigin(origin)); } }
Example 14
Source File: HttpVerticle.java From reactive-refarch-cloudformation with Apache License 2.0 | 4 votes |
private void checkHealth(final RoutingContext routingContext) { HttpServerResponse response = routingContext.request().response(); response.setStatusCode(200); response.putHeader("content-type", "application/json"); response.end(); }
Example 15
Source File: ProbeHandlers.java From weld-vertx with Apache License 2.0 | 4 votes |
static void setHeaders(HttpServerResponse resp, String contentType) { resp.putHeader("Content-type", contentType); setCorsHeaders(resp); }
Example 16
Source File: AfterRedirectController.java From nubes with Apache License 2.0 | 4 votes |
@GET("/after") public void handleRedirect(HttpServerResponse response) { response.putHeader("afterredirect-method", "true"); }
Example 17
Source File: ProbeHandlers.java From weld-vertx with Apache License 2.0 | 4 votes |
static void setCorsHeaders(HttpServerResponse resp) { // Support cross-site HTTP requests - we want to support external HTML5 clients // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS resp.putHeader("Access-Control-Allow-Origin", "*"); resp.putHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE"); }
Example 18
Source File: TestAssetsController.java From nubes with Apache License 2.0 | 4 votes |
@GET("/instrumented*") public void instrumentAsset(HttpServerResponse response, RoutingContext context) { response.putHeader(INSTRUMENT_HEADER, "yes"); context.next(); // in this case we HAVE TO since we want to delegate to another handler (out of Nubes scope) }
Example 19
Source File: RedirectController.java From nubes with Apache License 2.0 | 4 votes |
@GET("/client/permanent") @Redirect(value = REDIRECT_LOCATION, code = 301) public void redirectMePermanently(HttpServerResponse response) { response.putHeader("X-Custom-Header", "method-called"); }
Example 20
Source File: TestLocalMap.java From nubes with Apache License 2.0 | 4 votes |
@GET("/dynamicValueWithParamName") public void getDynamicValueWithParamName(HttpServerResponse response, @VertxLocalMap LocalMap<String, String> someMap, @Param String key) { response.putHeader("X-Map-Value", someMap.get(key)); response.end(); }