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


Java AtmosphereResource.getResponse方法代码示例

本文整理汇总了Java中org.atmosphere.cpr.AtmosphereResource.getResponse方法的典型用法代码示例。如果您正苦于以下问题:Java AtmosphereResource.getResponse方法的具体用法?Java AtmosphereResource.getResponse怎么用?Java AtmosphereResource.getResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.atmosphere.cpr.AtmosphereResource的用法示例。


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

示例1: handleServiceApi

import org.atmosphere.cpr.AtmosphereResource; //导入方法依赖的package包/类
/**
 * This is a middle level method to handle the details of Atmosphere and
 * http/ws level of processing request. It will eventually call
 * ApiFactory.process which handles the "pure" Jvm Java only processing
 * 
 * @param r
 *          r
 * @throws Exception
 *           e
 * 
 */
public void handleServiceApi(AtmosphereResource r) throws Exception {
  AtmosphereRequest request = r.getRequest();
  AtmosphereResponse response = r.getResponse();
  OutputStream out = response.getOutputStream();
  response.addHeader("Content-Type", CodecUtils.MIME_TYPE_JSON);
  
  String hack = null;
  byte[] data = null;
  if (request.body() != null) {
    hack = request.body().asString();
    // data = request.body().asBytes();
    if (hack != null){ // FIXME - hack because request.body().asBytes() ALWAYS returns null !!
      data = hack.getBytes();
    }
  }
  api.process(out, r.getRequest().getRequestURI(), data);
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:29,代码来源:WebGui.java

示例2: onStateChange

import org.atmosphere.cpr.AtmosphereResource; //导入方法依赖的package包/类
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
	HubMessage message = parseMessage(event);
	if (message == null) {
		return;
	}

	AtmosphereResource resource = event.getResource();
	AtmosphereResponse response = resource.getResponse();

	if (resource.isSuspended()) {
		getMessageHandler().handleMessage(
				new MessageContext(sessionsPool, sessionsPool.getSessionBySessionId(resource.uuid()), message, resource.getRequest().getLocale()));
		switch (resource.transport()) {
		case JSONP:
		case LONG_POLLING:
			event.getResource().resume();
			break;
		case WEBSOCKET:
		case STREAMING:
			response.getWriter().flush();
			break;
		default:
			break;
		}
	} else if (!event.isResuming()) {
		getMessageHandler().handleMessage(
				new MessageContext(sessionsPool, sessionsPool.getSessionBySessionId(resource.uuid()), new HubMessage(HubMessage.TYPE_LOGOUT), resource.getRequest().getLocale()));
		// event.broadcaster().broadcast(
		// new Data("Someone", "say bye bye!").toString());
	}

}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:34,代码来源:HubAtmosphereHandler.java

示例3: handleMessagesApi

import org.atmosphere.cpr.AtmosphereResource; //导入方法依赖的package包/类
/**
 * handleMessagesApi handles all requests sent to /api/messages It
 * suspends/upgrades the connection to a websocket It is a asynchronous
 * protocol - and all messages are wrapped in a message wrapper.
 * 
 * The ApiFactory will handle the details of de-serializing but its necessary
 * to setup some protocol details here for websockets and session management
 * which the ApiFactory should not be concerned with.
 * 
 * @param r - request and response objects from Atmosphere server
 */
public void handleMessagesApi(AtmosphereResource r) {
  try {
    AtmosphereResponse response = r.getResponse();
    AtmosphereRequest request = r.getRequest();
    OutputStream out = response.getOutputStream();

    if (!r.isSuspended()) {
      r.suspend();
    }
    response.addHeader("Content-Type", CodecUtils.MIME_TYPE_JSON);

    api.process(this, out, r.getRequest().getRequestURI(), request.body().asString());

    /*
     * // FIXME - GET or POST should work - so this "should" be unnecessary ..
     * if ("GET".equals(httpMethod)) { // if post and parts.length < 3 ?? //
     * respond(r, apiKey, "getPlatform", new Hello(Runtime.getId()));
     * HashMap<URI, ServiceEnvironment> env = Runtime.getEnvironments();
     * respond(r, apiKey, "getLocalServices", env); } else {
     * doNotUseThisProcessMessageAPI(codec, request.body()); // FIXME data is
     * double encoded .. can't put '1st' encoded json // api.process(this,
     * out, r.getRequest().getRequestURI(), request.body().asString()); }
     */

  } catch (Exception e) {
    log.error("handleMessagesApi -", e);
  }
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:40,代码来源:WebGui.java

示例4: inspect

import org.atmosphere.cpr.AtmosphereResource; //导入方法依赖的package包/类
@Override
public Action inspect(AtmosphereResource r) {
    final SecurityContextRepository securityContextRepo = getSecurityContextRepository(
        r.getAtmosphereConfig().getServletContext());
    if (securityContextRepo.containsContext(r.getRequest())) {
        LOGGER.trace("Loading the security context from the session");
        final HttpRequestResponseHolder requestResponse = new HttpRequestResponseHolder(r.getRequest(),
            r.getResponse());
        final SecurityContext securityContext = securityContextRepo.loadContext(requestResponse);
        SecurityContextHolder.setContext(securityContext);
    }
    return Action.CONTINUE;
}
 
开发者ID:peholmst,项目名称:vaadin4spring,代码行数:14,代码来源:PushSecurityInterceptor.java

示例5: handle

import org.atmosphere.cpr.AtmosphereResource; //导入方法依赖的package包/类
@Override
public void handle(AtmosphereResource r) {
  // TODO Auto-generated method stub
  try {

    /*
     * OpenCV opencv = (OpenCV) Runtime.start("opencv", "OpenCV");
     * OpenCVFilterFFMEG ffmpeg = new OpenCVFilterFFMEG("ffmpeg");
     * opencv.addFilter(ffmpeg); opencv.capture(); sleep(1000);
     * opencv.removeFilters(); ffmpeg.stopRecording();
     */

    AtmosphereResponse response = r.getResponse();
    // response.setContentType("video/mp4");
    // response.setContentType("video/x-flv");
    response.setContentType("video/avi");
    // FIXME - mime type of avi ??

    ServletOutputStream out = response.getOutputStream();
    // response.addHeader(name, value);

    // byte[] data = FileIO.fileToByteArray(new
    // File("flvTest.flv"));
    // byte[] data = FileIO.fileToByteArray(new
    // File("src/resource/WebGUI/video/ffmpeg.1443989700495.mp4"));
    // byte[] data = FileIO.fileToByteArray(new
    // File("mp4Test.mp4"));
    byte[] data = FileIO.toByteArray(new File("test.avi.h264.mp4"));

    log.info("bytes {}", data.length);
    out.write(data);
    out.flush();

    // out.close();
    // r.write(data);
    // r.writeOnTimeout(arg0)
    // r.forceBinaryWrite();
    // r.close();

  } catch (Exception e) {
    Logging.logError(e);
  }

}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:45,代码来源:WebGui.java


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