• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java HttpControl类的典型用法和代码示例

java 4次浏览

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

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

示例1: handleHttpRequest

点赞 3

import org.webbitserver.HttpControl; //导入依赖的package包/类
/**
 *
 * @param request
 * @param response
 * @param control
 * @throws Exception
 */
@Override
public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
  String path = request.uri();
  path = path.substring("/resources".length());
  if (path.contains("?")) {
    path = path.substring(0, path.indexOf('?'));
  }
  String mime = path.substring(path.lastIndexOf('.'));
  InputStream resource = ResourcesHandler.class.getResourceAsStream("/assets" + path);
  if (resource == null) {
    StringWriter writer = new StringWriter();
    response.header("Content-Type", "text/plain").content(path + " : resource not found").status(404).end();
    return;
  }
  int nRead;
  byte[] data = new byte[1024];
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  while ((nRead = resource.read(data, 0, data.length)) != -1) {
    buffer.write(data, 0, nRead);
  }
  buffer.flush();
  response.header("Content-Type", mimeTypes.get(mime)).content(buffer.toByteArray()).end();
}
 

开发者ID:LavaJUG,
项目名称:stream-catcher,
代码行数:31,
代码来源:ResourcesHandler.java

示例2: defineRoutes

点赞 2

import org.webbitserver.HttpControl; //导入依赖的package包/类
/**
 * 
 */
@PostConstruct
private void defineRoutes() {
  
  restWrapper.GET(ASYNC_REST_RESPONSE_URI+"{"+ASYNC_REST_RESPONSE_URI_KEY+"}", new HttpHandler() {
    
    @Override
    public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception 
    {
      String key = Rest.param(request, WebbitRestServerBean.ASYNC_REST_RESPONSE_URI_KEY);
      log.debug("Got key=> "+key);
      int code = eventReceiver.getResponseCode(key);
      if(code == HttpResponseStatus.OK.getCode())
      {
        String json = eventReceiver.getResponse(key);
        if(json != null)
          response.content(json).end();
        else
          response.status(HttpResponseStatus.GONE.getCode()).end();//gone
      }
      else
        response.status(code).end();
      
    }
  });
  
  log.info("[REST Listener] Scanning for JAX-RS annotated classes.. ");
  try 
  {
    mapServiceRoute(annotatedPkgToScan);
    
  } catch (Exception e) {
    throw new BeanCreationException("Unable to create factory bean", e);
  }
  log.info("[REST Listener] Loaded JAX-RS classes..");
  run();
}
 

开发者ID:javanotes,
项目名称:reactive-data,
代码行数:40,
代码来源:WebbitRestServerBean.java

示例3: handleHttpRequest

点赞 2

import org.webbitserver.HttpControl; //导入依赖的package包/类
@Override
public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
  log.debug(identifier()+"Got new request. ");
  if(method.isAsyncRest())
  {
    prepareAsyncResponse(request, response);
    return;
  }
  
  List<Object> args = extractArguments(request, false);
  prepareResponse(args, response);
  
}
 

开发者ID:javanotes,
项目名称:reactive-data,
代码行数:14,
代码来源:MethodInvocationHandler.java

示例4: handleHttpRequest

点赞 2

import org.webbitserver.HttpControl; //导入依赖的package包/类
/**
 *
 * @param request
 * @param response
 * @param control
 * @throws Exception
 */
@Override
public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
  String uri = request.uri();
  if (uri.contains("?")) {
    uri = uri.substring(0, uri.indexOf('?'));
  }
  Router.Route route = this.router.getRoute(uri, request.method());

  WebContext context = new WebContext();
  context.addParameter("profileManager", Configuration.getProfileManager());
  context.addParameter("sourceManager", Configuration.getSourceManager());
  context.addParameter("pluginManager", Configuration.getPluginManager());
  context.addParameter("outputManager", Configuration.getOutputManager());

  if (route == null) {
    StringWriter writer = new StringWriter();
    templateEngine.process("404", context, writer);
    response.header("Content-Type", "text/html").content(writer.toString()).end();
    return;
  }
  Class<?> clazz = route.getClazz();
  Controller controller = (Controller) clazz.newInstance();

  controller.setContext(context);
  controller.setCurrentPage(uri);
  controller.setRenderer(templateEngine);
  controller.setRequest(request);
  controller.setResponse(response);
  route.getAction().invoke(controller);
}
 

开发者ID:LavaJUG,
项目名称:stream-catcher,
代码行数:38,
代码来源:WebHandler.java

示例5: handleHttpRequest

点赞 2

import org.webbitserver.HttpControl; //导入依赖的package包/类
@Override
public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
    final String json = JSON.writeValueAsString(pojo);

    // Write the pojo as json
    response.status(HttpStatus.SC_OK)
            .header(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
            .content(json)
            .end();
}
 

开发者ID:reines,
项目名称:rcdroid,
代码行数:11,
代码来源:JsonPOJOHandler.java

示例6: createIOWorker

点赞 2

import org.webbitserver.HttpControl; //导入依赖的package包/类
@Override
protected ResourceWorker createIOWorker(HttpRequest request, HttpResponse response, HttpControl control) {
    return new ResourceWorker(request, response, control);
}
 

开发者ID:reines,
项目名称:rcdroid,
代码行数:5,
代码来源:AssetResourceHandler.java

示例7: ResourceWorker

点赞 2

import org.webbitserver.HttpControl; //导入依赖的package包/类
protected ResourceWorker(HttpRequest request, HttpResponse response, HttpControl control) {
    super(request.uri(), request, response, control);
    isDirectory = path.endsWith("/");
    pathWithoutTrailingSlash = withoutQuery(isDirectory ? path.substring(0, path.length() - 1) : path);
}
 

开发者ID:reines,
项目名称:rcdroid,
代码行数:6,
代码来源:AssetResourceHandler.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)