List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:com.hp.autonomy.frontend.find.core.view.AbstractViewController.java
private String getBaseUrl(final HttpServletRequest request) { final String path = request.getRequestURI().replaceFirst(request.getContextPath(), ""); final int depth = StringUtils.countMatches(path, "/") - 1; final String baseUrl; if (depth == 0) { baseUrl = "."; } else {/* w w w.j a v a 2 s . c o m*/ baseUrl = StringUtils.repeat("../", depth); } return baseUrl; }
From source file:com.googlecode.psiprobe.controllers.deploy.UndeployContextController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from w w w . j av a 2 s. co m*/ if (request.getContextPath().equals(contextName)) { throw new IllegalStateException( getMessageSourceAccessor().getMessage("probe.src.contextAction.cannotActOnSelf")); } getContainerWrapper().getTomcatContainer().remove(contextName); } catch (Exception e) { request.setAttribute("errorMessage", e.getMessage()); logger.error(e); return new ModelAndView( new InternalResourceView(getFailureViewName() == null ? getViewName() : getFailureViewName())); } return new ModelAndView(new RedirectView(request.getContextPath() + getViewName())); }
From source file:at.porscheinformatik.common.spring.web.extended.http.DefaultLinkCreator.java
/** * Subclasses may add something to the url before the default url parts get added * /* w ww. ja v a2 s. co m*/ * @param url the URL */ protected void prefix(StringBuilder url) { HttpServletRequest request = RequestResponseContextHolder.currentRequest(); if (request != null && request.getContextPath() != null) { url.append(request.getContextPath()); } }
From source file:de.highbyte_le.weberknecht.request.ModelHelper.java
@Deprecated public void setSelf(HttpServletRequest request) { StringBuilder b = new StringBuilder(); b.append(request.getContextPath()); b.append(request.getServletPath());// w ww . ja va 2 s.com setSelf(b.toString()); }
From source file:com.hp.autonomy.hod.sso.HodTokenLogoutSuccessHandlerTest.java
@Test public void redirectsWithAuthentication() throws IOException, ServletException { final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getContextPath()).thenReturn(CONTEXT_PATH); final String mockRedirectUrl = "/mock/redirect/url"; final HttpServletResponse response = mock(HttpServletResponse.class); final String expectedPath = CONTEXT_PATH + REDIRECT_PATH + "?token=CMB%3ASIMPLE%3Atoken-id%3Atoken-secret"; when(response.encodeRedirectURL(expectedPath)).thenReturn(mockRedirectUrl); final HodAuthenticationPrincipal principal = new HodAuthenticationPrincipal(UUID.randomUUID(), UUID.randomUUID(), new ResourceIdentifier("APP-DOMAIN", "APP-NAME"), new UserStoreInformation(UUID.randomUUID(), "STORE-DOMAIN", "STORE-NAME"), new AuthenticationInformation(UUID.randomUUID(), AuthenticationType.LEGACY_API_KEY), new AuthenticationInformation(UUID.randomUUID(), AuthenticationType.LEGACY_API_KEY), null, null, null);//from www. j a va2 s . com final HodAuthentication<EntityType.Combined> authentication = new HodAuthentication<>(tokenProxy, Collections.<GrantedAuthority>emptySet(), principal); logoutSuccessHandler.onLogoutSuccess(request, response, authentication); verify(response).sendRedirect(mockRedirectUrl); }
From source file:org.client.one.util.CustomLogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication auth) throws IOException, ServletException { String redirectUrl = request.getContextPath() + "/core/logoutSuccess"; response.sendRedirect(redirectUrl);//from w w w .ja v a 2 s .c o m }
From source file:es.ucm.fdi.storage.web.StorageController.java
@RequestMapping(method = RequestMethod.GET, value = "/storage/**") public void servirArchivos(HttpServletRequest request, HttpServletResponse response) throws IOException { String ctxPath = request.getContextPath(); String objectId = request.getRequestURI(); objectId = objectId.substring(ctxPath.length() + "/storage/".length()); int pos = objectId.indexOf('/'); if (pos < 0) { response.sendError(400, "Upps"); return;//from ww w . j a va2s . c o m } String bucket = objectId.substring(0, pos); String key = objectId.substring(pos + 1); StorageObject object = storage.getObject(bucket, key); String mimeType = object.getMimeType(); long length = object.getContentLength(); // set content attributes for the response response.setContentType(mimeType); response.setContentLength((int) length); try { object.transferTo(response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { logger.error("Error writing file to output stream. bucket=>'{}', key=>'{}'", bucket, key, ex); response.sendError(500, "Upps"); } }
From source file:br.com.semanticwot.cd.util.RedirectAfterLogin.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { response.sendRedirect(request.getContextPath()); }
From source file:org.appverse.web.framework.backend.frontfacade.mvc.swagger.controller.SwaggerOAuth2Controller.java
@RequestMapping(value = "/swaggeroauth2login", method = RequestMethod.GET) public String showSwaggerOAuth2LoginForm(Model model, HttpServletRequest req) throws MalformedURLException { String contextPath = req.getContextPath(); model.addAttribute("response_type", "token"); Map<String, String[]> map = req.getParameterMap(); model.addAllAttributes(convertParameters(map)); model.addAttribute("redirect_uri", req.getParameter("redirect_uri")); if (oauthAuthServerBaseUrl != null && !oauthAuthServerBaseUrl.isEmpty()) { // Is an external OAuth2 provider, not in the same webapplication as the resource server model.addAttribute("swaggerLoginFormAction", oauthAuthServerBaseUrl + oauth2LoginEndpoint); } else {//from w w w . j a v a 2 s . c om // The OAuth2 provider and the resource server reside in the same web application model.addAttribute("swaggerLoginFormAction", convertToRelativePath(contextPath, oauth2LoginEndpoint)); } model.addAttribute("swaggerClientId", swaggerClientId); return "oauth2loginform"; }
From source file:furkan.app.tictactoewebsocket.TicTacToeServlet.java
private void list(HttpServletRequest request, HttpServletResponse response) throws IOException { response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/tictactoe")); }