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:com.cloudbees.tomcat.valves.PrivateAppValveIntegratedTest.java

@Before
@Override//  ww w  .  ja  v a  2  s. c  o  m
public void setUp() throws Exception {
    super.setUp();

    Tomcat tomcat = getTomcatInstance();

    // Must have a real docBase - just use temp
    org.apache.catalina.Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));

    Tomcat.addServlet(context, "hello-servlet", new HttpServlet() {
        @Override
        protected void service(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            System.out.println(req.getRequestURL());
            IoUtils2.flush(req.getInputStream(), System.out);
            Enumeration<String> headers = req.getHeaderNames();
            while (headers.hasMoreElements()) {
                String header = headers.nextElement();
                System.out.println("   " + header + ": " + req.getHeader(header));
            }
            resp.addHeader("x-response", "hello");
            resp.getWriter().println("Hello world!");
        }
    });
    context.addServletMapping("/*", "hello-servlet");

    privateAppValve = new PrivateAppValve();
    privateAppValve.setSecretKey(secretKey);

    context.getPipeline().addValve(privateAppValve);

    tomcat.start();

    httpClient = new DefaultHttpClient();
    httpHost = new HttpHost("localhost", getPort());
}

From source file:com.jnj.b2b.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlWithoutReferer(final HttpServletRequest request) {
    final String originalReferer = (String) request.getSession()
            .getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + originalReferer;
    }//ww  w  .j a v  a 2 s .  co m

    final String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (referer != null && !referer.isEmpty()) {
        return REDIRECT_PREFIX + referer;
    }
    return REDIRECT_PREFIX + '/';
}

From source file:se.inera.certificate.proxy.filter.ProxyFilter.java

@Override
public Map<String, String> getHeaders(HttpServletRequest httpServletRequest) {
    Map<String, String> headers = newHashMap();
    headers.put("X-Proxy-Original-Servlet-ContextPath",
            defaultIfEmpty(httpServletRequest.getContextPath(), "/"));
    headers.put("X-Proxy-Original-Url", httpServletRequest.getRequestURL().toString());
    headers.put("X-Proxy-Key", this.proxyKey);
    if (headerProvider != null) {
        headers.putAll(headerProvider.getHeaders(httpServletRequest));
    }//from w  ww . j a  v a2s.co m
    return headers;
}

From source file:com.cisco.ca.cstg.pdi.filter.SessionTimeoutFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    try {//from   ww w.ja  va2 s  .co  m
        LOGGER.info("calling doFilter filter");
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        HttpSession session = request.getSession(false);
        String requestURL = "";
        String requestURI = "";
        String logoutUrl = "";
        if (null != request.getRequestURL()) {
            requestURL = request.getRequestURL().toString();
        }
        LOGGER.info("Current url: " + requestURL + ": URI: " + requestURI + " Session: " + session);
        LOGGER.info("Request URI : " + requestURI);
        if (request.getRequestURL() != null && !(request.getRequestURL().toString().contains(PINGPONG))
                && !(LOCAL_URL.equals(request.getRequestURL().toString().trim()))) {
            if ((session == null || session.getAttribute("userCec") == null)
                    && (!(requestURL.contains(SKIP_PROJ_ROOT_REQUEST) || requestURI == null
                            || requestURI.isEmpty()))) {
                LOGGER.info("Session timeout");
                LOGGER.info("geting X-Requested-With value : " + request.getHeader("X-Requested-With"));
                if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
                    LOGGER.info("Adding 403 error code for ajax call to redirect from client side");
                    response.sendError(403, "SESSION_TIMEOUT");
                } else {
                    LOGGER.info(
                            "Identifying the URL for redirecting from server side after session is expired..");
                    if (requestURL.toLowerCase().contains(CONTAINDEV)) {
                        logoutUrl = PdiConfig.getProperty("pdi.devLogout");
                        response.setHeader("Access-Control-Allow-Origin", "*");
                    } else if (requestURL.toLowerCase().contains(CONTAINSTG)) {
                        logoutUrl = PdiConfig.getProperty("pdi.stgLogout");
                    } else if (requestURL.toLowerCase().contains(CONTAINPROD)) {
                        logoutUrl = PdiConfig.getProperty("pdi.prodLogout");
                    } else {
                        LOGGER.info("Local logout");
                        logoutUrl = "j_spring_security_logout";
                    }
                    if (!logoutUrl.isEmpty()) {
                        response.sendRedirect(logoutUrl);
                    }
                }
            } else {
                LOGGER.info("Ready for calling to dispatcher servlet...");
                chain.doFilter(request, response);
            }
        }
    } catch (IOException e) {
        LOGGER.info("there is some problem in SessionLogoutListener to redirect.", e);
    } catch (Exception e) {
        LOGGER.info("there is some problem in SessionLogoutListener to redirect.", e);
    }

}

From source file:things.view.rest.ThingRestExceptionHandler.java

@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody/*from   w  w w. j a  v  a 2  s.co m*/
public ErrorInfo validationException(final HttpServletRequest req, final ConstraintViolationException cve) {

    StringBuffer msg = new StringBuffer("Invalid input:");

    cve.getConstraintViolations().forEach(cv -> {
        msg.append("  " + cv.getPropertyPath() + " -> " + cv.getMessage());
    });

    myLogger.debug(msg.toString());

    ErrorInfo ei = new ErrorInfo(req.getRequestURL().toString(), cve);
    ei.setMessage(msg.toString());

    return ei;
}

From source file:com.npower.dl.SoftwareDownloadServlet.java

public void doDownloadDescriptor(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String requestUrl = request.getRequestURL().toString();
    String requestUri = request.getRequestURI();
    log.info("Download Service: Download Descriptor: url: " + requestUrl);
    log.info("Download Service: Download Descriptor: uri: " + requestUri);

    String packageID = parserPackageID(requestUri);

    log.info("Software Download Service: Request package ID: " + packageID);

    DownloadDescriptor descriptor = new SoftwareDownloadDescriptor();
    descriptor.setDownloadID(packageID);

    try {//from   ww  w .  j a  v a2  s . com
        String serverURL = DownloadFactory.getServerURL(requestUrl);
        String baseURL = serverURL + request.getContextPath();

        descriptor.setDownloadURI(baseURL + "/download/software/");
        descriptor.setInstallNotifyURI(baseURL + "/download/notification/");

        String content = descriptor.getContent();
        response.setContentType(descriptor.getContentType());
        response.setContentLength(content.length());

        OutputStream out = response.getOutputStream();
        out.write(content.getBytes("UTF-8"));
        out.flush();
        out.close();

        log.debug("Download Descriptor Content: " + content);
    } catch (Exception ex) {
        throw new ServletException(ex);
    } finally {
    }
}

From source file:com.fujitsu.dc.engine.rs.StatusResource.java

/**
 * Service.//from w ww.  j  a  v  a  2 s.co m
 * @param path ??
 * @param req Request
 * @param res Response
 * @param is 
 * @return Response
 */
public final Response run(final String path, final HttpServletRequest req, final HttpServletResponse res,
        final InputStream is) {
    StringBuilder msg = new StringBuilder();
    msg.append(">>> Request Started ");
    msg.append(" method:");
    msg.append(req.getMethod());
    msg.append(" method:");
    msg.append(req.getRequestURL());
    msg.append(" url:");
    log.info(msg);

    // ? ????
    Enumeration<String> multiheaders = req.getHeaderNames();
    for (String headerName : Collections.list(multiheaders)) {
        Enumeration<String> headers = req.getHeaders(headerName);
        for (String header : Collections.list(headers)) {
            log.debug("RequestHeader['" + headerName + "'] = " + header);
        }
    }
    try {
        DcEngineConfig.reload();
    } catch (Exception e) {
        log.warn(" unknown Exception(" + e.getMessage() + ")");
        return errorResponse(new DcEngineException("500 Internal Server Error (Unknown Error)",
                DcEngineException.STATUSCODE_SERVER_ERROR));
    }
    return Response.status(HttpStatus.SC_NO_CONTENT).build();
}

From source file:io.personium.engine.rs.StatusResource.java

/**
 * Service.// www  . j  ava2 s.  c o m
 * @param path ??
 * @param req Request
 * @param res Response
 * @param is 
 * @return Response
 */
public final Response run(final String path, final HttpServletRequest req, final HttpServletResponse res,
        final InputStream is) {
    StringBuilder msg = new StringBuilder();
    msg.append(">>> Request Started ");
    msg.append(" method:");
    msg.append(req.getMethod());
    msg.append(" method:");
    msg.append(req.getRequestURL());
    msg.append(" url:");
    log.info(msg);

    // ? ????
    Enumeration<String> multiheaders = req.getHeaderNames();
    for (String headerName : Collections.list(multiheaders)) {
        Enumeration<String> headers = req.getHeaders(headerName);
        for (String header : Collections.list(headers)) {
            log.debug("RequestHeader['" + headerName + "'] = " + header);
        }
    }
    try {
        PersoniumEngineConfig.reload();
    } catch (Exception e) {
        log.warn(" unknown Exception(" + e.getMessage() + ")");
        return errorResponse(new PersoniumEngineException("500 Internal Server Error (Unknown Error)",
                PersoniumEngineException.STATUSCODE_SERVER_ERROR));
    }
    return Response.status(HttpStatus.SC_NO_CONTENT).build();
}

From source file:fi.aluesarjat.prototype.SubjectGraphServlet.java

@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    if (ifModifiedSince >= LAST_MODIFIED) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;//from   www.  j av  a  2  s . c o m
    }

    String subject = request.getRequestURL().toString();
    RDFConnection connection = repository.openConnection();
    try {
        SPARQLQuery query = connection.createQuery(QueryLanguage.SPARQL,
                "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }");
        query.setBinding("s", new UID(subject));
        String contentType = getAcceptedType(request, Format.RDFXML);
        response.setDateHeader("Last-Modified", System.currentTimeMillis());
        response.setContentType(contentType);
        query.streamTriples(response.getWriter(), contentType);
    } finally {
        connection.close();
    }

}