use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class SimpleHttpProtocol method onMessage.
@Override
public List<AtmosphereRequest> onMessage(WebSocket webSocket, String message) {
AtmosphereResourceImpl resource = (AtmosphereResourceImpl) webSocket.resource();
if (resource == null) {
logger.trace("The WebSocket has been closed before the message was processed.");
return null;
}
AtmosphereRequest request = resource.getRequest(false);
request.setAttribute(FrameworkConfig.WEBSOCKET_SUBPROTOCOL, FrameworkConfig.SIMPLE_HTTP_OVER_WEBSOCKET);
if (!resource.isInScope())
return Collections.emptyList();
String pathInfo = request.getPathInfo();
String requestURI = request.getRequestURI();
// This confuse some JAXRS servers like RestEasy
if (rewriteUri && (requestURI.startsWith("http://") || requestURI.startsWith("https://"))) {
logger.debug("Rewriting requestURI {}. To disable, add {} set to true as init-param", requestURI, ApplicationConfig.REWRITE_WEBSOCKET_REQUESTURI);
requestURI = URI.create(requestURI).getPath();
request.requestURI(requestURI);
}
if (message.startsWith(delimiter)) {
int delimiterLength = delimiter.length();
int bodyBeginIndex = message.indexOf(delimiter, delimiterLength);
if (bodyBeginIndex != -1) {
pathInfo = message.substring(delimiterLength, bodyBeginIndex);
requestURI += pathInfo;
message = message.substring(bodyBeginIndex + delimiterLength);
}
}
List<AtmosphereRequest> list = new ArrayList<AtmosphereRequest>();
list.add(constructRequest(webSocket, pathInfo, requestURI, methodType, contentType.equalsIgnoreCase(TEXT) ? null : contentType, destroyable).body(message).build());
return list;
}
use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class SimpleHttpProtocol method onMessage.
@Override
public List<AtmosphereRequest> onMessage(WebSocket webSocket, byte[] d, final int offset, final int length) {
//Converting to a string and delegating to onMessage(WebSocket webSocket, String d) causes issues because the binary data may not be a valid string.
AtmosphereResourceImpl resource = (AtmosphereResourceImpl) webSocket.resource();
if (resource == null) {
logger.trace("The WebSocket has been closed before the message was processed.");
return null;
}
AtmosphereRequest request = resource.getRequest(false);
request.setAttribute(FrameworkConfig.WEBSOCKET_SUBPROTOCOL, FrameworkConfig.SIMPLE_HTTP_OVER_WEBSOCKET);
if (!resource.isInScope())
return Collections.emptyList();
List<AtmosphereRequest> list = new ArrayList<AtmosphereRequest>();
list.add(constructRequest(webSocket, request.getPathInfo(), request.getRequestURI(), methodType, contentType.equalsIgnoreCase(TEXT) ? null : contentType, destroyable).body(d, offset, length).build());
return list;
}
use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class StreamingHttpProtocol method onTextStream.
@Override
public List<AtmosphereRequest> onTextStream(WebSocket webSocket, Reader r) {
//Converting to a string and delegating to onMessage(WebSocket webSocket, String d) causes issues because the binary data may not be a valid string.
AtmosphereResourceImpl resource = (AtmosphereResourceImpl) webSocket.resource();
if (resource == null) {
logger.trace("The WebSocket has been closed before the message was processed.");
return null;
}
AtmosphereRequest request = resource.getRequest();
request.setAttribute(FrameworkConfig.WEBSOCKET_SUBPROTOCOL, FrameworkConfig.STREAMING_HTTP_OVER_WEBSOCKET);
List<AtmosphereRequest> list = new ArrayList<AtmosphereRequest>();
list.add(constructRequest(webSocket, request.getPathInfo(), request.getRequestURI(), methodType, contentType.equalsIgnoreCase(TEXT) ? null : contentType, destroyable).reader(r).build());
return list;
}
use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class StreamingHttpProtocol method onBinaryStream.
@Override
public List<AtmosphereRequest> onBinaryStream(WebSocket webSocket, InputStream stream) {
//Converting to a string and delegating to onMessage(WebSocket webSocket, String d) causes issues because the binary data may not be a valid string.
AtmosphereResourceImpl resource = (AtmosphereResourceImpl) webSocket.resource();
if (resource == null) {
logger.trace("The WebSocket has been closed before the message was processed.");
return null;
}
AtmosphereRequest request = resource.getRequest();
request.setAttribute(FrameworkConfig.WEBSOCKET_SUBPROTOCOL, FrameworkConfig.STREAMING_HTTP_OVER_WEBSOCKET);
List<AtmosphereRequest> list = new ArrayList<AtmosphereRequest>();
list.add(constructRequest(webSocket, request.getPathInfo(), request.getRequestURI(), methodType, contentType.equalsIgnoreCase(TEXT) ? null : contentType, destroyable).inputStream(stream).build());
return list;
}
use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class EncoderDecoderTest method create.
@BeforeMethod
public void create() throws Throwable {
framework = new AtmosphereFramework();
framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
framework.addAnnotationPackage(ManagedMessage.class);
framework.setAsyncSupport(new AsynchronousProcessor(framework.getAtmosphereConfig()) {
@Override
public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
return suspended(req, res);
}
public void action(AtmosphereResourceImpl r) {
try {
resumed(r.getRequest(), r.getResponse());
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}
}).init(new ServletConfig() {
@Override
public String getServletName() {
return "void";
}
@Override
public ServletContext getServletContext() {
return mock(ServletContext.class);
}
@Override
public String getInitParameter(String name) {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return null;
}
});
latch.set(new CountDownLatch(1));
}
Aggregations