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:org.keycloak.example.CxfRsClient.java

public static List<String> getCustomers(HttpServletRequest req) throws Failure {
    KeycloakSecurityContext session = (KeycloakSecurityContext) req
            .getAttribute(KeycloakSecurityContext.class.getName());

    HttpClient client = new HttpClientBuilder().disableTrustManager().build();
    try {//from  w ww  .java 2  s. c  om
        HttpGet get = new HttpGet(
                UriUtils.getOrigin(req.getRequestURL().toString()) + "/cxf/customerservice/customers");
        get.addHeader("Authorization", "Bearer " + session.getTokenString());
        try {
            HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() != 200) {
                throw new Failure(response.getStatusLine().getStatusCode());
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            try {
                return JsonSerialization.readValue(is, TypedList.class);
            } finally {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.vmware.identity.openidconnect.common.HttpRequest.java

public static HttpRequest create(HttpServletRequest httpServletRequest) {
    Validate.notNull(httpServletRequest, "httpServletRequest");

    Map<String, String> parameters = new HashMap<String, String>();
    for (Map.Entry<String, String[]> entry : httpServletRequest.getParameterMap().entrySet()) {
        parameters.put(entry.getKey(), entry.getValue()[0]); // just take the first value
    }//  www . ja  va 2s .  co m

    String requestUrlString = httpServletRequest.getRequestURL().toString();
    URL requestUrl;
    try {
        requestUrl = new URL(requestUrlString);
    } catch (MalformedURLException e) {
        // this should not happen since the URL is formed off of httpServletRequest.getRequestURL()
        throw new IllegalArgumentException(e);
    }
    URI requestUri = URI.create(requestUrlString);

    return new HttpRequest(httpServletRequest, parameters, requestUrl, requestUri);
}

From source file:gov.nih.nci.caintegrator.web.SessionHelper.java

private static String getRequestBaseUrl(HttpServletRequest request) {
    String requestUri = request.getRequestURI();
    String requestUrl = request.getRequestURL().toString();
    return requestUrl.substring(0, requestUrl.length() - requestUri.length());
}

From source file:ServletUtils.java

/**
 * NOT UNIT TESTED Returns the URL (including query parameters) minus the scheme, host, and
 * context path.  This method probably be moved to a more general purpose
 * class./*ww w  .java  2s  . c o  m*/
 */
public static String getRelativeUrl(HttpServletRequest request) {

    String baseUrl = null;

    if ((request.getServerPort() == 80) || (request.getServerPort() == 443))
        baseUrl = request.getScheme() + "://" + request.getServerName() + request.getContextPath();
    else
        baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();

    StringBuffer buf = request.getRequestURL();

    if (request.getQueryString() != null) {
        buf.append("?");
        buf.append(request.getQueryString());
    }

    return buf.substring(baseUrl.length());
}

From source file:eionet.util.SecurityUtil.java

/**
 *
 * @param request//from   w w w  .java2 s  . co m
 * @return
 */
public static String buildAfterLoginURL(HttpServletRequest request) {

    String requestUri = (String) request.getAttribute("javax.servlet.forward.request_uri");
    if (requestUri == null) {
        requestUri = request.getRequestURL().toString();
    }

    String queryString = (String) request.getAttribute("javax.servlet.forward.query_string");
    if (queryString == null) {
        queryString = request.getQueryString();
    }

    return queryString == null ? requestUri : requestUri + "?" + queryString;
}

From source file:edu.harvard.i2b2.fhirserver.ws.I2b2Helper.java

static Bundle parsePatientIdToFetchPDO(HttpServletRequest request, HttpSession session, String resourceName,
        PatientBundleService service) throws XQueryUtilException, JAXBException, IOException,
        AuthenticationFailure, FhirServerException, InterruptedException {
    String patientId = I2b2Helper.extractPatientId(request.getQueryString());
    if (patientId == null)
        patientId = I2b2Helper.extractPatientId2(request.getRequestURL().toString(), resourceName);
    logger.info("PatientId:" + patientId);
    if (patientId != null) {
        // filter.put("Patient", "Patient/" + patientId);
        return I2b2Helper.getPdo(session, patientId, service);
    } else {/*from w  ww . j  a  v  a 2 s  .  co  m*/
        if (resourceName.equals("Patient"))
            return I2b2Helper.initAllPatients(session);

    }
    return null;
}

From source file:com.icloud.framework.http.URLUtil.java

public static String getRequestUrlString(HttpServletRequest request) {

    String fullURL = "";

    try {//from  w  w w  .  j ava  2 s . co  m

        String urlString = request.getRequestURL().toString();

        String encodedRequestURL = URIUtil.encodePath(urlString);

        String queryString = request.getQueryString();

        if (null == queryString) {
            fullURL = encodedRequestURL;
        } else {
            fullURL = encodedRequestURL + "?" + queryString;
        }

    } catch (URIException e1) {
        e1.printStackTrace();
    }
    // http://robinkin:8280/jproxy-feeder/urlset/add

    // request.getPathTranslated();
    // //
    // /home/liangwang/repo/mobile/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/jproxy/jproxy-feeder/urlset/add
    //
    // request.getPathInfo();
    // // /jproxy-feeder/urlset/add
    //
    // request.getRequestURI();
    // // /jproxy-feeder/urlset/add
    //
    // request.getContextPath();
    // /

    // url=http%3A%2F%2Fnews.sohu.com%2F20040723%2Fn221153893.shtml&setname=test

    // HttpGet will translate a urlString into a URI, so , we should do the
    // check first,
    // if failed, call the encoder
    //      try {
    //         URI url = new URI(fullURL);
    //      } catch (URISyntaxException e) {
    //         try {
    //            fullURL = URIUtil.encodePathQuery(fullURL);
    //         } catch (URIException e1) {
    //            e1.printStackTrace();
    //         }
    //      }

    return fullURL;
}

From source file:com.cisco.ca.cstg.pdi.utils.Util.java

public static String getLogoutUrl(HttpServletRequest request, String logoutUrl) {
    if (null != request.getRequestURL()) {
        String requestURL = request.getRequestURL().toString();

        if (requestURL.toLowerCase().contains(CONTAINDEV)) {
            logoutUrl = PdiConfig.getProperty(PDI_DEV_LOGOUT);
        } else if (requestURL.toLowerCase().contains(CONTAINSTG)) {
            logoutUrl = PdiConfig.getProperty(PDI_STAGE_LOGOUT);
        } else if (requestURL.toLowerCase().contains(CONTAINPROD)) {
            logoutUrl = PdiConfig.getProperty(PDI_PROD_LOGOUT);
        } else {//from ww  w. j  a  v  a  2s  .  com
            LOGGER.info("non lae logout");
            logoutUrl = "j_spring_security_logout";
        }
    }
    return logoutUrl;
}

From source file:edu.usu.sdl.openstorefront.security.SecurityUtil.java

/**
 * Constructs an Admin Audit Log Message
 *
 * @param request//from ww  w  .java2 s .com
 * @return message
 */
public static String adminAuditLogMessage(HttpServletRequest request) {
    StringBuilder message = new StringBuilder();

    message.append("User: ").append(getCurrentUserName()).append(" (").append(getClientIp(request)).append(") ")
            .append(" Called Admin API: ");
    if (request != null) {
        message.append(request.getMethod()).append(" ");
        if (StringUtils.isNotBlank(request.getQueryString())) {
            message.append(request.getRequestURL()).append("?").append(request.getQueryString());
        } else {
            message.append(request.getRequestURL());
        }
    }

    return message.toString();
}

From source file:com.ccf.util.ModDateHeaderUtil.java

/**
 * 1/*from   ww w . j  a va 2 s. co m*/
 * @param request
 * @param response
 * @return
 */
public static boolean respondIfNotModifiedOneDay(HttpServletRequest request, HttpServletResponse response) {
    long sinceDate = request.getDateHeader("If-Modified-Since");
    // truncate to seconds
    long lastModifiedTimeMillis = System.currentTimeMillis() - 24 * 60 * 60 * 1000;
    log.debug("since date = " + sinceDate);
    log.debug("last mod date (trucated to seconds) = " + lastModifiedTimeMillis);
    if (lastModifiedTimeMillis <= sinceDate) {
        log.debug("NOT MODIFIED " + request.getRequestURL());
        //response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    } else {
        return false;
    }
}