List of usage examples for io.netty.handler.codec.http HttpHeaderNames ACCESS_CONTROL_ALLOW_ORIGIN
AsciiString ACCESS_CONTROL_ALLOW_ORIGIN
To view the source code for io.netty.handler.codec.http HttpHeaderNames ACCESS_CONTROL_ALLOW_ORIGIN.
Click Source Link
From source file:dpfmanager.shell.modules.server.post.HttpPostHandler.java
License:Open Source License
/** * Util functions// ww w .j av a2 s .c o m */ private void writeResponse(Channel channel) { // Convert the response content to a ChannelBuffer. ByteBuf buf = copiedBuffer(responseContent.toString(), CharsetUtil.UTF_8); responseContent.setLength(0); // Decide whether to close the connection or not. boolean close = request.headers().contains(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE, true) || request.protocolVersion().equals(HttpVersion.HTTP_1_0) && !request.headers() .contains(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE, true); // Build the response object. FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf); response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8"); if (!close) { response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, buf.readableBytes()); } // Extra headers response.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN, "*"); // Write the response. ChannelFuture future = channel.writeAndFlush(response); // Close the connection after the write operation is done if necessary. if (close) { future.addListener(ChannelFutureListener.CLOSE); } }
From source file:eastwind.webpush.WebPushHandler.java
License:Apache License
private static void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res) { // Generate an error page if response getStatus code is not OK (200). if (res.status().code() != 200) { ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8); res.content().writeBytes(buf);/*from w w w. ja v a 2 s. c o m*/ buf.release(); } // Send the response and close the connection if necessary. res.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/json; charset=UTF-8"); res.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN, "*"); HttpUtil.setContentLength(res, res.content().readableBytes()); ChannelFuture f = ctx.channel().writeAndFlush(res); if (!HttpUtil.isKeepAlive(req) || res.status().code() != 200) { f.addListener(ChannelFutureListener.CLOSE); } }
From source file:net.anyflow.menton.http.HttpRequestRouter.java
License:Apache License
protected static void setDefaultHeaders(FullHttpRequest request, HttpResponse response) { response.headers().add(HttpHeaderNames.SERVER, net.anyflow.lannister.Settings.SELF.getProperty("menton.version")); boolean keepAlive = request.headers().get(HttpHeaderNames.CONNECTION) == HttpHeaderValues.KEEP_ALIVE .toString();/*from w w w . j av a 2s . com*/ if (keepAlive) { response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); } if (Settings.SELF.getProperty("menton.httpServer.allowCrossDomain", "false").equalsIgnoreCase("true")) { response.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN, "*"); response.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS, "POST, GET, PUT, DELETE"); response.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, "X-PINGARUNER"); response.headers().add(HttpHeaderNames.ACCESS_CONTROL_MAX_AGE, "1728000"); } response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()); }
From source file:org.ballerinalang.composer.service.ballerina.parser.service.BallerinaParserService.java
License:Open Source License
@OPTIONS @Path("/built-in-packages") @Consumes(MediaType.APPLICATION_JSON)//from w ww . ja v a 2 s . c o m @Produces(MediaType.APPLICATION_JSON) public Response getBuiltInPackages() { return Response.ok().header(HttpHeaderNames.ACCESS_CONTROL_MAX_AGE.toString(), "600 ") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), "*") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString(), "true") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS.toString(), "POST, GET, PUT, UPDATE, DELETE, OPTIONS, HEAD") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS.toString(), HttpHeaderNames.CONTENT_TYPE.toString() + ", " + HttpHeaderNames.ACCEPT.toString() + ", X-Requested-With") .build(); }
From source file:org.ballerinalang.composer.service.ballerina.parser.service.BallerinaParserService.java
License:Open Source License
@OPTIONS @Path("/endpoints") @Consumes(MediaType.APPLICATION_JSON)/*from w w w. j av a2 s . com*/ @Produces(MediaType.APPLICATION_JSON) public Response getEndpointOptions() { return Response.ok().header(HttpHeaderNames.ACCESS_CONTROL_MAX_AGE.toString(), "600 ") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), "*") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString(), "true") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS.toString(), "POST, GET, PUT, UPDATE, DELETE, OPTIONS, HEAD") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS.toString(), HttpHeaderNames.CONTENT_TYPE.toString() + ", " + HttpHeaderNames.ACCEPT.toString() + ", X-Requested-With") .build(); }
From source file:org.ballerinalang.composer.service.ballerina.parser.service.BallerinaParserService.java
License:Open Source License
@OPTIONS @Path("/actions") @Consumes(MediaType.APPLICATION_JSON)/*from w ww. j a v a 2s .c o m*/ @Produces(MediaType.APPLICATION_JSON) public Response getActionsOptions() { return Response.ok().header(HttpHeaderNames.ACCESS_CONTROL_MAX_AGE.toString(), "600 ") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), "*") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString(), "true") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS.toString(), "POST, GET, PUT, UPDATE, DELETE, OPTIONS, HEAD") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS.toString(), HttpHeaderNames.CONTENT_TYPE.toString() + ", " + HttpHeaderNames.ACCEPT.toString() + ", X-Requested-With") .build(); }
From source file:org.ballerinalang.composer.service.ballerina.parser.service.BallerinaParserService.java
License:Open Source License
@OPTIONS @Path("/built-in-types") @Consumes(MediaType.APPLICATION_JSON)/*from w w w . j ava 2 s .c om*/ @Produces(MediaType.APPLICATION_JSON) public Response getBuiltInTypesOptions() { return Response.ok().header(HttpHeaderNames.ACCESS_CONTROL_MAX_AGE.toString(), "600 ") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), "*") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString(), "true") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS.toString(), "POST, GET, PUT, UPDATE, DELETE, OPTIONS, HEAD") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS.toString(), HttpHeaderNames.CONTENT_TYPE.toString() + ", " + HttpHeaderNames.ACCEPT.toString() + ", X-Requested-With") .build(); }
From source file:org.ballerinalang.composer.service.ballerina.parser.service.BallerinaParserService.java
License:Open Source License
@GET @Path("/built-in-types") @Consumes(MediaType.APPLICATION_JSON)//from ww w . ja va 2s . com @Produces(MediaType.APPLICATION_JSON) public Response getBuiltInTypes() { JsonObject response = new JsonObject(); // add package info into response Gson gson = new Gson(); String json = gson.toJson(ParserUtils.getBuiltinTypes()); JsonParser parser = new JsonParser(); JsonArray packagesArray = parser.parse(json).getAsJsonArray(); response.add("types", packagesArray); return Response.status(Response.Status.OK).entity(response) .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), '*') .type(MediaType.APPLICATION_JSON).build(); }
From source file:org.ballerinalang.composer.service.ballerina.parser.service.BallerinaParserService.java
License:Open Source License
@POST @Path("/file/validate-and-parse") @Consumes(MediaType.APPLICATION_JSON)// w w w. j a va 2 s .c o m @Produces(MediaType.APPLICATION_JSON) public Response validateAndParseBFile(BFile bFileRequest) throws IOException, InvocationTargetException, IllegalAccessException { return Response.status(Response.Status.OK).entity(validateAndParse(bFileRequest)) .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), '*') .type(MediaType.APPLICATION_JSON).build(); }
From source file:org.ballerinalang.composer.service.ballerina.parser.service.BallerinaParserService.java
License:Open Source License
@OPTIONS @Path("/file/validate-and-parse") @Consumes(MediaType.APPLICATION_JSON)//from w w w. jav a 2 s . c o m @Produces(MediaType.APPLICATION_JSON) public Response validateAndParseOptions() { return Response.ok().header("Access-Control-Max-Age", "600 ") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString(), "*") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString(), "true") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS.toString(), "POST, GET, PUT, UPDATE, DELETE, OPTIONS, HEAD") .header(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS.toString(), HttpHeaderNames.CONTENT_TYPE.toString() + ", " + HttpHeaderNames.ACCEPT.toString() + ", X-Requested-With") .build(); }