List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:org.onebusaway.webapp.actions.rss.TripProblemReportsAction.java
@Override public String execute() { AgencyBean agency = _transitDataService.getAgency(_agencyId); if (agency == null) return INPUT; Calendar c = Calendar.getInstance(); long timeTo = c.getTimeInMillis(); c.add(Calendar.DAY_OF_WEEK, -_days); long timeFrom = c.getTimeInMillis(); TripProblemReportQueryBean query = new TripProblemReportQueryBean(); query.setAgencyId(_agencyId);//from w w w . jav a2 s .c o m query.setTimeFrom(timeFrom); query.setTimeTo(timeTo); if (_status != null) query.setStatus(EProblemReportStatus.valueOf(_status)); query.setLabel(_label); ListBean<TripProblemReportBean> result = _transitDataService.getTripProblemReports(query); List<TripProblemReportBean> reports = result.getList(); _feed = new SyndFeedImpl(); StringBuilder title = new StringBuilder(); title.append(getText("rss.OneBusAwayTripProblemReports")); title.append(" - "); title.append(agency.getName()); title.append(" - "); title.append(getText("rss.LastXDays", Arrays.asList((Object) _days))); HttpServletRequest request = ServletActionContext.getRequest(); StringBuilder b = new StringBuilder(); b.append("http://"); b.append(request.getServerName()); if (request.getServerPort() != 80) b.append(":").append(request.getServerPort()); if (request.getContextPath() != null) b.append(request.getContextPath()); String baseUrl = b.toString(); _feed.setTitle(title.toString()); _feed.setLink(baseUrl); _feed.setDescription( getText("rss.UserSubmittedTripProblemReports", Arrays.asList((Object) agency.getName(), _days))); List<SyndEntry> entries = new ArrayList<SyndEntry>(); _feed.setEntries(entries); for (TripProblemReportBean report : reports) { StopBean stop = report.getStop(); TripBean trip = report.getTrip(); SyndEntry entry = new SyndEntryImpl(); StringBuilder entryTitle = new StringBuilder(); if (trip == null) { entryTitle.append("trip_id="); entryTitle.append(report.getTripId()); entryTitle.append(" (?)"); } else { entryTitle.append(RoutePresenter.getNameForRoute(trip)); entryTitle.append(" - "); entryTitle.append(trip.getTripHeadsign()); } if (stop == null) { entryTitle.append(" - stop_id="); entryTitle.append(report.getStopId()); entryTitle.append(" (?)"); } else { entryTitle.append(" - "); entryTitle.append(getText("StopNum", new String[] { stop.getCode() })); entryTitle.append(" - "); entryTitle.append(stop.getName()); if (stop.getDirection() != null) { entryTitle.append(" - "); entryTitle.append(getText("bound", new String[] { stop.getDirection() })); } } StringBuilder entryUrl = new StringBuilder(); entryUrl.append(baseUrl); entryUrl.append("/admin/problems/trip-problem-report.action?tripId="); entryUrl.append(report.getTripId()); entryUrl.append("&id="); entryUrl.append(report.getId()); StringBuilder entryDesc = new StringBuilder(); entryDesc.append(getText("Data")); entryDesc.append(": "); entryDesc.append(report.getData()); entryDesc.append("<br/>"); if (report.getUserComment() != null) { entryDesc.append(getText("Comment")); entryDesc.append(": "); entryDesc.append(report.getUserComment()); entryDesc.append("<br/>"); } if (report.getStatus() != null) { entryDesc.append(getText("Status")); entryDesc.append(": "); entryDesc.append(report.getStatus()); entryDesc.append("<br/>"); } entry = new SyndEntryImpl(); entry.setTitle(entryTitle.toString()); entry.setLink(entryUrl.toString()); entry.setPublishedDate(new Date(report.getTime())); SyndContent description = new SyndContentImpl(); description.setType("text/html"); description.setValue(entryDesc.toString()); entry.setDescription(description); entries.add(entry); } return SUCCESS; }
From source file:com.sibvisions.rad.server.security.spring.authentication.SecurityManagerPreparer.java
/** * Builds the absolute logout process URL based on the request instance <code>pRequest</code> and <code>logoutProcessUrl</code>. * //from w w w . ja v a2s . c om * @param pRequest the request to build the logout process URL * * @return the absolute logout process URL */ protected String buildAbsoluteLogoutProcessUrl(HttpServletRequest pRequest) { if (logoutProcessUrl.startsWith("./") || UrlUtils.isAbsoluteUrl(logoutProcessUrl)) { return logoutProcessUrl; } RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme(pRequest.getScheme()); urlBuilder.setServerName(pRequest.getServerName()); urlBuilder.setPort(portResolver.getServerPort(pRequest)); urlBuilder.setContextPath(pRequest.getContextPath()); urlBuilder.setPathInfo(logoutProcessUrl); return urlBuilder.getUrl(); }
From source file:flex.messaging.services.http.proxy.SecurityFilter.java
private void sendSecurityInfo(ProxyContext context) { Target target = context.getTarget(); String targetHost = target.getUrl().getHost(); int statusCode = 200; boolean customAuth = target.useCustomAuthentication(); StatusLine statusLine = context.getHttpMethod().getStatusLine(); if (statusLine != null) { statusCode = statusLine.getStatusCode(); }/*from w w w . j a v a2s . c o m*/ context.setStatusCode(statusCode); if (statusCode == 401 || statusCode == 403) { if (!customAuth) { if (!context.isHttpRequest()) { throw new ProxyException(NO_BASIC_NOT_HTTP); } else if (context.isSoapRequest()) { // Note: if we remove this error, must do the proxyDomain/targetHost check as done above throw new ProxyException(NO_BASIC_FOR_SOAP); } else { // Don't allow a 401 (and 403, although this should never happen) to be sent to the client // if the service is not using custom authentication and the domains do not match if (!context.isLocalDomainAndPort()) { HttpServletRequest clientRequest = FlexContext.getHttpRequest(); String errorMessage = ProxyConstants.DOMAIN_ERROR + " . The proxy domain:port is " + clientRequest.getServerName() + ":" + clientRequest.getServerPort() + " and the target domain:port is " + targetHost + ":" + target.getUrl().getPort(); Log.getLogger(HTTPProxyService.LOG_CATEGORY).error(errorMessage); throw new ProxyException(DOMAIN_ERROR); } else { //For BASIC Auth, send back the status code HttpServletResponse clientResponse = FlexContext.getHttpResponse(); clientResponse.setStatus(statusCode); } } } else { String message = null; if (statusLine != null) message = statusLine.toString(); if (statusCode == 401) { ProxyException se = new ProxyException(); se.setCode("Client.Authentication"); if (message == null) { se.setMessage(LOGIN_REQUIRED); } else { se.setMessage(EMPTY_ERROR, new Object[] { message }); } Header header = context.getHttpMethod().getResponseHeader(ProxyConstants.HEADER_AUTHENTICATE); if (header != null) se.setDetails(header.getValue()); throw se; } else { ProxyException se = new ProxyException(); se.setCode("Client.Authentication"); if (message == null) { se.setMessage(UNAUTHORIZED_ERROR); } else { se.setMessage(EMPTY_ERROR, new Object[] { message }); } throw se; } } } }
From source file:com.saint.spring.saml.web.MetadataController.java
protected String getBaseURL(HttpServletRequest request) { String baseURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();//from ww w.j av a 2 s . c o m log.debug("Base URL {}", baseURL); return baseURL; }
From source file:org.cagrid.identifiers.namingauthority.impl.NamingAuthorityService.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response)/* w w w . j av a 2s . c om*/ */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug("getPathInfo[" + request.getPathInfo() + "]"); LOG.debug("getQueryString[" + request.getQueryString() + "]"); LOG.debug("getRequestURI[" + request.getRequestURI() + "]"); LOG.debug("getRequestURL[" + request.getRequestURL() + "]"); LOG.debug("getServerName[" + request.getServerName() + "]"); LOG.debug("getServerPort[" + request.getServerPort() + "]"); LOG.debug("getServletPath[" + request.getServletPath() + "]"); LOG.debug("User Identity[" + request.getAttribute(GSIConstants.GSI_USER_DN)); processor.process(request, response); }
From source file:com.haulmont.cuba.core.sys.remoting.RemotingServlet.java
/** * Check correctness of some configuration parameters and log the warning if necessary. *//*www . ja v a2 s .c o m*/ protected void checkConfiguration(HttpServletRequest request) { if (!checkCompleted) { GlobalConfig config = AppBeans.get(Configuration.class).getConfig(GlobalConfig.class); if (config.getLogIncorrectWebAppPropertiesEnabled()) { StringBuilder sb = new StringBuilder(); if (!request.getServerName().equals(config.getWebHostName())) { sb.append("***** cuba.webHostName=").append(config.getWebHostName()).append(", actual=") .append(request.getServerName()).append("\n"); } if (request.getServerPort() != Integer.parseInt(config.getWebPort())) { sb.append("***** cuba.webPort=").append(config.getWebPort()).append(", actual=") .append(request.getServerPort()).append("\n"); } String contextPath = request.getContextPath(); if (contextPath.startsWith("/")) contextPath = contextPath.substring(1); if (!contextPath.equals(config.getWebContextName())) { sb.append("***** cuba.webContextName=").append(config.getWebContextName()).append(", actual=") .append(contextPath).append("\n"); } if (sb.length() > 0) { sb.insert(0, "\n*****\n"); sb.append("*****"); log.warn(" Invalid configuration parameters that may cause problems:" + sb.toString()); } } checkCompleted = true; } }
From source file:com.sdl.odata.controller.AbstractODataController.java
/** * In cases when {@link HttpServletRequest} is wrapped, request url will consist values from top wrapper now. * Instead of schema, port and server name from inner {@link org.apache.coyote.Request}. * Default case is when service is behind load balancer and {@link org.apache.catalina.filters.RemoteIpFilter} * is used for X-Forwarded headers.// w w w . j a v a 2 s . c o m * * @param request wrapped/original request. * @return request URL based on values from wrapping Request. */ private StringBuilder getRequestURL(HttpServletRequest request) { String scheme = request.getScheme(); int port = request.getServerPort(); if (port < 0) { port = DEFAULT_PORT_NUMBER; } StringBuilder url = new StringBuilder(); url.append(scheme); url.append("://"); url.append(request.getServerName()); if ((scheme.equals("http") && (port != DEFAULT_PORT_NUMBER)) || (scheme.equals("https") && (port != DEFAULT_SSL_PORT_NUMBER))) { url.append(':'); url.append(port); } url.append(request.getRequestURI()); return url; }
From source file:fi.okm.mpass.shibboleth.authn.impl.BaseInitializeWilmaContext.java
/** * Constructs an URL where the user is redirected for authentication. * @param flowExecutionUrl The current flow execution URL, to be included in the redirect URL. * @param authenticationContext The context, also containing {@link WilmaAuthenticationContext}. * @return The redirect URL containing the checksum. *//*w w w.ja v a 2 s .c om*/ public String getRedirect(final String flowExecutionUrl, final AuthenticationContext authenticationContext) { final HttpServletRequest httpRequest = getHttpServletRequest(); final WilmaAuthenticationContext wilmaContext = authenticationContext .getSubcontext(WilmaAuthenticationContext.class); final StringBuffer redirectToBuffer = new StringBuffer( httpRequest.getScheme() + "://" + httpRequest.getServerName()); if (httpRequest.getServerPort() != 443) { redirectToBuffer.append(":" + httpRequest.getServerPort()); } redirectToBuffer.append(flowExecutionUrl).append(getAsParameter("&", "_eventId_proceed", "1")); redirectToBuffer .append(getAsParameter("&", WilmaAuthenticationContext.PARAM_NAME_NONCE, wilmaContext.getNonce())); final URLCodec urlCodec = new URLCodec(); try { final StringBuffer unsignedUrlBuffer = new StringBuffer(wilmaContext.getRedirectUrl()); unsignedUrlBuffer.append(getAsParameter("?", WilmaAuthenticationContext.PARAM_NAME_REDIRECT_TO, urlCodec.encode(redirectToBuffer.toString()))); if (authenticationContext.isForceAuthn()) { unsignedUrlBuffer .append(getAsParameter("&", WilmaAuthenticationContext.PARAM_NAME_FORCE_AUTH, "true")); } final String redirectUrl = unsignedUrlBuffer.toString() + getAsParameter("&", WilmaAuthenticationContext.PARAM_NAME_CHECKSUM, calculateChecksum(Mac.getInstance(algorithm), unsignedUrlBuffer.toString(), signatureKey)); return redirectUrl; } catch (EncoderException | NoSuchAlgorithmException e) { log.error("{}: Could not encode the following URL {}", getLogPrefix(), redirectToBuffer, e); } return null; }
From source file:br.com.insula.spring.security.janrain.Janrain.java
public String getTokenUrl(HttpServletRequest request, String path) { Assert.notNull(request, "'request' cannot be null"); Assert.notNull(request, "'path' cannot be null"); Assert.isTrue(path.startsWith("/"), "path must start with '/'"); String scheme = request.getScheme(); int serverPort = request.getServerPort(); if (isRequestInDefaultPort(scheme, serverPort)) { return String.format("%s://%s%s", scheme, request.getServerName(), path); } else {/*from ww w .jav a 2 s . c o m*/ return String.format("%s://%s:%d%s", scheme, request.getServerName(), serverPort, path); } }
From source file:com.ewcms.component.rss.web.RssServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String encoding = DEFAULT_ENCODING; initResponseHeader(response, encoding); String value = getParameterValue(request, "id"); String rss = ""; try {/*from ww w . j a v a 2 s .co m*/ int id = Integer.valueOf(value); String dns = request.getServerName(); rss = constructRss(id, dns); } catch (Exception e) { StringBuilder builder = new StringBuilder(); builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?> "); builder.append("<rss version=\"2.0\">"); builder.append("</xml>"); rss = builder.toString(); } Writer writer = response.getWriter(); writer.write(rss); writer.flush(); }