List of usage examples for javax.servlet.http HttpServletRequest getServerPort
public int getServerPort();
From source file:eionet.util.Util.java
/** * * @param request// w w w . j a va 2s. c o m * @return */ public static String getBaseHref(HttpServletRequest request) { String protocol = request.getProtocol().toLowerCase(); int i = protocol.indexOf('/'); if (i >= 0) { protocol = protocol.substring(0, i); } StringBuffer buf = new StringBuffer(protocol); buf.append("://").append(request.getServerName()); if (request.getServerPort() > 0) { buf.append(":").append(request.getServerPort()); } if (request.getContextPath() != null) { buf.append(request.getContextPath()); } if (buf.toString().endsWith("/") == false) { buf.append("/"); } return buf.toString(); }
From source file:com.qualogy.qafe.web.upload.DatagridUploadServlet.java
@SuppressWarnings("unchecked") private void writeUploadInfo(HttpServletRequest request) { writeLog("Document Upload!"); Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { Object name = headerNames.nextElement(); if (name != null) { writeLog("Header - " + name + " : " + request.getHeader((String) name)); }/*from ww w. ja v a2 s .c o m*/ } writeLog("ServletRemoteAddr: " + request.getRemoteAddr()); writeLog("Remote Host: " + request.getRemoteHost()); writeLog("Remote User: " + request.getRemoteUser()); writeLog("Protocol: " + request.getProtocol()); writeLog("Server Name: " + request.getServerName()); writeLog("Server Port: " + request.getServerPort()); writeLog("Request URL: " + request.getRequestURL()); }
From source file:org.sample.interceptor.TestServlet.java
/** * Processes requests for both HTTP//w w w .j a v a 2s .com * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet TestServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>"); Client client = ClientBuilder.newClient(); client.register(MyClientReaderInterceptor.class).register(MyClientWriterInterceptor.class); WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/webresources/fruits"); System.out.println("GET request"); String result = target.request().get(String.class); out.println("Received response: " + result + "<br><br>"); System.out.println("POST request"); result = target.request().post(Entity.text("1"), String.class); out.println("Received response: " + result + "<br><br>"); out.println("Check server.log for client/server interceptor output."); out.println("</body>"); out.println("</html>"); }
From source file:seava.j4e.web.controller.ui.extjs.AbstractUiExtjsController.java
protected void _prepare(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/html;charset=UTF-8"); if (logger.isInfoEnabled()) { logger.info("Handling request for ui.extjs: ", request.getPathInfo()); }//w w w . j a v a 2s . c om String server = request.getServerName(); int port = request.getServerPort(); String userRolesStr = null; this.prepareRequest(request, response); try { ISessionUser su = (ISessionUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); IUser user = su.getUser(); IUserSettings prefs = user.getSettings(); Session.user.set(user); model.put("statics", BeansWrapper.getDefaultInstance().getStaticModels()); model.put("constantsJsFragment", this.getConstantsJsFragment()); model.put("user", user); DateFormatAttribute[] masks = DateFormatAttribute.values(); Map<String, String> dateFormatMasks = new HashMap<String, String>(); for (int i = 0, len = masks.length; i < len; i++) { DateFormatAttribute mask = masks[i]; if (mask.isForJs()) { dateFormatMasks.put(mask.name().replace("EXTJS_", ""), prefs.getDateFormatMask(mask.name())); } } model.put("dateFormatMasks", dateFormatMasks); model.put("modelDateFormat", this.getSettings().get(Constants.PROP_EXTJS_MODEL_DATE_FORMAT)); model.put("decimalSeparator", prefs.getDecimalSeparator()); model.put("thousandSeparator", prefs.getThousandSeparator()); StringBuffer sb = new StringBuffer(); int i = 0; for (String role : user.getProfile().getRoles()) { if (i > 0) { sb.append(","); } sb.append("\"" + role + "\""); i++; } userRolesStr = sb.toString(); } catch (ClassCastException e) { // not authenticated } String hostUrl = ((request.isSecure()) ? "https" : "http") + "://" + server + ((port != 80) ? (":" + port) : "");// + contextPath; model.put("productName", StringEscapeUtils.escapeJavaScript(this.getSettings().getProductName())); model.put("productDescription", this.getSettings().getProductDescription()); model.put("productVersion", this.getSettings().getProductVersion()); model.put("productVendor", this.getSettings().getProductVendor()); model.put("productUrl", this.getSettings().getProductUrl()); model.put("hostUrl", hostUrl); model.put("ctxpath", this.getSettings().get(Constants.PROP_CTXPATH)); // themes model.put("urlUiExtjsThemes", getUiExtjsSettings().getUrlThemes()); // DNet extjs components in core and modules model.put("urlUiExtjsLib", getUiExtjsSettings().getUrlLib()); model.put("urlUiExtjsCore", getUiExtjsSettings().getUrlCore()); model.put("urlUiExtjsCoreI18n", getUiExtjsSettings().getUrlCoreI18n()); model.put("urlUiExtjsModules", getUiExtjsSettings().getUrlModules()); model.put("urlUiExtjsModuleSubpath", getUiExtjsSettings().getModuleSubpath()); model.put("urlUiExtjsModuleUseBundle", getUiExtjsSettings().isModuleUseBundle()); String lang = this.resolveLang(request, response); model.put("shortLanguage", StringEscapeUtils.escapeJavaScript(lang)); String theme = this.resolveTheme(request, response); model.put("theme", StringEscapeUtils.escapeJavaScript(theme)); model.put("sysCfg_workingMode", this.getSettings().get(Constants.PROP_WORKING_MODE)); model.put("userRolesStr", userRolesStr); }
From source file:jp.or.openid.eiwg.scim.servlet.ResourceTypes.java
/** * GET?/* w w w . ja v a2s .co m*/ * * @param request * @param response ? * @throws ServletException * @throws IOException */ protected void doGet(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 { // location?URL? String location = request.getScheme() + "://" + request.getServerName(); int serverPort = request.getServerPort(); if (serverPort != 80 && serverPort != 443) { location += ":" + Integer.toString(serverPort); } location += request.getContextPath(); // ? @SuppressWarnings("unchecked") ArrayList<LinkedHashMap<String, Object>> resourceTypes = (ArrayList<LinkedHashMap<String, Object>>) context .getAttribute("ResourceTypes"); // location? Iterator<LinkedHashMap<String, Object>> resourceTypesIt = resourceTypes.iterator(); while (resourceTypesIt.hasNext()) { LinkedHashMap<String, Object> resourceTypeInfo = resourceTypesIt.next(); // meta? Object metaObject = SCIMUtil.getAttribute(resourceTypeInfo, "meta"); if (metaObject != null && metaObject instanceof LinkedHashMap) { @SuppressWarnings("unchecked") LinkedHashMap<String, Object> metaInfo = (LinkedHashMap<String, Object>) metaObject; Object locationInfo = SCIMUtil.getAttribute(metaInfo, "location"); if (locationInfo != null && locationInfo instanceof String) { String locationValue = String.format(locationInfo.toString(), location); metaInfo.put("location", locationValue); resourceTypeInfo.put("meta", metaInfo); } } } try { // javaJSON?? ObjectMapper mapper = new ObjectMapper(); StringWriter writer = new StringWriter(); mapper.writeValue(writer, resourceTypes); // ?? String listResponse = "{\"schemas\":[\"urn:ietf:params:scim:api:messages:2.0:ListResponse\"],"; listResponse += "\"totalResults\":" + resourceTypes.size(); if (resourceTypes.size() > 0) { listResponse += ",\"Resources\":"; listResponse += writer.toString(); } listResponse += "}"; response.setContentType("application/scim+json;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(listResponse); } catch (IOException e) { e.printStackTrace(); } } }
From source file:jp.or.openid.eiwg.scim.servlet.Schemas.java
/** * GET?//from w w w. j av a 2 s .c o m * * @param request * @param response ? * @throws ServletException * @throws IOException */ protected void doGet(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 { // location?URL? String location = request.getScheme() + "://" + request.getServerName(); int serverPort = request.getServerPort(); if (serverPort != 80 && serverPort != 443) { location += ":" + Integer.toString(serverPort); } location += request.getContextPath(); // ? @SuppressWarnings("unchecked") ArrayList<LinkedHashMap<String, Object>> schemas = (ArrayList<LinkedHashMap<String, Object>>) context .getAttribute("Schemas"); // location? Iterator<LinkedHashMap<String, Object>> schemasIt = schemas.iterator(); while (schemasIt.hasNext()) { LinkedHashMap<String, Object> schemaInfo = schemasIt.next(); // meta? Object metaObject = SCIMUtil.getAttribute(schemaInfo, "meta"); if (metaObject != null && metaObject instanceof LinkedHashMap) { @SuppressWarnings("unchecked") LinkedHashMap<String, Object> metaInfo = (LinkedHashMap<String, Object>) metaObject; Object locationInfo = SCIMUtil.getAttribute(metaInfo, "location"); if (locationInfo != null && locationInfo instanceof String) { String locationValue = String.format(locationInfo.toString(), location); metaInfo.put("location", locationValue); schemaInfo.put("meta", metaInfo); } } } try { // javaJSON?? ObjectMapper mapper = new ObjectMapper(); StringWriter writer = new StringWriter(); mapper.writeValue(writer, schemas); // ?? String listResponse = "{\"schemas\":[\"urn:ietf:params:scim:api:messages:2.0:ListResponse\"],"; listResponse += "\"totalResults\":" + schemas.size(); if (schemas.size() > 0) { listResponse += ",\"Resources\":"; listResponse += writer.toString(); } listResponse += "}"; response.setContentType("application/scim+json;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(listResponse); } catch (IOException e) { e.printStackTrace(); } } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstSMWar.CFAstSMWarLoginHtml.java
protected void sendConfirmationEMail(ICFAstSecDeviceObj defDev, HttpServletRequest request, ICFAstSecUserObj confirmUser, ICFAstClusterObj cluster) throws IOException, MessagingException, NamingException { String clusterDescription = cluster.getRequiredDescription(); String thisURI = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI().toString(); int lastSlash = thisURI.lastIndexOf('/'); String baseURI = thisURI.substring(0, lastSlash); UUID confirmationUUID = confirmUser.getOptionalEMailConfirmationUuid(); String msgBody = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" + "<HTML>\n" + "<BODY>\n" + "<p>\n" + "You requested a new account for " + confirmUser.getRequiredEMailAddress() + " with " + clusterDescription + ".\n" + "<p>" + "Please click on the following link to confirm your email address:<br>\n" + "<A HRef=\"" + baseURI + "/CFAstSMWarConfirmEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "\">" + baseURI + "/CFAstSMWarConfirmEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "</A>\n" + "<p>" + "Or click on the following link to cancel the request for a new account:<br>\n" + "<A HRef=\"" + baseURI + "/CFAstSMWarCancelEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "\">" + baseURI + "/CFAstSMWarCancelEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "</A>\n" + "</BODY>\n" + "</HTML>\n"; CFAstSMWarUtil warUtil = new CFAstSMWarUtil(); warUtil.sendEMailToUser(confirmUser, "You requested an account with " + clusterDescription + "?", msgBody); }
From source file:dk.itst.oiosaml.sp.configuration.ConfigurationHandler.java
protected String getBaseUrl(HttpServletRequest request) { String url = request.getRequestURL().toString(); log.info("url (old method): " + url); // might only be necessary because of my crazy pagekite setup --pdurbin // url = request.getScheme() url = "https" + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI(); log.info("url (new method): " + url); int idx = url.lastIndexOf(request.getServletPath()); return url.substring(0, idx + request.getServletPath().length()); }
From source file:org.ambraproject.action.FeedbackAction.java
@SuppressWarnings("unchecked") public Map<String, String> getUserSessionAttributes() { final Map<String, String> headers = new LinkedHashMap<String, String>(); final HttpServletRequest request = ServletActionContext.getRequest(); {/* w w w .j a v a2 s . c o m*/ final Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { final String headerName = (String) headerNames.nextElement(); final List<String> headerValues = EnumerationUtils.toList(request.getHeaders(headerName)); headers.put(headerName, StringUtils.join(headerValues.iterator(), ",")); } } headers.put("server-name", request.getServerName() + ":" + request.getServerPort()); headers.put("remote-addr", request.getRemoteAddr()); headers.put("local-addr", request.getLocalAddr() + ":" + request.getLocalPort()); /* * Keeping this in case more values get passed from the client other than just the visible form * fields */ { final Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { final String paramName = (String) parameterNames.nextElement(); final String[] paramValues = request.getParameterValues(paramName); headers.put(paramName, StringUtils.join(paramValues, ",")); } } return headers; }