List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:com.bitium.confluence.saml.SAMLContext.java
private String getDefaultBaseURL(HttpServletRequest request) { StringBuilder sb = new StringBuilder(); sb.append(request.getScheme()).append("://").append(request.getServerName()).append(":") .append(request.getServerPort()); sb.append(request.getContextPath()); return sb.toString(); }
From source file:cn.vlabs.umt.ui.servlet.LoginServlet.java
private void saveParams(HttpServletRequest request) { int port = request.getServerPort(); HttpSession session = request.getSession(); String basePath = request.getScheme() + "://" + request.getServerName(); if (port != 80) { basePath += ":" + request.getServerPort(); }//from w w w. j a va2 s . c om session.setAttribute("rootPath", basePath); basePath += request.getContextPath(); session.setAttribute("basePath", basePath); Map<String, String> siteInfo = new HashMap<String, String>(); for (String param : Attributes.SSO_PARAMS) { if (request.getParameter(param) != null) { siteInfo.put(param, request.getParameter(param)); } } session.setAttribute(Attributes.SITE_INFO, siteInfo); }
From source file:com.feilong.servlet.http.RequestUtil.java
/** * scheme+serverName+port+getContextPath. * //from w w w . j av a2 s.co m * <p> * http https. * <p> * * @param request * the request * @return :http://localhost:8080/feilong/ * @see "org.apache.catalina.connector.Request#getRequestURL()" * @see "org.apache.catalina.realm.RealmBase#hasUserDataPermission(Request, Response, SecurityConstraint[])" * @see javax.servlet.http.HttpUtils#getRequestURL(HttpServletRequest) */ public static String getServerRootWithContextPath(HttpServletRequest request) { String scheme = request.getScheme(); int port = request.getServerPort() < 0 ? 80 : request.getServerPort();// Work around java.net.URL bug //************************************************************************************* StringBuilder sb = new StringBuilder(); sb.append(scheme); sb.append("://"); sb.append(request.getServerName()); if ((scheme.equals(SCHEME_HTTP) && (port != 80)) || (scheme.equals(SCHEME_HTTPS) && (port != 443))) { sb.append(':'); sb.append(port); } sb.append(request.getContextPath()); return sb.toString(); }
From source file:com.pontecultural.flashcards.DeckController.java
@RequestMapping(method = RequestMethod.GET) public String getUploadForm(HttpServletRequest req, Locale locale, Model model) { logger.info("List of decks"); // compute base URL to allow client to call us back. String baseURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath();//from w w w . ja va 2 s. com model.addAttribute("baseURL", baseURL); model.addAttribute("decks", jdbcFlashcardsDao.fetchAllDecks()); return "deckList"; }
From source file:org.ow2.chameleon.everest.servlet.RelationSerializationTest.java
@Test public void testRelationWithOneParameter() 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", new DefaultParameter().name("param").description("my param").type(String.class)); 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);/* w w w. jav a2s . 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"); final JsonNode param0 = rel.get("parameters").get(0); assertThat(param0.get("name").asText()).isEqualTo("param"); assertThat(param0.get("description").asText()).isEqualTo("my param"); assertThat(param0.get("type").asText()).isEqualTo(String.class.getName()); assertThat(param0.get("optional").asBoolean()).isFalse(); }
From source file:company.gonapps.loghut.controller.LoginFormController.java
@RequestMapping(value = "/login_form.do", method = RequestMethod.GET) public String loginForm(HttpServletRequest request) throws Exception { HttpSession session = request.getSession(false); if (session == null) { return "admin/login_form"; }// w w w. j a va2 s.com return "redirect:" + request.getScheme() + "://" + request.getServerName() + getSettingDao().getSetting("admin.url") + "/index.do"; }
From source file:alpine.filters.FqdnForwardFilter.java
/** * Forward requests...../*www . j a v a 2 s.c o m*/ * * @param request The request object. * @param response The response object. * @param chain Refers to the {@code FilterChain} object to pass control to the next {@code Filter}. * @throws IOException a IOException * @throws ServletException a ServletException */ public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { final HttpServletRequest req = (HttpServletRequest) request; final HttpServletResponse res = (HttpServletResponse) response; if (req.getServerName().equals(host)) { chain.doFilter(request, response); return; } res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); StringBuilder sb = new StringBuilder(); sb.append("http"); if (req.isSecure()) { sb.append("s"); } sb.append("://").append(host); if (StringUtils.isNotBlank(req.getPathInfo())) { sb.append(req.getPathInfo()); } if (StringUtils.isNotBlank(req.getQueryString())) { sb.append("?").append(req.getQueryString()); } res.setHeader("Location", sb.toString()); }
From source file:org.ow2.chameleon.everest.servlet.RelationSerializationTest.java
@Test public void testRelationWithTwoParameters() 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", new DefaultParameter().name("param").description("my param").type(String.class), new DefaultParameter().name("param2").description("my second param").type(Integer.TYPE) .optional(true));/*from ww w.ja v a 2 s . co m*/ 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); 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"); final JsonNode param0 = rel.get("parameters").get(0); assertThat(param0.get("name").asText()).isEqualTo("param"); assertThat(param0.get("description").asText()).isEqualTo("my param"); assertThat(param0.get("type").asText()).isEqualTo(String.class.getName()); assertThat(param0.get("optional").asBoolean()).isFalse(); final JsonNode param1 = rel.get("parameters").get(1); assertThat(param1.get("name").asText()).isEqualTo("param2"); assertThat(param1.get("description").asText()).isEqualTo("my second param"); assertThat(param1.get("type").asText()).isEqualTo(Integer.TYPE.getName()); assertThat(param1.get("optional").asBoolean()).isTrue(); }
From source file:com.brokenmodel.swats.RouterServlet.java
private void handleRequest(HttpServletRequest request, HttpServletResponse response, ControllerRequest.Type type) { try {/*w w w.jav a 2 s .co m*/ URL rootURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + request.getServletPath()); String appRoot = rootURL.getFile(); String htmlRoot = request.getContextPath(); MatchedRoute matchedRoute = controllers.matchRoute(request.getPathInfo()); ControllerRequest controllerRequest = new ControllerRequest(request, response, appRoot, htmlRoot, matchedRoute.getUrlParams(), type, handleMultipart(request), getDataSource()); AbstractController controller = matchedRoute.getController(); controller.doRequest(controllerRequest); } catch (Throwable t) { log(t); try { // only will work if output stream has not been opened PrintWriter pw = new PrintWriter(response.getWriter()); pw.append("<pre>"); pw.append("We're sorry - an error has occurred:\n\n"); t.printStackTrace(pw); pw.append("</pre>"); } catch (Throwable t2) { } } }
From source file:com.paladin.mvc.URLMappingFilter.java
private String _GetTemplateBase(HttpServletRequest req) { String base = null;/*www . j av a2 s.c o m*/ String prefix = req.getServerName().toLowerCase(); int idx = (rootDomain != null) ? prefix.indexOf(rootDomain) : 0; if (idx > 0) { prefix = prefix.substring(0, idx - 1); base = other_base.get(prefix); } return (base == null) ? default_base : base; }