Java tutorial
/** * Copyright 2013 Ben Navetta <ben@bennavetta.com> * * 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. */ package com.bennavetta.appsite.serve; import java.nio.charset.Charset; import java.util.Locale; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.RequestMethod; import com.bennavetta.appsite.processing.Request; import com.google.common.net.MediaType; public class HttpServletReq implements Request { private HttpServletRequest request; public HttpServletReq(HttpServletRequest request) { super(); this.request = request; } @Override public String getHeader(String name) { return request.getHeader(name); } @Override public String getCookie(String name) { for (Cookie cookie : request.getCookies()) { if (cookie.getName().equals(name)) { return cookie.getValue(); } } return ""; } @Override public String getParameter(String name) { return request.getParameter(name); } @Override public String getURI() { return request.getRequestURI(); } @Override public RequestMethod getMethod() { return RequestMethod.valueOf(request.getMethod()); } @Override public Locale getLocale() { return request.getLocale(); } @Override public Charset getCharacterEncoding() { return (request.getCharacterEncoding() == null ? Charset.defaultCharset() : Charset.forName(request.getCharacterEncoding())); } @Override public int getContentLength() { return request.getContentLength(); } @Override public MediaType getContentType() { return (request.getContentType() == null ? MediaType.ANY_TYPE : MediaType.parse(request.getContentType())); } }