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.ow2.chameleon.everest.servlet.RelationSerializationTest.java

@Test
public void testRelationWithTwoParameters() throws IllegalResourceException, IOException {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getScheme()).thenReturn("http");
    when(request.getServerName()).thenReturn("server");
    when(request.getServerPort()).thenReturn(1234);

    Relation relation = new DefaultRelation(Path.from("/foo/bar"), Action.READ, "test", "description",
            new DefaultParameter().name("param").description("my param").type(String.class),
            new DefaultParameter().name("param2").description("my second param").type(Integer.TYPE)
                    .optional(true));//from   w  w w.  j a  v a2 s . c  o  m
    Resource resource = new DefaultResource.Builder().fromPath(Path.from("/foo")).with(relation).build();
    EverestServlet servlet = new EverestServlet();
    JsonNode node = servlet.toJSON(request, resource);

    System.out.println(node);
    assertThat(node.get("__relations")).isNotNull();

    final JsonNode rel = node.get("__relations").get("test");
    assertThat(rel).isNotNull();
    assertThat(rel.get("href").asText()).isEqualTo("http://server:1234/everest/foo/bar");
    assertThat(rel.get("action").asText()).isEqualTo("READ");
    assertThat(rel.get("name").asText()).isEqualTo("test");
    assertThat(rel.get("description").asText()).isEqualTo("description");

    final JsonNode param0 = rel.get("parameters").get(0);
    assertThat(param0.get("name").asText()).isEqualTo("param");
    assertThat(param0.get("description").asText()).isEqualTo("my param");
    assertThat(param0.get("type").asText()).isEqualTo(String.class.getName());
    assertThat(param0.get("optional").asBoolean()).isFalse();

    final JsonNode param1 = rel.get("parameters").get(1);
    assertThat(param1.get("name").asText()).isEqualTo("param2");
    assertThat(param1.get("description").asText()).isEqualTo("my second param");
    assertThat(param1.get("type").asText()).isEqualTo(Integer.TYPE.getName());
    assertThat(param1.get("optional").asBoolean()).isTrue();
}

From source file:org.magnum.dataup.CopyOfMyVideoController.java

private String getUrlBaseForLocalServer() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();/*  ww  w.  ja  va  2  s  . co  m*/
    String base = "http://" + request.getServerName()
            + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
    //System.out.println(base);
    return base;
}

From source file:org.jahia.test.JahiaTestCase.java

protected String getBaseServerURL() {
    HttpServletRequest req = getRequest();
    String url = req != null ? req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
            : BASE_URL;//w  ww  . j  a v a2 s  .c o  m
    logger.info("Base URL for tests is: " + url);
    return url;
}

From source file:org.coursera.cmbrehm.kewlvideo.server.VideoController.java

private String getUrlBaseForLocalServer() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();/* w w w  .  j a  v  a2  s .c  o m*/
    String base = "http://" + request.getServerName()
            + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
    return base;
}

From source file:com.pontecultural.flashcards.CardController.java

@RequestMapping(method = RequestMethod.GET)
public String getUploadForm(HttpServletRequest req, Locale locale, Model model,
        @RequestParam("id") Integer aId) {
    logger.info("get cards for deck");
    // compute base URL to allow client to call us back.
    String callbackURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
            + req.getContextPath() + "/deckId/" + aId.toString() + "/cards.json";

    model.addAttribute("callbackURL", callbackURL);
    model.addAttribute("deckname", jdbcFlashcardsDao.fetchDeckname(aId));
    model.addAttribute("deckId", aId.toString());
    return "viewCards";
}

From source file:org.apache.struts.webapp.tiles.rssChannel.Channels.java

private String toFullUrl(HttpServletRequest request, String url) {
    StringBuffer buff = new StringBuffer();

    buff.append(request.getScheme()).append("://").append(request.getServerName());

    if (request.getServerPort() != 80) {
        buff.append(":").append(request.getServerPort());
    }//from  w w w  . j  a  v  a  2  s . c o  m

    buff.append(request.getContextPath()).append(url);

    return buff.toString();
}

From source file:gal.udc.fic.muei.tfm.dap.flipper.web.rest.AccountResource.java

@RequestMapping(value = "/account/reset_password/init", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE)
@Timed//from w  w  w  . ja  v a  2 s .  co  m
public ResponseEntity<?> requestPasswordReset(@RequestBody String mail, HttpServletRequest request) {

    return userService.requestPasswordReset(mail).map(user -> {
        String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        mailService.sendPasswordResetMail(user, baseUrl);
        return new ResponseEntity<>("e-mail was sent", HttpStatus.OK);
    }).orElse(new ResponseEntity<>("e-mail address not registered", HttpStatus.BAD_REQUEST));

}

From source file:be.fedict.eid.idp.protocol.openid.AbstractOpenIDIdentityHttpServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    LOG.debug("doGet");
    String location = "https://" + request.getServerName();

    if (request.getServerPort() != 443) {
        location += ":" + request.getServerPort();
    }//from   www .  ja  v a 2  s .  c  o m
    location += "/eid-idp";
    LOG.debug("location: " + location);

    PrintWriter printWriter = response.getWriter();
    if (request.getRequestURI().endsWith("/xrds")) {
        LOG.debug("returning the YADIS XRDS document");
        response.setContentType("application/xrds+xml");
        printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        printWriter.println("<xrds:XRDS xmlns:xrds=\"xri://$xrds\" xmlns=\"xri://$xrd*($v*2.0)\">");
        printWriter.println("<XRD>");

        printWriter.println("<Service>");
        printWriter.println("<Type>http://specs.openid.net/auth/2.0/server</Type>");
        printWriter.println("<Type>http://specs.openid.net/extensions/ui/1.0/lang-pref</Type>");
        for (String additionalServiceType : getAdditionalServiceTypes()) {
            printWriter.println("<Type>" + additionalServiceType + "</Type>");
        }
        printWriter.println("<URI>" + location + "/protocol/" + getPath() + "</URI>");
        printWriter.println("</Service>");

        printWriter.println("<Service>");
        printWriter.println("<Type>http://specs.openid.net/auth/2.0/signon</Type>");
        printWriter.println("<Type>http://specs.openid.net/extensions/pape/1.0</Type>");
        printWriter.println("<URI>" + location + "/protocol/" + getPath() + "</URI>");
        printWriter.println("</Service>");

        printWriter.println("</XRD>");
        printWriter.println("</xrds:XRDS>");
        return;
    }
    LOG.debug("returning the HTML identity document");
    String xrdsLocation = location + "/endpoints/" + getPath() + "/xrds";
    response.setContentType("text/html");
    response.addHeader("X-XRDS-Location", xrdsLocation);
    printWriter.println("<html>");
    printWriter.println("<head>");
    printWriter.println("<meta http-equiv=\"X-XRDS-Location\" content=\"" + xrdsLocation + "\"/>");
    printWriter.println("<title>OpenID Identity URL</title>");
    printWriter.println("</head>");
    printWriter.println("<body><p>OpenID Identity URL</p></body>");
    printWriter.println("</html>");
}

From source file:org.magnum.dataup.controller.VideoSvc.java

/**
 * Get base URL for local server//  w w  w.ja va 2 s.c o m
 * 
 * @return Base URL for local server
 */
private String getUrlBaseForLocalServer() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();
    String base = "http://" + request.getServerName()
            + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
    return base;
}

From source file:demo.rest.RestApi.java

private String getKmlUrl(HttpServletRequest request) {

    final String scheme = request.getScheme();
    final String serverName = request.getServerName();
    final int serverPort = request.getServerPort();
    final String contextPath = request.getContextPath();

    StringBuilder url = new StringBuilder();
    url.append(scheme).append("://").append(serverName);

    if ((serverPort != 80) && (serverPort != 443)) {
        url.append(":").append(serverPort);
    }//from  w w w  .  ja v  a 2 s. c  o  m

    url.append(contextPath).append("/api/kml/");
    return url.toString();
}