use of javax.servlet.ServletInputStream in project async-http-client by AsyncHttpClient.
the class NonAsciiContentLengthTest method setUpGlobal.
@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
server = new Server();
ServerConnector connector = addHttpConnector(server);
server.setHandler(new AbstractHandler() {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Can only handle bodies of up to 1024 bytes.
int MAX_BODY_SIZE = 1024;
byte[] b = new byte[MAX_BODY_SIZE];
int offset = 0;
int numBytesRead;
try (ServletInputStream is = request.getInputStream()) {
while ((numBytesRead = is.read(b, offset, MAX_BODY_SIZE - offset)) != -1) {
offset += numBytesRead;
}
}
assertEquals(request.getContentLength(), offset);
response.setStatus(200);
response.setCharacterEncoding(request.getCharacterEncoding());
response.setContentLength(request.getContentLength());
try (ServletOutputStream os = response.getOutputStream()) {
os.write(b, 0, offset);
}
}
});
server.start();
port1 = connector.getLocalPort();
}
use of javax.servlet.ServletInputStream in project Asqatasun by Asqatasun.
the class LoginControllerTest method testDisplayLoginPage.
/**
* Test of displayLoginPage method, of class LoginController.
*/
public void testDisplayLoginPage() {
System.out.println("displayLoginPage");
Model model = new ExtendedModelMap();
setUpMockAuthenticationContext();
LoginController instance = new LoginController();
String expResult = TgolKeyStore.LOGIN_VIEW_NAME;
String result = instance.displayLoginPage("", new HttpServletRequest() {
@Override
public String getAuthType() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Cookie[] getCookies() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long getDateHeader(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getHeader(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Enumeration getHeaders(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Enumeration getHeaderNames() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getIntHeader(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getMethod() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getPathInfo() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getPathTranslated() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getContextPath() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getQueryString() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getRemoteUser() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isUserInRole(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Principal getUserPrincipal() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getRequestedSessionId() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getRequestURI() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public StringBuffer getRequestURL() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getServletPath() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public HttpSession getSession(boolean bln) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public HttpSession getSession() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isRequestedSessionIdValid() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isRequestedSessionIdFromCookie() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isRequestedSessionIdFromURL() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isRequestedSessionIdFromUrl() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getAttribute(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Enumeration getAttributeNames() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getCharacterEncoding() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterEncoding(String string) throws UnsupportedEncodingException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getContentLength() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getContentType() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ServletInputStream getInputStream() throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getParameter(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Enumeration getParameterNames() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String[] getParameterValues(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Map getParameterMap() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getProtocol() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getScheme() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getServerName() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getServerPort() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BufferedReader getReader() throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getRemoteAddr() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getRemoteHost() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAttribute(String string, Object o) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void removeAttribute(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Locale getLocale() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Enumeration getLocales() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isSecure() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public RequestDispatcher getRequestDispatcher(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getRealPath(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getRemotePort() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getLocalName() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getLocalAddr() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getLocalPort() {
throw new UnsupportedOperationException("Not supported yet.");
}
}, model);
assertEquals(expResult, result);
}
use of javax.servlet.ServletInputStream in project calcite-avatica by apache.
the class AvaticaProtobufHandler method handle.
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try (final Context ctx = this.requestTimer.start()) {
// Check if the user is OK to proceed.
if (!isUserPermitted(serverConfig, request, response)) {
LOG.debug("HTTP request from {} is unauthenticated and authentication is required", request.getRemoteAddr());
return;
}
response.setContentType("application/octet-stream;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
if (request.getMethod().equals("POST")) {
final byte[] requestBytes;
// Avoid a new buffer creation for every HTTP request
final UnsynchronizedBuffer buffer = threadLocalBuffer.get();
try (ServletInputStream inputStream = request.getInputStream()) {
requestBytes = AvaticaUtils.readFullyToBytes(inputStream, buffer);
} finally {
buffer.reset();
}
HandlerResponse<byte[]> handlerResponse;
try {
if (null != serverConfig && serverConfig.supportsImpersonation()) {
// If we can't extract a user, need to throw 401 in that case.
String remoteUser = serverConfig.getRemoteUserExtractor().extract(request);
// Invoke the ProtobufHandler inside as doAs for the remote user.
// The doAsRemoteUser call may disallow a user, need to throw 403 in that case.
handlerResponse = serverConfig.doAsRemoteUser(remoteUser, request.getRemoteAddr(), new Callable<HandlerResponse<byte[]>>() {
@Override
public HandlerResponse<byte[]> call() {
return pbHandler.apply(requestBytes);
}
});
} else {
handlerResponse = pbHandler.apply(requestBytes);
}
} catch (RemoteUserExtractionException e) {
LOG.debug("Failed to extract remote user from request", e);
handlerResponse = pbHandler.unauthenticatedErrorResponse(e);
} catch (RemoteUserDisallowedException e) {
LOG.debug("Remote user is not authorized", e);
handlerResponse = pbHandler.unauthorizedErrorResponse(e);
} catch (Exception e) {
LOG.debug("Error invoking request from {}", baseRequest.getRemoteAddr(), e);
// Catch at the highest level of exceptions
handlerResponse = pbHandler.convertToErrorResponse(e);
}
baseRequest.setHandled(true);
response.setStatus(handlerResponse.getStatusCode());
response.getOutputStream().write(handlerResponse.getResponse());
}
}
}
use of javax.servlet.ServletInputStream in project lucene-solr by apache.
the class SolrRequestParserTest method testParameterIncompatibilityException1.
@Test
public void testParameterIncompatibilityException1() throws Exception {
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100);
// we emulate Jetty that returns empty stream when parameters were parsed before:
when(request.getInputStream()).thenReturn(new ServletInputStream() {
@Override
public int read() {
return -1;
}
@Override
public boolean isFinished() {
return true;
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener readListener) {
}
});
FormDataRequestParser formdata = new FormDataRequestParser(2048);
try {
formdata.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
fail("should throw SolrException");
} catch (SolrException solre) {
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
assertEquals(500, solre.code());
}
verify(request).getInputStream();
}
use of javax.servlet.ServletInputStream in project undertow by undertow-io.
the class AsyncInputStreamServlet method doPost.
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext context = req.startAsync();
final ServletOutputStream outputStream = resp.getOutputStream();
ServletInputStream inputStream = req.getInputStream();
final MyListener listener = new MyListener(outputStream, inputStream, context);
inputStream.setReadListener(listener);
outputStream.setWriteListener(listener);
}
Aggregations