Example usage for javax.servlet.http HttpServletRequest getServerName

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

Introduction

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

Prototype

public String getServerName();

Source Link

Document

Returns the host name of the server to which the request was sent.

Usage

From source file:net.eusashead.hateoas.response.impl.PostResponseBuilderImpl.java

public PostResponseBuilderImpl(HttpServletRequest request) {
    super(request);

    // Set the root URL
    this.domain = request.getScheme() + "://" + request.getServerName();
}

From source file:be.fedict.eid.idp.protocol.saml2.AbstractSAML2MetadataHttpServlet.java

private String getLocation(HttpServletRequest request) {

    String location = "https://" + request.getServerName();
    if (request.getServerPort() != 443) {
        location += ":" + request.getServerPort();
    }/*from   w w w  .  j  a  v  a  2s.  c  o m*/
    location += request.getContextPath() + IdentityProviderProtocolService.PROTOCOL_ENDPOINT_PATH + "/"
            + getPath();
    LOG.debug("location: " + location);
    return location;
}

From source file:com.greenline.guahao.web.module.common.exception.PortalExceptionResolver.java

@Override
public ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {/*  w w  w . j a va2  s. c  om*/
    logger.error("url=" + (request.getServerName() + CommonUtils.getBeforeRepath(request)));
    // ?
    ModelAndView mv = super.doResolveException(request, response, handler, ex);
    mv.setViewName(domainFilter.getAuthorization(request).getErrorViewName(request, response));
    response.setStatus(HttpServletResponse.SC_OK);
    String servername = (String) request.getAttribute("servername");
    if (StringUtils.isNotBlank(servername)) {
        // ???url 0 1?
        String domain_showurl = (String) request.getAttribute("domain_showurl");
        if (StringUtils.isNotBlank(domain_showurl) && "0".equals(domain_showurl)) {
            String domainservername = request.getScheme() + "://" + servername
                    + CommonUtils.getServerPort(request);
            mv.getModelMap().put("guahaoServer", domainservername);
        }
    }
    return mv;
}

From source file:info.magnolia.cms.util.RequestDispatchUtil.java

/**
 * Returns true if processing took place, even if it fails.
 *///from  www  . j av  a2 s  .co  m
public static boolean dispatch(String targetUri, HttpServletRequest request, HttpServletResponse response) {

    if (targetUri == null) {
        return false;
    }

    if (targetUri.startsWith(REDIRECT_PREFIX)) {
        String redirectUrl = StringUtils.substringAfter(targetUri, REDIRECT_PREFIX);
        try {

            if (isInternal(redirectUrl)) {
                redirectUrl = request.getContextPath() + redirectUrl;
            }

            response.sendRedirect(response.encodeRedirectURL(redirectUrl));

        } catch (IOException e) {
            log.error("Failed to redirect to {}:{}", targetUri, e.getMessage());
        }
        return true;
    }

    if (targetUri.startsWith(PERMANENT_PREFIX)) {
        String permanentUrl = StringUtils.substringAfter(targetUri, PERMANENT_PREFIX);
        try {

            if (isInternal(permanentUrl)) {
                if (isUsingStandardPort(request)) {
                    permanentUrl = new URL(request.getScheme(), request.getServerName(),
                            request.getContextPath() + permanentUrl).toExternalForm();
                } else {
                    permanentUrl = new URL(request.getScheme(), request.getServerName(),
                            request.getServerPort(), request.getContextPath() + permanentUrl).toExternalForm();
                }
            }

            response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            response.setHeader("Location", permanentUrl);

        } catch (MalformedURLException e) {
            log.error("Failed to create permanent url to redirect to {}:{}", targetUri, e.getMessage());
        }
        return true;
    }

    if (targetUri.startsWith(FORWARD_PREFIX)) {
        String forwardUrl = StringUtils.substringAfter(targetUri, FORWARD_PREFIX);
        try {
            request.getRequestDispatcher(forwardUrl).forward(request, response);
        } catch (Exception e) {
            log.error("Failed to forward to {} - {}:{}",
                    new Object[] { forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage() });
        }
        return true;
    }

    return false;
}

From source file:org.cloudifysource.rest.controllers.AdminAPIController.java

private String getRemoteHostAddress(HttpServletRequest httpServletRequest) {
    String host = httpServletRequest.getServerName();
    int port = httpServletRequest.getServerPort();
    return "http://" + host + ":" + port;
}

From source file:com.google.ie.web.controller.ImageController.java

/**
 * Construct the url for the default image
 * /*w  w w  .  ja  va  2s. c  o  m*/
 * @param req the {@link HttpServletRequest} object
 * @return the url of the default image
 */
protected String constructDefaultImageURL(HttpServletRequest req) {
    String baseURL = req.getProtocol() + "://" + req.getServerName() + PATH_TO_DEFAULT_IMAGE;
    return baseURL;
}

From source file:fi.helsinki.opintoni.security.SAMLLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    String serverName = request.getServerName();
    String ssoLogoutUri = appConfiguration.get("ssoLogoutUri");

    response.sendRedirect(ssoLogoutUri + "?return=" + "https://" + serverName);
}

From source file:cn.vlabs.duckling.api.umt.sso.configable.servlet.LogoutServlet.java

/**
 * url?contextPath//from w  ww . j  a v a2s  .c  o  m
 * @param request http
 * */
private String getRootUrlWithOutContextPath(HttpServletRequest request) {
    String url = request.getScheme() + "://" + request.getServerName();
    int port = request.getServerPort();
    if ((port != HTTP_DEFAULT_PORT) && (port != HTTPS_DEFAULT_PORT)) {
        url = url + ":" + port;
    }
    return url;
}

From source file:be.fedict.eid.dss.sp.bean.SignatureRequestServiceBean.java

@Override
public String getSPDestination() {

    HttpServletRequest httpServletRequest = getHttpServletRequest();

    return httpServletRequest.getScheme() + "://" + httpServletRequest.getServerName() + ":"
            + httpServletRequest.getServerPort() + httpServletRequest.getContextPath() + "/dss-response";

    // return "../eid-dss-sp/dss-response";
}

From source file:be.fedict.eid.idp.protocol.saml2.artifact.AbstractSAML2ArtifactMetadataHttpServlet.java

@Override
public EntityDescriptor getEntityDescriptor(HttpServletRequest request,
        IdentityProviderConfiguration configuration) {

    String artifactResolutionLocation = "https://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + IdentityProviderProtocolService.WS_ENDPOINT_CONTEXT_PATH
            + "/saml2/artifact";
    LOG.debug("Artifact resolution location: " + artifactResolutionLocation);

    EntityDescriptor entityDescriptor = super.getEntityDescriptor(request, configuration);

    // add ArtifactResolutionService
    ArtifactResolutionService artifactResolutionService = Saml2Util
            .buildXMLObject(ArtifactResolutionService.class, ArtifactResolutionService.DEFAULT_ELEMENT_NAME);
    artifactResolutionService.setLocation(artifactResolutionLocation);
    artifactResolutionService.setBinding(SAMLConstants.SAML2_SOAP11_BINDING_URI);
    artifactResolutionService.setIndex(0);
    artifactResolutionService.setIsDefault(true);

    IDPSSODescriptor idpssoDescriptor = (IDPSSODescriptor) entityDescriptor.getRoleDescriptors().get(0);
    idpssoDescriptor.getArtifactResolutionServices().add(artifactResolutionService);

    return entityDescriptor;
}