List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:edu.wisc.my.redirect.PortalUrlRedirectController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { final String serverName = request.getServerName(); final PortalUrl portalUrl = this.portalUrlProvider.getPortalUrl(serverName); if (this.portletFunctionalName != null) { portalUrl.setTargetPortlet(this.portletFunctionalName); }//from w w w . ja va 2 s . co m if (this.tabIndex != null) { portalUrl.setTabIndex(this.tabIndex); } //If strict param matching only run if the request parameter keyset matches the mapped parameter keyset final Set<?> requestParameterKeys = request.getParameterMap().keySet(); if (this.strictParameterMatching && !requestParameterKeys.equals(this.parameterMappings.keySet())) { if (this.logger.isInfoEnabled()) { this.logger.info("Sending not found error, requested parameter key set " + requestParameterKeys + " does not match mapped parameter key set " + this.parameterMappings.keySet()); } response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; } //Map static parameters logger.debug("Mapping " + staticParameters.size() + " static parameters"); for (final Map.Entry<String, List<String>> parameterMappingEntry : this.staticParameters.entrySet()) { final String name = parameterMappingEntry.getKey(); final List<String> values = parameterMappingEntry.getValue(); if (this.logger.isDebugEnabled()) { this.logger.debug("Adding static parameter '" + name + "' with values: " + values); } portalUrl.setParameter(name, values.toArray(new String[values.size()])); } //Map request parameters logger.debug("Mapping " + parameterMappings.entrySet().size() + " request parameters"); for (final Map.Entry<String, Set<String>> parameterMappingEntry : this.parameterMappings.entrySet()) { final String name = parameterMappingEntry.getKey(); logger.debug("Mapping parameter " + name); final String[] values = request.getParameterValues(name); if (values != null) { for (final String mappedName : parameterMappingEntry.getValue()) { if (this.logger.isDebugEnabled()) { this.logger.debug("Mapping parameter '" + name + "' to portal parameter '" + mappedName + "' with values: " + Arrays.asList(values)); } portalUrl.setParameter(mappedName, values); } //Add any conditional parameters for the URL parameter final Map<String, List<String>> conditionalParameters = this.conditionalParameterMappings.get(name); if (conditionalParameters != null) { for (final Map.Entry<String, List<String>> conditionalParameterEntry : conditionalParameters .entrySet()) { final String condName = conditionalParameterEntry.getKey(); final List<String> condValues = conditionalParameterEntry.getValue(); if (this.logger.isDebugEnabled()) { this.logger.debug( "Adding conditional parameter '" + condName + "' with values: " + condValues); } portalUrl.setParameter(condName, condValues.toArray(new String[condValues.size()])); } } } else if (this.logger.isDebugEnabled()) { this.logger.debug( "Skipping mapped parameter '" + name + "' since it was not specified on the original URL"); } } //Set public based on if remoteUser is set final String remoteUser = request.getRemoteUser(); final boolean isAuthenticated = StringUtils.isNotBlank(remoteUser); portalUrl.setPublic(!isAuthenticated); if (this.windowState != null) { portalUrl.setWindowState(this.windowState); } if (this.portletMode != null) { portalUrl.setWindowState(this.portletMode); } portalUrl.setType(RequestType.ACTION); final String redirectUrl = portalUrl.toString(); if (this.logger.isInfoEnabled()) { this.logger.info("Redirecting to: " + redirectUrl); } return new ModelAndView(new RedirectView(redirectUrl, false)); }
From source file:com.esri.gpt.control.arcims.ServletConnectorProxy.java
/** * Sets redirect url to next door GPT application * /* w w w. ja v a 2 s . c om*/ * @param request * the servlet request */ private void setURL(HttpServletRequest request) { StringBuffer sb = new StringBuffer(); sb.append("http://").append(request.getServerName()).append(":").append(request.getServerPort()) .append(_redirectURL); _redirectURL = sb.toString(); LOGGER.finer(_redirectURL); }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AbstractPageController.java
@ModelAttribute("jirafeApplicationId") public String getJirafeApplicationId(final HttpServletRequest request) { return getHostConfigService().getProperty(ThirdPartyConstants.Jirafe.APPLICATION_ID, request.getServerName()); }
From source file:de.hybris.alantrails.storefront.controllers.pages.PickupInStoreController.java
@ModelAttribute("googleEmbedApiKey") public String getGoogleEmbedApiKey(final HttpServletRequest request) { final String googleEmbedApiKey = getHostConfigService().getProperty(GOOGLE_EMBED_API_KEY_ID, request.getServerName()); if (StringUtils.isEmpty(googleEmbedApiKey)) { LOG.warn("No Google Embed API key found for server: " + request.getServerName()); }//from w w w . jav a 2s . c o m return googleEmbedApiKey; }
From source file:org.esigate.servlet.impl.RequestFactory.java
public IncomingRequest create(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException { HttpServletRequestContext context = new HttpServletRequestContext(request, response, servletContext, filterChain);//ww w.ja v a 2s . co m // create request line String uri = UriUtils.createURI(request.getScheme(), request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString(), null); ProtocolVersion protocolVersion = BasicLineParser.parseProtocolVersion(request.getProtocol(), null); IncomingRequest.Builder builder = IncomingRequest .builder(new BasicRequestLine(request.getMethod(), uri, protocolVersion)); builder.setContext(context); // copy headers @SuppressWarnings("rawtypes") Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); @SuppressWarnings("rawtypes") Enumeration values = request.getHeaders(name); while (values.hasMoreElements()) { String value = (String) values.nextElement(); builder.addHeader(name, value); } } // create entity HttpServletRequestEntity entity = new HttpServletRequestEntity(request); builder.setEntity(entity); builder.setRemoteAddr(request.getRemoteAddr()); builder.setRemoteUser(request.getRemoteUser()); HttpSession session = request.getSession(false); if (session != null) { builder.setSessionId(session.getId()); } builder.setUserPrincipal(request.getUserPrincipal()); // Copy cookies // As cookie header contains only name=value so we don't need to copy // all attributes! javax.servlet.http.Cookie[] src = request.getCookies(); if (src != null) { for (int i = 0; i < src.length; i++) { javax.servlet.http.Cookie c = src[i]; BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue()); builder.addCookie(dest); } } builder.setSession(new HttpServletSession(request)); builder.setContextPath(request.getContextPath()); return builder.build(); }
From source file:com.junly.service.helper.TicketHelper.java
/** <p class="detail"> * cookie// w w w. j av a 2s .c om * </p> * @author junly * @date 2016422 * @param response * @param ticket */ public void setCookie(HttpServletRequest request, HttpServletResponse response, String ticket) { // ? Cookie cookie = new Cookie(ViewContants.LOGIN_TICKET_KEY, ticket); // ? ??? cookie.setDomain(request.getServerName()); // path cookie.setPath("/"); // ?? cookie.setMaxAge(ViewContants.TRUST_COOKIE_TIME); // response.addCookie(cookie); }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AbstractPageController.java
@ModelAttribute("googleAnalyticsTrackingId") public String getGoogleAnalyticsTrackingId(final HttpServletRequest request) { return getHostConfigService().getProperty(ThirdPartyConstants.Google.ANALYTICS_TRACKING_ID, request.getServerName()); }
From source file:io.fabric8.api.registry.ApiRegistryService.java
protected void checkForUrlPrefix() { if (urlPrefix == null && messageContext != null) { HttpServletRequest request = messageContext.getHttpServletRequest(); ServletContext servletContext = messageContext.getServletContext(); if (request != null && servletContext != null) { String swaggerPrefix = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); String contextPath = servletContext.getContextPath(); urlPrefix = urlPathJoin(swaggerPrefix, contextPath); finder.setUrlPrefix(urlPrefix); }/*w w w . j av a 2 s . c o m*/ } }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.GrailsAccessDeniedHandlerImpl.java
/** * {@inheritDoc}/*w w w .j av a 2s . co m*/ * @see org.springframework.security.ui.AccessDeniedHandler#handle( * javax.servlet.ServletRequest, javax.servlet.ServletResponse, * org.springframework.security.AccessDeniedException) */ public void handle(final ServletRequest req, final ServletResponse res, final AccessDeniedException e) throws IOException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (errorPage != null || (ajaxErrorPage != null && request.getHeader(ajaxHeader) != null)) { boolean includePort = true; String scheme = request.getScheme(); String serverName = request.getServerName(); int serverPort = portResolver.getServerPort(request); String contextPath = request.getContextPath(); boolean inHttp = "http".equals(scheme.toLowerCase()); boolean inHttps = "https".equals(scheme.toLowerCase()); if (inHttp && (serverPort == 80)) { includePort = false; } else if (inHttps && (serverPort == 443)) { includePort = false; } String commonRedirectUrl = scheme + "://" + serverName + ((includePort) ? (":" + serverPort) : "") + contextPath; String redirectUrl = commonRedirectUrl; if (ajaxErrorPage != null && request.getHeader(ajaxHeader) != null) { redirectUrl += ajaxErrorPage; } else if (errorPage != null) { redirectUrl += errorPage; } else { response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage()); } response.sendRedirect(response.encodeRedirectURL(redirectUrl)); } if (!response.isCommitted()) { // Send 403 (we do this after response has been written) response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage()); } }
From source file:br.gov.jfrj.siga.base.SigaHTTP.java
/** * @param URL//from w w w . jav a 2s . com * @param request (se for modulo play, setar pra null) * @param cookieValue (necessario apenas nos modulos play) */ public String get(String URL, HttpServletRequest request, String cookieValue) { String html = ""; if (URL.startsWith("/")) URL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + URL; try { // Efetua o request para o Service Provider (mdulo) Request req = Request.Get(URL); // req.addHeader(COOKIE, JSESSIONID_PREFIX+getCookie(request, cookieValue)); // Atribui o html retornado e pega o header do Response // Se a aplicao j efetuou a autenticao entre o mdulo da URL o contedo ser trago nesse primeiro GET // Caso contrrio passar pelo processo de autenticao (if abaixo) html = req.execute().handleResponse(new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException { // O atributo que importa nesse header o set-cookie que ser utilizado posteriormente headers = httpResponse.getAllHeaders(); return IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8"); } }); // Verifica se retornou o form de autenticao do picketlink if (html.contains(HTTP_POST_BINDING_REQUEST)) { // Atribui o cookie recuperado no response anterior String setCookie = null; try { setCookie = extractCookieFromHeader(getHeader(SET_COOKIE)); } catch (ElementNotFoundException elnf) { log.warning("Nao encontrou o set-cookie"); setCookie = getCookie(request, cookieValue); } // Atribui o valor do SAMLRequest contido no html retornado no GET efetuado. String SAMLRequestValue = getAttributeValueFromHtml(html, SAMLRequest); // Atribui a URL do IDP (sigaidp) String idpURL = getAttributeActionFromHtml(html); // Faz um novo POST para o IDP com o SAMLRequest como parametro e utilizando o sessionID do IDP html = Request.Post(idpURL).addHeader(COOKIE, JSESSIONID_PREFIX + getIdp(request)) .bodyForm(Form.form().add(SAMLRequest, SAMLRequestValue).build()).execute().returnContent() .toString(); // Extrai o valor do SAMLResponse // Caso o SAMLResponse no esteja disponvel aqui, porque o JSESSIONID utilizado no foi o do IDP. String SAMLResponseValue = getAttributeValueFromHtml(html, SAMLResponse); // Faz um POST para o SP com o atributo SAMLResponse utilizando o sessionid do primeiro GET // O retorno discartado pois o resultado um 302. Request.Post(URL).addHeader(COOKIE, JSESSIONID_PREFIX + setCookie) .bodyForm(Form.form().add(SAMLResponse, SAMLResponseValue).build()).execute() .discardContent(); // Agora que estamos autenticado efetua o GET para pgina desejada. html = Request.Get(URL).addHeader(COOKIE, JSESSIONID_PREFIX + setCookie).execute().returnContent() .toString(); if (html.contains(HTTP_POST_BINDING_REQUEST)) { log.info("Alguma coisa falhou na autenticao!: " + idpURL); } } } catch (Exception io) { io.printStackTrace(); } return html; }