use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class PathTest method testPathVar.
@Test
public void testPathVar() throws IOException, ServletException {
instanceCount = 0;
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/pathVar/aaa/pathTest/b123").method("GET").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertEquals(instanceCount, 1);
assertNotNull(r.get());
assertEquals(r.get(), "aaa#b123");
}
use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class PathTest method testAtmosphereResourceInjection.
@Test
public void testAtmosphereResourceInjection() throws IOException, ServletException {
instanceCount = 0;
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/resource/b123").method("GET").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertEquals(instanceCount, 1);
assertNotNull(r.get());
assertEquals(r.get(), "/resource/b123");
}
use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class PathTest method testAtmosphereResourceEventInjection.
@Test(enabled = true)
public void testAtmosphereResourceEventInjection() throws IOException, ServletException {
instanceCount = 0;
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/resourceEvent/b123").method("GET").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertEquals(instanceCount, 1);
assertNotNull(r.get());
assertEquals(r.get(), "/resourceEvent/b123");
}
use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class PathTest method testNamedInjection.
@Test
public void testNamedInjection() throws IOException, ServletException {
instanceCount = 0;
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/inject/b123").method("GET").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertEquals(instanceCount, 1);
assertNotNull(r.get());
assertEquals(r.get(), "/b123");
}
use of org.atmosphere.runtime.AtmosphereRequest in project atmosphere by Atmosphere.
the class IOUtils method readEntirelyAsByte.
public static byte[] readEntirelyAsByte(AtmosphereResource r) throws IOException {
AtmosphereRequest request = r.getRequest();
boolean readGetBody = r.getAtmosphereConfig().getInitParameter(ApplicationConfig.READ_GET_BODY, false);
if (!readGetBody && AtmosphereResourceImpl.class.cast(r).getRequest(false).getMethod().equalsIgnoreCase("GET")) {
logger.debug("Blocking an I/O read operation from a GET request. To enable GET + body, set {} to true", ApplicationConfig.READ_GET_BODY);
return new byte[0];
}
AtmosphereRequestImpl.Body body = request.body();
if (request.body().isEmpty()) {
BufferedInputStream bufferedStream = null;
ByteArrayOutputStream bbIS = new ByteArrayOutputStream();
try {
try {
InputStream inputStream = request.getInputStream();
if (inputStream != null) {
bufferedStream = new BufferedInputStream(inputStream);
}
} catch (IllegalStateException ex) {
logger.trace("", ex);
Reader reader = request.getReader();
if (reader != null) {
bufferedStream = new BufferedInputStream(new ReaderInputStream(reader));
}
}
if (bufferedStream != null) {
byte[] bytes = new byte[8192];
int bytesRead = 0;
while (bytesRead != -1) {
bytesRead = bufferedStream.read(bytes);
if (bytesRead > 0)
bbIS.write(bytes, 0, bytesRead);
}
} else {
bbIS.write("".getBytes());
}
} finally {
if (bufferedStream != null) {
try {
bufferedStream.close();
} catch (IOException ex) {
logger.warn("", ex);
}
}
}
return bbIS.toByteArray();
} else if (body.hasString()) {
try {
return readEntirelyAsString(r).toString().getBytes(request.getCharacterEncoding());
} catch (UnsupportedEncodingException e) {
logger.error("", e);
}
} else if (body.hasBytes()) {
return Arrays.copyOfRange(body.asBytes(), body.byteOffset(), body.byteOffset() + body.byteLength());
}
throw new IllegalStateException("No body " + r);
}
Aggregations