use of javax.servlet.ServletInputStream in project ninja by ninjaframework.
the class NinjaServletContextTest method testGetUTF8ParameterInMultipart.
@Test
public void testGetUTF8ParameterInMultipart() throws Exception {
String body = "------Ninja\r\n" + "Content-Disposition: form-data; name=\"utf8\"\r\n" + "\r\n" + "✓\r\n" + "------Ninja--\r\n";
ServletInputStream sis = createHttpServletRequestInputStream(body.getBytes(NinjaConstant.UTF_8));
when(httpServletRequest.getContentType()).thenReturn("multipart/form-data; boundary=----Ninja");
when(httpServletRequest.getMethod()).thenReturn("POST");
when(ninjaProperties.getIntegerWithDefault(NinjaConstant.UPLOADS_MAX_FILE_SIZE, -1)).thenReturn(1024);
when(ninjaProperties.getIntegerWithDefault(NinjaConstant.UPLOADS_MAX_TOTAL_SIZE, -1)).thenReturn(1024);
when(httpServletRequest.getInputStream()).thenReturn(sis);
context.init(servletContext, httpServletRequest, httpServletResponse);
assertEquals("✓", context.getParameter("utf8"));
}
use of javax.servlet.ServletInputStream in project dropwizard by dropwizard.
the class TaskServletTest method passesQueryStringParamsAlong.
@Test
public void passesQueryStringParamsAlong() throws Exception {
final PrintWriter output = mock(PrintWriter.class);
final ServletInputStream bodyStream = new TestServletInputStream(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)));
when(request.getMethod()).thenReturn("POST");
when(request.getPathInfo()).thenReturn("/gc");
when(request.getParameterNames()).thenReturn(Collections.enumeration(ImmutableList.of("runs")));
when(request.getParameterValues("runs")).thenReturn(new String[] { "1" });
when(request.getInputStream()).thenReturn(bodyStream);
when(response.getWriter()).thenReturn(output);
servlet.service(request, response);
verify(gc).execute(ImmutableMultimap.of("runs", "1"), output);
}
use of javax.servlet.ServletInputStream in project Axe by DongyuCai.
the class TestFilter4 method doFilter.
@Override
public boolean doFilter(HttpServletRequest request, HttpServletResponse response, Param param, Handler handler) throws RestException {
try {
ServletInputStream in = request.getInputStream();
byte[] data = new byte[1024];
int len = 0;
while ((len = in.read(data, 0, data.length)) > 0) {
System.out.println("read:" + len);
}
} catch (Exception e) {
}
return true;
}
use of javax.servlet.ServletInputStream in project OpenAM by OpenRock.
the class SOAPReceiver method doPost.
/**
* Processes HTTP request and sends back HTTP response. It gets called
* internally by the servlet engine.
*
* @param request the HTTP request.
* @param response the HTTP response.
* @throws IOException if an IO error occurs while processing
the request
* @throws ServletException if an servlet error occurs while processing
* the request
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
MimeHeaders mimeHeaders = SAMLUtils.getMimeHeaders(request);
ServletInputStream sInputStream = request.getInputStream();
SOAPMessage soapMessage = msgFactory.createMessage(mimeHeaders, sInputStream);
SOAPMessage soapMessageReply = this.onMessage(soapMessage, request);
if (soapMessageReply != null) {
SAMLUtils.setMimeHeaders(soapMessageReply.getMimeHeaders(), response);
ServletOutputStream sOutputStream = response.getOutputStream();
soapMessageReply.writeTo(sOutputStream);
sOutputStream.flush();
} else {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} catch (SOAPException se) {
throw new ServletException(se);
}
}
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);
}
Aggregations