Example usage for javax.servlet.http HttpServletRequest setCharacterEncoding

List of usage examples for javax.servlet.http HttpServletRequest setCharacterEncoding

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest setCharacterEncoding.

Prototype

public void setCharacterEncoding(String env) throws UnsupportedEncodingException;

Source Link

Document

Overrides the name of the character encoding used in the body of this request.

Usage

From source file:org.gbif.portal.web.controller.occurrence.OccurrenceFilterController.java

/**
 * Retrieves the counts against the marine zone for this set of criteria
 * //  w ww  . j  ava  2s .  c o m
 * @param request
 * @param response
 * @return ModelAndView which contains the provider list and counts
 * @throws UnsupportedEncodingException
 */
public ModelAndView searchMarineZones(HttpServletRequest request, HttpServletResponse response)
        throws Exception, ServiceException, UnsupportedEncodingException {
    // interrogate the criteria - if it only contains a taxon filter then switch
    CriteriaDTO criteriaDTO = CriteriaUtil.getCriteria(request, occurrenceFilters.getFilters());
    // fix criteria value
    request.setCharacterEncoding("ISO-8859-1");
    CriteriaUtil.fixEncoding(request, criteriaDTO);
    if (criteriaDTO.size() == 1) {
        logger.debug("Switching to using service layer method getMarineZoneCountsForTaxonConcept");
        CriterionDTO criterionDTO = criteriaDTO.get(0);
        FilterDTO filterDTO = FilterUtils.getFilterById(occurrenceFilters.getFilters(),
                criterionDTO.getSubject());
        if (filterDTO.getSubject().equals(classificationFilter.getSubject())) {
            List<CountDTO> counts = taxonomyManager.getMarineZoneCountsForTaxonConcept(criterionDTO.getValue());
            ModelAndView mav = new ModelAndView(occurrenceFilterMarineZoneCountsView);
            mav.addObject(countsModelKey, counts);
            mav.addObject(resultsModelKey, counts);
            // add filters
            mav.addObject(filtersRequestKey, occurrenceFilters.getFilters());
            mav.addObject(criteriaRequestKey, criteriaDTO);
            mav.addObject(countsAvailableModelKey, true);
            return mav;
        }
    }
    int totalNoOfMarineZones = departmentManager.getTotalMarineZoneCount();
    return getCountryCountsView(request, response, "SERVICE.OCCURRENCE.QUERY.RETURNFIELDS.MARINEZONECOUNTS",
            occurrenceFilterMarineZoneCountsView, new SearchConstraints(0, totalNoOfMarineZones));
}

From source file:org.gbif.portal.web.controller.occurrence.OccurrenceFilterController.java

/**
 * Retrieves the counts against the countries for this set of criteria
 * /*  ww  w .j  ava 2s .c o m*/
 * @param request
 * @param response
 * @return ModelAndView which contains the provider list and counts
 * @throws UnsupportedEncodingException
 */
public ModelAndView searchCountries(HttpServletRequest request, HttpServletResponse response)
        throws Exception, ServiceException, UnsupportedEncodingException {
    // interrogate the criteria - if it only contains a taxon filter then switch
    CriteriaDTO criteriaDTO = CriteriaUtil.getCriteria(request, occurrenceFilters.getFilters());
    // fix criteria value
    request.setCharacterEncoding("ISO-8859-1");
    CriteriaUtil.fixEncoding(request, criteriaDTO);
    if (criteriaDTO.size() == 1) {
        logger.debug("Switching to using service layer method getCountryCountsForTaxonConcept");
        CriterionDTO criterionDTO = criteriaDTO.get(0);
        FilterDTO filterDTO = FilterUtils.getFilterById(occurrenceFilters.getFilters(),
                criterionDTO.getSubject());
        if (filterDTO.getSubject().equals(classificationFilter.getSubject())) {
            List<CountDTO> counts = taxonomyManager.getCountryCountsForTaxonConcept(criterionDTO.getValue(),
                    RequestContextUtils.getLocale(request));
            ModelAndView mav = new ModelAndView(occurrenceFilterCountryCountsView);
            mav.addObject(countsModelKey, counts);
            mav.addObject(resultsModelKey, counts);
            // add filters
            mav.addObject(filtersRequestKey, occurrenceFilters.getFilters());
            mav.addObject(criteriaRequestKey, criteriaDTO);
            mav.addObject(countsAvailableModelKey, true);
            return mav;
        }
    }
    int totalNoOfCountries = geospatialManager.getTotalCountryCount();
    return getCountryCountsView(request, response, "SERVICE.OCCURRENCE.QUERY.RETURNFIELDS.COUNTRYCOUNTS",
            occurrenceFilterCountryCountsView, new SearchConstraints(0, totalNoOfCountries));
}

From source file:org.gbif.portal.web.controller.occurrence.OccurrenceFilterController.java

/**
 * Retrieves the counts against the protected area for this set of criteria
 * //from  ww  w  . j  av a2s .co m
 * @param request
 * @param response
 * @return ModelAndView which contains the provider list and counts
 * @throws UnsupportedEncodingException
 */
public ModelAndView searchProtectedAreas(HttpServletRequest request, HttpServletResponse response)
        throws Exception, ServiceException, UnsupportedEncodingException {
    // interrogate the criteria - if it only contains a taxon filter then switch
    CriteriaDTO criteriaDTO = CriteriaUtil.getCriteria(request, occurrenceFilters.getFilters());
    // fix criteria value
    request.setCharacterEncoding("ISO-8859-1");
    CriteriaUtil.fixEncoding(request, criteriaDTO);
    if (criteriaDTO.size() == 1) {
        logger.debug("Switching to using service layer method getProtectedAreaCountsForTaxonConcept");
        CriterionDTO criterionDTO = criteriaDTO.get(0);
        FilterDTO filterDTO = FilterUtils.getFilterById(occurrenceFilters.getFilters(),
                criterionDTO.getSubject());
        if (filterDTO.getSubject().equals(classificationFilter.getSubject())) {
            List<CountDTO> counts = taxonomyManager
                    .getProtectedAreaCountsForTaxonConcept(criterionDTO.getValue());
            ModelAndView mav = new ModelAndView(occurrenceFilterProtectedAreaCountsView);
            mav.addObject(countsModelKey, counts);
            mav.addObject(resultsModelKey, counts);
            // add filters
            mav.addObject(filtersRequestKey, occurrenceFilters.getFilters());
            mav.addObject(criteriaRequestKey, criteriaDTO);
            mav.addObject(countsAvailableModelKey, true);
            return mav;
        }
    }
    int totalNoOfProtectedAreas = departmentManager.getTotalProtectedAreaCount();
    return getCountryCountsView(request, response, "SERVICE.OCCURRENCE.QUERY.RETURNFIELDS.PROTECTEDAREACOUNTS",
            occurrenceFilterProtectedAreaCountsView, new SearchConstraints(0, totalNoOfProtectedAreas));
}

From source file:org.gbif.portal.web.controller.occurrence.OccurrenceFilterController.java

/**
 * Retrieves the counts against the zonificacion for this set of criteria
 * //w  w w  .  j  av a 2  s.  com
 * @param request
 * @param response
 * @return ModelAndView which contains the provider list and counts
 * @throws UnsupportedEncodingException
 */
public ModelAndView searchZonificaciones(HttpServletRequest request, HttpServletResponse response)
        throws Exception, ServiceException, UnsupportedEncodingException {
    // interrogate the criteria - if it only contains a taxon filter then switch
    CriteriaDTO criteriaDTO = CriteriaUtil.getCriteria(request, occurrenceFilters.getFilters());
    // fix criteria value
    request.setCharacterEncoding("ISO-8859-1");
    CriteriaUtil.fixEncoding(request, criteriaDTO);
    if (criteriaDTO.size() == 1) {
        logger.debug("Switching to using service layer method getZonificacionCountsForTaxonConcept");
        CriterionDTO criterionDTO = criteriaDTO.get(0);
        FilterDTO filterDTO = FilterUtils.getFilterById(occurrenceFilters.getFilters(),
                criterionDTO.getSubject());
        if (filterDTO.getSubject().equals(classificationFilter.getSubject())) {
            List<CountDTO> counts = taxonomyManager
                    .getZonificacionCountsForTaxonConcept(criterionDTO.getValue());
            ModelAndView mav = new ModelAndView(occurrenceFilterZonificacionCountsView);
            mav.addObject(countsModelKey, counts);
            mav.addObject(resultsModelKey, counts);
            // add filters
            mav.addObject(filtersRequestKey, occurrenceFilters.getFilters());
            mav.addObject(criteriaRequestKey, criteriaDTO);
            mav.addObject(countsAvailableModelKey, true);
            return mav;
        }
    }
    int totalNoOfZonificaciones = departmentManager.getTotalZonificacionCount();
    return getCountryCountsView(request, response, "SERVICE.OCCURRENCE.QUERY.RETURNFIELDS.ZONIFICACIONCOUNTS",
            occurrenceFilterZonificacionCountsView, new SearchConstraints(0, totalNoOfZonificaciones));
}

From source file:org.gbif.portal.web.controller.occurrence.OccurrenceFilterController.java

/**
 * Retrieves the counts against the ecosystem for this set of criteria
 * //from  ww w .j  a  v a 2 s  .co m
 * @param request
 * @param response
 * @return ModelAndView which contains the provider list and counts
 * @throws UnsupportedEncodingException
 */
public ModelAndView searchEcosystems(HttpServletRequest request, HttpServletResponse response)
        throws Exception, ServiceException, UnsupportedEncodingException {
    // interrogate the criteria - if it only contains a taxon filter then switch
    CriteriaDTO criteriaDTO = CriteriaUtil.getCriteria(request, occurrenceFilters.getFilters());
    // fix criteria value
    request.setCharacterEncoding("ISO-8859-1");
    CriteriaUtil.fixEncoding(request, criteriaDTO);
    if (criteriaDTO.size() == 1) {
        logger.debug("Switching to using service layer method getEcosystemCountsForTaxonConcept");
        CriterionDTO criterionDTO = criteriaDTO.get(0);
        FilterDTO filterDTO = FilterUtils.getFilterById(occurrenceFilters.getFilters(),
                criterionDTO.getSubject());
        if (filterDTO.getSubject().equals(classificationFilter.getSubject())) {
            List<CountDTO> counts = taxonomyManager.getEcosystemCountsForTaxonConcept(criterionDTO.getValue());
            ModelAndView mav = new ModelAndView(occurrenceFilterEcosystemCountsView);
            mav.addObject(countsModelKey, counts);
            mav.addObject(resultsModelKey, counts);
            // add filters
            mav.addObject(filtersRequestKey, occurrenceFilters.getFilters());
            mav.addObject(criteriaRequestKey, criteriaDTO);
            mav.addObject(countsAvailableModelKey, true);
            return mav;
        }
    }
    int totalNoOfEcosystems = departmentManager.getTotalEcosystemCount();
    String view;
    if (criteriaDTO.get(0).getValue() == "1") {
        view = "SERVICE.OCCURRENCE.QUERY.RETURNFIELDS.ECOSYSTEMCOUNTS";
    } else {
        view = "SERVICE.OCCURRENCE.QUERY.RETURNFIELDS.PARAMOCOUNTS";
    }
    return getCountryCountsView(request, response, view, occurrenceFilterEcosystemCountsView,
            new SearchConstraints(0, totalNoOfEcosystems));
}

From source file:org.gbif.portal.web.controller.occurrence.OccurrenceFilterController.java

/**
 * Retrieves the counts against the providers for this set of criteria
 * /*from w w w.j  a  va2 s .  com*/
 * @param request
 * @param response
 * @return ModelAndView which contains the provider list and counts
 * @throws UnsupportedEncodingException
 */
public ModelAndView searchProviders(HttpServletRequest request, HttpServletResponse response)
        throws Exception, ServiceException, UnsupportedEncodingException {
    // interrogate the criteria - if it only contains a country filter then switch
    CriteriaDTO criteriaDTO = CriteriaUtil.getCriteria(request, occurrenceFilters.getFilters());
    // fix criteria value
    request.setCharacterEncoding("ISO-8859-1");
    CriteriaUtil.fixEncoding(request, criteriaDTO);
    if (criteriaDTO.size() == 0) {
        logger.debug("Switching to using service layer method getAllDataProviders");
        ModelAndView mav = new ModelAndView(occurrenceFilterProviderCountsView);
        List<DataProviderDTO> dps = dataResourceManager.getAllDataProviders();
        mav.addObject(countsModelKey, dps);
        mav.addObject(resultsModelKey, dps);
        // add filters
        mav.addObject(filtersRequestKey, occurrenceFilters.getFilters());
        mav.addObject(criteriaRequestKey, criteriaDTO);
        mav.addObject(countsAvailableModelKey, true);
        return mav;
    }
    if (criteriaDTO.size() == 1) {
        logger.debug("Switching to using service layer method getDataProviderCountsForCountry");
        CriterionDTO criterionDTO = criteriaDTO.get(0);
        FilterDTO filterDTO = FilterUtils.getFilterById(occurrenceFilters.getFilters(),
                criterionDTO.getSubject());
        if (filterDTO.getSubject().equals(countryFilter.getSubject())) {
            List<CountDTO> counts = geospatialManager.getDataProviderCountsForCountry(criterionDTO.getValue());
            ModelAndView mav = new ModelAndView(occurrenceFilterProviderCountsView);
            mav.addObject(countsModelKey, counts);
            mav.addObject(resultsModelKey, counts);
            // add filters
            mav.addObject(filtersRequestKey, occurrenceFilters.getFilters());
            mav.addObject(criteriaRequestKey, criteriaDTO);
            mav.addObject(countsAvailableModelKey, true);
            return mav;
        }
    }
    int totalNoOfDataProviders = dataResourceManager.getTotalDataProviderCount();
    return getCountsView(request, response, "SERVICE.OCCURRENCE.QUERY.RETURNFIELDS.PROVIDERCOUNTS",
            occurrenceFilterProviderCountsView, new SearchConstraints(0, totalNoOfDataProviders));
}

From source file:org.gbif.portal.web.controller.occurrence.OccurrenceFilterController.java

/**
 * Performs the count triplet query and returns the generic count view for occurrences.
 * //from   www. ja  v  a 2s .  c  om
 * @param triplets
 * @return
 * @throws UnsupportedEncodingException
 */
@SuppressWarnings("unchecked")
private ModelAndView getCountryCountsView(HttpServletRequest request, HttpServletResponse response,
        String returnFieldsKey, String viewName, SearchConstraints searchConstraints)
        throws Exception, ServiceException, UnsupportedEncodingException {
    CriteriaDTO criteriaDTO = CriteriaUtil.getCriteria(request, occurrenceFilters.getFilters());
    // fix criteria value
    request.setCharacterEncoding("UTF-8");
    CriteriaUtil.fixEncoding(request, criteriaDTO);
    List<PropertyStoreTripletDTO> triplets = queryHelper.getTriplets(occurrenceFilters.getFilters(),
            criteriaDTO, request, response);
    triplets.add(new PropertyStoreTripletDTO(queryHelper.getQueryNamespace(), selectFieldSubject,
            returnPredicateSubject, returnFieldsKey));
    SearchResultsDTO searchResults = countsQueryManager.doTripletQuery(triplets, criteriaDTO.isMatchAll(),
            searchConstraints);

    List<CountDTO> countDTOs = searchResults.getResults();
    final Locale locale = RequestContextUtils.getLocale(request);

    Collections.sort(countDTOs, new Comparator() {

        public int compare(Object count1, Object count2) {
            CountDTO countDTO1 = (CountDTO) count1;
            CountDTO countDTO2 = (CountDTO) count2;

            CountryDTO countryDTO1 = geospatialManager.getCountryForIsoCountryCode(countDTO1.getKey(), locale);
            CountryDTO countryDTO2 = geospatialManager.getCountryForIsoCountryCode(countDTO2.getKey(), locale);

            if (countryDTO1 == null)
                return 1;
            if (countryDTO2 == null)
                return -1;

            return countryDTO1.getName().compareToIgnoreCase(countryDTO2.getName());
        }
    });

    ModelAndView mav = new ModelAndView(viewName);
    mav.addObject(countsModelKey, searchResults);
    mav.addObject(resultsModelKey, countDTOs);
    // add filters
    mav.addObject(filtersRequestKey, occurrenceFilters.getFilters());
    mav.addObject(criteriaRequestKey, criteriaDTO);
    return mav;
}

From source file:org.etudes.jforum.ActionServletRequest.java

/**
 * Default constructor.//from   w  ww  .jav a 2  s.  c  om
 * 
 * @param superRequest Original <code>HttpServletRequest</code> instance
 * @throws IOException
 */
public ActionServletRequest(HttpServletRequest superRequest) throws IOException {
    super(superRequest);

    if (logger.isDebugEnabled())
        logger.debug("building an ActionServletRequest");

    this.query = new HashMap();
    boolean isMultipart = false;

    String requestType = (superRequest.getMethod()).toUpperCase();
    String requestUri = superRequest.getRequestURI();

    // Remove the "jsessionid" (or similar) from the URI
    // Probably this is not the right way to go, since we're
    // discarting the value...
    int index = requestUri.indexOf(';');

    if (index > -1) {
        int lastIndex = requestUri.indexOf('?', index);

        if (lastIndex == -1) {
            lastIndex = requestUri.indexOf('&', index);
        }

        if (lastIndex == -1) {
            requestUri = requestUri.substring(0, index);
        } else {
            String part1 = requestUri.substring(0, index);
            requestUri = part1 + requestUri.substring(lastIndex);
        }
    }

    // String encoding = SystemGlobals.getValue(ConfigKeys.ENCODING);
    String encoding = SakaiSystemGlobals.getValue(ConfigKeys.ENCODING);

    if ((("GET").equals(requestType) && (StringUtils.trimToNull(superRequest.getQueryString()) == null))
            && requestUri.endsWith(SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION))) {
        //superRequest.setCharacterEncoding(SystemGlobals.getValue(ConfigKeys.ENCODING));  
        superRequest.setCharacterEncoding(SakaiSystemGlobals.getValue(ConfigKeys.ENCODING));
        String[] urlModel = requestUri.split("/");

        // If (context name is not null) {
        // 0: empty
        // 1: context name
        // 2: module
        // 3: action
        // 4 .. n: request dependent data
        // } else {
        // 0: empty
        // 1: module
        // 2: action
        // 3 .. n: request dependent data
        // }

        int moduleIndex = 2;
        int actionIndex = 3;
        int baseLen = 4;

        String contextName = superRequest.getContextPath();
        if ((contextName == null) || contextName.equals("")) {
            moduleIndex = 1;
            actionIndex = 2;
            baseLen = 3;
        }

        urlModel[urlModel.length - 1] = (urlModel[urlModel.length - 1]).substring(0,
                (urlModel[urlModel.length - 1]).indexOf(SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION)));

        // <moduleName>.<actionName>.<numberOfParameters>
        UrlPattern url = UrlPatternCollection.findPattern(
                urlModel[moduleIndex] + "." + urlModel[actionIndex] + "." + (urlModel.length - baseLen));

        if (url == null) {
            throw new InvalidURLPatternException("The request '" + superRequest.getRequestURI()
                    + "' is not valid. A correspondent URL Pattern was not found");
        }

        this.addParameter("module", urlModel[moduleIndex]);
        this.addParameter("action", urlModel[actionIndex]);

        // We have parameters? 
        if (url.getSize() >= urlModel.length - baseLen) {
            for (int i = 0; i < url.getSize(); i++) {
                this.addParameter(url.getVars()[i], urlModel[i + baseLen]);
            }
        }
    } else if (("POST").equals(requestType)) {

        isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(superRequest));
        if (isMultipart) {
            String tmpDir = SystemGlobals.getApplicationPath() + "/"
                    + SystemGlobals.getValue(ConfigKeys.TMP_DIR);
            ServletFileUpload upload = new ServletFileUpload(
                    new DiskFileItemFactory(100 * 1024, new File(tmpDir)));

            try {
                List items = upload.parseRequest(superRequest);
                for (Iterator iter = items.iterator(); iter.hasNext();) {
                    FileItem item = (FileItem) iter.next();
                    if (item.isFormField()) {
                        //<<<11/15/06 Murthy - added to capture mutiple values for controls like select etc
                        if (this.query.containsKey(item.getFieldName())) {
                            String paramValuesExisting[] = (String[]) this.query
                                    .get(item.getFieldName() + "ParamValues");
                            String paramValues[] = null;
                            if (paramValuesExisting != null) {
                                paramValues = new String[paramValuesExisting.length + 1];
                                System.arraycopy(paramValuesExisting, 0, paramValues, 0,
                                        paramValuesExisting.length);
                                paramValues[paramValuesExisting.length] = item.getString(encoding);
                            } else {
                                paramValues = new String[2];
                                paramValues[0] = (String) this.query.get(item.getFieldName());
                                paramValues[1] = item.getString(encoding);
                            }
                            this.query.put(item.getFieldName() + "ParamValues", paramValues);
                        }
                        //>>>11/15/06 Murthy - added to capture mutiple values for controls like select etc
                        this.query.put(item.getFieldName(), item.getString(encoding));
                    } else {
                        if (item.getSize() > 0) {
                            this.query.put(item.getFieldName(), item);
                        }
                    }
                }
            } catch (FileUploadException e) {
                throw new MultipartHandlingException("Error while processing multipart content: " + e);
            }
        }
    }

    if (isMultipart == false) {
        superRequest.setCharacterEncoding(encoding);
        String containerEncoding = SystemGlobals.getValue(ConfigKeys.DEFAULT_CONTAINER_ENCODING);

        for (Enumeration e = superRequest.getParameterNames(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            this.query.put(name,
                    new String(superRequest.getParameter(name).getBytes(containerEncoding), encoding));
        }
    }
}

From source file:org.geoserver.ows.Dispatcher.java

protected void preprocessRequest(HttpServletRequest request) throws Exception {
    //set the charset
    Charset charSet = null;/*from ww w . j a  v  a 2s .  com*/

    //TODO: make this server settable
    charSet = UTF8;
    if (request.getCharacterEncoding() != null)
        try {
            charSet = Charset.forName(request.getCharacterEncoding());
        } catch (Exception e) {
            // ok, we tried...
        }

    request.setCharacterEncoding(charSet.name());
}

From source file:org.georchestra.security.Proxy.java

private HttpRequestBase makeRequest(HttpServletRequest request, RequestType requestType, String sURL)
        throws IOException {
    HttpRequestBase targetRequest;/*www.j  a  va 2  s  .  c  o  m*/
    try {
        // Split URL
        URL url = new URL(sURL);
        URI uri = buildUri(url);

        switch (requestType) {
        case GET: {
            logger.debug("New request is: " + sURL + "\nRequest is GET");

            HttpGet get = new HttpGet(uri);
            targetRequest = get;
            break;
        }
        case POST: {
            logger.debug("New request is: " + sURL + "\nRequest is POST");

            HttpPost post = new HttpPost(uri);
            HttpEntity entity;
            request.setCharacterEncoding("UTF8");
            if (isFormContentType(request)) {
                logger.debug("Post is recognized as a form post.");
                List<NameValuePair> parameters = new ArrayList<NameValuePair>();
                for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
                    String name = (String) e.nextElement();
                    String[] v = request.getParameterValues(name);
                    for (String value : v) {
                        NameValuePair nv = new BasicNameValuePair(name, value);
                        parameters.add(nv);
                    }
                }
                String charset = request.getCharacterEncoding();
                try {
                    Charset.forName(charset);
                } catch (Throwable t) {
                    charset = null;
                }
                if (charset == null) {
                    charset = defaultCharset;
                }
                entity = new UrlEncodedFormEntity(parameters, charset);
                post.setEntity(entity);

            } else {
                logger.debug("Post is NOT recognized as a form post. (Not an error, just a comment)");
                int contentLength = request.getContentLength();
                ServletInputStream inputStream = request.getInputStream();
                entity = new InputStreamEntity(inputStream, contentLength);
            }
            post.setEntity(entity);
            targetRequest = post;
            break;
        }
        case TRACE: {
            logger.debug("New request is: " + sURL + "\nRequest is TRACE");

            HttpTrace post = new HttpTrace(uri);

            targetRequest = post;
            break;
        }
        case OPTIONS: {
            logger.debug("New request is: " + sURL + "\nRequest is OPTIONS");

            HttpOptions post = new HttpOptions(uri);

            targetRequest = post;
            break;
        }
        case HEAD: {
            logger.debug("New request is: " + sURL + "\nRequest is HEAD");

            HttpHead post = new HttpHead(uri);

            targetRequest = post;
            break;
        }
        case PUT: {
            logger.debug("New request is: " + sURL + "\nRequest is PUT");

            HttpPut put = new HttpPut(uri);

            put.setEntity(new InputStreamEntity(request.getInputStream(), request.getContentLength()));

            targetRequest = put;
            break;
        }
        case DELETE: {
            logger.debug("New request is: " + sURL + "\nRequest is DELETE");

            HttpDelete delete = new HttpDelete(uri);

            targetRequest = delete;
            break;
        }
        default: {
            String msg = requestType + " not yet supported";
            logger.error(msg);
            throw new IllegalArgumentException(msg);
        }

        }
    } catch (URISyntaxException e) {
        logger.error("ERROR creating URI from " + sURL, e);
        throw new IOException(e);
    }

    return targetRequest;
}