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:org.jm.spring.controller.EndpointDocumentationController.java

/**
 * Construct base path//  w  w w .  ja  v  a 2  s  .  c om
 * 
 * @param httpServletRequest
 * @return
 */
private String getBasePath(HttpServletRequest httpServletRequest) {
    String scheme = httpServletRequest.getScheme(); // http
    String serverName = httpServletRequest.getServerName(); // hostname.com
    int serverPort = httpServletRequest.getServerPort(); // 80

    StringBuffer basePath = new StringBuffer();
    basePath.append(scheme).append("://").append(serverName);
    if (serverPort != 80) {
        basePath.append(":").append(serverPort);
    }
    return basePath.toString();
}

From source file:org.socialhistoryservices.pid.ws.WsdlAdapter.java

/**
 * We override this method because we need to be able to return absolute URLs.
 *
 * @param location Location of the wsdl/*from   ww  w. j a v a 2 s.  co m*/
 * @param request Http request
 * @return The absolute url
 */
@Override
protected String transformLocation(String location, HttpServletRequest request) {

    if (!location.startsWith("/"))
        return location;
    StringBuilder url = new StringBuilder(request.getScheme());
    url.append("://").append(request.getServerName()).append(':').append(request.getServerPort());
    // a relative path, prepend the context path
    url.append(request.getContextPath()).append(location);
    return url.toString();
}

From source file:de.thm.arsnova.controller.SocketController.java

@RequestMapping(value = "/url", method = RequestMethod.GET)
public String getSocketUrl(final HttpServletRequest request) {
    StringBuilder url = new StringBuilder();

    url.append(server.isUseSSL() ? "https://" : "http://");
    url.append(request.getServerName() + ":" + server.getPortNumber());

    return url.toString();
}

From source file:ch.puzzle.modjprof.control.ControlServlet.java

private String getBaseUri(HttpServletRequest request) {
    String baseURI = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
    return baseURI;
}

From source file:inet.util.FileStorage.java

public FileStorage(inet.common.jsf.request.MultipartRequest multipartRequest, String targe) {
    this.multipartRequest = multipartRequest;
    HttpServletRequest request = (HttpServletRequest) multipartRequest.getRequest();
    realPath = request.getServletContext().getRealPath("/");
    realUri = "http://" + request.getServerName()
            + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + request.getContextPath();
    this.targe = targe;
}

From source file:fr.xebia.cocktail.CocktailRssView.java

@Override
protected void buildFeedMetadata(Map<String, Object> model, Channel feed, HttpServletRequest request) {

    feed.setTitle("Cocktail App");
    feed.setDescription("Java Tutorials and Examples");
    feed.setLink(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath());

    super.buildFeedMetadata(model, feed, request);
}

From source file:de.hybris.platform.chinesestoreaddon.interceptors.beforeview.BaiduMapsBeforeViewHandler.java

@Override
public void beforeView(final HttpServletRequest request, final HttpServletResponse response,
        final ModelAndView modelAndView) throws Exception {
    final String baiduApiKey = getHostConfigService().getProperty("baiduApiKey", request.getServerName());
    if (StringUtils.isNotEmpty(baiduApiKey)) {
        // Over-write the Google Maps API key in order to reuse its implementation
        modelAndView.addObject("googleApiKey", baiduApiKey);
    }//from   w w w .  ja v  a  2 s.  com
}

From source file:org.geonode.security.GeoNodeAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication, HttpServletRequest request)
        throws AuthenticationException {
    this.client.setRequestUrl("http://" + request.getServerName() + "/");
    if (authentication instanceof UsernamePasswordAuthenticationToken) {
        UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
        String username = token.getName();
        String password = (String) token.getCredentials();

        // ignore this - let the other provider(s) handle things
        if (GeoServerUser.ROOT_USERNAME.equals(username)
                && GeoServerUser.DEFAULT_ADMIN_PASSWD.equals(username)) {
            return null;
        }//from  w  w  w  . j  a v  a 2 s  .  c o m

        try {
            if (username == "" && password == null) {
                return client.authenticateAnonymous();
            } else {
                // if an anonymous session cookie exists in the request but
                // the user is logging in via the admin or other form mechanism,
                // it's possible that the GeoNodeCookieProcessingFilter will
                // 'overwrite' the credentials... it will check for this
                Authentication auth = client.authenticateUserPwd(username, password);
                if (auth.isAuthenticated()) {
                    SecurityContextHolder.getContext().setAuthentication(auth);
                }
                return auth;
            }
        } catch (IOException e) {
            throw new AuthenticationServiceException(
                    "Communication with GeoNode failed (UsernamePasswordAuthenticationToken)", e);
        }
    } else if (authentication instanceof GeoNodeSessionAuthToken) {
        try {
            return client.authenticateCookie((String) authentication.getCredentials());
        } catch (IOException e) {
            throw new AuthenticationServiceException(
                    "Communication with GeoNode failed (GeoNodeSessionAuthToken)", e);
        }
    } else if (authentication instanceof AnonymousGeoNodeAuthenticationToken) {
        try {
            return client.authenticateAnonymous();
        } catch (IOException e) {
            throw new AuthenticationServiceException(
                    "Communication with GeoNode failed (AnonymousGeoNodeAuthenticationToken)", e);
        }
    } else {
        throw new IllegalArgumentException(
                "GeoNodeAuthenticationProvider accepts only UsernamePasswordAuthenticationToken and GeoNodeSessionAuthToken; received "
                        + authentication);
    }
}

From source file:de.appsolve.padelcampus.utils.LoginUtil.java

private void deleteCookie(HttpServletRequest request, HttpServletResponse response, String path) {
    Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, null);
    cookie.setDomain(request.getServerName());
    cookie.setMaxAge(0);/*  www .ja  v a2s .  c  o  m*/
    if (!StringUtils.isEmpty(path)) {
        cookie.setPath(path);
    }
    response.addCookie(cookie);
}

From source file:org.ow2.chameleon.everest.servlet.RelationSerializationTest.java

@Test
public void testRelationWithoutParameter() throws IllegalResourceException, IOException {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getScheme()).thenReturn("http");
    when(request.getServerName()).thenReturn("server");
    when(request.getServerPort()).thenReturn(1234);

    Relation relation = new DefaultRelation(Path.from("/foo/bar"), Action.READ, "test", "description");
    Resource resource = new DefaultResource.Builder().fromPath(Path.from("/foo")).with(relation).build();
    EverestServlet servlet = new EverestServlet();
    JsonNode node = servlet.toJSON(request, resource);

    System.out.println(node);/*from  ww  w.  ja va 2  s .  c o m*/
    assertThat(node.get("__relations")).isNotNull();
    final JsonNode rel = node.get("__relations").get("test");
    assertThat(rel).isNotNull();
    assertThat(rel.get("href").asText()).isEqualTo("http://server:1234/everest/foo/bar");
    assertThat(rel.get("action").asText()).isEqualTo("READ");
    assertThat(rel.get("name").asText()).isEqualTo("test");
    assertThat(rel.get("description").asText()).isEqualTo("description");

}