Example usage for javax.servlet.http HttpServletRequest getRequestURL

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

Introduction

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

Prototype

public StringBuffer getRequestURL();

Source Link

Document

Reconstructs the URL the client used to make the request.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet.java

/**
 * If logging on the subclass is set to the TRACE level, dump the HTTP
 * headers on the request.//from w  w  w  .j  a  v a2 s.  c o  m
 */
private void dumpRequestHeaders(HttpServletRequest req) {
    @SuppressWarnings("unchecked")
    Enumeration<String> names = req.getHeaderNames();

    Log subclassLog = LogFactory.getLog(this.getClass());
    subclassLog.trace("----------------------request:" + req.getRequestURL());
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        if (!BORING_HEADERS.contains(name)) {
            subclassLog.trace(name + "=" + req.getHeader(name));
        }
    }
}

From source file:hu.fnf.devel.wishbox.gateway.GatewayREST.java

@RequestMapping(value = "/persistence/**", method = RequestMethod.GET)
public @ResponseBody String proxy(HttpServletRequest request) {
    String req = "";
    StringBuilder content = new StringBuilder();
    try {/*from  ww w .  j ava2s .  c  o  m*/
        while (request.getReader().ready()) {
            content.append(request.getReader().readLine());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    req = "user";
    try {
        req = request.getRequestURL().toString().split("/gateway/persistence")[1];
    } catch (ArrayIndexOutOfBoundsException e) {
        req = "/";
    }
    System.out.println(request.getRequestURL());

    System.out.println("Proxy call: " + req);
    System.out.println("Conent: " + content);

    RestTemplate restTemplate = new RestTemplate();
    try {
        return restTemplate.getForObject("http://localhost:9090/" + req, String.class);
    } catch (HttpClientErrorException e) {
        throw new HttpClientErrorException(e.getStatusCode());
    }
}

From source file:org.n52.restfulwpsproxy.webapp.rest.ProcessController.java

@RequestMapping(value = "/{processId:.+}/jobs", method = RequestMethod.POST)
public ResponseEntity<?> execute(@PathVariable("processId") String processId,
        @RequestParam(value = "sync-execute", required = false, defaultValue = "false") boolean syncExecute,
        @RequestBody ExecuteDocument executeDocument, HttpServletRequest request) throws URISyntaxException {

    if (!syncExecute) {
        executeDocument.getExecute().setMode(ExecuteRequestType.Mode.Enum.forString("async"));
        StatusInfoDocument asyncExecute = executeClient.asyncExecute(processId, executeDocument);

        String jobId = asyncExecute.getStatusInfo().getJobID();

        URI created = URI.create(request.getRequestURL().append("/").append(jobId).toString());

        getJobsClient.addJobId(processId, jobId);

        return ResponseEntity.created(created).build();
    } else {//  www .j  av a2 s . c  om
        executeDocument.getExecute().setMode(ExecuteRequestType.Mode.Enum.forString("sync"));
        ResultDocument execute = executeClient.syncExecute(processId, executeDocument);

        return ResponseEntity.ok(execute);
    }
}

From source file:com.ibm.bluemix.mobilestarterkit.service.ServiceAPI.java

@Path("/login")
@POST//from w ww  . j  ava 2 s.  c o m
public String checkLogin(@Context HttpServletRequest request, @Context UriInfo uriInfo, String creds) {

    System.out.println("checkLogin () ");

    // PAGE 
    String PAGE_ADDRESS = request.getRequestURL().toString();

    // IP_ADDRESS
    String IP_ADDRESS = request.getHeader("X-FORWARDED-FOR");
    if (IP_ADDRESS == null)
        IP_ADDRESS = request.getRemoteAddr();

    // ?
    String BROWSER = request.getHeader("User-Agent");

    // Insert log into LogTable
    saveLog(PAGE_ADDRESS, IP_ADDRESS, BROWSER);
    //System.out.println(">>> " + PAGE_ADDRESS + "  " + IP_ADDRESS + "  " + BROWSER);

    try {
        JSONObject credentials = new JSONObject(creds);
        String userID = credentials.getString("user_id");
        String password = credentials.getString("password");

        if (userID.equals("admin") && password.equals("password")) {
            return "Successful";
        } else {
            return "Failed";
        }

    } catch (JSONException e) {
        e.getStackTrace();
        return "Failed";

    }
}

From source file:com.stimulus.archiva.presentation.MessageBean.java

protected void viewMessage(Email email, boolean isOriginalMessage) {
    try {/*ww w  .  j  a  v  a  2  s .  c o m*/
        this.email = email;
        logger.info("view email {" + email + ", " + getMailArchivaPrincipal() + "}");
        audit.info("view email {" + email + ", " + getMailArchivaPrincipal() + "}");

        //deleteExtractedMessage();
        HttpServletRequest hsr = ActionContext.getActionContext().getRequest();
        String baseURL = hsr.getRequestURL().substring(0,
                hsr.getRequestURL().lastIndexOf(hsr.getServletPath()));
        messageExtraction = null; // can take a while to extract message
        lock.lock();
        try {
            messageExtraction = MessageService.extractMessage(email, baseURL, isOriginalMessage);
            extracted.signal();
        } finally {
            lock.unlock();
        }
    } catch (Exception e) {

        logger.error("failed to extract message", e);
    }
}

From source file:com.openmeap.admin.web.servlet.AdminServlet.java

@SuppressWarnings("unchecked")
@Override//  w  w  w  . ja v a 2s  .c  o m
public void service(HttpServletRequest request, HttpServletResponse response) {

    logger.trace("Entering service()");

    try {
        DocumentProcessor documentProcessor = null;

        logger.debug("Request uri: {}", request.getRequestURI());
        logger.debug("Request url: {}", request.getRequestURL());
        logger.debug("Query string: {}", request.getQueryString());
        if (logger.isDebugEnabled()) {
            logger.debug("Parameter map: {}", ParameterMapUtils.toString(request.getParameterMap()));
        }

        if (request.getParameter("logout") != null) {
            logger.trace("Executing logout");
            request.getSession().invalidate();
            response.sendRedirect(request.getContextPath() + "/interface/");
        }

        if (request.getParameter("refreshContext") != null && context instanceof AbstractApplicationContext) {
            logger.trace("Refreshing context");
            ((AbstractApplicationContext) context).refresh();
        }

        // support for clearing the persistence context
        if (request.getParameter("clearPersistenceContext") != null
                && context instanceof AbstractApplicationContext) {
            logger.trace("Clearing the persistence context");
            ModelServiceImpl ms = (ModelServiceImpl) ((AbstractApplicationContext) context)
                    .getBean("modelService");
            ms.clearPersistenceContext();
        }

        // default to the mainOptionPage, unless otherwise specified
        String pageBean = null;
        if (request.getParameter(FormConstants.PAGE_BEAN) != null)
            pageBean = request.getParameter(FormConstants.PAGE_BEAN);
        else
            pageBean = FormConstants.PAGE_BEAN_MAIN;
        logger.debug("Using page bean: {}", pageBean);
        documentProcessor = (DocumentProcessor) context.getBean(pageBean);

        ModelManager mgr = getModelManager();
        Map<Object, Object> map = new HashMap<Object, Object>();

        // TODO: I'm not really happy with this hacky work-around for the login form not being in actual request scope
        if (documentProcessor.getProcessesFormData()) {
            GlobalSettings settings = mgr.getGlobalSettings();
            map = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(),
                    settings.getTemporaryStoragePath(), request);
            map.put("userPrincipalName", new String[] { request.getUserPrincipal().getName() });
            AuthorizerImpl authorizer = (AuthorizerImpl) context.getBean("authorizer");
            authorizer.setRequest(request);
        }

        response.setContentType(FormConstants.CONT_TYPE_HTML);

        Map<Object, Object> defaultTemplateVars = new HashMap<Object, Object>();
        defaultTemplateVars.put("request", new BeanModel(request, new DefaultObjectWrapper()));
        documentProcessor.setTemplateVariables(defaultTemplateVars);
        documentProcessor.handleProcessAndRender(map, response.getWriter());

        response.getWriter().flush();
        response.getWriter().close();
    } catch (IOException te) {
        throw new RuntimeException(te);
    }

    logger.trace("Leaving service()");
}

From source file:de.hybris.platform.ycommercewebservices.context.impl.DefaultContextInformationLoader.java

/**
 * Method resolves base site uid from request URL and set it as current site i.e<br>
 * <i>/rest/v1/mysite/cart</i>, or <br>
 * <i>/rest/v1/mysite/customers/current</i><br>
 * would try to set base site with uid=mysite as a current site.<br>
 * /* w w w.  j a  va 2s .c  o  m*/
 * One should define the path which is expected to be before the site resource in the project properties file
 * (<b>commercewebservices.rootcontext</b>).<br>
 * Default and fallback value equals to <i>/rest/v1/</i><br>
 * 
 * Method uses also a comma separated list of url special characters that are used to parse the site id resource. You
 * can reconfigure it in properties file (<b>commercewebservices.url.special.characters</b>). The default and
 * fallback value is equal to <i>"?,/</i>".
 * 
 * Method will throw {@link InvalidResourceException} if it fails to find the site which is in the resource url.<br>
 * However, you can configure exceptions that doesn't require the site mapping in the resource path. You can
 * configure them in a spring bean called 'baseFilterResourceExceptions'.<br>
 * 
 * @param request
 *           - request from which we should get base site uid
 * 
 * @return baseSite set as current site or null
 * @throws InvalidResourceException
 */
@Override
public BaseSiteModel initializeSiteFromRequest(final HttpServletRequest request)
        throws InvalidResourceException {
    final String requestURL = request.getRequestURL().toString();
    final String requestMapping = getRequestMapping(requestURL);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requested resource : " + requestMapping);
    }
    if (requestMapping == null || isNotBaseSiteResource(requestMapping)) {
        return null;
    }

    final String baseSiteUid = parseBaseSiteId(requestMapping);

    final BaseSiteModel requestedBaseSite = getBaseSiteService().getBaseSiteForUID(baseSiteUid);

    if (requestedBaseSite != null) {
        final BaseSiteModel currentBaseSite = getBaseSiteService().getCurrentBaseSite();

        if (!requestedBaseSite.equals(currentBaseSite)) {
            setCurrentBaseSite(requestedBaseSite);
        }
    } else {
        throw new InvalidResourceException(baseSiteUid);
    }

    return requestedBaseSite;
}

From source file:com.acc.context.impl.DefaultContextInformationLoader.java

/**
 * Method resolves base site uid from request URL and set it as current site i.e<br>
 * <i>/rest/v1/mysite/cart</i>, or <br>
 * <i>/rest/v1/mysite/customers/current</i><br>
 * would try to set base site with uid=mysite as a current site.<br>
 * //from  w ww  .  j a va2s.com
 * One should define the path which is expected to be before the site resource in the project properties file
 * (<b>commercewebservices.rootcontext</b>).<br>
 * Default and fallback value equals to <i>/rest/v1/</i><br>
 * 
 * Method uses also a comma separated list of url special characters that are used to parse the site id resource. You
 * can reconfigure it in properties file (<b>commercewebservices.url.special.characters</b>). The default and
 * fallback value is equal to <i>"?,/</i>".
 * 
 * Method will throw {@link InvalidResourceException} if it fails to find the site which is in the resource url.<br>
 * However, you can configure exceptions that doesn't require the site mapping in the resource path. You can
 * configure them in a spring bean called 'baseFilterResourceExceptions'.<br>
 * 
 * @param request
 *           - request from which we should get base site uid
 * 
 * @return baseSite set as current site or null
 * @throws InvalidResourceException
 */
@Override
public BaseSiteModel initializeSiteFromRequest(final HttpServletRequest request)
        throws InvalidResourceException {
    final String requestURL = request.getRequestURL().toString();
    final String requestMapping = getRequestMapping(requestURL);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requested resource : " + requestMapping);
    }

    if (requestMapping == null || isNotBaseSiteResource(requestMapping)) {
        return null;
    }

    final String baseSiteUid = parseBaseSiteId(requestMapping);

    final BaseSiteModel requestedBaseSite = getBaseSiteService().getBaseSiteForUID(baseSiteUid);

    if (requestedBaseSite != null) {
        final BaseSiteModel currentBaseSite = getBaseSiteService().getCurrentBaseSite();

        if (!requestedBaseSite.equals(currentBaseSite)) {
            setCurrentBaseSite(requestedBaseSite);
        }
    } else {
        throw new InvalidResourceException(baseSiteUid);
    }

    return requestedBaseSite;
}

From source file:com.nagarro.core.context.impl.DefaultContextInformationLoader.java

/**
 * Method resolves base site uid from request URL and set it as current site i.e<br>
 * <i>/rest/v1/mysite/cart</i>, or <br>
 * <i>/rest/v1/mysite/customers/current</i><br>
 * would try to set base site with uid=mysite as a current site.<br>
 * /*w  w  w  .j a v a2s .  c o  m*/
 * One should define the path which is expected to be before the site resource in the project properties file
 * (<b>commercewebservices.rootcontext</b>).<br>
 * Default and fallback value equals to <i>/rest/v1/</i><br>
 * 
 * Method uses also a comma separated list of url special characters that are used to parse the site id resource. You
 * can reconfigure it in properties file (<b>commercewebservices.url.special.characters</b>). The default and
 * fallback value is equal to <i>"?,/</i>".
 * 
 * Method will throw {@link InvalidResourceException} if it fails to find the site which is in the resource url.<br>
 * However, you can configure exceptions that doesn't require the site mapping in the resource path. You can
 * configure them in a spring bean called 'baseFilterResourceExceptions'.<br>
 * 
 * @param request
 *           - request from which we should get base site uid
 * 
 * @return baseSite set as current site or null
 * @throws InvalidResourceException
 */
@Override
public BaseSiteModel initializeSiteFromRequest(final HttpServletRequest request)
        throws InvalidResourceException {
    final String requestURL = request.getRequestURL().toString();
    final String requestMapping = getRequestMapping(requestURL);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requested resource : " + YSanitizer.sanitize(requestMapping));
    }
    if (requestMapping == null || isNotBaseSiteResource(requestMapping)) {
        return null;
    }

    final String baseSiteUid = parseBaseSiteId(requestMapping);

    final BaseSiteModel requestedBaseSite = getBaseSiteService().getBaseSiteForUID(baseSiteUid);

    if (requestedBaseSite != null) {
        final BaseSiteModel currentBaseSite = getBaseSiteService().getCurrentBaseSite();

        if (!requestedBaseSite.equals(currentBaseSite)) {
            setCurrentBaseSite(requestedBaseSite);
        }
    } else {
        throw new InvalidResourceException(YSanitizer.sanitize(baseSiteUid));
    }

    return requestedBaseSite;
}

From source file:org.dataone.proto.trove.mn.rest.base.AbstractWebController.java

protected void debugRequest(HttpServletRequest request) {
    /*     see values with just a plain old request object being sent through */
    logger.debug("request RequestURL: " + request.getRequestURL());
    logger.debug("request RequestURI: " + request.getRequestURI());
    logger.debug("request PathInfo: " + request.getPathInfo());
    logger.debug("request PathTranslated: " + request.getPathTranslated());
    logger.debug("request QueryString: " + request.getQueryString());
    logger.debug("request ContextPath: " + request.getContextPath());
    logger.debug("request ServletPath: " + request.getServletPath());
    logger.debug("request toString:" + request.toString());
    Enumeration<String> attributeNames = request.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
        String attributeName = attributeNames.nextElement();
        logger.debug("request " + attributeName + ": " + request.getAttribute(attributeName));
    }//w  w  w. ja v a  2 s  . c o m
    /*      values of proxyServletWrapper request object to be sent through */
    logger.info("");

    /*      uncomment to see what the parameters of servlet passed in are  */
    Map<String, String[]> parameterMap = request.getParameterMap();

    for (Object key : parameterMap.keySet()) {
        String[] values = parameterMap.get((String) key);
        for (int i = 0; i < values.length; ++i) {
            logger.info("request ParameterMap: " + (String) key + " = " + values[i]);
        }

    }
    logger.debug("");

}