org.dmonix.servlet.Request Maven / Gradle / Ivy
Show all versions of simple-servlet-framework Show documentation
/**
* Copyright 2016 Peter Nerg
*
* 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 org.dmonix.servlet;
import javascalautils.Option;
import javascalautils.Try;
import javax.servlet.http.HttpServletRequest;
/**
* Wrapper for the {@link HttpServletRequest} class.
* @author Peter Nerg
* @since 1.0
*/
public final class Request {
private final HttpServletRequest request;
Request(HttpServletRequest request) {
this.request = request;
}
/**
* Get the wrapped {@link HttpServletRequest}
* @return The original HTTP request
*/
public HttpServletRequest request() {
return request;
}
/**
* Get the path info as specified in the URI.
*
* @return The path info, i.e. the last part of the URI
*/
public Option getPathInfo() {
return ParserUtils.getPathInfo(request);
}
/**
* Parses an object from the json stream in the HTTP request
* @param type The type to parse
* @param The return type
* @return The parsed object
*/
public Try fromJson(Class type) {
return fromJson("UTF-8", type);
}
/**
* Parses an object from the json stream in the HTTP request
* @param charsetName The charset to expect
* @param type The type to parse
* @param The return type
* @return The parsed object
*/
public Try fromJson(String charsetName, Class type) {
return ParserUtils.fromJson(request, charsetName, type);
}
}