473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ClassCastException on HttpServletRequest

Hi,

We have a customized HttpServletRequest object, when we run the
application on webshpere 4.0.7,got a ClassCastException on this
object, but was Ok on WAS4.0.1,

Anyone know why, is this something related to the was407 patch?

Here's the code:

public class InfobalHttpServletRequestWrapper
implements HttpServletRequest
{

private String userName = null;
private Principal userPrincipal = null;
private Set roleSet = new HashSet();

private Map parameterMapDecoration = new HashMap();

// ------------------------------------------------------------
Constructor
/**
* Configure a new request wrapper.
*
* @param request The request we are wrapping
* @param remoteUser The name of the user
* @param roles The roles permitted the user, delimited by commas
*/
public ASAHttpServletRequestWrapper (
HttpServletRequest request,
String remoteUser,
String roles) {
super(request);
Assert.assertNotNull ("You must wrap a real request",
request);
Assert.assertNotNull ("You must supply a remote user",
remoteUser);
Assert.assertNotNull ("The user must have roles", roles);
this.userName = remoteUser;
userPrincipal = new Principal ()
{
public boolean equals (Object o) {
if ( o.getClass().equals(this.getClass()) )
return userName.equals( ((Principal)
o).getName() );
else return false;
}
public String getName () { return userName; }
public int hashCode () { return userName.hashCode();
}
public String toString () { return userName; }
};
StringTokenizer st = new StringTokenizer(roles,",");
while ( st.hasMoreTokens() ) {
roleSet.add( st.nextToken() );
}
}

public boolean isUserInRole (String role) {
return roleSet.contains(role);
}

public Principal getUserPrincipal () {
return userPrincipal;
}

public String getRemoteUser () {
return userName;
}

/**
* Returns the value of a request parameter as a String, or
* null if the parameter does not exist.
*
* @param name the key name for the parameter
* @return the parameter value associated with a key name
*/
public String getParameter(String name) {
String[] params = (String[]) parameterMapDecoration.get(name);
if ( params == null ) {
return super.getParameter(name);
}
else if ( params.length == 0 ) {
return null;
}
else return params[0];
}

public void setParameter (String name, String value) {
String[] valueArray = { value };
this.setParameterValues(name, valueArray);

}

final class DecoratedEnumeration
implements Enumeration
{
private Iterator iter;
public DecoratedEnumeration (Set inNameSet, Enumeration
nameEnumeration) {
Set nameSet = new HashSet();
nameSet.addAll( inNameSet );
while ( nameEnumeration.hasMoreElements() )
nameSet.add(nameEnumeration.nextElement());
iter = nameSet.iterator();
}
public boolean hasMoreElements () {
return iter.hasNext();
}
public Object nextElement () {
return iter.next();
}
}

/**
* Returns an Enumeration of String objects containing the
* names of the parameters contained in this request.
*
* @return an Enumeration of all the parameter names
*/
public Enumeration getParameterNames() {
return new DecoratedEnumeration(parameterMapDecoration.keySet (),
super.getParameterNames());
}
/**
* Returns an array of String objects containing all of the
* values the given request parameter has, or null if the
* parameter does not exist.
*
* @param name the key name for the parameter
* @return an array of Strings for the given key name
*/
public String[] getParameterValues(String name) {
String[] params = (String[]) parameterMapDecoration.get(name);
if ( params == null ) {
return super.getParameterValues(name);
}
else return params;
}

public void setParameterValues (String name, String[] values) {
parameterMapDecoration.put(name, values);
}

HttpServletRequest req = null;

/**
* Create an HttpServletRequestWrapper around some other
* HttpServletRequest impl. The wrapper adds the ability to
* add/remove parameter values.
*
* @param req the underlying HttpServletRequest
*/
public InfobalHttpServletRequestWrapper(HttpServletReques t ireq) {
req = ireq;
}
//-------------------- HttpServletRequest --------------------
/**
* Returns the name of the authentication scheme used to protect
the servlet, for example, "BASIC" or "SSL," or null if the servlet was
not protected.
*/
public String getAuthType() {return req.getAuthType();}

/**
* Returns the portion of the request URI that indicates the
context of the request.
*/
public String getContextPath() {return req.getContextPath();}

/**
* Returns an array containing all of the Cookie objects the
client sent with this request.
*/
public Cookie[] getCookies() {return req.getCookies();}

/**
* Returns the value of the specified request header as a long
value that represents a Date object.
*/
public long getDateHeader(String name) {return
req.getDateHeader(name);}

/**
* Returns the value of the specified request header as a String.
*/
public String getHeader(String name) {return req.getHeader(name);}

/**
* Returns an enumeration of all the header names this request
contains.
*/
public Enumeration getHeaderNames() {return req.getHeaderNames();}

/**
* Returns all the values of the specified request header as an
Enumeration of String objects.
*/
public Enumeration getHeaders(String name) {return
req.getHeaders(name);}

/**
* Returns the value of the specified request header as an int.
*/
public int getIntHeader(String name) {return
req.getIntHeader(name);}

/**
* Returns the name of the HTTP method with which this request was
made, for example, GET, POST, or PUT.
*/
public String getMethod() {return req.getMethod();}

/**
* Returns any extra path information associated with the URL the
client sent when it made this request.
*/
public String getPathInfo() {return req.getPathInfo();}

/**
* Returns any extra path information after the servlet name but
before the query string, and translates it to a real path.
*/
public String getPathTranslated() {return
req.getPathTranslated();}

/**
* Returns the query string that is contained in the request URL
after the path.
*/
public String getQueryString() {return req.getQueryString();}

/**
* Returns the login of the user making this request, if the user
has been authenticated, or null if the user has not been
authenticated.
*/
public String getRemoteUser() {return req.getRemoteUser();}

/**
* Returns the session ID specified by the client.
*/
public String getRequestedSessionId() {return
req.getRequestedSessionId();}

/**
* Returns the part of this request's URL from the protocol name
up to the query string in the first line of the HTTP request.
*/
public String getRequestURI() {return req.getRequestURI();}

/*
//csc_013102.1_start - added to comply with Servlet 2.3 spec
**
* Reconstructs the URL the client used to make the request. The
returned URL contains a protocol, server name, port number, and server
path, but it does not include query string parameters.
*
public StringBuffer getRequestURL() {return req.getRequestURL();}
//csc_013102.1_end - added to comply with Servlet 2.3 spec
*/
/**
* Returns the part of this request's URL that calls the servlet.
*/
public String getServletPath() {return req.getServletPath();}

/**
* Returns the current session associated with this request, or if
the request does not have a session, creates one.
*/
public HttpSession getSession() {return req.getSession();}

/**
* Returns the current HttpSession associated with this request
or, if if there is no current session and create is true, returns a
new session.
*/
public HttpSession getSession(boolean create) {return
req.getSession(create);}

/**
* Returns a java.security.Principal object containing the name of
the current authenticated user.
*/
public Principal getUserPrincipal() {return
req.getUserPrincipal();}

/**
* Checks whether the requested session ID came in as a cookie.
*/
public boolean isRequestedSessionIdFromCookie() {return
req.isRequestedSessionIdFromCookie();}

/**
* Deprecated. As of Version 2.1 of the Java Servlet API, use
isRequestedSessionIdFromURL() {return req.();}instead.
*/
public boolean isRequestedSessionIdFromUrl() {return
req.isRequestedSessionIdFromUrl();}

/**
* Checks whether the requested session ID came in as part of the
request URL.
*/
public boolean isRequestedSessionIdFromURL() {return
req.isRequestedSessionIdFromURL();}

/**
* Checks whether the requested session ID is still valid.
*/
public boolean isRequestedSessionIdValid() {return
req.isRequestedSessionIdValid();}

/**
* Returns a boolean indicating whether the authenticated user is
included in the specified logical "role".
*/
public boolean isUserInRole(String role) {return
req.isUserInRole(role);}
//-------------------- ServletRequest ------------------------
/**
* Returns the value of the named attribute as an Object, or null
if no attribute of the given name exists.
*/
public Object getAttribute(String name) {return
req.getAttribute(name);}

/**
* Returns an Enumeration containing the names of the attributes
available to this request.
*/
public Enumeration getAttributeNames() {return
req.getAttributeNames();}

/**
* Returns the name of the character encoding used in the body of
this request.
*/
public String getCharacterEncoding() {return
req.getCharacterEncoding();}

/**
* Returns the length, in bytes, of the request body and made
available by the input stream, or -1 if the length is not known.
*/
public int getContentLength() {return req.getContentLength();}

/**
* Returns the MIME type of the body of the request, or null if
the type is not known.
*/
public String getContentType() {return req.getContentType();}

/**
* Retrieves the body of the request as binary data using a
ServletInputStream.
*/
public ServletInputStream getInputStream() throws IOException
{return req.getInputStream();}

/**
* Returns the preferred Locale that the client will accept
content in, based on the Accept-Language header.
*/
public Locale getLocale() {return req.getLocale();}

/**
* Returns an Enumeration of Locale objects indicating, in
decreasing order starting with the preferred locale, the locales that
are acceptable to the client based on the Accept-Language header.
*/
public Enumeration getLocales() {return req.getLocales();}

/**
* Returns the value of a request parameter as a String, or
* null if the parameter does not exist.
*
* @param name the key name for the parameter
* @return the parameter value associated with a key name
*/
public String getParameter(String name) { return
req.getParameter(name); }

/**
* Returns an Enumeration of String objects containing the
* names of the parameters contained in this request.
*
* @return an Enumeration of all the parameter names
*/
public Enumeration getParameterNames() { return
req.getParameterNames(); }
/**
* Returns an array of String objects containing all of the
* values the given request parameter has, or null if the
* parameter does not exist.
*
* @param name the key name for the parameter
* @return an array of Strings for the given key name
*/
public String[] getParameterValues(String name) { return
req.getParameterValues(name); }

/**
* Returns the name and version of the protocol the request uses
in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
*/
public String getProtocol() {return req.getProtocol();}

/**
* Retrieves the body of the request as character data using a
BufferedReader.
*/
public BufferedReader getReader() throws IOException {return
req.getReader();}

/**
* Deprecated. As of Version 2.1 of the Java Servlet API, use
ServletContext.getRealPath(String) {return req.();}instead.
*/
public String getRealPath(String path) {return
req.getRealPath(path);}

/**
* Returns the Internet Protocol (IP) {return req.();}address of
the client that sent the request.
*/
public String getRemoteAddr() {return req.getRemoteAddr();}

/**
* Returns the fully qualified name of the client that sent the
request, or the IP address of the client if the name cannot be
determined.
*/
public String getRemoteHost() {return req.getRemoteHost();}

/**
* Returns a RequestDispatcher object that acts as a wrapper for
the resource located at the given path.
*/
public RequestDispatcher getRequestDispatcher(String path) {return
req.getRequestDispatcher(path);}

/**
* Returns the name of the scheme used to make this request, for
example, http, https, or ftp.
*/
public String getScheme() {return req.getScheme();}

/**
* Returns the host name of the server that received the request.
*/
public String getServerName() {return req.getServerName();}

/**
* Returns the port number on which this request was received.
*/
public int getServerPort() {return req.getServerPort();}

/**
* Returns a boolean indicating whether this request was made
using a secure channel, such as HTTPS.
*/
public boolean isSecure() {return req.isSecure();}

/**
* Removes an attribute from this request.
*/
public void removeAttribute(String name)
{req.removeAttribute(name);}

/**
* Stores an attribute in this request.
*/
public void setAttribute(String name, Object o)
{req.setAttribute(name, o);}

/*
//csc_013102.1_start - added these methods to comply with Servlet
2.3 spec
**
* Overrides the name of the character encoding used in the body
* of this request. This method must be called prior to reading
* request parameters or reading input using getReader().
*
public void setCharacterEncoding(String env) throws
UnsupportedEncodingException {
req.setCharacterEncoding(env);
}

**
* Returns a java.util.Map of the parameters of this request.
* Request parameters are extra information sent with the request.
* For HTTP servlets, parameters are contained in the query string
* or posted form data.
*
public Map getParameterMap() { return req.getParameterMap(); }
//csc_013102.1_end
*/
/**
* Get the underlying servlet request. The only reason you
* should ever have to do this is if you are trying to forward
* a request. Some containers check to make sure that the
* request object being forwarded is an instance of their own
* implementation...
*
* @return the underlying servlet request object
*/
protected HttpServletRequest getCoreRequest() {
return req;
}
}
Jul 17 '05 #1
0 2737

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon-Paul Dobson | last post by:
Hi, We have an applet that implements the MouseListener interface but when trying to add the applet to the glasspane of another applet a classcastexception is thrown. This all seemed to work...
5
by: Casper B | last post by:
Since I am only able to pass simple beans around using my Web Service framework, I wonder how to incorporate business logic around these beans. My idea was to let my Beans be the base class and...
1
by: Chris | last post by:
I use websphere connection pooling and had a failure attempting a CLOB.createTemporary. tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION); Here's an excerpt of the exception...
1
by: Johannes Lebek | last post by:
Hi there, I made some changes to my XSL stylesheet and now Xalan 2.5.1 is facing ClassCastExceptions. I'm pretty sure, that the changes I made should work (they are quite complicated -- I'd like...
1
by: kanthi84 | last post by:
hi, while i was trying to insert value into a blob column, i got an exception saying java.lang.ClassCastException: com.evermind.sql.OrclResultSet
2
by: mfsiddiq | last post by:
Hi Everyone I need help regarding how to get the handle for httpServlet while using webService.Since we are using webservice,i am not able to get handle of httpServletRequest and...
1
by: cristina1234 | last post by:
I have a constructor that takes a java.awt.Component as an argument: public DesignContainer(Component comp,...){...} If I pass it a javax.media.opengl.GLCanvas object,it takes it,but the...
1
by: mrityunjay11 | last post by:
String description = ""; String query1 = ""; int grade_autoid,count=0; rSet1= DBHelper.getQueryResult(query); %> ...
2
by: star111792 | last post by:
helo all, i am working with JSP and EJBs. i have written a simple code for verifying username and password of user by using session beans. my problem is that i m getting exception named...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.