List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
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 w w w. j a v a 2 s . com*/ 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"); }
From source file:com.toughland.helpmechoose.common.Helper.java
public String getUrl(HttpServletRequest request) { return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/"; }
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 ww.j ava2s . 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: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: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: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 .j av a 2 s . c o 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: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:com.glaf.core.util.RequestUtils.java
public static String getServiceUrl(HttpServletRequest request) { String scheme = request.getScheme(); String serviceUrl = scheme + "://" + request.getServerName(); if (request.getServerPort() != 80) { serviceUrl += ":" + request.getServerPort(); }//from w w w . j ava 2 s . c o m if (!"/".equals(request.getContextPath())) { serviceUrl += request.getContextPath(); } return serviceUrl; }
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(); }//w w w . j av a 2 s .com 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.education.lessons.ui.server.login.OpenIDLoginController.java
/** * Builds the current base URL; up to the the domain name, e.g. * http://www.mydomain.com///w w w. j a va 2s . co m */ private String getRealm(HttpServletRequest request) { String scheme = request.getScheme(); String serverName = request.getServerName(); int serverPort = request.getServerPort(); StringBuilder sb = new StringBuilder(); sb.append(scheme).append("://").append(serverName); if (serverPort != 80) { sb.append(":").append(serverPort); } sb.append("/"); return sb.toString(); }