List of usage examples for javax.servlet.http HttpServletRequest getServerPort
public int getServerPort();
From source file:com.spstudio.session.filter.SessionAOP.java
@Around(value = "@annotation(com.spstudio.session.UserSession)") public Object aroundManager(ProceedingJoinPoint pj) throws Exception { HttpServletRequest request = SysContent.getRequest(); HttpServletResponse response = SysContent.getResponse(); HttpSession session = SysContent.getSession(); String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; UserSessionType type = this.getSessionType(pj); if (type == null) { throw new Exception("The value of NeedSession is must."); }/*www . j av a 2 s . c o m*/ Object uobj = session.getAttribute("user"); Object mobj = session.getAttribute("manager"); boolean isUser = type == UserSessionType.USER && uobj != null; boolean isManager = type == UserSessionType.MANAGER && mobj != null; boolean isUserOrManager = type == UserSessionType.OR && (mobj != null || uobj != null); try { if (isUser || isManager || isUserOrManager) { return pj.proceed(); } else { // ?session if (request.getHeader("x-requested-with") != null && request.getHeader("x-requested-with").equalsIgnoreCase( //ajax? "XMLHttpRequest")) { response.addHeader("sessionstatus", "timeout"); // EasyUi //response.getWriter().print("{\"rows\":[],\"success\":false,\"total\":0}"); } else {//http? response.sendRedirect(basePath + "error/nosession"); } } } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.mycompany.frogsssa.testDD.java
@Override public void data(String source, byte[] data) { String msg = new String(data); System.out.println("DATA src: " + source + " d: " + msg); if (msg.substring(0, 10).equals("REGISTERED")) { if (!msg.contains(":")) { System.out.println("Wrong response format from the configuration architecture\n" + "Expected REGISTERED:<ID app> instead of " + msg); }// www . j a v a 2 s . c om String id = msg.split(":")[1]; //URI ad = uriInfo.getBaseUri(); MessageContext msgCtxt = ConnectionModule.wsCtxt.getMessageContext(); HttpServletRequest request = (HttpServletRequest) msgCtxt.get(MessageContext.SERVLET_REQUEST); String hostName = request.getServerName(); int port = request.getServerPort(); String contextPath = request.getContextPath(); String uri = "http://" + hostName + ":" + port + contextPath; this.publish("public." + id + "/restServer", uri); } ConnectionModule.someConfiguration(this.name, new String(data)); }
From source file:com.cpjit.swagger4j.support.struts2.ApiAction.java
private Properties loadSettings(HttpServletRequest request) throws IOException { Properties props = new Properties(); InputStream is = ResourceUtil.getResourceAsStream("swagger.properties"); props.load(is);/*from w w w . ja v a 2s .c om*/ String path = request.getContextPath(); String host = request.getServerName() + ":" + request.getServerPort() + path; props.setProperty("apiHost", host); String apiFile = props.getProperty("apiFile"); if (StringUtils.isBlank(apiFile)) { apiFile = DEFAULT_API_FILE; } String apiFilePath = request.getServletContext().getRealPath(apiFile); props.setProperty("apiFile", apiFilePath); if (StringUtils.isBlank(props.getProperty("devMode"))) { props.setProperty("devMode", devMode); } String suffix = props.getProperty("suffix"); if (StringUtils.isBlank(suffix)) { suffix = ""; } props.put("suffix", suffix); return props; }
From source file:com.qperior.gsa.oneboxprovider.QPOneBoxProviderServlet.java
/** * Called by the application server's servlet runner when GET method * requests are made for this servlet. OneBox clients (such as the * Google Search Appliance) make HTTP requests to OneBox providers * exclusivley using the GET method.//from w ww . ja v a 2 s. c o m */ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logHeaders(request); this.webAppBaseURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/"; processRequest(request, response); }
From source file:ManageDatasetFiles.java
public String getServerUrl(HttpServletRequest request) { String uri = request.getScheme() + "://" + // "http" + ":// request.getServerName() + // "myhost" ":" + // ":" request.getServerPort() + // "8080" request.getRequestURI();//+ // "/people" int lastbackslash = uri.lastIndexOf("/"); return uri.substring(0, lastbackslash); }
From source file:es.itecban.deployment.executionmanager.web.controller.UnitInverseDependenciesController.java
private String getXMLDependencyGraphURL(DeploymentUnitType unit, HttpServletRequest request) throws Exception { String file = request.getRequestURI(); if (request.getQueryString() != null) { file += '?' + request.getQueryString() + "&justGraph=true"; }/*w w w. jav a 2 s. c om*/ URL reconstructedURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), file); return reconstructedURL.toString(); }
From source file:org.magnum.dataup.VideoSvcCtrl.java
/** * Helps the helper method for getting the url of a video by * generating the urlbase for a local server *///from ww w . j a v a 2s .co m public String getUrlBaseForLocalServer() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); String base = "http://" + request.getServerName() + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : ""); return base; }
From source file:com.boyuanitsm.fort.web.rest.AccountResource.java
/** * POST /account/reset_password/init : Send an e-mail to reset the password of the user * * @param mail the mail of the user/* ww w . j av a 2 s.c o m*/ * @param request the HTTP request * @return the ResponseEntity with status 200 (OK) if the e-mail was sent, or status 400 (Bad Request) if the e-mail address is not registred */ @RequestMapping(value = "/account/reset_password/init", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) @Timed public ResponseEntity<?> requestPasswordReset(@RequestBody String mail, HttpServletRequest request) { return userService.requestPasswordReset(mail).map(user -> { String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); mailService.sendPasswordResetMail(user, baseUrl); return new ResponseEntity<>("e-mail was sent", HttpStatus.OK); }).orElse(new ResponseEntity<>("e-mail address not registered", HttpStatus.BAD_REQUEST)); }
From source file:org.jasig.portlet.notice.controller.rest.JPANotificationRESTController.java
/** * Build the URL for a specific notification. * * @param request the Http request/*from w w w .j a v a2 s . c om*/ * @param id the notification id * @return the URL to hit that specific id */ private String getSingleNotificationRESTUrl(HttpServletRequest request, long id) { String path = request.getContextPath() + API_ROOT + REQUEST_ROOT + id; try { URL url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), path); return url.toExternalForm(); } catch (MalformedURLException e) { // if it fails, just return a relative path. Not ideal, but better than nothing... log.warn("Error building Location header", e); return path; } }
From source file:com.twocharts.www.samples.apps.marketplace.OpenIdServlet.java
/** * Dynamically constructs the base URL for the application based on the current request * * @param request Current servlet request * @return Base URL (path to servlet context) *//* ww w .ja v a 2 s . c om*/ String baseUrl(HttpServletRequest request) { StringBuffer url = new StringBuffer(request.getScheme()).append("://").append(request.getServerName()); if ((request.getScheme().equalsIgnoreCase("http") && request.getServerPort() != 80) || (request.getScheme().equalsIgnoreCase("https") && request.getServerPort() != 443)) { url.append(":").append(request.getServerPort()); } return url.toString(); }