Java Code Examples for javax.servlet.http.HttpServletRequest.getScheme()

The following are Jave code examples for showing how to use getScheme() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: xproject   File: HttpUtils.java   View Source Code Vote up 7 votes
public static String getRequestURL(HttpServletRequest request, boolean includeQueryString) {
	StringBuffer url = new StringBuffer();
       String scheme = request.getScheme();
       int port = request.getServerPort();
       String urlPath = request.getRequestURI();

       url.append (scheme);                // http, https
       url.append ("://");
       url.append (request.getServerName());
       if ((scheme.equals ("http") && port != 80)
               || (scheme.equals ("https") && port != 443)) {
           url.append (':');
           url.append (request.getServerPort());
       }
       url.append(urlPath);
       if(includeQueryString && !StringUtils.isEmpty(request.getQueryString())){
       	url.append("?" + request.getQueryString());
	}
       return url.toString();
}
 
Example 2
Project: unitimes   File: PdfExamReportQueueItem.java   View Source Code Vote up 7 votes
public PdfExamReportQueueItem(Session session, UserContext owner, ExamPdfReportForm form, HttpServletRequest request, ExamSolverProxy examSolver) {
	super(session, owner);
	iForm = form;
	iUrl = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
	iExamSolver = examSolver;
	iName = ExamTypeDAO.getInstance().get(iForm.getExamType()).getLabel() + " ";
       for (int i=0;i<iForm.getReports().length;i++) {
       	if (i > 0) iName += ", ";
       	iName += iForm.getReports()[i];
       }
       if (!iForm.getAll()) {
       	iName += " (";
           for (int i=0;i<iForm.getSubjects().length;i++) {
               SubjectArea subject = new SubjectAreaDAO().get(Long.valueOf(iForm.getSubjects()[i]));
               if (i > 0) iName += ", ";
               iName += subject.getSubjectAreaAbbreviation();
           }
           iName += ")";
       }
       iSubjectIndependent = (owner == null || owner.getCurrentAuthority() == null ? false : owner.getCurrentAuthority().hasRight(Right.DepartmentIndependent));
       iForm.setSubjectAreas(SubjectArea.getUserSubjectAreas(owner, false));
}
 
Example 3
Project: kettle_support_kettle8.0   File: Authentication2Filter.java   View Source Code Vote up 6 votes
private String getDefaultBackUrl(HttpServletRequest request) {
	String scheme = request.getScheme();
	String domain = request.getServerName();
	int port = request.getServerPort();
	String contextPath = request.getContextPath();
	StringBuilder backUrl = new StringBuilder(scheme);
	backUrl.append("://");
	backUrl.append(domain);
	if ("http".equalsIgnoreCase(scheme) && port != 80) {
		backUrl.append(":").append(String.valueOf(port));
	} else if ("https".equalsIgnoreCase(scheme) && port != 443) {
		backUrl.append(":").append(String.valueOf(port));
	}
	backUrl.append(contextPath);
	backUrl.append(getSuccessUrl());
	return backUrl.toString();
}
 
Example 4
Project: bumblebee   File: LoginFilter.java   View Source Code Vote up 6 votes
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    String requestURI = request.getRequestURI();
    requestURI = requestURI.replaceAll("/+", "/").replaceAll("/+", "/");
    LOG.info("LoginFilter receive request uri : " + requestURI);

    if (requestURI.equals("/")||requestURI.equals("/web/login")||requestURI.equals("/web/doLogin")||requestURI.startsWith("/resources")|| requestURI.startsWith("/terminal/")) {
        filterChain.doFilter(request, response);
        return;
    }
    String path = request.getContextPath();
    this.basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

    HttpSession session = request.getSession();

    BumblebeeUser user=(BumblebeeUser) session.getAttribute("curUser");
    if(null==user){
        java.io.PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<script>");
        out.println("window.open ('"+basePath+"','_top')");
        out.println("</script>");
        out.println("</html>");
    }else{
        filterChain.doFilter(request, response);
        return;
    }


}
 
Example 5
Project: ofmeet-openfire-plugin   File: ConfigServlet.java   View Source Code Vote up 6 votes
/**
 * Generates an URL on which client / BOSH connections are expected.
 *
 * This method will verify if the websocket plugin is available. If it is, the websocket endpoint is returned. When
 * websocket is not available, the http-bind endpoint is returned.
 *
 * The request that is made to this servlet is used to determine if the client prefers secure/encrypted connections
 * (https, wss) over plain ones (http, ws), and to determine what the server address and port is.
 *
 * @param request the request to this servlet.
 * @return An URI (never null).
 * @throws URISyntaxException When an URI could not be constructed.
 */
public static URI getMostPreferredConnectionURL( HttpServletRequest request ) throws URISyntaxException
{
    Log.debug( "[{}] Generating BOSH URL based on {}", request.getRemoteAddr(), request.getRequestURL() );
    if ( XMPPServer.getInstance().getPluginManager().getPlugin( "websocket" ) != null )
    {
        Log.debug( "[{}] Websocket plugin is available. Returning a websocket address.", request.getRemoteAddr() );
        final String websocketScheme;
        if ( request.getScheme().endsWith( "s" ) )
        {
            websocketScheme = "wss";
        }
        else
        {
            websocketScheme = "ws";
        }

        return new URI( websocketScheme, null, request.getServerName(), request.getServerPort(), "/ws", null, null);
    }
    else
    {
        Log.debug( "[{}] No Websocket plugin available. Returning an HTTP-BIND address.", request.getRemoteAddr() );
        return new URI( request.getScheme(), null, request.getServerName(), request.getServerPort(), "/http-bind/", null, null);
    }
}
 
Example 6
Project: kettle_support_kettle8.0   File: Saved2Request.java   View Source Code Vote up 5 votes
public Saved2Request(HttpServletRequest request, String backUrl) {
	super(request);
	this.scheme = request.getScheme();
	this.domain = request.getServerName();
	this.port = request.getServerPort();
	this.backUrl = backUrl;
	this.contextPath = request.getContextPath();
}
 
Example 7
Project: apache-tomcat-7.0.73-with-comment   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithCustomValues() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");
    filterDef.addInitParameter("remoteIpHeader", "x-my-forwarded-for");
    filterDef.addInitParameter("httpServerPort", "8080");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setSecure(true);
    request.setScheme("https");
    request.setHeader("x-my-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    boolean actualSecure = actualRequest.isSecure();
    assertFalse("request must be unsecured as header x-forwarded-proto said it is http", actualSecure);

    String actualScheme = actualRequest.getScheme();
    assertEquals("scheme must be http as header x-forwarded-proto said it is http", "http", actualScheme);

    int actualServerPort = actualRequest.getServerPort();
    assertEquals("wrong http server port", 8080, actualServerPort);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
Example 8
Project: ctsms   File: WebUtil.java   View Source Code Vote up 5 votes
public static String getApplicationRootUrl() {
	try {
		HttpServletRequest request = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
		URL reconstructedUrl = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "");
		return reconstructedUrl.toString();
	} catch (Exception e) {
		return getHttpBaseUrl();
	}
}
 
Example 9
Project: framework   File: RequestUtils.java   View Source Code Vote up 5 votes
/**
 * 获取Http请求的完整路径,包括参数
 *
 * @param request
 * @return
 */
public static String getFullURL(HttpServletRequest request) {
	String url = "";
	url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getServletPath();
	if (request.getQueryString() != null) {
		url += "?" + request.getQueryString();
	}
	return url;
}
 
Example 10
Project: framework   File: RequestUtils.java   View Source Code Vote up 5 votes
/**
 * 获取Http请求的完整路径,包括参数,不包括端口号
 *
 * @param request
 * @return
 */
public static String getFullURLWithOutPort(HttpServletRequest request) {
	String url = "";
	url = request.getScheme() + "://" + request.getServerName() + request.getServletPath();
	if (request.getQueryString() != null) {
		url += "?" + request.getQueryString();
	}
	return url;
}
 
Example 11
Project: unitimes   File: DataImportAction.java   View Source Code Vote up 5 votes
public DataExchangeQueueItem(Session session, UserContext owner, DataImportForm form, HttpServletRequest request, boolean isImport) {
	super(session, owner);
	iForm = (DataImportForm)form.clone();
	iUrl = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
	iImport = isImport;
	iSessionName = session.getAcademicTerm() + session.getAcademicYear() + session.getAcademicInitiative();
	iProgress = Progress.getInstance(this);
	iProgress.addProgressListener(new ProgressListener() {
		@Override
		public void statusChanged(String status) {
			log(status);
		}
		
		@Override
		public void progressSaved() {}
		
		@Override
		public void progressRestored() {}
		
		@Override
		public void progressMessagePrinted(Message message) {
			log(message.toHtmlString());
		}
		
		@Override
		public void progressChanged(long currentProgress, long maxProgress) {}
		
		@Override
		public void phaseChanged(String phase) {}
	});
}
 
Example 12
Project: DWSurvey   File: MyCollectAction.java   View Source Code Vote up 5 votes
@Override
public String execute() throws Exception {
	HttpServletRequest request=Struts2Utils.getRequest();
	String tabId=request.getParameter("tabId");

	String baseUrl = "";
	baseUrl = request.getScheme() +"://" + request.getServerName()  
					+ (request.getServerPort() == 80 ? "" : ":" +request.getServerPort())
                       + request.getContextPath();

	request.setAttribute("baseUrl", baseUrl);

	User user=accountManager.getCurUser();
   	if(user!=null){
   		SurveyDirectory surveyDirectory=surveyDirectoryManager.getSurveyByUser(surveyId, user.getId());
   		if(surveyDirectory!=null){
   			request.setAttribute("survey", surveyDirectory);
   			if(IFRAME.equals(tabId)){
   				return IFRAME;
   			}else if(SITECOMP.equals(tabId)){
   				return SITECOMP;
   			}else if(WEIXIN.equals(tabId)){
   				return WEIXIN;
   			}else if(SHARE.equals(tabId)){
   				return SHARE;
   			}
   			return COLLECT1;
   		}
   	}
	return null;
}
 
Example 13
Project: alfresco-remote-api   File: SysAdminParamsBaseUrlGenerator.java   View Source Code Vote up 5 votes
protected String getServerScheme(HttpServletRequest request)
{
	String scheme = sysAdminParams.getAlfrescoProtocol();
       if (scheme == null)
       {
           scheme = request.getScheme();
       }
       scheme = request.getScheme();
       return scheme;
}
 
Example 14
Project: mumu   File: SysIforgetController.java   View Source Code Vote up 5 votes
/**
 * 发送邮箱验证码
 * @param email 邮箱账号
 * @param request
 * @return
 */
@ResponseBody
@RequestMapping(value = "/sendEmail",method = RequestMethod.POST)
public ResponseEntity sendEmail(String email, HttpServletRequest request){
    if(email==null||!ValidateUtils.isEmail(email)){
        return new ResponseEntity(400,"error","邮箱账号错误!");
    }
    //发送注册邮件
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+ request.getContextPath()+"/";
    Map<String,Object> modelMap=new HashMap<String,Object>();
    modelMap.put("USERNAME","baby慕慕");
    modelMap.put("LOGOIMG",basePath+"resources/img/logo.png");
    int verifyCode = RandomUtils.nextInt(100000, 999999);
    request.getSession().setAttribute("VERIFYCODE",String.valueOf(verifyCode));
    modelMap.put("VERIFYCODE",verifyCode);
    modelMap.put("IFORGOTURL",basePath+"system/iforget");
    modelMap.put("LOGINURL",basePath+"system/login");
    modelMap.put("OFFICIALURL",basePath);
    String content= VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "tpl/verifyCodeEmail.html","UTF-8",modelMap);
    try {
        boolean sendSuccess=emailService.send(email,null,"baby慕慕开放平台-验证码找回密码",content);
        if(sendSuccess){
            return new ResponseEntity(200,"success","验证码发送成功");
        }
    } catch (EmailException e) {
        e.printStackTrace();
    }
    return new ResponseEntity(400,"error","邮箱发送失败!");
}
 
Example 15
Project: apache-tomcat-7.0.73-with-comment   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithDefaultValues() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setSecure(true);
    request.setScheme("https");
    request.setHeader("x-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    boolean actualSecure = actualRequest.isSecure();
    assertFalse("request must be unsecured as header x-forwarded-proto said it is http", actualSecure);

    String actualScheme = actualRequest.getScheme();
    assertEquals("scheme must be http as header x-forwarded-proto said it is http", "http", actualScheme);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);

}
 
Example 16
Project: logistimo-web-service   File: HttpUtil.java   View Source Code Vote up 5 votes
public static String getUrlBase(HttpServletRequest request) {
  if ((request.getServerPort() == 80) || (request.getServerPort() == 443)) {
    return request.getScheme() + "://" + request.getServerName();
  } else {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
  }
}
 
Example 17
Project: FastBootWeixin   File: HttpRequestMessageParameter.java   View Source Code Vote up 4 votes
public HttpRequestMessageParameter(HttpServletRequest request) {
    if (request != null && request.getScheme() != null) {
        this.requestUrl = request.getRequestURL().toString();
    }
    this.createTime = new Date();
}
 
Example 18
Project: DDNS_Server   File: ValidateServlet.java   View Source Code Vote up 4 votes
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	// TODO Auto-generated method stub
	HttpSession session = request.getSession(true);
	
	DB dbProperties = new DB(getServletContext().getInitParameter("dbHost"), getServletContext().getInitParameter("dbPort"), getServletContext().getInitParameter("dbName"), getServletContext().getInitParameter("dbUser"), getServletContext().getInitParameter("dbPassword"));
   	
	DynUser current = null;
	String scheme = request.getScheme() + "://";
       String serverName = request.getServerName();
       String serverPort = (request.getServerPort() == 80) ? "" : ":" + request.getServerPort();
       String contextPath = request.getContextPath();
	
	String key1 = request.getParameter("key1");
	String key2 = request.getParameter("key2");
	String email = request.getParameter("email");
	String action = request.getParameter("action");
	
	
	if (key1 != null && key2 != null && email != null && action != null) {
		if (action.equals("forgot"))
		{
			if (ValidateDao.checkForgot(key1, key2, email, dbProperties)) {
				if (ValidateDao.validateUser(email, key1, key2, dbProperties)) {
					current = ValidateDao.loadUser(email, key1, key2, dbProperties);
					session.setAttribute("LoggedUser", current);
					System.out.println("User Validated and Logged In - "+email);
					ValidateDao.setNotForgot(current.getID(), dbProperties);
				} else {
					System.out.println("User Not Validated - "+email);
				}
			}
		}
		
		if (action.equals("activate"))
		{
			if (ValidateDao.checkNotEnabled(key1, key2, email, dbProperties)) {
				if (ValidateDao.validateUser(email, key1, key2, dbProperties)) {
					
					current = ValidateDao.loadUser(email, key1, key2, dbProperties);
					session.setAttribute("LoggedUser", current);
					System.out.println("User Enabled and Logged In - "+email);
					ValidateDao.setEnabled(current.getID(), dbProperties);
					ValidateDao.enableUserZone(current.getUsername(), dbProperties);
				} else {
					System.out.println("User Not Validated - "+email);
				}
			}
		}
		
	}
	response.sendRedirect(scheme + serverName + serverPort + contextPath +"/index.jsp");
}
 
Example 19
Project: gitplex-mit   File: ServletRequestCopy.java   View Source Code Vote up 4 votes
public ServletRequestCopy(HttpServletRequest request) {
	this.servletPath = request.getServletPath();
	this.contextPath = request.getContextPath();
	this.pathInfo = request.getPathInfo();
	this.requestUri = request.getRequestURI();
	this.requestURL = request.getRequestURL();
	this.method = request.getMethod();
	this.serverName = request.getServerName();
	this.serverPort = request.getServerPort();
	this.protocol = request.getProtocol();
	this.scheme = request.getScheme();
	
	
	/*
	 * have to comment out below two lines as otherwise web socket will
	 * report UnSupportedOperationException upon connection
	 */
	//this.characterEncoding = request.getCharacterEncoding();
	//this.contentType = request.getContentType();
	//this.requestedSessionId = request.getRequestedSessionId();
	this.characterEncoding = null;
	this.contentType = null;
	this.requestedSessionId = null;
	
	this.locale = request.getLocale();
	this.locales = request.getLocales();
	this.isSecure = request.isSecure();
	this.remoteUser = request.getRemoteUser();
	this.remoteAddr = request.getRemoteAddr();
	this.remoteHost = request.getRemoteHost();
	this.remotePort = request.getRemotePort();
	this.localAddr = request.getLocalAddr();
	this.localName = request.getLocalName();
	this.localPort = request.getLocalPort();
	this.pathTranslated = request.getPathTranslated();
	this.principal = request.getUserPrincipal();

	HttpSession session = request.getSession(true);
	httpSession = new HttpSessionCopy(session);

	String s;
	Enumeration<String> e = request.getHeaderNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		Enumeration<String> headerValues = request.getHeaders(s);
		this.headers.put(s, headerValues);
	}

	e = request.getAttributeNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		attributes.put(s, request.getAttribute(s));
	}

	e = request.getParameterNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		parameters.put(s, request.getParameterValues(s));
	}
}
 
Example 20
Project: angit   File: WebHelper.java   View Source Code Vote up 2 votes
/**
 * 获取访问路径
 *
 * @param request HttpServletRequest
 * @return 访问路径 base url
 */
public static String getBaseURL(HttpServletRequest request) {
    String path = request.getContextPath();
    return request.getScheme() + "://"
        + request.getServerName() + ":" + request.getServerPort() + path + "/";
}