List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:at.gv.egiz.bku.online.webapp.WebRequestHandler.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { BindingProcessorManager bindingProcessorManager = (BindingProcessorManager) getServletContext() .getAttribute("bindingProcessorManager"); if (bindingProcessorManager == null) { String msg = "Configuration error: BindingProcessorManager missing!"; log.error(msg);/*from w w w. j a v a 2s. com*/ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); return; } Configuration conf = ((BindingProcessorManagerImpl) bindingProcessorManager).getConfiguration(); if (conf == null) log.error("No configuration"); else MoccaParameterBean.setP3PHeader(conf, resp); Id id = (Id) req.getAttribute("id"); if (id == null) { String msg = "No request id! Configuration error: ServletFilter missing?"; log.error(msg); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); return; } // if binding processor with same id is present: remove bindingProcessorManager.removeBindingProcessor(id); Locale locale = AcceptLanguage.getLocale(req.getHeader("Accept-Language")); if (log.isInfoEnabled()) { log.info("Received request (Accept-Language locale: {}).", locale); } // create new binding processor String protocol = MoccaParameterBean.getInitParameter("protocol", getServletConfig(), getServletContext()); if (protocol == null || protocol.isEmpty()) { protocol = req.getScheme(); } HTTPBindingProcessor bindingProcessor = (HTTPBindingProcessor) bindingProcessorManager .createBindingProcessor(protocol, locale); // set headers LinkedHashMap<String, String> headerMap = new LinkedHashMap<String, String>(); if (req.getHeaderNames() != null) { for (Enumeration<?> headerName = req.getHeaderNames(); headerName.hasMoreElements();) { String name = (String) headerName.nextElement(); // Account for multiple headers with the same field-name, but // they are very rare, so we are not using a StringBuffer. Enumeration<?> headers = req.getHeaders(name); String value = null; while (headers.hasMoreElements()) { value = (value == null) ? (String) headers.nextElement() : value + ", " + headers.nextElement(); } headerMap.put(name, value); } } // set request stream InputStream inputStream; if (req.getMethod().equals("POST")) { inputStream = req.getInputStream(); } else { headerMap.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, InputDecoderFactory.URL_ENCODED); String queryString = req.getQueryString(); if (queryString != null) { inputStream = new ByteArrayInputStream(queryString.getBytes("UTF-8")); } else { inputStream = new ByteArrayInputStream(new byte[] {}); } } bindingProcessor.setHTTPHeaders(headerMap); bindingProcessor.consumeRequestStream(req.getRequestURL().toString(), inputStream); inputStream.close(); // process bindingProcessorManager.process(id, bindingProcessor); log.debug("Sending redirect to user interface."); resp.sendRedirect(resp.encodeRedirectURL(uiRedirectUrl)); }
From source file:org.wrml.server.WrmlServlet.java
/** * Get the requested resource's id from the the {@link HttpServletRequest}. * * @param request The {@link HttpServletRequest} that holds the {@link URI}. * @return The requested resource's id from the the {@link HttpServletRequest}. * @throws URISyntaxException Thrown if there is a syntax problem when constructing the {@link URI}. *//*from w ww . ja va2 s.c o m*/ URI getRequestUri(final HttpServletRequest request) throws URISyntaxException { // Due to the quirky nature of a servlet container, we're after the entire path. // This seems to work with servlet 3.0 and Tomcat 7.X String path = request.getServletPath(); String extra = request.getPathInfo(); if (path != null && extra != null) { path += request.getPathInfo(); } else if (path == null) { path = extra; } if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } final String host = StringUtils.defaultIfEmpty(request.getHeader(WRML_HOST_HEADER_NAME), request.getRemoteHost()); final String portString = StringUtils.defaultIfEmpty(request.getHeader(WRML_PORT_HEADER_NAME), Integer.toString(request.getRemotePort())); final String scheme = StringUtils.defaultIfEmpty(request.getHeader(WRML_SCHEME_HEADER_NAME), request.getScheme()); int port = -1; port = Integer.parseInt(portString); if (port == 80) { port = -1; } final URI requestUri = new URI(scheme, null, host, port, path, null, null); LOGGER.debug("Determined request URI: {}", requestUri); return requestUri; }
From source file:lucee.runtime.engine.CFMLEngineImpl.java
@Override public CFMLFactory getCFMLFactory(ServletConfig srvConfig, HttpServletRequest req) throws ServletException { ServletContext srvContext = srvConfig.getServletContext(); String real = ReqRspUtil.getRootPath(srvContext); ConfigServerImpl cs = getConfigServerImpl(); // Load JspFactory CFMLFactory factory = contextes.get(real); if (factory == null) { factory = initContextes.get(real); if (factory == null) { factory = loadJSPFactory(cs, srvConfig, initContextes.size()); initContextes.put(real, factory); }/*from www.j a v a 2 s. c o m*/ contextes.put(real, factory); try { String cp = req.getContextPath(); if (cp == null) cp = ""; ((CFMLFactoryImpl) factory) .setURL(new URL(req.getScheme(), req.getServerName(), req.getServerPort(), cp)); } catch (MalformedURLException e) { e.printStackTrace(); } } return factory; }
From source file:org.jahia.services.seo.urlrewrite.ServerNameToSiteMapper.java
public void analyzeLink(HttpServletRequest request, String ctx, String language, String siteKey, String path) { String currentSiteKey = getSiteKeyByServerName(request); boolean matches = currentSiteKey.equals(siteKey); request.setAttribute(ATTR_NAME_SITE_KEY_MATCHES, Boolean.valueOf(matches)); try {/* w w w. j ava 2 s .c o m*/ boolean languageMatches = JahiaSitesService.getInstance().getSiteDefaultLanguage(siteKey) .equals(language); request.setAttribute(ATTR_NAME_DEFAULT_LANG_MATCHES, languageMatches); request.setAttribute(ATTR_NAME_LANG_TOKEN, languageMatches ? "" : "/" + language); } catch (JahiaException e) { logger.error("Error resolving language " + language + " for siteKey '" + siteKey + "'", e); } if (!matches && currentSiteKey.length() > 0 && SettingsBean.getInstance().isUrlRewriteUseAbsoluteUrls()) { JahiaSite siteByKey = null; try { siteByKey = JahiaSitesService.getInstance().getSiteByKey(siteKey); } catch (JahiaException e) { logger.error("Error resolving site for site key " + siteKey, e); } String serverName = siteByKey != null && !Url.isLocalhost(siteByKey.getServerName()) ? siteByKey.getServerName() : null; if (StringUtils.isNotEmpty(serverName)) { int port = SettingsBean.getInstance().getSiteURLPortOverride(); if (port == 0) { port = request.getServerPort(); } if (!(port == 80 && "http".equals(request.getScheme()) || port == 443 && "https".equals(request.getScheme()))) { serverName = new StringBuilder().append(serverName).append(":").append(port).toString(); } } request.setAttribute(ATTR_NAME_SITE_KEY_FOR_LINK, serverName); request.setAttribute(ATTR_NAME_SERVERNAME_FOR_LINK, serverName != null ? (request.getScheme() + "://" + serverName) : null); } checkCmsPrefix(request, ctx, path); if (logger.isDebugEnabled()) { logger.debug("analyzeLink({}, {}, {}, {}) | currentSiteKey={} targetSiteKey={} matches={}", new Object[] { ctx, language, siteKey, path, currentSiteKey, siteKey, matches }); } }
From source file:org.esco.cas.client.CasSingleLogoutClusterFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { CasSingleLogoutClusterFilter.LOG.trace("Filtering with request: [{}] ; method: [{}]", request); if (!this.peers.isEmpty() && (request instanceof HttpServletRequest)) { final HttpServletRequest httpRequest = (HttpServletRequest) request; CasSingleLogoutClusterFilter.LOG.trace("Filtering with HTTP method: [{}] ; parameters: [{}] ", httpRequest.getMethod(), httpRequest.getParameterMap().toString()); if ("POST".equals(httpRequest.getMethod())) { //This a CAS client method I use final String logoutRequest = CommonUtils.safeGetParameter(httpRequest, CasSingleLogoutClusterFilter.CAS_LOGOUT_REQUEST_HTTP_PARAM); //final String logoutRequest = httpRequest.getParameter(CasSingleLogoutClusterFilter.CAS_LOGOUT_REQUEST_HTTP_PARAM); CasSingleLogoutClusterFilter.LOG.debug("{}: [{}]", CasSingleLogoutClusterFilter.CAS_LOGOUT_REQUEST_HTTP_PARAM, logoutRequest); // Set a flag so an application getting a rebroadcast doesn't rebroadcast it. don't want a packet storm final String rebroadcast = httpRequest .getHeader(CasSingleLogoutClusterFilter.X_FORWARDED_LOGOUT_HEADER); CasSingleLogoutClusterFilter.LOG.debug("rebroadcast: [{}]", rebroadcast); if (StringUtils.hasText(logoutRequest) && (rebroadcast == null)) { try { final String path = httpRequest.getServletPath(); final String context = httpRequest.getContextPath(); final String protocol = httpRequest.getScheme(); CasSingleLogoutClusterFilter.LOG.debug( "Got a single logout request ; protocol: [{}] ; context: [{}] ; path: [{}].", new Object[] { protocol, context, path }); // Set up the http client connection CasSingleLogoutClusterFilter.LOG.debug("Attempting to rebroadcast"); // Peers are set in the init() method for (Peer peer : this.peers) { if (!peer.getHostName().equals(this.clientHostName)) { // don't rebroadcast to your self! CasSingleLogoutClusterFilter.LOG.debug("Processing peer: [{}]", peer); // set rebroadcast=false so peers don't rebroacast. Only first recipient reboradcasts this.sendLogoutRequestToPeer(peer, context + path, logoutRequest, true); }//from w w w. ja v a2 s .co m } } catch (Exception e) { CasSingleLogoutClusterFilter.LOG.error("Error while broadcasting logout request !", e); } } } } chain.doFilter(request, response); }
From source file:org.frontcache.FrontCacheEngine.java
/** * Works for Servlets and ServletFilters * /*from w w w.j av a 2s.c om*/ * @param servletRequest * @param servletResponse * @param filterChain */ private RequestContext init(HttpServletRequest servletRequest, HttpServletResponse servletResponse, FilterChain filterChain) { RequestContext context = new RequestContext(); context.setFrontCacheId(fcHostId); context.setRequest(servletRequest); context.setResponse(servletResponse); String uri = FCUtils.buildRequestURI(servletRequest); if (-1 < uri.indexOf(";jsessionid=")) // remove JSESSIONID from URI uri = uri.replaceAll(";jsessionid=.*?(?=\\?|$)", ""); context.setRequestURI(uri); String queryString = servletRequest.getQueryString(); // FCUtils.getQueryString(servletRequest, context); queryString = (null == queryString) ? "" : "?" + queryString; context.setRequestQueryString(queryString); context.setFrontCacheHost(servletRequest.getServerName()); context.setFrontCacheHttpPort(frontcacheHttpPort); context.setFrontCacheHttpsPort(frontcacheHttpsPort); DomainContext domainContex = getDomainContext(context.getRequest().getServerName()); context.setDomainContext(domainContex); String protocol = "https".equalsIgnoreCase(servletRequest.getScheme()) ? "https" : "http"; context.setFrontCacheProtocol(protocol); context.setOriginURL(getOriginUrl(context)); if (logToHeadersConfig || "true".equalsIgnoreCase(servletRequest.getHeader(FCHeaders.X_FRONTCACHE_TRACE))) { context.setLogToHTTPHeaders(); } String requestId = servletRequest.getHeader(FCHeaders.X_FRONTCACHE_REQUEST_ID); String requestType = FCHeaders.COMPONENT_INCLUDE; String includeLevelStr = servletRequest.getHeader(FCHeaders.X_FRONTCACHE_INCLUDE_LEVEL); if (null == requestId) { requestId = UUID.randomUUID().toString(); requestType = FCHeaders.COMPONENT_TOPLEVEL; } else { // can be include // or top_level (e.g. FC1 in scenario browser -> FC2 -> FC1 -> app ) if ("0".equals(includeLevelStr)) // it's second level FC (e.g. FC1 in scenario browser -> FC2 -> FC1 -> app ) { requestType = FCHeaders.COMPONENT_TOPLEVEL; } else { if (null != servletRequest.getHeader(FCHeaders.X_FRONTCACHE_ASYNC_INCLUDE)) requestType = FCHeaders.COMPONENT_ASYNC_INCLUDE; else requestType = FCHeaders.COMPONENT_INCLUDE; } context.setRequestFromFrontcache(); } if (null == includeLevelStr) includeLevelStr = INCLUDE_LEVEL_TOP_LEVEL; // default (top level) context.setIncludeLevel(includeLevelStr); // top level context.setRequestId(requestId); context.setRequestType(requestType); context.setClientType(getClientType(servletRequest, domainContex.getDomain())); // client type = bot | browser based on User-Agent Header and bots.conf if (null != filterChain) context.setFilterChain(filterChain); return context; }
From source file:org.dbflute.saflute.web.servlet.filter.RequestLoggingFilter.java
protected void buildRequestInfo(StringBuilder sb, HttpServletRequest request, HttpServletResponse response, boolean showResponse) { sb.append("Request class=" + request.getClass().getName()); sb.append(", RequestedSessionId=").append(request.getRequestedSessionId()); sb.append(LF).append(IND);//ww w .j a v a 2s . c o m sb.append(", REQUEST_URI=").append(request.getRequestURI()); sb.append(", SERVLET_PATH=").append(request.getServletPath()); sb.append(", CharacterEncoding=" + request.getCharacterEncoding()); sb.append(", ContentLength=").append(request.getContentLength()); sb.append(LF).append(IND); sb.append(", ContentType=").append(request.getContentType()); sb.append(", Locale=").append(request.getLocale()); sb.append(", Locales="); final Enumeration<?> locales = request.getLocales(); boolean first = true; while (locales.hasMoreElements()) { final Locale locale = (Locale) locales.nextElement(); if (first) { first = false; } else { sb.append(", "); } sb.append(locale.toString()); } sb.append(", Scheme=").append(request.getScheme()); sb.append(", isSecure=").append(request.isSecure()); sb.append(LF).append(IND); sb.append(", SERVER_PROTOCOL=").append(request.getProtocol()); sb.append(", REMOTE_ADDR=").append(request.getRemoteAddr()); sb.append(", REMOTE_HOST=").append(request.getRemoteHost()); sb.append(", SERVER_NAME=").append(request.getServerName()); sb.append(", SERVER_PORT=").append(request.getServerPort()); sb.append(LF).append(IND); sb.append(", ContextPath=").append(request.getContextPath()); sb.append(", REQUEST_METHOD=").append(request.getMethod()); sb.append(", PathInfo=").append(request.getPathInfo()); sb.append(", RemoteUser=").append(request.getRemoteUser()); sb.append(LF).append(IND); sb.append(", REQUEST_URL=").append(request.getRequestURL()); sb.append(LF).append(IND); sb.append(", QUERY_STRING=").append(request.getQueryString()); if (showResponse) { sb.append(LF).append(IND); buildResponseInfo(sb, request, response); } sb.append(LF); buildRequestHeaders(sb, request); buildRequestParameters(sb, request); buildCookies(sb, request); buildRequestAttributes(sb, request); buildSessionAttributes(sb, request); }
From source file:com.ah.be.common.NmsUtil.java
/** * The function will return the web application url String with http (not https) * * @param request -// w ww .ja v a 2 s.c o m * @return - */ public static String getWebAppHttpUrl(HttpServletRequest request) { String httpUrl; if (useHttpProxy) { // with proxy setting, the url will be hard coded httpUrl = "http://" + request.getServerName() + ":8080" + request.getContextPath() + "/"; } else { // rewrite by the request information if ("https".equals(request.getScheme())) { if (request.getServerPort() == 8443) { httpUrl = "http://" + request.getServerName() + ":8080" + request.getContextPath() + "/"; } else { httpUrl = "http://" + request.getServerName() + request.getContextPath() + "/"; } } else { httpUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/"; } } log.info("getWebAppHttpUrl", httpUrl); return httpUrl; }
From source file:jp.or.openid.eiwg.scim.servlet.Users.java
/** * POST?/*from w ww . j av a2s . c o m*/ * * @param request * @param response ? * @throws ServletException * @throws IOException */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // ? ServletContext context = getServletContext(); // ?? Operation op = new Operation(); boolean result = op.Authentication(context, request); if (!result) { // errorResponse(response, op.getErrorCode(), op.getErrorType(), op.getErrorMessage()); } else { // ? String targetId = request.getPathInfo(); String attributes = request.getParameter("attributes"); if (targetId != null && !targetId.isEmpty()) { // ?'/'??? targetId = targetId.substring(1); } if (targetId == null || targetId.isEmpty()) { // POST(JSON)? request.setCharacterEncoding("UTF-8"); String body = IOUtils.toString(request.getReader()); // ? LinkedHashMap<String, Object> resultObject = op.createUserInfo(context, request, attributes, body); if (resultObject != null) { // javaJSON?? ObjectMapper mapper = new ObjectMapper(); StringWriter writer = new StringWriter(); mapper.writeValue(writer, resultObject); // Location?URL? String location = request.getScheme() + "://" + request.getServerName(); int serverPort = request.getServerPort(); if (serverPort != 80 && serverPort != 443) { location += ":" + Integer.toString(serverPort); } location += request.getContextPath(); location += "/scim/Users/"; if (resultObject.get("id") != null) { location += resultObject.get("id").toString(); } // ?? response.setStatus(HttpServletResponse.SC_CREATED); response.setContentType("application/scim+json;charset=UTF-8"); response.setHeader("Location", location); PrintWriter out = response.getWriter(); out.println(writer.toString()); } else { // errorResponse(response, op.getErrorCode(), op.getErrorType(), op.getErrorMessage()); } } else { errorResponse(response, HttpServletResponse.SC_BAD_REQUEST, null, MessageConstants.ERROR_NOT_SUPPORT_OPERATION); } } }
From source file:org.jahia.params.ParamBean.java
@SuppressWarnings("unchecked") private void copyRequestData(final HttpServletRequest request) { if (request == null) { return;/*from ww w. jav a 2 s. c om*/ } if (isMultipartRequest(request)) { // multipart is processed only if it's not a portlet request. // otherwise it's the task the portlet if (!isPortletRequest(request)) { final String savePath = settings().getTmpContentDiskPath(); final File tmp = new File(savePath); if (!tmp.exists()) { tmp.mkdirs(); } try { fupload = new FileUpload(request, savePath, Integer.MAX_VALUE); Set<String> names = fupload.getParameterNames(); for (String name : names) { getCustomParameters().put(name, fupload.getParameterValues(name)); } } catch (IOException e) { logger.error("Cannot parse multipart data !", e); } } else { logger.debug("Mulipart request is not processed. It's the task of the portlet"); } } // first let's copy all the parameters from the request object getCustomParameters().putAll(request.getParameterMap()); setScheme(request.getScheme()); setRequestURI(request.getRequestURI()); setContextPath(request.getContextPath()); setServletPath(request.getServletPath()); setPathInfo(request.getPathInfo()); setQueryString(request.getQueryString()); setServerName(request.getServerName()); setServerPort(request.getServerPort()); setRemoteAddr(request.getRemoteAddr()); setSessionState(new HttpSessionState(request.getSession())); }