Skip to content

Instantly share code, notes, and snippets.

@feliperazeek
Created June 18, 2011 23:22
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feliperazeek/1033587 to your computer and use it in GitHub Desktop.
Save feliperazeek/1033587 to your computer and use it in GitHub Desktop.
Adapter class to define a HttpServletRequest from a Play Framework Request Object
/**
* Copyright 2011 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Felipe Oliveira (http://mashup.fm)
*
*/
package mashup.fm.play.http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.Enumeration;
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 play.mvc.Http.Request;
/**
* The Class PlayHttpServletRequest.
*/
public class PlayHttpServletRequest implements HttpServletRequest {
/** The req. */
private Request req;
/**
* Instantiates a new play http servlet request.
*
* @param request
* the request
*/
public PlayHttpServletRequest(Request request) {
req = request;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
*/
@Override
public Object getAttribute(String name) {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getAttributeNames()
*/
@Override
public Enumeration getAttributeNames() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getCharacterEncoding()
*/
@Override
public String getCharacterEncoding() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
*/
@Override
public void setCharacterEncoding(String env)
throws UnsupportedEncodingException {
// return this.req.contentType ; // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getContentLength()
*/
@Override
public int getContentLength() {
// return this.req.con; // throw new
// RuntimeException("Method not implemented!");
return -1;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getContentType()
*/
@Override
public String getContentType() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getInputStream()
*/
@Override
public ServletInputStream getInputStream() throws IOException {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getParameter(java.lang.String)
*/
@Override
public String getParameter(String name) {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getParameterNames()
*/
@Override
public Enumeration getParameterNames() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
*/
@Override
public String[] getParameterValues(String name) {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getParameterMap()
*/
@Override
public Map getParameterMap() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getProtocol()
*/
@Override
public String getProtocol() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getScheme()
*/
@Override
public String getScheme() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getServerName()
*/
@Override
public String getServerName() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getServerPort()
*/
@Override
public int getServerPort() {
return req.port; // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getReader()
*/
@Override
public BufferedReader getReader() throws IOException {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getRemoteAddr()
*/
@Override
public String getRemoteAddr() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getRemoteHost()
*/
@Override
public String getRemoteHost() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#setAttribute(java.lang.String,
* java.lang.Object)
*/
@Override
public void setAttribute(String name, Object o) {
req.params.put(name, String.valueOf(o)); // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
*/
@Override
public void removeAttribute(String name) {
req.params.remove(name); // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getLocale()
*/
@Override
public Locale getLocale() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getLocales()
*/
@Override
public Enumeration getLocales() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#isSecure()
*/
@Override
public boolean isSecure() {
return req.secure;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
*/
@Override
public RequestDispatcher getRequestDispatcher(String path) {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
*/
@Override
public String getRealPath(String path) {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getRemotePort()
*/
@Override
public int getRemotePort() {
return req.port; // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getLocalName()
*/
@Override
public String getLocalName() {
return req.domain;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getLocalAddr()
*/
@Override
public String getLocalAddr() {
return req.host;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.ServletRequest#getLocalPort()
*/
@Override
public int getLocalPort() {
return req.port;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getAuthType()
*/
@Override
public String getAuthType() {
return null;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getCookies()
*/
@Override
public Cookie[] getCookies() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
*/
@Override
public long getDateHeader(String name) {
return -1; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
*/
@Override
public String getHeader(String name) {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
*/
@Override
public Enumeration getHeaders(String name) {
return null;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getHeaderNames()
*/
@Override
public Enumeration getHeaderNames() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
*/
@Override
public int getIntHeader(String name) {
return req.params.get(name, Integer.class); // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getMethod()
*/
@Override
public String getMethod() {
return req.method;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getPathInfo()
*/
@Override
public String getPathInfo() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getPathTranslated()
*/
@Override
public String getPathTranslated() {
return req.path; // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getContextPath()
*/
@Override
public String getContextPath() {
return req.path; // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getQueryString()
*/
@Override
public String getQueryString() {
return req.querystring;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getRemoteUser()
*/
@Override
public String getRemoteUser() {
return req.user; // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
*/
@Override
public boolean isUserInRole(String role) {
return false; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
*/
@Override
public Principal getUserPrincipal() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
*/
@Override
public String getRequestedSessionId() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getRequestURI()
*/
@Override
public String getRequestURI() {
return req.url;
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getRequestURL()
*/
@Override
public StringBuffer getRequestURL() {
return new StringBuffer(req.url);
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getServletPath()
*/
@Override
public String getServletPath() {
return req.path; // throw new
// RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getSession(boolean)
*/
@Override
public HttpSession getSession(boolean create) {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#getSession()
*/
@Override
public HttpSession getSession() {
return null; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
*/
@Override
public boolean isRequestedSessionIdValid() {
return false; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
*/
@Override
public boolean isRequestedSessionIdFromCookie() {
return false; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
*/
@Override
public boolean isRequestedSessionIdFromURL() {
return false; // throw new RuntimeException("Method not implemented!");
}
/**
* (non-Javadoc)
*
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
*/
@Override
public boolean isRequestedSessionIdFromUrl() {
return false; // throw new RuntimeException("Method not implemented!");
}
}
@ninozhang
Copy link

Very Helpful, Thanks.

@visualskyrim
Copy link

Thx a lot! Now I can use OLTU.

@maswang32
Copy link

LtiVerifier ltiVerifier = new LtiOauthVerifier();

    models.PlayHttpServletRequest temp = new PlayHttpServletRequest(request);
    LtiVerificationResult ltiResult = ltiVerifier.verify(temp, SECRET);

This is giving me a nullpointer exception error, can anyone help me?

@ash-smith
Copy link

@feliperazeek any updated version for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment