Example usage for javax.servlet.http HttpServletRequest getServerPort

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

Introduction

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

Prototype

public int getServerPort();

Source Link

Document

Returns the port number to which the request was sent.

Usage

From source file:it.cnr.icar.eric.server.interfaces.soap.RegistrySAMLServlet.java

/**
 * This method is a copy of the respective method from RegistrySOAPServlet.
 * It informs the user about GET requests and the corresponding URL for Web
 * Access.//from   ww w . j  ava 2  s  .  c om
 */

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("text/plain");

    String scheme = request.getScheme();
    String serverName = request.getServerName();

    String ericName = RegistryProperties.getInstance().getProperty("eric.name", "eric");

    int serverPort = request.getServerPort();

    StringBuffer sb = new StringBuffer();

    sb.append(scheme).append("://").append(serverName).append(':');
    sb.append(serverPort);
    sb.append('/');
    sb.append(ericName);
    sb.append("/registry/thin/browser.jsp");

    String url = sb.toString();

    PrintWriter wt = response.getWriter();

    wt.println(ServerResourceBundle.getInstance().getString("message.urlForSOAP"));
    wt.println(ServerResourceBundle.getInstance().getString("message.urlForWebAccess", new Object[] { url }));

    wt.flush();
    wt.close();
}

From source file:jp.co.opentone.bsol.framework.web.view.util.ViewHelper.java

private String getPort(HttpServletRequest request) {
    final int portHttp = 80;
    final int portHttps = 443;
    switch (request.getServerPort()) {
    case portHttp:
    case portHttps:
        return "";
    default://ww  w.j a v  a  2 s . c  om
        return String.format(":%s", request.getServerPort());
    }
}

From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java

@RequestMapping(value = "/pulseVersion", method = RequestMethod.GET)
public void pulseVersion(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // json object to be sent as response
    ObjectNode responseJSON = mapper.createObjectNode();

    try {/*from www.  ja v  a  2  s  .  c om*/
        // Reference to repository
        Repository repository = Repository.get();
        // set pulse web app url
        String pulseWebAppUrl = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + request.getContextPath();

        repository.setPulseWebAppUrl(pulseWebAppUrl);

        // Response
        responseJSON.put("pulseVersion", PulseController.pulseVersion.getPulseVersion());
        responseJSON.put("buildId", PulseController.pulseVersion.getPulseBuildId());
        responseJSON.put("buildDate", PulseController.pulseVersion.getPulseBuildDate());
        responseJSON.put("sourceDate", PulseController.pulseVersion.getPulseSourceDate());
        responseJSON.put("sourceRevision", PulseController.pulseVersion.getPulseSourceRevision());
        responseJSON.put("sourceRepository", PulseController.pulseVersion.getPulseSourceRepository());

    } catch (Exception e) {
        if (LOGGER.fineEnabled()) {
            LOGGER.fine("Exception Occured : " + e.getMessage());
        }
    }

    // Send json response
    response.getOutputStream().write(responseJSON.toString().getBytes());
}

From source file:org.italiangrid.voms.aa.x509.ACServlet.java

/**
 * /*from   www .j a v a2  s . c o m*/
 * @param request
 * @return
 */
protected RequestContext newRequestContext(HttpServletRequest request) {

    RequestContext context = RequestContextFactory.newContext();

    String subject = CurrentAdmin.instance().getRealSubject();

    String issuer = CurrentAdmin.instance().getRealIssuer();

    context.getRequest().setRequesterSubject(subject);
    context.getRequest().setRequesterIssuer(issuer);
    context.getRequest().setHolderSubject(subject);
    context.getRequest().setHolderIssuer(issuer);

    context.setVOName(VOMSConfiguration.instance().getVOName());
    context.setHost(VOMSConfiguration.instance().getHostname());
    context.setPort(request.getServerPort());

    return context;
}

From source file:com.pivotal.gemfire.tools.pulse.internal.controllers.PulseController.java

@RequestMapping(value = "/pulseVersion", method = RequestMethod.GET)
public void pulseVersion(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // json object to be sent as response
    JSONObject responseJSON = new JSONObject();

    try {/*from   w w w .j  ava2  s .c  o  m*/
        // Reference to repository
        Repository repository = Repository.get();
        // set pulse web app url
        String pulseWebAppUrl = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + request.getContextPath();

        repository.setPulseWebAppUrl(pulseWebAppUrl);

        // Response
        responseJSON.put("pulseVersion", PulseController.pulseVersion.getPulseVersion());
        responseJSON.put("buildId", PulseController.pulseVersion.getPulseBuildId());
        responseJSON.put("buildDate", PulseController.pulseVersion.getPulseBuildDate());
        responseJSON.put("sourceDate", PulseController.pulseVersion.getPulseSourceDate());
        responseJSON.put("sourceRevision", PulseController.pulseVersion.getPulseSourceRevision());
        responseJSON.put("sourceRepository", PulseController.pulseVersion.getPulseSourceRepository());

    } catch (JSONException eJSON) {
        LOGGER.logJSONError(eJSON, new String[] { "pulseVersionData :" + PulseController.pulseVersion });
    } catch (Exception e) {
        if (LOGGER.fineEnabled()) {
            LOGGER.fine("Exception Occured : " + e.getMessage());
        }
    }

    // Send json response
    response.getOutputStream().write(responseJSON.toString().getBytes());
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSMWar.CFAsteriskSMWarCreateNewAccountHtml.java

protected void sendConfirmationEMail(HttpServletRequest request, ICFSecuritySecUserObj confirmUser,
        ICFSecurityClusterObj cluster) throws IOException, MessagingException, NamingException {
    final String S_ProcName = "sendConfirmationEMail";

    Properties props = System.getProperties();
    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 login " + confirmUser.getRequiredLoginId() + " with "
            + clusterDescription + ".\n" + "<p>"
            + "Please click on the following link to confirm your email address:<br>\n" + "<A HRef=\"" + baseURI
            + "/CFAsteriskSMWarConfirmEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "\">"
            + baseURI + "/CFAsteriskSMWarConfirmEMailAddressHtml?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 + "/CFAsteriskSMWarCancelEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString()
            + "\">" + baseURI + "/CFAsteriskSMWarCancelEMailAddressHtml?ConfirmationUUID="
            + confirmationUUID.toString() + "</A>\n" + "</BODY>\n" + "</HTML>\n";

    CFAsteriskSMWarUtil warUtil = new CFAsteriskSMWarUtil();
    warUtil.sendEMailToUser(confirmUser, "You requested an account with " + clusterDescription + "?", msgBody);
}

From source file:org.apache.atlas.web.filters.AtlasKnoxSSOAuthenticationFilter.java

/**
 * Create the URL to be used for authentication of the user in the absence
 * of a JWT token within the incoming request.
 *
 * @param request for getting the original request URL
 * @return url to use as login url for redirect
 *//* w w  w .jav  a 2  s. c  om*/
protected String constructLoginURL(HttpServletRequest request, boolean isXMLRequest) {
    String delimiter = "?";
    if (authenticationProviderUrl.contains("?")) {
        delimiter = "&";
    }
    StringBuilder loginURL = new StringBuilder();
    if (isXMLRequest) {
        String atlasApplicationURL = "";
        String referalURL = request.getHeader("referer");

        if (referalURL == null) {
            atlasApplicationURL = request.getScheme() + "://" + request.getServerName() + ":"
                    + request.getServerPort() + request.getContextPath();
        } else {
            atlasApplicationURL = referalURL;
        }

        loginURL.append(authenticationProviderUrl).append(delimiter).append(originalUrlQueryParam).append("=")
                .append(atlasApplicationURL);
    } else {
        loginURL.append(authenticationProviderUrl).append(delimiter).append(originalUrlQueryParam).append("=")
                .append(request.getRequestURL().append(getOriginalQueryString(request)));
    }
    return loginURL.toString();
}

From source file:com.linkcm.core.sso.CasAuthenticationEntryPoint.java

public final void commence(final HttpServletRequest servletRequest, final HttpServletResponse response,
        final AuthenticationException authenticationException) throws IOException, ServletException {
    StringBuilder tempLoginUrl = new StringBuilder();
    StringBuilder serverUrl = new StringBuilder();
    StringBuilder clientUrl = new StringBuilder();

    tempLoginUrl.append(servletRequest.getScheme()).append("://");
    tempLoginUrl.append(servletRequest.getServerName());

    if (serverPort != null && !"".equals(serverPort)) {
        serverUrl.append(tempLoginUrl).append(":").append(serverPort);
    }//from  w  ww  .  j  a  v  a  2 s . c o  m
    serverUrl.append("/cas/login");
    loginUrl = serverUrl.toString();

    if (clientPort != null && !"".equals(clientPort)) {
        clientUrl.append(tempLoginUrl).append(":").append(servletRequest.getServerPort());
        clientUrl.append(servletRequest.getContextPath());
        clientUrl.append("/j_spring_cas_security_check");
        serviceProperties.setService(clientUrl.toString());
    }

    final String urlEncodedService = createServiceUrl(servletRequest, response);
    final String redirectUrl = createRedirectUrl(urlEncodedService);

    preCommence(servletRequest, response);
    response.sendRedirect(redirectUrl);
}

From source file:it.cnr.icar.eric.server.interfaces.soap.RegistryBSTServlet.java

@SuppressWarnings("unused")
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");

    String requestUri = req.getRequestURI();
    String servletPath = req.getServletPath();
    String scheme = req.getScheme();
    String serverName = req.getServerName();
    String queryString = req.getQueryString();
    String ericName = RegistryProperties.getInstance().getProperty("eric.name", "eric");
    int serverPort = req.getServerPort();
    StringBuffer sb = new StringBuffer();
    sb.append(scheme).append("://").append(serverName).append(':');
    sb.append(serverPort);//from w w w. j ava 2  s . co  m
    sb.append('/');
    sb.append(ericName);
    sb.append("/registry/thin/browser.jsp");
    String url = sb.toString();

    PrintWriter wt = resp.getWriter();
    wt.println(ServerResourceBundle.getInstance().getString("message.urlForSOAP"));
    wt.println(ServerResourceBundle.getInstance().getString("message.urlForWebAccess", new Object[] { url }));
    wt.flush();
    wt.close();
}