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:be.milieuinfo.core.proxy.controller.ProxyServlet.java

private String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl) {
    //TODO document example paths
    if (theUrl.startsWith(this.targetUri.toString())) {
        String curUrl = servletRequest.getRequestURL().toString();//no query
        String pathInfo = servletRequest.getPathInfo();
        if (pathInfo != null) {
            assert curUrl.endsWith(pathInfo);
            curUrl = curUrl.substring(0, curUrl.length() - pathInfo.length());//take pathInfo off
        }/*from w  ww . j  av  a2s. c om*/
        theUrl = curUrl + theUrl.substring(this.targetUri.toString().length());
    }
    return theUrl;
}

From source file:au.org.paperminer.main.UserFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain)
        throws IOException, ServletException {
    m_logger.info("userFilter doFilter");

    HttpServletRequest httpReq = (HttpServletRequest) req;
    String remoteReq = httpReq.getRequestURL().toString();
    int idx = remoteReq.lastIndexOf('/');
    if (remoteReq.substring(idx).startsWith("/opn")) {
        m_logger.debug(" userFilter open");
        openUser(req, resp);//  w  ww.jav  a 2  s .  c o m
    } else if (remoteReq.substring(idx).startsWith("/info")) {
        m_logger.debug(" userFilter user info");
        getPrefs((HttpServletRequest) req, (HttpServletResponse) resp);
    } else if (remoteReq.substring(idx).startsWith("/add")) {
        m_logger.debug(" userFilter add");
        addUser(req, resp);
    } else if (remoteReq.substring(idx).startsWith("/cls")) {
        m_logger.debug(" userFilter close");
        removeCookie((HttpServletResponse) resp);
    } else if (remoteReq.substring(idx).startsWith("/vfy")) {
        m_logger.debug(" userFilter verify");
        setStatus(PaperMinerConstants.USER_VALIDATED, req, resp);
    } else if (remoteReq.substring(idx).startsWith("/mod")) {
        m_logger.debug(" userFilter modify");
        updateUser((HttpServletRequest) req, (HttpServletResponse) resp);
    } else if (remoteReq.substring(idx).startsWith("/qsave")) {
        m_logger.debug(" userFilter save query");
        saveQuery((HttpServletRequest) req, (HttpServletResponse) resp);
    } else if (remoteReq.substring(idx).startsWith("/qget")) {
        m_logger.debug(" userFilter get queries");
        getQueryData((HttpServletRequest) req, (HttpServletResponse) resp);
    } else if (remoteReq.substring(idx).startsWith("/qdel")) {
        m_logger.debug(" userFilter delete query");
        deleteQuery((HttpServletRequest) req, (HttpServletResponse) resp);
    }
    filterChain.doFilter(req, resp);
    return;
}

From source file:org.openmrs.module.idcards.web.controller.TemplateFormController.java

/**
 * Handles the user's submission of the form.
 *//*  w  ww  .j a  v a 2  s .c  o m*/
@RequestMapping(method = RequestMethod.POST, params = "action=saveAndReprint")
public void onSaveAndReprint(@ModelAttribute("template") IdcardsTemplate template, HttpServletRequest request,
        HttpServletResponse response) throws IOException {

    if (Context.isAuthenticated()) {
        IdcardsService service = (IdcardsService) Context.getService(IdcardsService.class);
        service.saveIdcardsTemplate(template);

        Cohort cohort = new Cohort();
        cohort.addMember(1);
        cohort.addMember(2);

        try {
            StringBuffer requestURL = request.getRequestURL();
            String baseURL = requestURL.substring(0, requestURL.indexOf("/module"));

            PrintIdcardsServlet.generateOutput(template, baseURL, cohort, response);
        } catch (Exception e) {
            log.error("Unable to print cards", e);
            e.printStackTrace(response.getWriter());
        }
    }

}

From source file:com.sap.cloudlabs.connectivity.proxy.ProxyServlet.java

/**
 * Returns the URL to the proxy servlet and used destination. 
 *//*from www  .j a  v a2  s. c  om*/
private String getProxyUrl(HttpServletRequest request) throws MalformedURLException {
    URL url = new URL(request.getRequestURL().toString());
    String proxyUrl = request.getScheme() + "://" + url.getAuthority() + request.getContextPath()
            + request.getServletPath();
    return proxyUrl;
}

From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.Cas2Authenticator.java

public Boolean needLoginPrompt(HttpServletRequest httpRequest) {

    log.debug(String.format("needLoginPrompt %s", httpRequest.getRequestURL().toString()));
    String requestedURI = httpRequest.getRequestURI();
    String context = httpRequest.getContextPath() + '/';
    requestedURI = requestedURI.substring(context.length());
    for (String prefixURL : excludePromptURLs) {
        if (requestedURI.startsWith(prefixURL)) {
            return false;
        }// ww w .  j  a v  a  2s  .  c o  m
    }
    return promptLogin;
}

From source file:de.hybris.platform.chinesepspalipaymockaddon.controllers.pages.AlipayMockController.java

@RequestMapping(value = "/refund", method = RequestMethod.GET)
public String view(final Model model, final HttpServletRequest request) {
    final Map<String, String[]> requestParamMap = request.getParameterMap();
    if (requestParamMap == null) {
        return AlipayMockControllerConstants.Pages.AlipayRefundTestPage;
    }//from   w ww .  ja v a  2  s.  c o  m
    final String baseGateWay = request.getRequestURL().toString();
    model.addAttribute("baseGateWay", baseGateWay);

    model.addAttribute("storefront", (StringUtils.substringBetween(request.getContextPath(), "/")));

    final Map<String, String> clearParams = removeUselessValue(requestParamMap);
    setCSRFToken(clearParams, request);
    return AlipayMockControllerConstants.Pages.AlipayRefundTestPage;
}

From source file:eea.eprtr.cms.controller.FileOpsController.java

/**
 * Upload file for transfer./*w  w  w.  j a  v a2 s . c  om*/
 */
@RequestMapping(value = "/filecatalogue", method = RequestMethod.POST)
public String importFile(@RequestParam("file") MultipartFile myFile,
        final RedirectAttributes redirectAttributes, final HttpServletRequest request) throws IOException {

    if (myFile == null || myFile.getOriginalFilename() == null) {
        redirectAttributes.addFlashAttribute("message", "Select a file to upload");
        return "redirect:filecatalogue";
    }
    String fileName = storeFile(myFile);
    redirectAttributes.addFlashAttribute("filename", fileName);
    StringBuffer requestUrl = request.getRequestURL();
    redirectAttributes.addFlashAttribute("url",
            requestUrl.substring(0, requestUrl.length() - "/filecatalogue".length()));
    return "redirect:filecatalogue";
}

From source file:org.apache.cxf.fediz.spring.web.FederationAuthenticationEntryPoint.java

public final void commence(final HttpServletRequest servletRequest, final HttpServletResponse response,
        final AuthenticationException authenticationException) throws IOException, ServletException {

    FedizContext fedContext = federationConfig.getFedizContext();
    LOG.debug("Federation context: {}", fedContext);

    if (servletRequest.getRequestURL().indexOf(FederationConstants.METADATA_PATH_URI) != -1
            || servletRequest.getRequestURL().indexOf(getMetadataURI(fedContext)) != -1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Metadata document requested");
        }/*from w w  w  . j a v  a2s.  co m*/
        response.setContentType("text/xml");
        PrintWriter out = response.getWriter();

        FedizProcessor wfProc = FedizProcessorFactory.newFedizProcessor(fedContext.getProtocol());
        try {
            Document metadata = wfProc.getMetaData(servletRequest, fedContext);
            out.write(DOM2Writer.nodeToString(metadata));
            return;
        } catch (Exception ex) {
            LOG.warn("Failed to get metadata document: " + ex.getMessage());
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }
    }

    String redirectUrl = null;
    try {
        FedizProcessor wfProc = FedizProcessorFactory.newFedizProcessor(fedContext.getProtocol());
        RedirectionResponse redirectionResponse = wfProc.createSignInRequest(servletRequest, fedContext);
        redirectUrl = redirectionResponse.getRedirectionURL();

        if (redirectUrl == null) {
            LOG.warn("Failed to create SignInRequest. Redirect URL null");
            throw new ServletException("Failed to create SignInRequest. Redirect URL null");
        }

        Map<String, String> headers = redirectionResponse.getHeaders();
        if (!headers.isEmpty()) {
            for (String headerName : headers.keySet()) {
                response.addHeader(headerName, headers.get(headerName));
            }
        }

    } catch (ProcessingException ex) {
        LOG.warn("Failed to create SignInRequest", ex);
        throw new ServletException("Failed to create SignInRequest: " + ex.getMessage());
    }

    preCommence(servletRequest, response);
    if (LOG.isInfoEnabled()) {
        LOG.info("Redirecting to IDP: " + redirectUrl);
    }
    response.sendRedirect(redirectUrl);
}

From source file:com.sixt.service.framework.jetty.RpcReadException.java

public String toJson(HttpServletRequest req) {
    JsonObject obj = new JsonObject();

    Enumeration<String> h = req.getHeaderNames();
    while (h.hasMoreElements()) {
        String hKey = h.nextElement();
        String hValue = req.getHeader(hKey);
        obj.addProperty("request_header_" + hKey, hValue);
    }/*from  w  w w.j a  v a2s  .c om*/

    obj.addProperty("exception_message", this.getMessage());
    obj.addProperty("request_query_string", req.getQueryString());
    obj.addProperty("request_url", req.getRequestURL().toString());
    obj.addProperty("request_remote_addr", req.getRemoteAddr());
    obj.addProperty("request_remote_port", req.getRemotePort());
    obj.addProperty("request_remote_host", req.getRemoteHost());
    obj.addProperty("request_remote_user", req.getRemoteUser());

    String readBody = "success";
    // read the whole remaining body and put the joined base64 encoded message into the json object
    try {
        byte[] ba = IOUtils.toByteArray(this.in);
        byte[] combined;
        if ((ba != null) && (this.incomplete != null)) {
            combined = new byte[ba.length + this.incomplete.length];
            System.arraycopy(incomplete, 0, combined, 0, this.incomplete.length);
            System.arraycopy(ba, 0, combined, this.incomplete.length, ba.length);
            obj.addProperty("request_body", Base64.getEncoder().encodeToString(combined));
        } else if (ba != null) {
            combined = ba;
        } else if (this.incomplete != null) {
            combined = this.incomplete;
        } else {
            readBody = "body is empty";
        }
    } catch (Exception ex) {
        readBody = String.format("failed because: %s", ex.getCause());
    }
    obj.addProperty("read_body", readBody);

    return obj.toString();
}

From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.Cas2Authenticator.java

@Override
public boolean onSuccess(HttpServletRequest arg0, HttpServletResponse arg1) {
    log.debug(String.format("checkCasTicket %s", arg0.getRequestURL().toString()));
    return false;
}