All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xlcloud.console.context.request.QueryHttpServletRequest Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2012 AMG.lab, a Bull Group Company
 * 
 * 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.xlcloud.console.context.request;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

/**
 * Wrapper for {@link HttpServletRequest} which is able to return request URL/URI with query params.
 * @author Konrad Król, AMG.net
 */
public class QueryHttpServletRequest {
    
    private HttpServletRequest request;
    
    public QueryHttpServletRequest(HttpServletRequest request) {
        this.request = request;
    }
    
    /**
     * Gets the value of {@link #request}.
     * @return value of {@link #request}
     */
    public HttpServletRequest getRequest() {
        return request;
    }

    /**
     * Sets the value of {@link #request}.
     * @param request - value
     */
    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
    
    /**
     * Returns full request URL from wrapped {@link HttpServletRequest}.
     * Returned value is concatenation of {@link HttpServletRequest#getRequestURL()} and {@link HttpServletRequest#getQueryString()} if any parameter occured.
     * @return full request URL
     */
    public String getFullRequestURL() {
        StringBuffer requestUrl = request.getRequestURL();
        
        String queryString = request.getQueryString();
        if(StringUtils.isNotBlank(queryString)) {
            requestUrl.append("?" + queryString);
        }
        
        return requestUrl.toString();
    }
    
    /**
     * Returns full request URI from wrapped {@link HttpServletRequest}.
     * Returned value is concatenation of {@link HttpServletRequest#getRequestURI()} and {@link HttpServletRequest#getQueryString()} if any parameters occured.
     * @return full request URI
     */
    public String getFullRequestURI() {
        String requestUri = request.getRequestURI();
        
        String queryString = request.getQueryString();
        if(StringUtils.isNotBlank(queryString)) {
            requestUri += ("?" + queryString);
        }
        
        return requestUri;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy