/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) Ericsson AB, 2004-2008. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.jvnet.glassfish.comms.clb.core.common.chr;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.jvnet.glassfish.comms.clb.proxy.http.util.HttpRequest;
import com.ericsson.ssa.sip.EnumerationConverter;
import com.sun.grizzly.util.http.Cookies;
import com.sun.grizzly.util.http.ServerCookie;
/**
* Adapter to convert a {@link HttpRequest} to a {@link HttpServletRequest}.
* Note that some methods are unsupported.
* @author qbinjoe
*
*/
public class HttpRequestAdapter implements HttpServletRequest {
private HttpRequest httpRequest;
public HttpRequestAdapter(HttpRequest httpRequest) {
this.httpRequest = httpRequest;
}
/**
* See {@link HttpServletRequest}.
*/
public String getAuthType() {
return httpRequest.getAuthType().getString();
}
/**
* Not supported.
*/
public String getContextPath() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* See {@link HttpServletRequest}.
*/
public Cookie[] getCookies() {
Cookies cookies = httpRequest.getCookies();
Cookie[] returnValue = new Cookie[cookies.getCookieCount()];
for (int i = 0; i < returnValue.length; i++) {
ServerCookie cookie = cookies.getCookie(i);
returnValue[i] = new Cookie(cookie.getName().getString(), cookie.getValue().getString());
}
return returnValue;
}
/**
* Not supported.
*/
public long getDateHeader(String s) {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* See {@link HttpServletRequest}.
*/
public String getHeader(String s) {
return httpRequest.getHeader(s);
}
/**
* Not supported.
*/
@SuppressWarnings("unchecked")
public Enumeration getHeaderNames() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
@SuppressWarnings("unchecked")
public Enumeration getHeaders(String s) {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public int getIntHeader(String s) {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public String getMethod() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public String getPathInfo() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public String getPathTranslated() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* See {@link HttpServletRequest}.
*/
public String getQueryString() {
return httpRequest.queryString().getString();
}
/**
* See {@link HttpServletRequest}.
*/
public String getRemoteUser() {
return httpRequest.getRemoteUser().getString();
}
/**
* See {@link HttpServletRequest}.
*/
public String getRequestURI() {
// TODO make sure it follows spec
return httpRequest.requestURI().getString();
}
/**
* See {@link HttpServletRequest}.
*/
public StringBuffer getRequestURL() {
// TODO make sure it follows spec
return new StringBuffer(httpRequest.requestURI().getString());
}
/**
* Not supported.
*/
public String getRequestedSessionId() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public String getServletPath() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public HttpSession getSession() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public HttpSession getSession(boolean flag) {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public Principal getUserPrincipal() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public boolean isRequestedSessionIdFromCookie() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public boolean isRequestedSessionIdFromURL() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public boolean isRequestedSessionIdFromUrl() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public boolean isRequestedSessionIdValid() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public boolean isUserInRole(String s) {
throw new UnsupportedOperationException("Not implemented!");
}
public Object getAttribute(String s) {
return httpRequest.getAttribute(s);
}
/**
* See {@link HttpServletRequest}.
*/
@SuppressWarnings("unchecked")
public Enumeration getAttributeNames() {
return new EnumerationConverter(httpRequest.getAttributes().keySet());
}
/**
* See {@link HttpServletRequest}.
*/
public String getCharacterEncoding() {
return httpRequest.getCharacterEncoding();
}
/**
* See {@link HttpServletRequest}.
*/
public int getContentLength() {
return httpRequest.getContentLength();
}
/**
* See {@link HttpServletRequest}.
*/
public String getContentType() {
return httpRequest.getContentType();
}
/**
* Not supported.
*/
public ServletInputStream getInputStream() throws IOException {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* See {@link HttpServletRequest}.
*/
public String getLocalAddr() {
return httpRequest.localAddr().getString();
}
/**
* See {@link HttpServletRequest}.
*/
public String getLocalName() {
return httpRequest.getLocalHost();
}
/**
* See {@link HttpServletRequest}.
*/
public int getLocalPort() {
return httpRequest.getLocalPort();
}
/**
* Not supported.
*/
public Locale getLocale() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
@SuppressWarnings("unchecked")
public Enumeration getLocales() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* See {@link HttpServletRequest}.
*/
public String getParameter(String s) {
return httpRequest.getParameters().getParameter(s);
}
/**
* See {@link HttpServletRequest}.
*/
@SuppressWarnings("unchecked")
public Map getParameterMap() {
Map paramMap = new HashMap();
Enumeration names = httpRequest.getParameters().getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
paramMap.put(name, httpRequest.getParameters().get(name));
}
return paramMap;
}
/**
* See {@link HttpServletRequest}.
*/
@SuppressWarnings("unchecked")
public Enumeration getParameterNames() {
return httpRequest.getParameters().getParameterNames();
}
/**
* See {@link HttpServletRequest}.
*/
public String[] getParameterValues(String s) {
return httpRequest.getParameters().getParameterValues(s);
}
/**
* Not supported.
*/
public String getProtocol() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public BufferedReader getReader() throws IOException {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public String getRealPath(String s) {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* See {@link HttpServletRequest}.
*/
public String getRemoteAddr() {
return httpRequest.remoteHost().getString();
}
/**
* See {@link HttpServletRequest}.
*/
public String getRemoteHost() {
return httpRequest.remoteHost().getString();
}
/**
* See {@link HttpServletRequest}.
*/
public int getRemotePort() {
return httpRequest.getRemotePort();
}
/**
* Not supported.
*/
public RequestDispatcher getRequestDispatcher(String s) {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public String getScheme() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public String getServerName() {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public int getServerPort() {
throw new UnsupportedOperationException("Not implemented!");
}
public boolean isSecure() {
return httpRequest.isSecure();
}
/**
* Not supported.
*/
public void removeAttribute(String s) {
throw new UnsupportedOperationException("Not implemented!");
}
/**
* Not supported.
*/
public void setAttribute(String s, Object obj) {
throw new UnsupportedOperationException("Not implemented!");
}
public void setCharacterEncoding(String s)
throws UnsupportedEncodingException {
throw new UnsupportedOperationException("Not implemented!");
}
}