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.sample.endpoint.TestServlet.java

/**
 * Processes requests for both HTTP/*from   ww w  . ja  va 2s.c om*/
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
        Client client = ClientBuilder.newClient();
        client.register(new LoggingFilter(Logger.getAnonymousLogger(), true));
        WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath() + "/webresources/fruit");

        // POST
        out.print("POSTing...<br>");
        target.request().post(Entity.text("apple"));
        out.format("POSTed %1$s ...<br>", "apple");

        // PUT
        out.print("<br>PUTing...<br>");
        target.request().put(Entity.text("banana"));
        out.format("PUTed %1$s ...<br>", "banana");

        // GET (all)
        out.print("<br>GETing...<br>");
        String r = target.request().get(String.class);
        out.format("GETed %1$s items ...<br>", r);

        // GET (one)
        out.print("<br>GETing...<br>");
        r = target.path("apple").request().get(String.class);
        out.format("GETed %1$s items ...<br>", r);

        // DELETE
        out.print("<br>DELETEing...<br>");
        target.path("banana").request().delete();
        out.format("DELETEed %1$s items ...<br>", "banana");

        // GET (all)
        out.print("<br>GETing...<br>");
        r = target.request().get(String.class);
        out.format("GETed %1$s items ...<br>", r);

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:com.icb123.Controller.BusinessController.java

@RequestMapping(value = "/appoint")
public void customerAppointment(HttpServletRequest request, HttpServletResponse response) {
    try {//from  w w w .j  ava2  s  .  c  o m
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        Constants.root = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();
        String sysRootPath = request.getSession().getServletContext().getRealPath("\\");
        SystemStaticArgsSet.setSysRootPath(sysRootPath);
        String requestType = request.getParameter("requestType") == null ? ""
                : request.getParameter("requestType");
        String userCode = request.getParameter("userCode") == null ? "" : request.getParameter("userCode");
        String openid = request.getParameter("openid") == null ? "" : request.getParameter("openid");
        //openid="111111";
        if (StringUtils.isBlank(openid) && StringUtils.isNotBlank(userCode)) {
            openid = WeixinUntil.getUserOoenid(userCode);
        }
        if (weixinCustomerManager.findByOpenid(openid) == null) {
            String accessToken = WeixinUntil.getAccessToken();
            WeixinCustomer wx = customerBusinessManager.getCustomerInfo(openid, accessToken, "");
            weixinCustomerManager.save(wx);
        }
        //System.out.println(PropertiesUtils.getValueByKey("token"));
        Employee emp = (Employee) request.getSession().getAttribute("Employee");
        String empCode = "";
        if (emp != null) {
            empCode = emp.getCode();
        } else {
            if (!"".equals(openid)) {
                empCode = employeeManager.findEmployeeCodeByOpenid(openid);
            }
        }
        if ("1".equals(requestType)) {//
            String paramObj = request.getParameter("paramObj");
            JSONObject json = JSONObject.fromObject(paramObj);
            JSONArray arr = (JSONArray) json.get("service");
            String[] serviceArray = new String[arr.size()];
            serviceArray = (String[]) arr.toArray(serviceArray);
            Map<String, String> result = null;
            if (StringUtils.isNotBlank((String) json.get("userCode"))) {
                openid = WeixinUntil.getUserOoenid((String) json.get("userCode"));
            } else {
                openid = null;
            }
            try {
                result = businessManager.appointmentMaintenance((String) json.get("date"),
                        (String) json.get("timeCode"), (String) json.get("mobile"), (String) json.get("name"),
                        openid, (String) json.get("carCode"), (String) json.get("license"),
                        (String) json.get("code"), (String) json.get("totalPrice"),
                        (String) json.get("address"), (String) json.get("remark"),
                        (String) json.get("appTypeCode"), (String) json.get("type"), serviceArray);
            } catch (Exception e) {
                outPutErrorInfor(BusinessController.class.getName(), "", e);
            }
            OutputUtil.outPutJsonObject(response, result);
        } else if ("2".equals(requestType)) {//         
            String status = request.getParameter("status") == null ? "" : request.getParameter("status");
            String currentPageStr = request.getParameter("currentPage") == null ? ""
                    : request.getParameter("currentPage");
            String sizeStr = request.getParameter("pageSize") == null ? "" : request.getParameter("pageSize");
            String ctime = request.getParameter("ctime") == null ? "" : request.getParameter("ctime");
            String mobile = request.getParameter("smobile") == null ? "" : request.getParameter("smobile");
            String atime = request.getParameter("atime") == null ? "" : request.getParameter("atime");
            try {
                Map<String, String> argMap = new HashMap<String, String>();
                argMap.put("status", status);
                if (StringUtils.isNotBlank(currentPageStr) && StringUtils.isNotBlank(sizeStr)) {
                    int currentPage = Integer.valueOf(currentPageStr);
                    int size = Integer.valueOf(sizeStr);
                    int begin = (currentPage - 1) * size;
                    argMap.put("size", size + "");
                    argMap.put("begin", begin + "");
                    argMap.put("currentPage", currentPageStr);
                    argMap.put("ctime", ctime);
                    argMap.put("atime", atime);
                    argMap.put("mobile", mobile);
                }
                PageBean page = businessManager.selectAppointment(argMap);
                OutputUtil.outPutJsonObject(response, page);
            } catch (Exception e) {
                outPutErrorInfor(BusinessController.class.getName(), "?", e);
            }
        } else if ("3".equals(requestType)) {//
            String appcode = request.getParameter("code") == null ? "" : request.getParameter("code");
            Map map = businessManager.findDetailedAppointment(appcode);
            OutputUtil.outPutJsonObject(response, map);
        } else if ("4".equals(requestType)) {//
            String paramObj = request.getParameter("paramObj");
            JSONObject json = JSONObject.fromObject(paramObj);
            JSONArray arr = (JSONArray) json.get("service");
            String[] serviceArray = new String[arr.size()];
            serviceArray = (String[]) arr.toArray(serviceArray);
            Map<String, String> result = null;
            try {
                result = businessManager.appointmentConfirm((String) json.get("timeCode"),
                        (String) json.get("date"), (String) json.get("time"), (String) json.get("carCode"),
                        (String) json.get("license"), (String) json.get("haveCar"),
                        (String) json.get("modelsCode"), (String) json.get("modelsStr"),
                        (String) json.get("cusCode"), (String) json.get("mobile"), (String) json.get("name"),
                        (String) json.get("address"), (String) json.get("code"), (String) json.get("remark"),
                        (String) json.get("totalPrice"), serviceArray, emp.getCode(),
                        (String) json.get("status"), (String) json.get("wxCode"));
            } catch (Exception e) {
                outPutErrorInfor(BusinessController.class.getName(), "", e);
            }
            OutputUtil.outPutJsonObject(response, result);
        } else if ("5".equals(requestType)) {//?
            String appcode = request.getParameter("code") == null ? "" : request.getParameter("code");
            String reason = request.getParameter("reason") == null ? "" : request.getParameter("reason");
            Map<String, String> result = businessManager.appointmentCancel(appcode, empCode, reason);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("6".equals(requestType)) {//?
            String date = request.getParameter("date") == null ? "" : request.getParameter("date");
            String time = request.getParameter("time") == null ? "" : request.getParameter("time");
            List<Team> list = businessManager.findFreeTeam(date, time);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("7".equals(requestType)) {//
            String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode");
            String teamCode = request.getParameter("teamCode") == null ? "" : request.getParameter("teamCode");
            String[] empArr = request.getParameterValues("emp");
            Map<String, String> result = businessManager.distributeWork(appCode, empCode, teamCode, empArr);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("8".equals(requestType)) {//
            String currentPageStr = request.getParameter("currentPage") == null ? ""
                    : request.getParameter("currentPage");
            String sizeStr = request.getParameter("pageSize") == null ? "" : request.getParameter("pageSize");
            try {
                Map<String, String> argMap = new HashMap<String, String>();
                argMap.put("empCode", empCode);
                if (StringUtils.isNotBlank(currentPageStr) && StringUtils.isNotBlank(sizeStr)) {
                    int currentPage = Integer.valueOf(currentPageStr);
                    int size = Integer.valueOf(sizeStr);
                    int begin = (currentPage - 1) * size;
                    argMap.put("size", size + "");
                    argMap.put("begin", begin + "");
                    argMap.put("currentPage", currentPageStr);
                }
                PageBean page = businessManager.selectPersonalAppointment(argMap);
                OutputUtil.outPutJsonObject(response, page);
            } catch (Exception e) {
                outPutErrorInfor(BusinessController.class.getName(), "", e);
            }
        } else if ("9".equals(requestType)) {//
            String empcode = request.getParameter("code") == null ? "" : request.getParameter("code");
            String position = request.getParameter("position") == null ? "" : request.getParameter("position");
            List<Employee> list = businessManager.findFreeEmp(empcode, position);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("10".equals(requestType)) {//?
            String appcode = request.getParameter("code") == null ? "" : request.getParameter("code");
            Map<String, String> result = businessManager.daleteDistributeWork(appcode, empCode);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("11".equals(requestType)) {//?
            String appcode = request.getParameter("code") == null ? "" : request.getParameter("code");
            List<WorkRecord> list = workRecordManager.findByAppCode(appcode);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("12".equals(requestType)) {//???
            String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile");
            Map<String, String> result = sendManager.mobileValidate(mobile);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("13".equals(requestType)) {//?
            String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile");
            String validate = request.getParameter("validate") == null ? "" : request.getParameter("validate");
            Map<String, String> result = businessManager.mobileValidate(mobile, validate);//?
            OutputUtil.outPutJsonObject(response, result);
        } else if ("14".equals(requestType)) {//??
            /*String model=request.getParameter("model") == null ? "": request.getParameter("model");
            String appcode=request.getParameter("code") == null ? "": request.getParameter("code");
            String weixinCode=request.getParameter("weixinCode") == null ? "": request.getParameter("weixinCode");
            Map<String, String> result=businessManager.writeAccessoriesModel(appcode,model,weixinCode);
            OutputUtil.outPutJsonObject(response, result);*/
        } else if ("15".equals(requestType)) {//
            String appcode = request.getParameter("code") == null ? "" : request.getParameter("code");
            String vipCondition = request.getParameter("condition") == null ? ""
                    : request.getParameter("condition");
            Map<String, String> result = businessManager.finishAppointment(appcode, vipCondition);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("16".equals(requestType)) {//??
            String kfpwd = "qweasd";
            String validate = request.getParameter("code") == null ? "" : request.getParameter("code");
            Map<String, String> result = new HashMap<String, String>();
            if (validate.equals(kfpwd)) {
                result.put("flag", "1");
            } else {
                result.put("flag", "-1");
            }
            OutputUtil.outPutJsonObject(response, result);
        } else if ("17".equals(requestType)) {//???
            String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile");
            List<Map<String, Object>> result = businessManager
                    .searchCustomerPensonalAppointmentByMobile(mobile);
            OutputUtil.outPutJsonArrary(response, result);
        } else if ("18".equals(requestType)) {
            //?  
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "No-cache");
            response.setDateHeader("Expires", 0);
            //?  
            response.setContentType("image/jpeg");
            IdentifyingImg img = new IdentifyingImg();
            ImageIO.write(img.creat(), "JPEG", response.getOutputStream());
        } else if ("19".equals(requestType)) {//??
            Map<String, Object> map = weixinCustomerManager.findCustomerInfo(openid);
            OutputUtil.outPutJsonObject(response, map);
        } else if ("20".equals(requestType)) {//????
            List<Map> result = businessManager.findCurrentAppByOpenid(openid);
            OutputUtil.outPutJsonArrary(response, result);
        } else if ("21".equals(requestType)) {//???
            //List<Map> result=businessManager.searchCustomerPensonalAppointmentByOpenid(openid);
            List<CustomerCar> result = businessManager.findHistoryCar(openid);
            OutputUtil.outPutJsonArrary(response, result);
        } else if ("22".equals(requestType)) {//??
            Map<String, String> result = new HashMap<String, String>();
            String path = weixinCustomerManager.creatEwmByWeixinCustomer(openid);
            result.put("path", path);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("23".equals(requestType)) {//???   
            Map<String, String> result = null;
            Customer cus = customerManager.findCustomerByOpenid(openid);
            if (cus != null) {
                result = new HashMap<String, String>();
                result.put("name", cus.getName());
                result.put("mobile", cus.getMobile());
            }
            OutputUtil.outPutJsonObject(response, result);
        } else if ("24".equals(requestType)) {//??
            String name = request.getParameter("name") == null ? "" : request.getParameter("name");
            String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile");
            Map<String, String> result = weixinCustomerManager.saveCustomerInfo(openid, name, mobile);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("25".equals(requestType)) {//??
            List<Map> result = businessManager.findCurrentCar(openid);
            OutputUtil.outPutJsonArrary(response, result);
        } else if ("26".equals(requestType)) {//?
            List<Map<String, String>> list = weixinCustomerManager.findConsumptionRecordByOpenid(openid);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("27".equals(requestType)) {//??
            String busnessType = request.getParameter("type") == null ? "" : request.getParameter("type");
            String totalPrice = request.getParameter("totalPrice") == null ? ""
                    : request.getParameter("totalPrice");
            double pay = integralManager.maxOutIntegral(openid, Integer.valueOf(busnessType),
                    Double.valueOf(totalPrice));
            Map<String, String> map = new HashMap<String, String>();
            map.put("pay", (int) pay + "");
            OutputUtil.outPutJsonObject(response, map);
        } else if ("28".equals(requestType)) {//
            String code = request.getParameter("code") == null ? "" : request.getParameter("code");
            String busnessType = request.getParameter("type") == null ? "" : request.getParameter("type");
            String pay = request.getParameter("pay") == null ? "" : request.getParameter("pay");
            Map<String, String> map = businessManager.integralPay(code, openid, busnessType, pay);
            OutputUtil.outPutJsonObject(response, map);
        } else if ("29".equals(requestType)) {//?
            String date = request.getParameter("date") == null ? "" : request.getParameter("date");
            List<AppointmentTime> list = businessManager.findAppTime(date);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("30".equals(requestType)) {//?
            String code = request.getParameter("code") == null ? "" : request.getParameter("code");
            String score = request.getParameter("scorce") == null ? "" : request.getParameter("scorce");
            Map<String, String> result = businessManager.saveCustomerScore(code, score);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("31".equals(requestType)) {//?
            String code = request.getParameter("weixinCode") == null ? "" : request.getParameter("weixinCode");
            Map<String, Object> result = weixinCustomerManager.openGiftView(code);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("32".equals(requestType)) {//
            String code = request.getParameter("weixinCode") == null ? "" : request.getParameter("weixinCode");
            String accept = request.getParameter("accept") == null ? "" : request.getParameter("accept");
            List<WeixinAcceptRecord> list = weixinCustomerManager.acceptGift(code, accept);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("33".equals(requestType)) {//??
            String carCdoe = request.getParameter("code") == null ? "" : request.getParameter("code");
            List<Map> list = businessManager.findHistoryAppByCarCode(carCdoe);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("100".equals(requestType)) {//???
            String paramObj = request.getParameter("paramObj") == null ? "" : request.getParameter("paramObj");
            JSONObject json = JSONObject.fromObject(paramObj);
            Map<String, String> result = businessManager.inPutFinishInfo(json, emp.getCode());
            OutputUtil.outPutJsonObject(response, result);
        } else if ("101".equals(requestType)) {//
            String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode");
            List<CustomerCarSituation> list = customerManager.findByAppCode(appCode);
            Map<String, List<CustomerCarSituation>> result = new HashMap<String, List<CustomerCarSituation>>();
            result.put("ccs", list);
            OutputUtil.outPutJsonObject(response, result);
        } else if ("102".equals(requestType)) {//?
            String position = request.getParameter("position") == null ? "" : request.getParameter("position");
            List<Employee> list = employeeManager.findEmployeeByPosition(position);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("103".equals(requestType)) {//??
            String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode");
            List<WorkRecord> list = workRecordManager.findByAppCode(appCode);
            OutputUtil.outPutJsonArrary(response, list);
        } else if ("104".equals(requestType)) {//
            List<Team> list = carMaintenanceManager.findAllTeam();
            OutputUtil.outPutJsonArrary(response, list);
        }
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        outPutErrorInfor(BusinessController.class.getName(), "?", e);
    } catch (IOException e) {
        outPutErrorInfor(BusinessController.class.getName(), "?", e);
    }
}

From source file:eg.agrimarket.controller.ProductController.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String productName = request.getParameter("product_Name");
    List<Product> products = (List<Product>) request.getServletContext().getAttribute("products");
    if (products != null) {
        Iterator<Product> iterator = products.iterator();
        while (iterator.hasNext()) {
            if (iterator.next().getName().equals(productName)) {
                iterator.remove();//from  w  ww.j  a  va 2  s  .  c  o m
            }
        }

        request.getServletContext().setAttribute("products", products);

    }
    ProductDao dao = new ProductDaoImp();
    dao.removeProduct(productName);
    response.sendRedirect("http://" + request.getServerName() + ":" + request.getServerPort()
            + "/AgriMarket/admin/getProducts?#product-div");

}

From source file:com.wabacus.system.assistant.WabacusAssistant.java

public String replaceAllImgPathInExportDataFile(HttpServletRequest request, String displayvalue) {
    String serverName = request.getServerName();
    String serverPort = String.valueOf(request.getServerPort());
    return replaceAllImgPathInExportDataFile("http://" + serverName + ":" + serverPort, displayvalue);
}

From source file:com.identityconcepts.shibboleth.WSFedLoginHandler.java

/**
 * return URL to which redirect will be done
 * depending on the X509 handler configuration,
 * a full URL will be used or a path in the web app
 *
 * @param  request  HTTPServletRequest//from w w  w.jav  a  2 s  . com
 * @return          URL for redirection
 */
private String getRedirectURL(HttpServletRequest request, String url) {
    URLBuilder urlBuilder = null;
    // if URL configured
    if (url.startsWith("http")) {
        urlBuilder = new URLBuilder(url);
    } else {
        // if path configured
        log.debug("No URL configured in loginPageURL: {}", url);

        StringBuilder pathBuilder = new StringBuilder();
        urlBuilder = new URLBuilder();
        urlBuilder.setScheme(request.getScheme());
        urlBuilder.setHost(request.getServerName());
        // set port if not standard port
        if (!(request.getScheme().equals("http")) || (request.getScheme().equals("https"))) {
            urlBuilder.setPort(request.getServerPort());
        }

        pathBuilder.append(request.getContextPath());
        if (!loginPageURL.startsWith("/")) {
            pathBuilder.append("/");
        }
        pathBuilder.append(url);

        urlBuilder.setPath(pathBuilder.toString());
    }
    return urlBuilder.buildURL();
}

From source file:org.mitre.ptmatchadapter.service.ServerAuthorizationService.java

/**
 * Process a request to create a Server Authorization (i.e., request to grant
 * ptmatchadapter authorization to access a particular fhir server)
 * /*w ww  .j  a  v a2s .  c  o  m*/
 * @param serverAuth
 * @param reqHdrs
 * @param respHdrs
 * @return
 */
private final ServerAuthorization processServerAuthRequest(ServerAuthorization serverAuth,
        @Headers Map<String, Object> reqHdrs, @OutHeaders Map<String, Object> respHdrs) {
    final String serverUrl = serverAuth.getServerUrl();
    final String accessToken = serverAuth.getAccessToken();

    // if request doesn't contain a server URL, it is an error
    if (serverUrl == null || serverUrl.isEmpty()) {
        respHdrs.put(Exchange.HTTP_RESPONSE_CODE, 400); // BAD REQUEST
        return null;
    }
    // else if the request body doesn't include an access token, redirect user
    // to an authorization server
    else if (accessToken == null || accessToken.isEmpty()) {
        // create a state identifier
        final String stateKey = newStateKey();

        respHdrs.put(STATE_PARAM, stateKey);

        final AuthorizationRequestInfo requestInfo = new AuthorizationRequestInfo();
        requestInfo.put(SERVER_AUTH, serverAuth);
        sessionData.put(stateKey, requestInfo);

        // Construct URL we will invoke on authorization server
        // GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz
        // &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
        final StringBuilder authUrl = new StringBuilder(100);
        if (getAuthorizationServer() != null) {
            authUrl.append(getAuthorizationServer());
        }
        authUrl.append(getAuthorizationEndpoint());
        authUrl.append("?");

        authUrl.append("response_type=code&client_id=");
        try {
            authUrl.append(URLEncoder.encode(getClientId(), "UTF-8"));
            authUrl.append("&");
            authUrl.append(STATE_PARAM);
            authUrl.append("=");
            authUrl.append(stateKey);
            authUrl.append("&redirect_uri=");

            final HttpServletRequest req = (HttpServletRequest) reqHdrs.get(Exchange.HTTP_SERVLET_REQUEST);
            final String redirectUri = URLEncoder.encode(
                    getClientAuthRedirectUri(req.getScheme(), req.getServerName(), req.getServerPort()),
                    "UTF-8");
            authUrl.append(redirectUri);
            // we need to provide redirect uri with access token request, so save it
            requestInfo.put("redirectUri", redirectUri);
        } catch (UnsupportedEncodingException e) {
            // Should never happen, which is why I wrap all above once
            LOG.error("Usupported encoding used on authorization redirect", e);
        }

        respHdrs.put(Exchange.HTTP_RESPONSE_CODE, 302); // FOUND
        respHdrs.put(Exchange.CONTENT_TYPE, "text/plain");
        respHdrs.put("Location", authUrl.toString());

        return null;
    } else {
        LOG.warn("NOT IMPLEMENTED");
        return null;
    }
}

From source file:org.jahia.services.render.URLGenerator.java

/**
 * Returns the server URL, including scheme, host and port, depending on the current site. The URL is in the form <code><scheme><host>:<port></code>, e.g. <code>http://www.jahia.org:8080</code>. The port is omitted in case of standard
 * HTTP (80) and HTTPS (443) ports.// w  ww  .j  a  v  a  2 s  . co  m
 * <p/>
 * If the site's server name is configured to be "localhost", then take the servername from the request.
 *
 * @return the server URL, including scheme, host and port, depending on the current site
 */
public String getServer() {
    if (server == null) {
        StringBuilder url = new StringBuilder(255); // use a greater than default (16) allocated StringBuilder to avoid having to resize it
        final HttpServletRequest request = context.getRequest();
        String scheme = request.getScheme();
        String host = context.getSite().getServerName();
        if (Url.isLocalhost(host)) {
            host = request.getServerName();
        }

        int port = SettingsBean.getInstance().getSiteURLPortOverride();

        if (port == 0) {
            port = request.getServerPort();
        }

        url.append(scheme).append("://").append(host);

        if (!(port == 80 && "http".equals(scheme) || port == 443 && "https".equals(scheme))) {
            url.append(":").append(port);
        }

        server = url.toString();
    }

    return server;
}

From source file:org.alfresco.web.forms.xforms.XFormsBean.java

/**
 * Initializes the chiba process with the xform and registers any necessary
 * event listeners.//from  ww  w. ja  v  a 2 s .co m
 */
public XFormsSession createSession(final Document formInstanceData, final String formInstanceDataName,
        final Form form) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("initializing xforms session with form " + form.getName() + " and instance data "
                + formInstanceDataName + " (" + formInstanceData + ")");
    }

    final FacesContext facesContext = FacesContext.getCurrentInstance();
    final ExternalContext externalContext = facesContext.getExternalContext();
    final HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();

    final String baseUrl = (request.getScheme() + "://" + request.getServerName() + ':'
            + request.getServerPort() + request.getContextPath());
    return this.new XFormsSession(formInstanceData, formInstanceDataName, form, baseUrl,
            getSchema2XFormsProperties().isFormatCaption());
}

From source file:org.jahia.modules.newsletter.action.SubscribeAction.java

private boolean sendConfirmationMail(JCRSessionWrapper session, String email, JCRNodeWrapper node,
        JCRNodeWrapper newSubscriptionNode, final Locale locale, HttpServletRequest req)
        throws RepositoryException, JSONException {
    if (mailConfirmationTemplate != null) {
        String confirmationKey = subscriptionService.generateConfirmationKey(newSubscriptionNode);
        newSubscriptionNode.setProperty(SubscriptionService.J_CONFIRMED, false);
        newSubscriptionNode.setProperty(SubscriptionService.J_CONFIRMATION_KEY, confirmationKey);
        session.save();/*from  w  w w .j  av  a 2 s. c o m*/
        Map<String, Object> bindings = new HashMap<String, Object>();
        bindings.put("newsletter", node);

        bindings.put("confirmationlink",
                req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
                        + Jahia.getContextPath() + Render.getRenderServletPath() + "/live/" + node.getLanguage()
                        + node.getPath() + ".confirm.do?key=" + confirmationKey + "&exec=add");
        try {
            mailService.sendMessageWithTemplate(mailConfirmationTemplate, bindings, email,
                    mailService.defaultSender(), null, null, locale, "Jahia Newsletter");
        } catch (ScriptException e) {
            logger.error("Cannot generate confirmation mail", e);
        }

        return true;
    }
    return false;
}

From source file:edu.isi.wings.portal.classes.config.Config.java

private void createDefaultPortalConfig(HttpServletRequest request) {
    String server = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    String storageDir = null;/* w w w. j ava  2  s  .  c om*/
    String home = System.getProperty("user.home");
    if (home != null && !home.equals(""))
        storageDir = home + File.separator + ".wings" + File.separator + "storage";
    else
        storageDir = System.getProperty("java.io.tmpdir") + File.separator + "wings" + File.separator
                + "storage";
    if (!new File(storageDir).mkdirs())
        System.err.println("Cannot create storage directory: " + storageDir);

    PropertyListConfiguration config = new PropertyListConfiguration();
    config.addProperty("storage.local", storageDir);
    config.addProperty("storage.tdb", storageDir + File.separator + "TDB");
    config.addProperty("server", server);

    File loc1 = new File("/usr/bin/dot");
    File loc2 = new File("/usr/local/bin/dot");
    config.addProperty("graphviz", loc2.exists() ? loc2.getAbsolutePath() : loc1.getAbsolutePath());
    config.addProperty("ontology.data", ontdirurl + "/data.owl");
    config.addProperty("ontology.component", ontdirurl + "/component.owl");
    config.addProperty("ontology.workflow", ontdirurl + "/workflow.owl");
    config.addProperty("ontology.execution", ontdirurl + "/execution.owl");
    config.addProperty("ontology.resource", ontdirurl + "/resource.owl");

    this.addEngineConfig(config,
            new ExeEngine("Local", LocalExecutionEngine.class.getCanonicalName(), ExeEngine.Type.BOTH));
    this.addEngineConfig(config, new ExeEngine("Distributed",
            DistributedExecutionEngine.class.getCanonicalName(), ExeEngine.Type.BOTH));

    /*this.addEngineConfig(config, new ExeEngine("OODT",
    OODTExecutionEngine.class.getCanonicalName(), ExeEngine.Type.PLAN));
            
    this.addEngineConfig(config, new ExeEngine("Pegasus", 
    PegasusExecutionEngine.class.getCanonicalName(), ExeEngine.Type.PLAN));*/

    try {
        config.save(this.configFile);
    } catch (Exception e) {
        e.printStackTrace();
    }
}