Search in sources :

Example 41 with ServletOutputStream

use of javax.servlet.ServletOutputStream in project Openfire by igniterealtime.

the class ImageServlet method writeBytesToStream.

/**
     * Writes out a <code>byte</code> to the ServletOuputStream.
     *
     * @param bytes the bytes to write to the <code>ServletOutputStream</code>.
     * @param response the HttpServeltResponse.
     */
public void writeBytesToStream(byte[] bytes, HttpServletResponse response) {
    if (bytes == null) {
        return;
    }
    response.setContentType(CONTENT_TYPE);
    // Send back image
    try {
        ServletOutputStream sos = response.getOutputStream();
        sos.write(bytes);
        sos.flush();
        sos.close();
    } catch (IOException e) {
    // Ignore.
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) IOException(java.io.IOException)

Example 42 with ServletOutputStream

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

the class FSSSOAndFedService method returnSOAPMessage.

/**
     * Forms and Returns SOAP message to the requested client.
     *
     * @param msg <code>SOAPMessage</code> to be returned
     * @param response <code>HttpServletResponse</code> object
     */
private void returnSOAPMessage(SOAPMessage msg, HttpServletResponse response) {
    try {
        if (msg != null) {
            SAMLUtils.setMimeHeaders(msg.getMimeHeaders(), response);
            ServletOutputStream servletoutputstream = response.getOutputStream();
            msg.writeTo(servletoutputstream);
            servletoutputstream.flush();
            return;
        } else {
            response.flushBuffer();
            return;
        }
    } catch (Exception e) {
        FSUtils.debug.error("FSSSOAndFedService.returnSOAPMessage: " + "Exception::", e);
        return;
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) 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)

Example 43 with ServletOutputStream

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

the class CDCServlet method showError.

private void showError(HttpServletResponse response, String msg) {
    ServletOutputStream out = null;
    try {
        out = response.getOutputStream();
        out.println(msg);
        out.flush();
    } catch (IOException e) {
        debug.error("CDCServlet.showError: " + "Could not show error message to the user", e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException ex) {
        //ignored
        }
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) IOException(java.io.IOException)

Example 44 with ServletOutputStream

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

the class SSOTokenSampleServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) {
    ServletOutputStream out = null;
    try {
        try {
            response.setContentType("text/html");
            out = response.getOutputStream();
            // create the sso token from http request 
            SSOTokenManager manager = SSOTokenManager.getInstance();
            SSOToken token = manager.createSSOToken(request);
            if (manager.isValidToken(token)) {
                //print some of the values from the token.
                String host = token.getHostName();
                java.security.Principal principal = token.getPrincipal();
                String authType = token.getAuthType();
                int level = token.getAuthLevel();
                InetAddress ipAddress = token.getIPAddress();
                out.println("SSOToken host name: " + host);
                out.println("<br />");
                out.println("SSOToken Principal name: " + principal.getName());
                out.println("<br />");
                out.println("Authentication type used: " + authType);
                out.println("<br />");
                out.println("IPAddress of the host: " + ipAddress.getHostAddress());
                out.println("<br />");
            }
            /* Validate the token again, with another method.
                 * if token is invalid, this method throws exception
                 */
            manager.validateToken(token);
            out.println("SSO Token validation test succeeded");
            out.println("<br />");
            // Get the SSOTokenID associated with the token and print it.
            SSOTokenID tokenId = token.getTokenID();
            out.println("The token id is " + tokenId.toString());
            out.println("<br />");
            // Set and get some properties in the token.
            token.setProperty("Company", "Sun Microsystems");
            token.setProperty("Country", "USA");
            String name = token.getProperty("Company");
            String country = token.getProperty("Country");
            out.println("Property: Company: " + name);
            out.println("<br />");
            out.println("Property: Country: " + country);
            out.println("<br />");
            // Retrieve user profile and print them
            AMIdentity userIdentity = IdUtils.getIdentity(token);
            Map attrs = userIdentity.getAttributes();
            out.println("User Attributes: " + attrs);
            /* let us add a listener to the SSOToken. Whenever a token
                 * event arrives, ssoTokenChanged method of the listener will
                 * get called.
                 */
            SSOTokenListener myListener = new SampleTokenListener();
            token.addSSOTokenListener(myListener);
        } catch (SSOException e) {
            out.println("SSO Exception: " + e);
            out.println("<p>Authenticate to OpenAM server before visiting this page.</p>");
            e.printStackTrace();
        } catch (IdRepoException e) {
            out.println("IdRepo Exception: " + e);
            e.printStackTrace();
        } catch (IOException e) {
            out.println("IO Exception: " + e);
            e.printStackTrace();
        } finally {
            out.flush();
        }
    } catch (IOException e) {
    // ignored
    }
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOTokenID(com.iplanet.sso.SSOTokenID) SSOToken(com.iplanet.sso.SSOToken) ServletOutputStream(javax.servlet.ServletOutputStream) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) SSOTokenListener(com.iplanet.sso.SSOTokenListener) AMIdentity(com.sun.identity.idm.AMIdentity) InetAddress(java.net.InetAddress) Map(java.util.Map)

Example 45 with ServletOutputStream

use of javax.servlet.ServletOutputStream 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);
    }
}
Also used : ServletException(javax.servlet.ServletException) MimeHeaders(javax.xml.soap.MimeHeaders) ServletInputStream(javax.servlet.ServletInputStream) ServletOutputStream(javax.servlet.ServletOutputStream) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Aggregations

ServletOutputStream (javax.servlet.ServletOutputStream)515 IOException (java.io.IOException)211 HttpServletResponse (javax.servlet.http.HttpServletResponse)148 Test (org.junit.Test)112 HttpServletRequest (javax.servlet.http.HttpServletRequest)108 ServletException (javax.servlet.ServletException)90 InputStream (java.io.InputStream)63 File (java.io.File)57 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 FileInputStream (java.io.FileInputStream)40 PrintWriter (java.io.PrintWriter)27 CountDownLatch (java.util.concurrent.CountDownLatch)27 WriteListener (javax.servlet.WriteListener)27 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)27 HttpServlet (javax.servlet.http.HttpServlet)25 AsyncContext (javax.servlet.AsyncContext)23 ServletInputStream (javax.servlet.ServletInputStream)23 ArrayList (java.util.ArrayList)21 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19