Example usage for javax.servlet.http HttpServletRequest getServerName

List of usage examples for javax.servlet.http HttpServletRequest getServerName

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getServerName.

Prototype

public String getServerName();

Source Link

Document

Returns the host name of the server to which the request was sent.

Usage

From source file:uk.ac.ebi.intact.editor.controller.misc.MyNotesController.java

public MyNotesController() {
    this.queryMacros = new ArrayList<QueryMacro>();

    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    this.absoluteContextPath = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + request.getContextPath();
}

From source file:edu.indiana.d2i.sloan.ui.LoginSuccessAction.java

private String getServerContext() {
    HttpServletRequest request = getServletRequest();
    final StringBuilder serverPath = new StringBuilder();
    serverPath.append(request.getScheme() + "://");
    serverPath.append(request.getServerName());
    if (request.getServerPort() != 80) {
        serverPath.append(":" + request.getServerPort());
    }//  w w w  . j a  v a  2s .  co m
    serverPath.append(request.getContextPath());
    return serverPath.toString();
}

From source file:org.jasig.portlet.notice.controller.rest.JPANotificationRESTController.java

/**
 * Build the URL for a specific notification.
 *
 * @param request the Http request//from  www.  j a  v a 2s . 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.meltmedia.cadmium.servlets.jersey.StatusService.java

@GET
@Path("/health")
@Produces("text/plain")
public String health(@Context HttpServletRequest request) {
    StringBuilder builder = new StringBuilder();
    builder.append("Server: " + request.getServerName() + "\n");
    builder.append("Scheme: " + request.getScheme() + "\n");
    builder.append("Port: " + request.getServerPort() + "\n");
    builder.append("ContextPath:  " + request.getContextPath() + "\n");
    builder.append("ServletPath: " + request.getServletPath() + "\n");
    builder.append("Uri: " + request.getRequestURI() + "\n");
    builder.append("Query: " + request.getQueryString() + "\n");
    Enumeration<?> headerNames = request.getHeaderNames();
    builder.append("Headers:\n");
    while (headerNames.hasMoreElements()) {
        String name = (String) headerNames.nextElement();
        Enumeration<?> headers = request.getHeaders(name);
        builder.append("  '" + name + "':\n");
        while (headers.hasMoreElements()) {
            String headerValue = (String) headers.nextElement();
            builder.append("    -" + headerValue + "\n");
        }/*from   ww  w .j  a  v  a  2 s  .  co  m*/
    }
    if (request.getCookies() != null) {
        builder.append("Cookies:\n");
        for (Cookie cookie : request.getCookies()) {
            builder.append("  '" + cookie.getName() + "':\n");
            builder.append("    value: " + cookie.getValue() + "\n");
            builder.append("    domain: " + cookie.getDomain() + "\n");
            builder.append("    path: " + cookie.getPath() + "\n");
            builder.append("    maxAge: " + cookie.getMaxAge() + "\n");
            builder.append("    version: " + cookie.getVersion() + "\n");
            builder.append("    comment: " + cookie.getComment() + "\n");
            builder.append("    secure: " + cookie.getSecure() + "\n");
        }
    }
    return builder.toString();
}

From source file:org.openmrs.module.webservices.rest.web.controller.SwaggerSpecificationController.java

@RequestMapping(method = RequestMethod.GET)
public @ResponseBody String getSwaggerSpecification(HttpServletRequest request) throws Exception {

    String swaggerSpecificationJSON = "";
    StringBuilder baseUrl = new StringBuilder();
    String scheme = request.getScheme();
    int port = request.getServerPort();

    baseUrl.append(scheme); // http, https
    baseUrl.append("://");
    baseUrl.append(request.getServerName());
    if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) {
        baseUrl.append(':');
        baseUrl.append(request.getServerPort());
    }// ww  w.j  ava  2  s  .  c  o m

    baseUrl.append(request.getContextPath());

    String resourcesUrl = Context.getAdministrationService()
            .getGlobalProperty(RestConstants.URI_PREFIX_GLOBAL_PROPERTY_NAME, baseUrl.toString());

    if (!resourcesUrl.endsWith("/")) {
        resourcesUrl += "/";
    }

    resourcesUrl += "ws/rest";

    String urlWithoutScheme = "";

    /* Swagger appends scheme to urls, so we should remove it */
    if (scheme.equals("http"))
        urlWithoutScheme = resourcesUrl.replace("http://", "");

    else if (scheme.equals("https"))
        urlWithoutScheme = resourcesUrl.replace("https://", "");

    SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(urlWithoutScheme);

    swaggerSpecificationJSON = creator.BuildJSON();

    return swaggerSpecificationJSON;

}

From source file:seava.j4e.web.controller.ui.extjs.UiExtjsFrameController.java

/**
 * Helper method to create , configure and return an DependencyLoader
 * instance/*from   www.ja  va  2  s . c  o  m*/
 * 
 * @return
 */
private DependencyLoader getDependencyLoader(HttpServletRequest request) {
    String protocol = "http";
    if (request.getProtocol().startsWith("HTTPS")) {
        protocol = "https";
    }
    String host = protocol + "://" + request.getServerName();
    if (request.getServerPort() != 80) {
        host += ":" + request.getServerPort();
    }
    host += "/";
    if (logger.isDebugEnabled()) {
        logger.debug("Get dependency loader for host: " + host + ", modules url: "
                + getUiExtjsSettings().getUrlModules());
    }
    DependencyLoader loader = new DependencyLoader(host);
    loader.setUrlUiExtjsModules(getUiExtjsSettings().getUrlModules());
    loader.setModuleUseBundle(getUiExtjsSettings().isModuleUseBundle());
    loader.setUrlUiExtjsModuleSubpath(getUiExtjsSettings().getModuleSubpath());
    return loader;
}

From source file:it.cnr.icar.eric.client.ui.thin.RegistryBrowser.java

private static String getRegistryUrl() {
    ProviderProperties props = ProviderProperties.getInstance();
    String registryUrl = props.getProperty("jaxr-ebxml.soap.url");

    if (registryUrl == null || registryUrl.length() == 0) {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
                .getRequest();// w w  w.j a v a  2s .  co  m
        final String SUFFIX = "/registry/soap";
        try {
            URL url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(),
                    request.getContextPath() + SUFFIX);
            registryUrl = url.toString();
        } catch (MalformedURLException e) {
            // This should not happen
            log.error(WebUIResourceBundle.getInstance().getString("message.FailedToDefineRegistrySoapURL"), e);
        }
    }
    props.put("javax.xml.registry.queryManagerURL", registryUrl);
    return registryUrl;
}

From source file:cn.edu.zjnu.acm.judge.user.ResetPasswordController.java

private String getPath(HttpServletRequest request, String... params) {
    int serverPort = request.getServerPort();
    int defaultPort = request.isSecure() ? 443 : 80;
    StringBuilder sb = new StringBuilder(80);

    sb.append(request.getScheme()).append("://").append(request.getServerName());
    if (serverPort != defaultPort) {
        sb.append(":").append(serverPort);
    }/*from  w  ww. j  ava 2 s .c  o m*/
    sb.append(request.getContextPath());
    for (String param : params) {
        sb.append(param);
    }
    return sb.toString();
}

From source file:com.aimluck.eip.services.social.gadgets.ALGadgetContext.java

public String getServerBase() {
    HttpServletRequest request = ((JetspeedRunData) runData).getRequest();

    StringBuilder builder = new StringBuilder();
    String scheme = request.getScheme();
    String serverName = request.getServerName();
    int serverPort = request.getServerPort();

    builder.append(scheme).append("://");
    if (isLockedDomainRequired()) {
        byte[] sha1 = DigestUtils.sha(appUrl);
        String hash = new String(Base32.encodeBase32(sha1));
        builder.append(hash).append(getLockedDomainSuffix());
    } else {/* w w w  .j  av  a2s  .  c  o m*/
        builder.append(serverName);
        if (serverPort != 80 || serverPort != 443) {
            builder.append(":").append(serverPort);
        }
    }
    String containerPath = JetspeedResources.getString("aipo.container.path");

    return builder.append(containerPath == null ? "" : containerPath).append("/gadgets/").toString();
}

From source file:org.onebusaway.webapp.actions.rss.StopProblemReportsAction.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();

    StopProblemReportQueryBean query = new StopProblemReportQueryBean();
    query.setAgencyId(_agencyId);/*from w w  w .  j a  va  2  s.  co m*/
    query.setTimeFrom(timeFrom);
    query.setTimeTo(timeTo);
    if (_status != null)
        query.setStatus(EProblemReportStatus.valueOf(_status));

    ListBean<StopProblemReportBean> result = _transitDataService.getStopProblemReports(query);
    List<StopProblemReportBean> reports = result.getList();

    _feed = new SyndFeedImpl();

    StringBuilder title = new StringBuilder();
    title.append(getText("rss.OneBusAwayStopProblemReports"));
    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.UserSubmittedStopProblemReports", Arrays.asList((Object) agency.getName(), _days)));

    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    _feed.setEntries(entries);

    for (StopProblemReportBean report : reports) {

        StopBean stop = report.getStop();
        SyndEntry entry = new SyndEntryImpl();

        StringBuilder entryTitle = new StringBuilder();
        if (stop == null) {
            entryTitle.append("stopId=");
            entryTitle.append(report.getStopId());
            entryTitle.append(" (?)");
        } else {
            entryTitle.append(getText("StopNum", Arrays.asList(stop.getCode())));
            entryTitle.append(" - ");
            entryTitle.append(stop.getName());
            if (stop.getDirection() != null)
                entryTitle.append(" - ").append(getText("bound", Arrays.asList(stop.getDirection())));
        }

        StringBuilder entryUrl = new StringBuilder();
        entryUrl.append(baseUrl);
        entryUrl.append("/admin/problems/stop-problem-reports!edit.action?stopId=");
        entryUrl.append(report.getStopId());
        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;
}