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:net.sourceforge.fenixedu.presentationTier.util.ExceptionInformation.java

private static String getRequestFullUrl(HttpServletRequest request) {
    StringBuffer requestFullURL = request.getRequestURL();
    String queryString = request.getQueryString();
    return queryString == null ? requestFullURL.toString()
            : requestFullURL.append('?').append(queryString).toString();
}

From source file:de.unirostock.sems.cbarchive.web.Tools.java

/**
 * Generates a redirect URI to an archive.
 *
 * @param requestContext the request context
 * @param archiveId the archive id/*from   w w w.  ja  v a 2 s  .c om*/
 * @return the uri
 */
public static URI generateArchiveRedirectUri(HttpServletRequest requestContext, String archiveId) {
    URI newLocation = null;
    try {
        if (requestContext != null) {
            String uri = requestContext.getRequestURL().toString();
            uri = uri.substring(0, uri.indexOf("rest/"));
            LOGGER.info("redirect to ", requestContext.getRequestURL(), " to ", uri);
            newLocation = new URI(uri + "#archive/" + archiveId);
        } else
            newLocation = new URI("../#archive/" + archiveId);

    } catch (URISyntaxException e) {
        LOGGER.error(e, "Cannot generate relative URL to main app");
        return null;
    }

    return newLocation;
}

From source file:de.unirostock.sems.cbarchive.web.Tools.java

/**
 * Generates Share URI to a workspace.//from  www.  j a va  2  s  .co  m
 *
 * @param requestContext the request context
 * @param workspaceId the workspace id
 * @return the uri
 */
public static URI generateWorkspaceRedirectUri(HttpServletRequest requestContext, String workspaceId) {
    URI newLocation = null;
    try {
        if (requestContext != null) {
            String uri = requestContext.getRequestURL().toString();
            uri = uri.substring(0, uri.indexOf("rest/"));
            LOGGER.info("redirect to ", requestContext.getRequestURL(), " to ", uri);
            newLocation = new URI(uri + "rest/share/" + workspaceId);
        } else
            newLocation = new URI("../rest/share/" + workspaceId);

    } catch (URISyntaxException e) {
        LOGGER.error(e, "Cannot generate relative URL to main app");
        return null;
    }

    return newLocation;
}

From source file:password.pwm.http.servlet.OAuthConsumerServlet.java

public static String figureOauthSelfEndPointUrl(final PwmRequest pwmRequest) {
    final HttpServletRequest req = pwmRequest.getHttpServletRequest();
    final String redirect_uri;
    try {/*from   ww w  . ja  v  a2 s .c  o  m*/
        final URI requestUri = new URI(req.getRequestURL().toString());
        redirect_uri = requestUri.getScheme() + "://" + requestUri.getHost()
                + (requestUri.getPort() > 0 ? ":" + requestUri.getPort() : "")
                + PwmServletDefinition.OAuthConsumer.servletUrl();
    } catch (URISyntaxException e) {
        throw new IllegalStateException(
                "unable to parse inbound request uri while generating oauth redirect: " + e.getMessage());
    }
    return redirect_uri;
}

From source file:net.oauth.example.consumer.webapp.CookieConsumer.java

/**
 * Get a fresh access token from the service provider.
 * //from   w  w  w.j a v a 2 s  .c o  m
 * @throws RedirectException
 *             to obtain authorization
 */
private static void getAccessToken(HttpServletRequest request, CookieMap cookies, OAuthAccessor accessor)
        throws Exception {
    CLIENT.getRequestToken(accessor);
    String consumerName = (String) accessor.consumer.getProperty("name");
    cookies.put(consumerName + ".requestToken", accessor.requestToken);
    cookies.put(consumerName + ".tokenSecret", accessor.tokenSecret);
    String authorizationURL = accessor.consumer.serviceProvider.userAuthorizationURL;
    if (authorizationURL.startsWith("/")) {
        authorizationURL = (new URL(new URL(request.getRequestURL().toString()),
                request.getContextPath() + authorizationURL)).toString();
    }
    URL callbackURL = new URL(new URL(request.getRequestURL().toString()),
            request.getContextPath() + Callback.PATH);
    throw new RedirectException(OAuth.addParameters(authorizationURL //
            , "oauth_token", accessor.requestToken //
            , "oauth_callback", OAuth.addParameters(callbackURL.toString() //
                    , "consumer", consumerName //
                    , "returnTo", getRequestPath(request) //
            )));
}

From source file:cn.bc.web.util.WebUtils.java

/**
 * ?Server?:[0]-IP?,[1]-??,[2]-url/*from w  w w.  j a  va 2s . c om*/
 * 
 * @return
 */
public static String[] getServer(HttpServletRequest request) {
    String[] server = new String[] { null, null, null };
    try {
        InetAddress localhost = InetAddress.getLocalHost();
        server[0] = localhost.getHostAddress();
        server[1] = localhost.getHostName();
    } catch (UnknownHostException e) {
        server[0] = "unknown";
        server[1] = "unknown";
    }
    server[2] = request != null ? request.getRequestURL().toString() : "unknown";
    return server;
}

From source file:ie.wombat.rt.fireeagle.CookieConsumer.java

/**
 * Get a fresh access token from the service provider.
 * @throws IOException //from ww  w .j  av a  2 s. co  m
 * @throws URISyntaxException 
 * 
 * @throws RedirectException
 *             to obtain authorization
 */
private static void getAccessToken(HttpServletRequest request, CookieMap cookies, OAuthAccessor accessor)
        throws OAuthException, IOException, URISyntaxException {
    CLIENT.getRequestToken(accessor);
    String consumerName = (String) accessor.consumer.getProperty("name");
    cookies.put(consumerName + ".requestToken", accessor.requestToken);
    cookies.put(consumerName + ".tokenSecret", accessor.tokenSecret);
    String authorizationURL = accessor.consumer.serviceProvider.userAuthorizationURL;
    if (authorizationURL.startsWith("/")) {
        authorizationURL = (new URL(new URL(request.getRequestURL().toString()),
                request.getContextPath() + authorizationURL)).toString();
    }
    URL callbackURL = new URL(new URL(request.getRequestURL().toString()),
            request.getContextPath() + Callback.PATH);
    throw new RedirectException(OAuth.addParameters(authorizationURL //
            , "oauth_token", accessor.requestToken //
            , "oauth_callback", OAuth.addParameters(callbackURL.toString() //
                    , "consumer", consumerName //
                    , "returnTo", getRequestPath(request) //
            )));
}

From source file:edu.stanford.epad.epadws.xnat.XNATSessionOperations.java

public static String getJSessionIDFromRequest(HttpServletRequest servletRequest) {
    String jSessionID = null;/*from   www  . ja  v  a  2s.c om*/

    Cookie[] cookies = servletRequest.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if ("JSESSIONID".equalsIgnoreCase(cookie.getName())) {
                jSessionID = cookie.getValue();
                break;
            }
        }
    }
    if (jSessionID == null)
        log.warning("No JSESESSIONID cookie present in request " + servletRequest.getRequestURL());

    return jSessionID;
}

From source file:net.yacy.http.ProxyHandler.java

public final static synchronized void logProxyAccess(HttpServletRequest request) {

    final StringBuilder logMessage = new StringBuilder(80);

    // Timestamp//  w  w w  .  j a  v a 2s  .  c o  m
    logMessage.append(GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()));
    logMessage.append(' ');

    // Remote Host
    final String clientIP = request.getRemoteAddr();
    logMessage.append(clientIP);
    logMessage.append(' ');

    // Method
    final String requestMethod = request.getMethod();
    logMessage.append(requestMethod);
    logMessage.append(' ');

    // URL
    logMessage.append(request.getRequestURL());
    final String requestArgs = request.getQueryString();
    if (requestArgs != null) {
        logMessage.append("?").append(requestArgs);
    }

    HTTPDProxyHandler.proxyLog.fine(logMessage.toString());

}

From source file:org.mitre.openid.connect.client.AbstractOIDCAuthenticationFilter.java

/**
 * Builds the redirect_uri that will be sent to the Authorization Endpoint.
 * By default returns the URL of the current request minus zero or more
 * fields of the URL's query string.// ww  w  .java2  s .  c  om
 * 
 * @param request
 *            the current request which is being processed by this filter
 * @param ignoreFields
 *            an array of field names to ignore.
 * @return a URL built from the messaged parameters.
 */
public static String buildRedirectURI(HttpServletRequest request, String[] ignoreFields) {

    List<String> ignore = (ignoreFields != null) ? Arrays.asList(ignoreFields) : null;

    boolean isFirst = true;

    StringBuffer sb = request.getRequestURL();

    for (Enumeration<?> e = request.getParameterNames(); e.hasMoreElements();) {

        String name = (String) e.nextElement();

        if ((ignore == null) || (!ignore.contains(name))) {

            // Assume for simplicity that there is only one value

            String value = request.getParameter(name);

            if (value == null) {
                continue;
            }

            if (isFirst) {
                sb.append("?");
                isFirst = false;
            }

            sb.append(name).append("=").append(value);

            if (e.hasMoreElements()) {
                sb.append("&");
            }
        }
    }

    return sb.toString();
}