List of usage examples for javax.servlet.http HttpServletRequest getServerPort
public int getServerPort();
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 v a 2s .c o m*/ 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.ikon.util.WebUtils.java
/** * Prepare to send the file.// w w w .j ava 2s .co m */ public static void prepareSendFile(HttpServletRequest request, HttpServletResponse response, String fileName, String mimeType, boolean inline) throws UnsupportedEncodingException { String agent = request.getHeader("USER-AGENT"); // Disable browser cache response.setHeader("Expires", "Sat, 6 May 1971 12:00:00 GMT"); response.setHeader("Cache-Control", "must-revalidate"); response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate"); response.addHeader("Cache-Control", "post-check=0, pre-check=0"); response.setHeader("Pragma", "no-cache"); // Set MIME type response.setContentType(mimeType); if (null != agent && -1 != agent.indexOf("MSIE")) { log.debug("Agent: Explorer ({})", request.getServerPort()); fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", " "); if (request.getServerPort() == 443) { log.debug("HTTPS detected! Apply IE workaround..."); response.setHeader("Cache-Control", "max-age=1"); response.setHeader("Pragma", "public"); } } else if (null != agent && -1 != agent.indexOf("Mozilla")) { log.debug("Agent: Mozilla"); fileName = MimeUtility.encodeText(fileName, "UTF-8", "B"); } else { log.debug("Agent: Unknown"); } if (inline) { response.setHeader("Content-disposition", "inline; filename=\"" + fileName + "\""); } else { response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\""); } }
From source file:org.opendatakit.dwc.server.GreetingServiceImpl.java
public static String getServerURL(HttpServletRequest req, String relativeServletPath, boolean preserveQS) { // for now, only store the servlet context and the serverUrl String path = req.getContextPath(); Integer identifiedPort = req.getServerPort(); String identifiedHostname = req.getServerName(); if (identifiedHostname == null || identifiedHostname.length() == 0 || identifiedHostname.equals("0.0.0.0")) { try {//from www . java2s . c o m identifiedHostname = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { identifiedHostname = "127.0.0.1"; } } String identifiedScheme = "http"; if (identifiedPort == null || identifiedPort == 0) { if (req.getScheme().equals(identifiedScheme)) { identifiedPort = req.getServerPort(); } else { identifiedPort = HtmlConsts.WEB_PORT; } } boolean expectedPort = (identifiedScheme.equalsIgnoreCase("http") && identifiedPort == HtmlConsts.WEB_PORT) || (identifiedScheme.equalsIgnoreCase("https") && identifiedPort == HtmlConsts.SECURE_WEB_PORT); String serverUrl; if (!expectedPort) { serverUrl = identifiedScheme + "://" + identifiedHostname + BasicConsts.COLON + Integer.toString(identifiedPort) + path; } else { serverUrl = identifiedScheme + "://" + identifiedHostname + path; } String query = req.getQueryString(); if (query == null) { if (req.getServletPath().equals("/demowebclient/greet")) { if (CLIENT_WEBSITE_CODESVR_PORT.length() != 0) { query = "gwt.codesvr=127.0.0.1:" + CLIENT_WEBSITE_CODESVR_PORT; } else { query = ""; } } else { query = ""; } } if (query.length() != 0) { query = "?" + query; } return serverUrl + BasicConsts.FORWARDSLASH + relativeServletPath + (preserveQS ? query : ""); }
From source file:org.intermine.web.util.URLGenerator.java
private String getCurrentURL(HttpServletRequest request, String contextPath) { String port = ""; if (request.getServerPort() != 80) { port = ":" + request.getServerPort(); }/* w ww. j a va2s.c o m*/ String ret = request.getScheme() + "://" + request.getServerName() + port; if (contextPath.length() > 0) { ret += contextPath; } return ret; }
From source file:com.inferlytics.druidlet.resource.DruidResource.java
@POST @Consumes(MediaType.APPLICATION_JSON)//from ww w.j a va 2 s . c o m @Produces(MediaType.APPLICATION_JSON) public Response query(@Context HttpServletRequest req, String queryJson) { try { String indexKey = String.valueOf(req.getServerPort()); return Response.ok(Utils.JSON_MAPPER.writeValueAsString(DruidService.handleQuery(indexKey, queryJson))) .build(); } catch (JsonMappingException e) { return Response.status(Response.Status.BAD_REQUEST).entity(new FailureResponse(e.getMessage())).build(); } catch (Exception e) { LOG.error("Exception while handling query", e); return Response.serverError().entity(new FailureResponse("Internal Server Error")).build(); } }
From source file:org.simbasecurity.core.service.http.ChangePasswordController.java
private String reconstructSimbaWebURL(HttpServletRequest request) { return request.getScheme() + "://" + request.getServerName() + (request.getServerPort() != 80 ? ":" + request.getServerPort() : "") + request.getContextPath(); }
From source file:org.apache.archiva.web.api.DefaultRuntimeInfoService.java
protected String getBaseUrl(HttpServletRequest req) { return req.getScheme() + "://" + req.getServerName() + (req.getServerPort() == 80 ? "" : ":" + req.getServerPort()) + req.getContextPath(); }
From source file:com.github.javarch.jsf.context.FacesContextUtils.java
/** * Retorna o caminho da aplicao, incluindo protocolo http. * /* ww w . j av a 2 s . c o m*/ * @return Caminho da aplicao */ public String getApplicationPath() { HttpServletRequest request = getRequest(); return request.getScheme() + "://" + request.getServerName() + (request.getServerPort() != 80 ? ":" + request.getServerPort() : "") + request.getContextPath(); }
From source file:org.ow2.chameleon.everest.servlet.PathSerializer.java
public PathSerializer(HttpServletRequest request, String servletPath) { if (request != null) { m_server = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + servletPath;/*from ww w. java 2 s . c o m*/ } else { // No request, just keep the path as it is. m_server = ""; } }
From source file:fr.paris.lutece.util.http.SecurityUtil.java
/** * Write request variables into the dump stringbuffer * @param sb The dump stringbuffer//from ww w. ja v a2 s . co m * @param request The HTTP request */ private static void dumpVariables(StringBuffer sb, HttpServletRequest request) { dumpVariable(sb, "AUTH_TYPE", request.getAuthType()); dumpVariable(sb, "REQUEST_METHOD", request.getMethod()); dumpVariable(sb, "PATH_INFO", request.getPathInfo()); dumpVariable(sb, "PATH_TRANSLATED", request.getPathTranslated()); dumpVariable(sb, "QUERY_STRING", request.getQueryString()); dumpVariable(sb, "REQUEST_URI", request.getRequestURI()); dumpVariable(sb, "SCRIPT_NAME", request.getServletPath()); dumpVariable(sb, "LOCAL_ADDR", request.getLocalAddr()); dumpVariable(sb, "SERVER_PROTOCOL", request.getProtocol()); dumpVariable(sb, "REMOTE_ADDR", request.getRemoteAddr()); dumpVariable(sb, "REMOTE_HOST", request.getRemoteHost()); dumpVariable(sb, "HTTPS", request.getScheme()); dumpVariable(sb, "SERVER_NAME", request.getServerName()); dumpVariable(sb, "SERVER_PORT", String.valueOf(request.getServerPort())); }