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:org.apache.catalina.authenticator.DigestAuthenticator.java

/**
 * Generates the WWW-Authenticate header.
 * <p>//from   w ww  . j  a v  a  2s  .  c om
 * The header MUST follow this template :
 * <pre>
 *      WWW-Authenticate    = "WWW-Authenticate" ":" "Digest"
 *                            digest-challenge
 *
 *      digest-challenge    = 1#( realm | [ domain ] | nOnce |
 *                  [ digest-opaque ] |[ stale ] | [ algorithm ] )
 *
 *      realm               = "realm" "=" realm-value
 *      realm-value         = quoted-string
 *      domain              = "domain" "=" <"> 1#URI <">
 *      nonce               = "nonce" "=" nonce-value
 *      nonce-value         = quoted-string
 *      opaque              = "opaque" "=" quoted-string
 *      stale               = "stale" "=" ( "true" | "false" )
 *      algorithm           = "algorithm" "=" ( "MD5" | token )
 * </pre>
 *
 * @param request HTTP Servlet request
 * @param response HTTP Servlet response
 * @param config    Login configuration describing how authentication
 *              should be performed
 * @param nOnce nonce token
 */
protected void setAuthenticateHeader(HttpServletRequest request, HttpServletResponse response,
        LoginConfig config, String nOnce) {

    // Get the realm name
    String realmName = config.getRealmName();
    if (realmName == null)
        realmName = request.getServerName() + ":" + request.getServerPort();

    byte[] buffer = md5Helper.digest(nOnce.getBytes());

    String authenticateHeader = "Digest realm=\"" + realmName + "\", " + "qop=\"auth\", nonce=\"" + nOnce
            + "\", " + "opaque=\"" + md5Encoder.encode(buffer) + "\"";
    // System.out.println("Authenticate header value : "
    //                   + authenticateHeader);
    response.setHeader("WWW-Authenticate", authenticateHeader);

}

From source file:com.sun.identity.provider.springsecurity.OpenSSOProcessingFilterEntryPoint.java

private String buildGotoUrl(HttpServletRequest request) {
    StringBuffer result = new StringBuffer();
    if (getGotoUrl() != null && getGotoUrl().length() > 0) {
        result.append(getGotoUrl());//from   w  w  w.  jav a 2  s  .co m
    } else {
        result.append(getScheme() == null ? request.getScheme() : getScheme());
        result.append("://");
        result.append(getServerName() == null ? request.getServerName() : getServerName());
        if (getServerPort() != null) {
            result.append(":").append(getServerPort());
        } else if (request.getServerPort() != 80 && request.getServerPort() != 443) {
            result.append(":").append(request.getServerPort());
        }
        result.append(request.getContextPath());
        if (getFilterProcessesUrl() != null) {
            result.append(getFilterProcessesUrl());
        }
    }
    return result.toString();
}

From source file:org.infoglue.calendar.actions.ViewEventSearchAction.java

/**
 * This is the entry point for the main listing.
 *//*w  w w . j a  va  2  s  .com*/

public String execute() throws Exception {
    Session session = getSession(true);

    if (startDateTime != null && startDateTime.length() > 0)
        startCalendar = getCalendar(startDateTime + " " + startTime, "yyyy-MM-dd HH:mm", true);

    if (endDateTime != null && endDateTime.length() > 0)
        endCalendar = getCalendar(endDateTime + " " + endTime, "yyyy-MM-dd HH:mm", true);

    log.info("price:" + price);

    this.events = EventController.getController().getEventList(name, startCalendar, endCalendar, organizerName,
            lecturer, customLocation, alternativeLocation, contactName, contactEmail, contactPhone, price,
            maximumParticipants, sortAscending, categoryId, calendarId, locationId, stateId, session);

    // should we create result files?
    if (this.events.size() > 0 && exportResult) {

        Map parameters = new HashMap();
        parameters.put("headLine", "Events found");

        HttpServletRequest request = ServletActionContext.getRequest();
        EventSearchResultfilesConstructor results = new EventSearchResultfilesConstructor(parameters,
                this.events, getTempFilePath(), request.getScheme(), request.getServerName(),
                request.getServerPort(), resultValues, (CalendarAbstractAction) this);
        searchResultFiles = results.getResults();
    }

    return Action.SUCCESS;
}

From source file:org.apache.ofbiz.base.util.UtilHttp.java

private static StringBuilder prepareServerRootUrl(HttpServletRequest request) {
    StringBuilder requestUrl = new StringBuilder();
    requestUrl.append(request.getScheme());
    requestUrl.append("://" + request.getServerName());
    if (request.getServerPort() != 80 && request.getServerPort() != 443)
        requestUrl.append(":" + request.getServerPort());
    return requestUrl;
}

From source file:com.rxx.base.interceptor.ActionInterceptor.java

/**
 * action,basebasepath//from www  . j a v  a  2  s  . com
 * @param request HttpServletRequest
 * @param response HttpServletResponse 
 * @param handler 
 * @throws Exception 
 * @return true
 */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    String modelId = request.getParameter(MODEL_ID); //
    if (StringUtil.isInteger(modelId)) {
        request.getSession().setAttribute(SessionConst.MODEL_ID_SESSION.toString(), modelId);
        request.getSession().setAttribute(SessionConst.MODEL_TITLE_SESSION.toString(),
                request.getParameter("modelTitle"));

    }
    request.setAttribute(BASE, Const.BASE);
    request.setAttribute(BASE_PATH, request.getScheme() + "://" + request.getServerName()
            + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + Const.BASE);
    request.setAttribute(BASE_URL,
            request.getScheme() + "://" + request.getServerName()
                    + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort())
                    + request.getContextPath() + request.getServletPath()
                    + (request.getQueryString() == null ? "" : "?" + request.getQueryString()));
    return true;
}

From source file:org.tsm.concharto.web.eventsearch.SearchHelper.java

/**
 * Utility to get the google maps API key from a properties file
 * @param request used to find the url and port
 * @return google maps API key/*from   w ww .  j  a  v  a  2  s  .c o m*/
 */
public String makeMapKeyCode(HttpServletRequest request) {
    //map.${pageContext.request.serverName}.${pageContext.request.serverPort}.key
    return new StringBuffer("map.").append(request.getServerName()).append('.').append(request.getServerPort())
            .append('.').append("key").toString();
}

From source file:org.bigbluebuttonproject.fileupload.web.FileUploadController.java

/**
 * This handler method overwriting the method in MultiActionController.
 * Its purpose is to stream slide XML from server to the HTTP response.
 * It writes the response using HttpServletResponse.
 * /*  w ww . jav a 2  s.com*/
 * @param request HttpServletRequest
 * @param response HttpServletResponse where the Slide XML is sent
 * 
 * @return the xml slides
 * 
 * @throws Exception the exception
 */
public ModelAndView getXmlSlides(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Integer room = new Integer(request.getParameterValues("room")[0]);

    logger.info("Getting XML Slides [" + room + "]");
    logger.info("Servlet Path = [" + request.getServletPath() + "]");
    logger.info("Host = [" + request.getServerName() + ":" + request.getServerPort() + "]");
    logger.info("Request URI = [" + request.getRequestURI() + "]");
    logger.info("Request URL = [" + request.getRequestURL() + "]");

    // get URL from client request
    int lastIndex = request.getRequestURL().lastIndexOf("/");
    String url = request.getRequestURL().substring(0, lastIndex);

    // create slide presentation descriptor XML
    String slidesXml = createXml(url, getSlidesForRoom(room));
    //      String slidesXml = this.slideDatabase.getSlidesInXml(room);

    logger.info("XML Slides = " + slidesXml);

    // before sending the xml string to the client,
    // set content type and header
    response.setContentType("text/xml");
    //Ask browser not to chache images
    response.setHeader("Cache-Control", "no-cache");

    // get ServletOutputStream from HttpServletResponse
    ServletOutputStream out = response.getOutputStream();
    // send the xml string to client
    out.print(slidesXml);
    out.flush();
    out.close();
    return null;
}

From source file:net.paulgray.mocklti2.tools.LtiToolController.java

@RequestMapping(value = "/api/profile", method = RequestMethod.GET)
public ResponseEntity getConsumerProfile(HttpServletRequest request, HttpServletResponse response,
        @RequestParam String toolId) {
    response.setHeader("Content-type", "application/vnd.ims.lti.v2.ToolConsumerProfile+json");
    ToolConsumer me = new ToolConsumer("guid", "version", "tcp", config);
    me.addCapabilites(Arrays.asList(LtiCapability.BASICLTI_LAUNCH, LtiCapability.USER_ID,
            LtiCapability.USER_IMAGE, LtiCapability.COURSE_SECTION_ID, LtiCapability.MEMBERSHIP_ROLE));
    String endpoint = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/api/tool_proxy_registration?toolId=" + toolId;
    me.addServiceOffered(new ServiceOffered(endpoint, "tcp:ToolProxy.collection", "RestService",
            ToolProxy.CONTENT_TYPE, "POST"));
    return new ResponseEntity(me, HttpStatus.OK);
}

From source file:net.sf.qooxdoo.rpc.RpcServlet.java

protected String getDomainURL(HttpServletRequest request) {
    // reconstruct the start of the URL
    StringBuffer domainURL = new StringBuffer();
    String scheme = request.getScheme();
    int port = request.getServerPort();

    domainURL.append(scheme);//from  www.j a v  a  2s.  c om
    domainURL.append("://");
    domainURL.append(request.getServerName());
    if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) {
        domainURL.append(':');
        domainURL.append(request.getServerPort());
    }
    domainURL.append('/');

    return domainURL.toString();
}

From source file:org.apache.beehive.netui.pageflow.scoping.internal.ScopedRequestImpl.java

public StringBuffer getRequestURL() {
    HttpServletRequest outerRequest = getOuterRequest();
    StringBuffer url = new StringBuffer(outerRequest.getScheme());
    url.append("://").append(outerRequest.getServerName());
    url.append(':').append(outerRequest.getServerPort());
    url.append(getRequestURI());// w ww.j  a va2s  . c  o m
    return url;
}