Search in sources :

Example 71 with ServletInputStream

use of javax.servlet.ServletInputStream in project nutz by nutzam.

the class UploadingUnitTest method test_cast_dt01.

@Test
public void test_cast_dt01() throws UploadException {
    MockHttpServletRequest req = Mock.servlet.request();
    req.setHeader("content-type", "multipart/form-data; boundary=----ESDT-321271401654cc6d669eef664aac");
    Uploading up = UploadUnit.TYPE.born();
    ServletInputStream ins = Mock.servlet.ins("org/nutz/mvc/upload/files/cast_dt01");
    req.setInputStream(ins);
    req.init();
    Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
    assertEquals(1, map.size());
    assertEquals("Shapes100.jpg", ((TempFile) map.get("fileData")).getSubmittedFileName());
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Uploading(org.nutz.mvc.upload.Uploading) Test(org.junit.Test)

Example 72 with ServletInputStream

use of javax.servlet.ServletInputStream in project OpenRefine by OpenRefine.

the class RefineBrokerTests method call.

private JSONObject call(boolean successful, RefineBroker broker, HttpServletRequest request, HttpServletResponse response, String service, String... params) throws Exception {
    if (params != null) {
        for (int i = 0; i < params.length; ) {
            String name = params[i++];
            String value = params[i++];
            if ("data".equals(name)) {
                final ByteArrayInputStream inputStream = new ByteArrayInputStream(value.getBytes("UTF-8"));
                when(request.getInputStream()).thenReturn(new ServletInputStream() {

                    public int read() throws IOException {
                        return inputStream.read();
                    }
                });
            } else {
                when(request.getParameter(name)).thenReturn(value);
            }
        }
    }
    StringWriter writer = new StringWriter();
    when(response.getWriter()).thenReturn(new PrintWriter(writer));
    broker.process(service, request, response);
    JSONObject result = new JSONObject(writer.toString());
    if (successful) {
        assertJSON(result, "status", "ok");
    } else {
        assertJSON(result, "status", "error");
    }
    logger.info(result.toString());
    return result;
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) StringWriter(java.io.StringWriter) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 73 with ServletInputStream

use of javax.servlet.ServletInputStream in project async-http-client by AsyncHttpClient.

the class FilePartLargeFileTest method configureHandler.

@Override
public AbstractHandler configureHandler() throws Exception {
    return new AbstractHandler() {

        public void handle(String target, Request baseRequest, HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
            ServletInputStream in = req.getInputStream();
            byte[] b = new byte[8192];
            int count = -1;
            int total = 0;
            while ((count = in.read(b)) != -1) {
                b = new byte[8192];
                total += count;
            }
            resp.setStatus(200);
            resp.addHeader("X-TRANFERED", String.valueOf(total));
            resp.getOutputStream().flush();
            resp.getOutputStream().close();
            baseRequest.setHandled(true);
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler)

Example 74 with ServletInputStream

use of javax.servlet.ServletInputStream in project wildfly by wildfly.

the class TestReadListener method onDataAvailable.

@Override
public void onDataAvailable() throws IOException {
    ServletInputStream input = handler.getWebConnection().getInputStream();
    int len = -1;
    byte[] b = new byte[1024];
    if (input.isReady()) {
        // Expected data is "dummy request#"
        len = input.read(b);
        if (len > 0) {
            String data = new String(b, 0, len);
            if (data.endsWith("#")) {
                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(handler.getWebConnection().getOutputStream()));
                writeLine(writer, "isPostConstructCallbackInvoked: " + handler.isPostConstructCallbackInvoked());
                writeLine(writer, "isInjectionOk: " + handler.isInjectionOk());
                writeLine(writer, "isInterceptorInvoked: " + isInterceptorInvoked());
                writeLine(writer, "END");
                writer.flush();
            }
        }
    }
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 75 with ServletInputStream

use of javax.servlet.ServletInputStream in project OpenAM by OpenRock.

the class FSSSOAndFedService method doPost.

/**
     * Processes single sign on POST request.
     * @param request <code>HttpServletRequest</code> object
     * @param response <code>HttpServletResponse</code> object
     * @exception ServletException, IOException if an error occurred
     */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    FSUtils.debug.message("FSSSOAndFedService.doPost: Called");
    if ((request == null) || (response == null)) {
        response.sendError(response.SC_INTERNAL_SERVER_ERROR, FSUtils.bundle.getString("nullInputParameter"));
        return;
    }
    if (FSUtils.needSetLBCookieAndRedirect(request, response, true)) {
        return;
    }
    // Check if it's an LECP request
    if (isLECPRequest(request)) {
        // TODO: assume auth framework will understand this param
        String useForward = (String) request.getAttribute(Constants.FORWARD_PARAM);
        if (useForward != null && useForward.equals(Constants.FORWARD_YES_VALUE)) {
            // this is a forward POST after authentication, need to
            // use GET instead of POST here
            FSUtils.debug.message("FSSSOAndFedService.doPost: LECP forward");
            this.doGet(request, response);
        } else {
            try {
                MimeHeaders mimeHeaders = SAMLUtils.getMimeHeaders(request);
                ServletInputStream sInputStream = request.getInputStream();
                SOAPMessage soapMessage = msgFactory.createMessage(mimeHeaders, sInputStream);
                this.onMessage(request, response, soapMessage);
            } catch (SOAPException se) {
                throw new ServletException(se);
            }
        }
        return;
    }
    // obtain AuthnRequest message
    String enocodedAuthnRequest = request.getParameter(IFSConstants.POST_AUTHN_REQUEST_PARAM);
    if (enocodedAuthnRequest == null) {
        doGet(request, response);
        return;
    }
    enocodedAuthnRequest = enocodedAuthnRequest.replace(' ', '\n');
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSSSOAndFedService.doPost: " + "BASE64 encoded AuthnRequest at the RECEIVER: " + enocodedAuthnRequest);
    }
    //decode and create FSAuthnRequest object
    FSAuthnRequest authnRequest = null;
    try {
        authnRequest = FSAuthnRequest.parseBASE64EncodedString(enocodedAuthnRequest);
        if (authnRequest == null) {
            FSUtils.debug.error("FSSSOAndFedService: " + FSUtils.bundle.getString("invalidAuthnRequest"));
            String[] data = { FSUtils.bundle.getString("invalidAuthnRequest") };
            LogUtil.error(Level.INFO, LogUtil.INVALID_AUTHN_REQUEST, data);
            response.sendError(response.SC_BAD_REQUEST, FSUtils.bundle.getString("invalidAuthnRequest"));
            return;
        } else {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedService: " + "AuthnRequest received:" + authnRequest.toXMLString());
            }
        }
    } catch (FSException e) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSSSOAndFedService: " + FSUtils.bundle.getString("invalidAuthnRequest"), e);
        }
        response.sendError(response.SC_BAD_REQUEST, FSUtils.bundle.getString("invalidAuthnRequest"));
        return;
    }
    String metaAlias = null;
    String realm = null;
    String hostEntityId = null;
    IDPDescriptorType hostedDesc = null;
    BaseConfigType hostedConfig = null;
    try {
        metaAlias = FSServiceUtils.getMetaAlias(request);
        realm = IDFFMetaUtils.getRealmByMetaAlias(metaAlias);
        hostEntityId = metaManager.getEntityIDByMetaAlias(metaAlias);
        hostedDesc = metaManager.getIDPDescriptor(realm, hostEntityId);
        hostedConfig = metaManager.getIDPDescriptorConfig(realm, hostEntityId);
    } catch (Exception e) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSSSOAndFedService: couldn't obtain hosted entity id:", e);
        }
    }
    handleAuthnRequest(request, response, authnRequest, false, false, realm, hostEntityId, metaAlias, hostedDesc, hostedConfig);
    return;
}
Also used : ServletException(javax.servlet.ServletException) IDPDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType) BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) MimeHeaders(javax.xml.soap.MimeHeaders) ServletInputStream(javax.servlet.ServletInputStream) SOAPException(javax.xml.soap.SOAPException) FSAuthnRequest(com.sun.identity.federation.message.FSAuthnRequest) FSException(com.sun.identity.federation.common.FSException) SOAPMessage(javax.xml.soap.SOAPMessage) ServletException(javax.servlet.ServletException) SOAPException(javax.xml.soap.SOAPException) SessionException(com.sun.identity.plugin.session.SessionException) FSException(com.sun.identity.federation.common.FSException) IOException(java.io.IOException) FSAccountMgmtException(com.sun.identity.federation.accountmgmt.FSAccountMgmtException)

Aggregations

ServletInputStream (javax.servlet.ServletInputStream)79 IOException (java.io.IOException)51 HttpServletRequest (javax.servlet.http.HttpServletRequest)43 Test (org.junit.Test)43 ServletException (javax.servlet.ServletException)41 HttpServletResponse (javax.servlet.http.HttpServletResponse)40 CountDownLatch (java.util.concurrent.CountDownLatch)26 HttpServlet (javax.servlet.http.HttpServlet)20 DeferredContentProvider (org.eclipse.jetty.client.util.DeferredContentProvider)20 InterruptedIOException (java.io.InterruptedIOException)18 AsyncContext (javax.servlet.AsyncContext)17 ReadListener (javax.servlet.ReadListener)17 ServletOutputStream (javax.servlet.ServletOutputStream)16 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)16 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)15 Request (org.eclipse.jetty.server.Request)14 Response (org.eclipse.jetty.client.api.Response)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 PrintWriter (java.io.PrintWriter)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8