本文整理汇总了Java中org.glassfish.grizzly.http.server.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于org.glassfish.grizzly.http.server包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePost
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void handlePost(@FormParam("g-recaptcha-response") String content, @Context Request req)
{
try
{
//Bukkit.getLogger().info("A capatcha has been recieved from " + req.getRemoteAddr());
if (validateCaptcha(Capatchafy.configs.getCapatchaSecret(), content, req.getRemoteAddr()))
{
//Bukkit.getLogger().info("Capatcha from " + req.getRemoteAddr() + " is valid.");
Capatchafy.configs.setAuthorized(req.getRemoteAddr(), true);
}
}
catch (Exception e)
{
System.out.print(e.getLocalizedMessage());
}
}
示例2: WebServer
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
public WebServer(URI endpoint) throws IOException {
this.server = GrizzlyServerFactory.createHttpServer(endpoint, new HttpHandler() {
@Override
public void service(Request rqst, Response rspns) throws Exception {
rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found");
rspns.getWriter().write("404: not found");
}
});
WebappContext context = new WebappContext("WebappContext", BASE_PATH);
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
PackagesResourceConfig.class.getName());
StringJoiner sj = new StringJoiner(",");
for (String s : PACKAGES) {
sj.add(s);
}
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, sj.toString());
registration.addMapping(BASE_PATH);
context.deploy(server);
}
示例3: whiteSheetVerifier
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
private boolean whiteSheetVerifier(Request request) {
String ips = null;
try {
ips = NulsContext.MODULES_CONFIG.getCfgValue(RpcConstant.CFG_RPC_SECTION, RpcConstant.CFG_RPC_REQUEST_WHITE_SHEET);
} catch (NulsException e) {
Log.error(e);
}
if (StringUtils.isBlank(ips)) {
return false;
}
String[] ipArray = ips.split(RpcConstant.WHITE_SHEET_SPLIT);
String realIp = request.getRemoteAddr();
for (String ip : ipArray) {
if (ip.equals(realIp)) {
return true;
}
}
// Log.debug(request.getRemoteAddr());
// Log.debug(request.getRemoteHost());
// Log.debug(request.getRemotePort());
// Log.debug(request.getRemoteUser());
return false;
}
示例4: getScreenshotFromDb
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@GET
@Produces("image/png")
public Response getScreenshotFromDb(@PathParam("collection") String collection, @PathParam("_id") String imgId,
@Context Request request) {
EndpointUtil.printClientInfo(request);
BasicDBObject screenshotQuery = new BasicDBObject();
screenshotQuery.put("_id", new ObjectId(imgId));
GridFSDBFile screenshotFound = null;
switch (collection.toLowerCase()) {
case "photo":
screenshotFound = GFS_PHOTO.findOne(screenshotQuery);
break;
case "diff_photos":
screenshotFound = GFS_DIFF_PHOTOS.findOne(screenshotQuery);
break;
}
return Response.ok().entity(screenshotFound.getInputStream()).build();
}
示例5: start
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
public static void start(int port) throws IOException {
String baseUrl = "http://localhost:"+port+"/";
System.out.println("Starting Weather App local testing server: " + baseUrl);
System.out.println("Not for production use");
final ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(RestWeatherCollectorEndpoint.class);
resourceConfig.register(RestWeatherQueryEndpoint.class);
resourceConfig.register(GenericExceptionMapper.class);
resourceConfig.register(new MyApplicationBinder());
server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUrl), resourceConfig, false);
HttpServerProbe probe = new HttpServerProbe.Adapter() {
@Override
public void onRequestReceiveEvent(HttpServerFilter filter, @SuppressWarnings("rawtypes") Connection connection, Request request) {
System.out.println(request.getRequestURI());
}
};
server.getServerConfiguration().getMonitoringConfig().getWebServerConfig().addProbes(probe);
System.out.println(format("Weather Server started.\n url=%s\n", baseUrl));
server.start();
}
示例6: service
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@Override
public void service(Request request, Response resp) throws Exception {
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html");
Writer writer = resp.getWriter();
writer.write("<html><head><title>HtmlSocket</title></head><body>");
writer.write("<h3>HtmlSocket manger</h3><hr><ul>");
int count = 0;
MessageCenter sever = ctx.getMessageCenter();
Collection<ThreadMap> allsub = sever.getSubscribers();
for (ThreadMap subs : allsub) {
for (Map.Entry<Long, ISubscriber> item : subs.entrySet()) {
if (count++ < 20) {
ISubscriber value = item.getValue();
String topic = value.getTopic();
long id = value.getId();
writer.write(String.format("<li>ID:[%s],Topic:[%s]-[%s]</li>", id, topic, value));
}
}
}
writer.write("</ul><hr>");
writer.write(String.format("订阅者[%s]", count));
writer.write("</body></html>");
}
示例7: startManagementHttpServer
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
private void startManagementHttpServer() throws Exception {
final String httpManagementServerUrl = _properties.getProperty("managementurl", HTTP_MANAGEMENTSERVER_URL);
final ResourceConfig config = new ResourceConfig().register(RaqetService.class).register(new RaqetBinder(_raqetControll));
final CLStaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(this.getClass().getClassLoader(), "/static/");
_httpManagementServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(httpManagementServerUrl), config);
_httpManagementServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/gui/");
/* Redirect users to the GUI */
_httpManagementServer.getServerConfiguration().addHttpHandler(new HttpHandler() {
@Override
public void service(final Request request, final Response response) throws Exception {
response.sendRedirect("/gui/");
}
}, "/index.html");
_httpManagementServer.start();
}
示例8: register
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@POST
@Path("/register")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<String> register(@Context final Request request, final Register target) {
final ClientInfo clientInfo = new ClientInfo();
clientInfo.setIpAddress(request.getRemoteAddr());
clientInfo.setClientid(target.getClientid());
clientInfo.setHostname(target.getHostname());
clientInfo.addLogging(target.getLogging());
clientInfo.setDevicemapping(target.getDevicemapping());
clientInfo.setHardwareid(target.getHardwareid());
LOG.info("register " + request.getRemoteAddr() + " " + target.getClientid() + " " + target.getHardwareid());
try {
_raqetControl.addClient(clientInfo);
}
catch (final Exception e) {
LOG.info("register failed", e);
LOG.info("addRemoteDevice failed during client registration", e);
}
final List<String> result= new ArrayList<String>();
return result;
}
示例9: diskinfo
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@POST
@Path("/diskinfo")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<String> diskinfo(@Context final Request request, final DiskInfoMessage diskInformation) {
final ClientInfo clientInfo = new ClientInfo();
clientInfo.setIpAddress(request.getRemoteAddr());
clientInfo.setClientid(diskInformation.getClientid());
clientInfo.setHostname(diskInformation.getHostname());
clientInfo.setHardwareid(diskInformation.getHardwareid());
LOG.info("diskinfo " + request.getRemoteAddr() + " " + diskInformation.getClientid() + " " + diskInformation.getHardwareid());
try {
_raqetControl.diskInformation(clientInfo, diskInformation);
}
catch (final Exception e) {
LOG.info("register failed", e);
LOG.info("addRemoteDevice failed during client registration", e);
}
final List<String> result = new ArrayList<String>();
return result;
}
示例10: GrizzlyServerHttpExchange
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public GrizzlyServerHttpExchange(Request request, Response response) {
this.request = request;
this.response = response;
request.getContext().getConnection().addCloseListener(new CloseListener<Closeable,
ICloseType>() {
@Override
public void onClosed(Closeable closeable, ICloseType type) throws
IOException {
closeActions.fire();
}
});
// To detect closed connection
// From https://github.com/GrizzlyNIO/grizzly-mirror/blob/2_3_17/modules/comet/src/main/java
// /org/glassfish/grizzly/comet/CometContext.java#L250
request.getInputBuffer().initiateAsyncronousDataReceiving();
response.suspend();
}
示例11: getUserMetadata
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
private Map<String, String> getUserMetadata(Request request) {
return StreamSupport.stream(request.getHeaderNames().spliterator(), false)
.filter(name -> name.toLowerCase().startsWith(META_HEADER_PREFIX.toLowerCase()))
.filter(name -> {
if (name.equalsIgnoreCase(META_HEADER_PREFIX) || RESERVED_METADATA.contains(name)) {
throw new BadRequestException();
}
if (name.length() - META_HEADER_PREFIX.length() > InfoResource.CONFIG.swift.max_meta_name_length ||
request.getHeader(name).length() > InfoResource.CONFIG.swift.max_meta_value_length) {
throw new BadRequestException();
}
return true;
})
.collect(Collectors.toMap(
name -> name.substring(META_HEADER_PREFIX.length()),
name -> request.getHeader(name)));
}
示例12: service
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
for (String parameterLabel : request.getParameterMap().keySet()) {
Matcher matcher;
// matcher = ANNOTATOR_PATTERN.matcher(parameterLabel);
// if (matcher.find()) {
// annotators.add(matcher.group(1));
// }
matcher = META_PATTERN.matcher(parameterLabel);
if (matcher.find()) {
String key = matcher.group(1);
meta.put(key, request.getParameter(parameterLabel));
}
}
if (meta.get("uri") == null || meta.get("uri").length() == 0) {
meta.put("uri", pipeline.getDefaultConfig().getProperty("default_uri"));
}
}
示例13: service
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
logger.debug("Starting service");
super.service(request, response);
String naf = request.getParameter("naf");
KAFDocument doc;
try {
doc = pipeline.parseFromString(naf);
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e);
}
// File temp = File.createTempFile("temp-file-name", ".tmp");
// logger.info("Created temp file " + temp.getAbsolutePath());
// doc.save(temp);
logger.trace(doc.toString());
writeOutput(response, "text/xml", doc.toString());
}
示例14: service
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
super.service(request, response);
String naf = request.getParameter("naf");
KAFDocument document = KAFDocument.createFromStream(new StringReader(naf));
NAFFilter filter = NAFFilter.builder().withSRLRoleLinking(false, false).withOpinionLinking(false, false).build();
RDFGenerator generator = RDFGenerator.DEFAULT;
Renderer renderer = Renderer.DEFAULT;
filter.filter(document);
final Model model = generator.generate(document, null);
StringWriter writer = new StringWriter();
renderer.renderAll(writer, document, model, null, null);
String res = writer.toString();
super.writeOutput(response, "text/html", res);
}
示例15: getClientIpAddr
import org.glassfish.grizzly.http.server.Request; //导入依赖的package包/类
public String getClientIpAddr(Request request) {
String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}