Example usage for javax.servlet ServletRequest getServerPort

List of usage examples for javax.servlet ServletRequest getServerPort

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getServerPort.

Prototype

public int getServerPort();

Source Link

Document

Returns the port number to which the request was sent.

Usage

From source file:de.iteratec.iteraplan.businesslogic.common.URLBuilder.java

/**
 * Retrieves the URL of the server. It is also needed in case of ServletReqeusts, where
 * ContextPath is not available, so URL is without application name. It should be something like:
 * https://localhost:8443 This method is private because the iteraplan.properties are not checked
 * to see if the user has entered an application url by hand as in the other methods. Therefore
 * there could be problems if this method is used directly and the user depends on the property
 * setting.// ww w.j  a va  2 s . c o  m
 * 
 * @param req
 *          The current servlet request providing the necessary information.
 * @return The constructed application URL.
 */
private static String getServerURL(ServletRequest req) {
    StringBuilder serverUrl = new StringBuilder(BUFFER_SIZE);

    serverUrl.append(req.getScheme());
    serverUrl.append(COLON);
    serverUrl.append(FORWARD_SLASH);
    serverUrl.append(FORWARD_SLASH);
    serverUrl.append(req.getServerName());

    int port = req.getServerPort();
    if (port != WEB_PORT) {
        serverUrl.append(COLON);
        serverUrl.append(Integer.toString(port));
    }

    return serverUrl.toString();
}

From source file:org.kie.appformer.backend.server.service.build.BuildAndDeployCallable.java

private void fireAppReadyEvent(File war, ServletRequest sreq) {
    final String url = "http://" + sreq.getServerName() + ":" + sreq.getServerPort() + "/"
            + war.getName().replace(".war", "");

    appReadyEvent.fire(new AppReady(url));
}

From source file:no.sesat.search.http.filters.SiteLocatorFilter.java

private static String getServerName(final ServletRequest servletRequest) {

    // find the current site. Since we are behind a ajp13 connection request.getServerName() won't work!
    // httpd.conf needs:
    //      1) "JkEnvVar SERVER_NAME" inside the virtual host directive.
    //      2) "UseCanonicalName Off" to assign ServerName from client's request.
    return null != servletRequest.getAttribute("SERVER_NAME")
            ? (String) servletRequest.getAttribute("SERVER_NAME")
            // falls back to this when not behind Apache. (Development machine).
            : servletRequest.getServerName() + ":" + servletRequest.getServerPort();
}

From source file:com.sourcesense.alfresco.opensso.AlfrescoOpenSSOFilter.java

protected String buildURLForRedirect(ServletRequest request) {
    String serverURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    String alfrescoContext = ((HttpServletRequest) request).getContextPath();
    return getOpenSSOLoginURL().concat("?goto=").concat(serverURL).concat(alfrescoContext);
}

From source file:GetKey.java

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    String key = getInitParameter("key");
    String host = req.getServerName();
    int port = req.getServerPort();

    if (!keyFitsServer(key, host, port)) {
        out.println("Pirated!");
    } else {//from  ww w  .  java  2s.co m
        out.println("Valid");
    }
}

From source file:pt.webdetails.cdc.plugin.CdcContentGenerator.java

private String getRoot() {

    ServletRequest wrapper = getRequest();
    String root = wrapper.getServerName() + ":" + wrapper.getServerPort();

    return root;//from www . j a va  2  s.  c o m
}

From source file:com.netpace.cms.sso.filter.AlfrescoOpenSSOFilter.java

protected String buildURLForRedirect(ServletRequest request) {
    String serverURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    String alfrescoContext = ((HttpServletRequest) request).getContextPath();
    System.out.println("ServerURL: " + serverURL);
    return getOpenSSOLoginURL().concat("?goto=").concat(serverURL).concat(alfrescoContext);
}

From source file:ServerSnoop.java

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    ServletContext context = getServletContext();
    out.println("req.getServerName(): " + req.getServerName());
    out.println("req.getServerPort(): " + req.getServerPort());
    out.println("context.getServerInfo(): " + context.getServerInfo());
    out.println("getServerInfo() name: " + getServerInfoName(context.getServerInfo()));
    out.println("getServerInfo() version: " + getServerInfoVersion(context.getServerInfo()));
    out.println("context.getAttributeNames():");
    Enumeration e = context.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println("  context.getAttribute(\"" + name + "\"): " + context.getAttribute(name));
    }//from w  w  w  .  ja v a2s  . c  o m
}

From source file:org.niord.core.NiordApp.java

/**
 * Registers the server name associated with the current thread (i.e. servlet request)
 * @param req the servlet request//from  ww  w .  j av a  2  s .  com
 */
public void registerServerNameForCurrentThread(ServletRequest req) {
    String scheme = StringUtils.defaultIfBlank(req.getScheme(), "http");
    String serverName = StringUtils.defaultIfBlank(req.getServerName(), "localhost");
    String port = (scheme.equalsIgnoreCase("https"))
            ? (req.getServerPort() == 443 ? "" : ":" + req.getServerPort())
            : (req.getServerPort() == 80 ? "" : ":" + req.getServerPort());
    if (StringUtils.isNotBlank(serverName)) {
        THREAD_LOCAL_SERVER_NAME.set(scheme + "://" + serverName + port);
    }
}

From source file:com.castlemock.web.mock.soap.web.mvc.controller.port.SoapPortController.java

/**
 * Returns an port that matches the incoming parameters (soapProjectId and soapPortId)
 * @param soapProjectId The id of the project which the port belongs to
 * @param soapPortId The id of the port that should be returned
 * @param request The incoming servlet request. Used to extract the address used to invoke the SOAP operation
 * @return Returns an port that matches the incoming parameters (projectId and soapPortId)
 */// w ww  .j  a  v a2  s  .c  o m
@PreAuthorize("hasAuthority('READER') or hasAuthority('MODIFIER') or hasAuthority('ADMIN')")
@RequestMapping(value = "/{soapProjectId}/port/{soapPortId}", method = RequestMethod.GET)
public ModelAndView getSoapPort(@PathVariable final String soapProjectId, @PathVariable final String soapPortId,
        final ServletRequest request) {
    final ReadSoapPortOutput readSoapPortOutput = serviceProcessor
            .process(new ReadSoapPortInput(soapProjectId, soapPortId));
    final SoapPortDto soapPort = readSoapPortOutput.getSoapPort();
    final String protocol = getProtocol(request);
    final String invokeAddress = getSoapInvokeAddress(protocol, request.getServerPort(), soapProjectId,
            soapPort.getUri());

    soapPort.setInvokeAddress(invokeAddress);
    final ModelAndView model = createPartialModelAndView(PAGE);
    model.addObject(SOAP_PROJECT_ID, soapProjectId);
    model.addObject(SOAP_PORT, soapPort);
    model.addObject(SOAP_OPERATION_STATUSES, getSoapOperationStatuses());
    model.addObject(SOAP_OPERATION_MODIFIER_COMMAND, new SoapOperationModifierCommand());
    return model;
}