Java Code Examples for org.springframework.web.bind.ServletRequestUtils#getRequiredStringParameter()

The following examples show how to use org.springframework.web.bind.ServletRequestUtils#getRequiredStringParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyController.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String url = ServletRequestUtils.getRequiredStringParameter(request, "url");

    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
    HttpGet method = new HttpGet(url);

    InputStream in = null;
    try {
        HttpResponse resp = client.execute(method);
        int statusCode = resp.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            response.sendError(statusCode);
        } else {
            in = resp.getEntity().getContent();
            IOUtils.copy(in, response.getOutputStream());
        }
    } finally {
        IOUtils.closeQuietly(in);
        client.getConnectionManager().shutdown();
    }
    return null;
}
 
Example 2
Source File: ProxyController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String url = ServletRequestUtils.getRequiredStringParameter(request, "url");

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(15000)
            .setSocketTimeout(15000)
            .build();
    HttpGet method = new HttpGet(url);
    method.setConfig(requestConfig);

    InputStream in = null;
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        try (CloseableHttpResponse resp = client.execute(method)) {
            int statusCode = resp.getStatusLine().getStatusCode();
            if (statusCode != OK.value()) {
                response.sendError(statusCode);
            } else {
                in = resp.getEntity().getContent();
                IOUtils.copy(in, response.getOutputStream());
            }
        }
    } finally {
        FileUtil.closeQuietly(in);
    }
    return null;
}
 
Example 3
Source File: SmsValidateCodeProcessor.java    From codeway_service with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
       String paramName = CommonConst.DEFAULT_PARAMETER_NAME_PHONE;
       String phone = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
	request.getResponse().setContentType("application/json;charset=UTF-8");
       try {
        smsCodeSender.send(phone, validateCode.getCode());
        request.getResponse().getWriter().write(objectMapper.writeValueAsString(JsonData.success()));
       }catch (Exception ex){
        LogBack.error("向手机:{},{},原因:{}",phone,StatusEnum.SMS_SEND_ERROR.getMsg(),ex.getCause(),ex);
        request.getResponse().getWriter().write(objectMapper.writeValueAsString(JsonData.failed(StatusEnum.SMS_SEND_ERROR)));

       }
}
 
Example 4
Source File: SmsValidateCodeProcessor.java    From codeway_service with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
       String paramName = CommonConst.DEFAULT_PARAMETER_NAME_PHONE;
       String phone = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
	request.getResponse().setContentType("application/json;charset=UTF-8");
       try {
        smsCodeSender.send(phone, validateCode.getCode());
        request.getResponse().getWriter().write(objectMapper.writeValueAsString(JsonData.success()));
       }catch (Exception ex){
        LogBack.error("向手机:{},{},原因:{}",phone,StatusEnum.SMS_SEND_ERROR.getMsg(),ex.getCause(),ex);
        request.getResponse().getWriter().write(objectMapper.writeValueAsString(JsonData.failed(StatusEnum.SMS_SEND_ERROR)));

       }
}
 
Example 5
Source File: ValidateCodeController.java    From imooc-security with Apache License 2.0 5 votes vote down vote up
@GetMapping("/code/sms")
public void createSmsCode(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletRequestBindingException {
    ValidateCode smsCode= smsCodeGenerator.generate(new ServletWebRequest(request));
    sessionStrategy.setAttribute(new ServletWebRequest(request),SESSION_KEY_CODE,smsCode);
    String mobile = ServletRequestUtils.getRequiredStringParameter(request, "mobile");
    smsCodeSender.send(mobile,smsCode.getCode());
}
 
Example 6
Source File: ProxyController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String url = ServletRequestUtils.getRequiredStringParameter(request, "url");

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(15000)
            .setSocketTimeout(15000)
            .build();
    HttpGet method = new HttpGet(url);
    method.setConfig(requestConfig);

    InputStream in = null;
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        try (CloseableHttpResponse resp = client.execute(method)) {
            int statusCode = resp.getStatusLine().getStatusCode();
            if (statusCode != OK.value()) {
                response.sendError(statusCode);
            } else {
                in = resp.getEntity().getContent();
                IOUtils.copy(in, response.getOutputStream());
            }
        }
    } finally {
        FileUtil.closeQuietly(in);
    }
    return null;
}
 
Example 7
Source File: SmsCodeProcessor.java    From imooc-security with Apache License 2.0 4 votes vote down vote up
@Override
protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
	String paramName = SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE;
	String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
	smsCodeSender.send(mobile, validateCode.getCode());
}
 
Example 8
Source File: EmailCodeProcessor.java    From paascloud-master with Apache License 2.0 3 votes vote down vote up
/**
 * Send.
 *
 * @param request      the request
 * @param validateCode the validate code
 *
 * @throws Exception the exception
 */
@Override
protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
	String paramName = SecurityConstants.DEFAULT_PARAMETER_NAME_EMAIL;
	String email = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
	emailCodeSender.send(email, validateCode.getCode());
}