com.sas.servlet.util
Class StreamContentServlet

com.sas.servlet.util.StreamContentServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class StreamContentServlet

The StreamContentServlet servlet is used to deliver arbitrary MIME type content to HTTP clients. In order to deliver content back to the client, the StreamContentServlet requires that the certain attributes be available on either the request or session object. If the CONTENT_KEY request parameter is set, then all other attributes must be set on the session using setAttribute. If it is not set, then they must be set on the request using setAttribute. The value of CONTENT_KEY is prepended to other attributes below to uniquely identify the content request.

Name of static class fieldsString valueUseRequired
CONTENT_TYPE sas_StreamContentServlet _ContentType specifies the MIME type of the content. Used as the parameter to the response.setContentType() method. Yes
CONTENT_DISPOSITION sas_StreamContentServlet_ContentDisposition specifies the value to be used to set the Content-Disposition response header field. No
CONTENT_BYTES sas_StreamContentServlet_ContentBytes specifies the content to be streamed back to the user. Yes
DISPOSE_CONTENTS sas_StreamContentServlet_DisposeContents specifies whether ot not to remove the attributes from the session after use. No

 Example using CONTENT_KEY and session attributes: 
<%@page import="com.sas.servlet.util.*"%> <% byte [] b = //get your bytes here String src = "testgif"; String url = "/mywebapp/StreamContentServlet?"+ StreamContentServlet.CONTENT_KEY + "=" + src; session.setAttribute(StreamContentServlet.CONTENT_TYPE + src, "image/gif"); session.setAttribute(StreamContentServlet.CONTENT_BYTES + src, bb); session.setAttribute(StreamContentServlet.CONTENT_DISPOSITION + src, "inline;filename=test.gif"); %> <img src="<%=url%>"/> Example using request attributes:
<%@page import="com.sas.servlet.util.*"%> <% byte [] b = //get your bytes here String url = "/mywebapp/StreamContentServlet?"; request.setAttribute(StreamContentServlet.CONTENT_TYPE, "image/gif"); request.setAttribute(StreamContentServlet.CONTENT_BYTES, b); request.setAttribute(StreamContentServlet.CONTENT_DISPOSITION, "inline;filename=test.gif"); %> <img src="<%=url%>"/>

In order to use the StreamContentServlet, you may need to register the servlet with the application server that you are deploying on. Please refer to the Deploying AppDev Studio Web Applications on Specific Application Servers section of the document entitled Web Application Deployment Tips and Tricks for more information on how to register the StreamContentServlet.

See Also:
StreamContent, Serialized Form

Field Summary
static java.lang.String CONTENT_BYTES
          The attribute key which stores the content bytes on the request or session.
static java.lang.String CONTENT_DISPOSITION
          The attribute key which stores the content disposition on the request or session.
static java.lang.String CONTENT_KEY
          The attribute key under which the servlet stores and retrieves request and session data.
static java.lang.String CONTENT_TYPE
          The attribute key which stores the content type on the request or session.
static java.lang.String DISPOSE_CONTENTS
          The attribute key which stores the dispose contents value on the request or session.
static java.lang.String NOOP
          The parameter which is set to perform a noop.
static java.lang.String PERSISTENCE
          The parameter which is set to disable connection persistence.
static java.lang.String RB_KEY
          ResourceBundle key.
 
Constructor Summary
StreamContentServlet()
           
 
Method Summary
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Overrides doGet in javax.servlet.http.HttpServlet
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Overrides doPost in javax.servlet.http.HttpServlet
 java.lang.String getServletInfo()
          Overrides the getServletInfo() defined by javax.servlet.http.HttpServlet.
 

Field Detail

CONTENT_KEY

public static final java.lang.String CONTENT_KEY
The attribute key under which the servlet stores and retrieves request and session data. If this key is not found on the request to this servlet, then this String will be prepended to the various parameter names (contentType, contentBytes, etc.). If this key is found, then the value appended to this key is used with other parameter names to uniquely identify the request.

See Also:
Constant Field Values

PERSISTENCE

public static final java.lang.String PERSISTENCE
The parameter which is set to disable connection persistence. The default is true and will call response.setContentLength(). Set this parameter to false on the request to avoid calling setContentLength().

See Also:
Constant Field Values

NOOP

public static final java.lang.String NOOP
The parameter which is set to perform a noop. The default is false. Set this parameter to true on the request for this Servlet to perform no operation.

See Also:
Constant Field Values

CONTENT_TYPE

public static final java.lang.String CONTENT_TYPE
The attribute key which stores the content type on the request or session.

See Also:
Constant Field Values

CONTENT_DISPOSITION

public static final java.lang.String CONTENT_DISPOSITION
The attribute key which stores the content disposition on the request or session.

See Also:
Constant Field Values

CONTENT_BYTES

public static final java.lang.String CONTENT_BYTES
The attribute key which stores the content bytes on the request or session.

See Also:
Constant Field Values

DISPOSE_CONTENTS

public static final java.lang.String DISPOSE_CONTENTS
The attribute key which stores the dispose contents value on the request or session.

See Also:
Constant Field Values

RB_KEY

public static final java.lang.String RB_KEY
ResourceBundle key.

See Also:
Constant Field Values
Constructor Detail

StreamContentServlet

public StreamContentServlet()
Method Detail

getServletInfo

public java.lang.String getServletInfo()
Overrides the getServletInfo() defined by javax.servlet.http.HttpServlet.

Specified by:
getServletInfo in interface javax.servlet.Servlet
Overrides:
getServletInfo in class javax.servlet.GenericServlet
Returns:
The string containing servlet information.

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException,
                   java.io.IOException
Overrides doPost in javax.servlet.http.HttpServlet

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
request - the servlet request object
response - the servlet response object
Throws:
javax.servlet.ServletException - if a servlet exception occurs
java.io.IOException - if an I/O exception occurs

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.servlet.ServletException,
                  java.io.IOException
Overrides doGet in javax.servlet.http.HttpServlet

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - the servlet request object
response - the servlet response object
Throws:
javax.servlet.ServletException - if a servlet exception occurs
java.io.IOException - if an I/O exception occurs



Copyright © 2009 SAS Institute Inc. All Rights Reserved.