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

The following are Jave code examples for showing how to use getParameterMap() 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: cas4.0.x-server-wechat   File: OpenIdService.java   View Source Code Vote up 6 votes
public static OpenIdService createServiceFrom(
        final HttpServletRequest request) {
    final String service = request.getParameter(CONST_PARAM_SERVICE);
    final String openIdIdentity = request.getParameter("openid.identity");
    final String signature = request.getParameter("openid.sig");

    if (openIdIdentity == null || !StringUtils.hasText(service)) {
        return null;
    }

    final String id = cleanupUrl(service);
    final String artifactId = request.getParameter("openid.assoc_handle");
    ParameterList paramList = new ParameterList(request.getParameterMap());

    return new OpenIdService(id, service, artifactId, openIdIdentity,
            signature, paramList);
}
 
Example 2
Project: open-kilda   File: LoggingFilter.java   View Source Code Vote up 6 votes
/**
 * Log request.
 *
 * @param request the request
 * @param the
 */
private void logRequest(final HttpServletRequest request) {
    StringBuilder msg = new StringBuilder();
    msg.append(REQUEST_PREFIX).append("\n\tid: '").append(request.getAttribute("Id"))
            .append("', ").append("\n\tcontent type: '").append(request.getContentType())
            .append("', ").append("\n\turl: '").append(request.getRequestURL());
    if (request.getQueryString() != null) {
        msg.append('?').append(request.getQueryString());
    }

    Map<String, String[]> parameters = request.getParameterMap();

    parameters.keySet().forEach((key) -> {
        msg.append("', \n\tparams: '").append(key + " : " + parameters.get(key));
    });

    _log.info("[logRequest] Request: " + msg.toString());
}
 
Example 3
Project: apache-tomcat-7.0.73-with-comment   File: TestApplicationHttpRequest.java   View Source Code Vote up 6 votes
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    Map map = req.getParameterMap();

    boolean insertWorks;
    try {
        map.put("test", new Integer[] { Integer.valueOf(0) });
        insertWorks = true;
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        insertWorks = false;
    }

    resp.setContentType("text/plain");
    resp.setCharacterEncoding("UTF-8");
    PrintWriter pw = resp.getWriter();
    if (insertWorks) {
        pw.print("FAIL");
    } else {
        pw.print("OK");
    }
}
 
Example 4
Project: JAVA-   File: AliPay.java   View Source Code Vote up 6 votes
/**
 * 将异步通知的参数转化为Map
 * 
 * @param request
 * @return
 */
public static Map<String, String> toMap(HttpServletRequest request) {
	Map<String, String> params = new HashMap<String, String>();
	Map<String, String[]> requestParams = request.getParameterMap();
	for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) {
		String name = (String) iter.next();
		String[] values = (String[]) requestParams.get(name);
		String valueStr = "";
		for (int i = 0; i < values.length; i++) {
			valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
		}
		// 乱码解决,这段代码在出现乱码时使用。
		// valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
		params.put(name, valueStr);
	}
	return params;
}
 
Example 5
Project: parabuild-ci   File: WebuiUtils.java   View Source Code Vote up 6 votes
public static Properties parametersFromHttpServletRequest(final HttpServletRequest httpServletRequest) {

    final Properties result = new Properties();
    final Map parameterMap = httpServletRequest.getParameterMap();
    if (parameterMap == null) {
      return result;
    }
    for (final Iterator i = parameterMap.entrySet().iterator(); i.hasNext(); ) {
      final Map.Entry entry = (Map.Entry) i.next();
      final String paramName = (String) entry.getKey();
      if (paramName.startsWith("vti") || paramName.startsWith("cid")) {
        continue;
      }// skip internal viewtier parameters
      final String[] paramValues = (String[]) entry.getValue();
      if (paramValues == null || paramValues.length == 0) {
        continue;
      }
      result.setProperty(paramName, paramValues[0]);
    }
    return result;
  }
 
Example 6
Project: cas-5.1.0   File: SmartOpenIdController.java   View Source Code Vote up 6 votes
/**
 * Gets the association response. Determines the mode first.
 * If mode is set to associate, will set the response. Then
 * builds the response parameters next and returns.
 *
 * @param request the request
 * @return the association response
 */
public Map<String, String> getAssociationResponse(final HttpServletRequest request) {
    final ParameterList parameters = new ParameterList(request.getParameterMap());

    final String mode = parameters.hasParameter(OpenIdProtocolConstants.OPENID_MODE)
            ? parameters.getParameterValue(OpenIdProtocolConstants.OPENID_MODE)
            : null;

    Message response = null;

    if (StringUtils.equals(mode, OpenIdProtocolConstants.ASSOCIATE)) {
        response = this.serverManager.associationResponse(parameters);
    }
    final Map<String, String> responseParams = new HashMap<>();
    if (response != null) {
        responseParams.putAll(response.getParameterMap());
    }

    return responseParams;

}
 
Example 7
Project: wish-pay   File: AliPayUtil.java   View Source Code Vote up 6 votes
/**
 * 获取阿里支付链接的所有参数列表
 *
 * @param request
 * @return
 */
public static Map<String, String> getAlipayNotify(HttpServletRequest request) {
    Map<String, String> params = Maps.newHashMap();
    Map requestParams = request.getParameterMap();
    for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
        String name = iter.next();
        String[] values = (String[]) requestParams.get(name);
        String valueStr = "";
        for (int i = 0; i < values.length; i++) {
            valueStr = (i == values.length - 1) ? valueStr + values[i]
                    : valueStr + values[i] + ",";
        }
        //乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
        //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "gbk");
        params.put(name, valueStr);
    }
    return params;
}
 
Example 8
Project: -Spring-SpringMVC-Mybatis-   File: RequestParameterUtil.java   View Source Code Vote up 6 votes
/**
 * 移除url中的code、username参数
 * @param request
 * @return
 */
public static String getParameterWithOutCode(HttpServletRequest request) {
    StringBuffer backUrl = request.getRequestURL();
    String params = "";
    Map<String, String[]> parameterMap = request.getParameterMap();
    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
        if (!entry.getKey().equals("upms_code") && !entry.getKey().equals("upms_username")) {
            if (params.equals("")) {
                params = entry.getKey() + "=" + entry.getValue()[0];
            } else {
                params += "&" + entry.getKey() + "=" + entry.getValue()[0];
            }
        }
    }
    if (!StringUtils.isBlank(params)) {
        backUrl = backUrl.append("?").append(params);
    }
    return backUrl.toString();
}
 
Example 9
Project: bot4j   File: SlackActionWebhookImpl.java   View Source Code Vote up 6 votes
@Override
public String post(final HttpServletRequest req, final HttpServletResponse res) {
	try {
		final String payload = req.getParameter("payload");
		final JsonParser jsonParser = new JsonParser();
		final JsonObject json = jsonParser.parse(payload).getAsJsonObject();

		final Map<String, String[]> params = req.getParameterMap();

		slackReceiveHandler.handleAction(json, params);
	} catch (final Exception e) {
		handleException(e);
	}

	return "";
}
 
Example 10
Project: logistimo-web-service   File: CreateEntityServlet.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private void switchDomain(HttpServletRequest req, HttpServletResponse resp, UsersService as)
    throws ServiceException, ObjectNotFoundException, IOException {
  xLogger.fine("Entered switchDomain");

  // Get the session
  HttpSession session = req.getSession();
  Map<String, String[]> domainDetails = req.getParameterMap();

  // Get the user Id and new domain ID to switch to
  String userId = null;
  Long domainId = null;
  if (domainDetails.containsKey(USERID)) {
    userId = domainDetails.get(USERID)[0];
    if (userId.equalsIgnoreCase("")) {
      writeToScreenWithMode(req, resp,
          "Sorry, could not switch domain since user ID is not specified.", Constants.MODE_MANAGE,
          Constants.VIEW_DOMAINS);
      return;
    }
  }
  if (domainDetails.containsKey(DOMAINID)) {
    String domainIdStr = domainDetails.get(DOMAINID)[0];
    if (domainIdStr.equalsIgnoreCase("")) {
      writeToScreenWithMode(req, resp,
          "Sorry, could not switch domains since domain ID is not specified.",
          Constants.MODE_MANAGE, Constants.VIEW_DOMAINS);
      return;
    }
    domainId = Long.valueOf(domainIdStr);
  }
  // Set the new domain in the session
  SessionMgr.setCurrentDomain(session, domainId);
  // Redirect to the home page
  resp.sendRedirect("/s/index.jsp");
  xLogger.fine("Exiting switchDomain");
}
 
Example 11
Project: Equella   File: LoggingContextFilter.java   View Source Code Vote up 5 votes
public void logRequest(HttpServletRequest request)
{
	final StringBuilder params = new StringBuilder(request.getRequestURI() + "\n");
	final Map<String, String[]> parameterMap = request.getParameterMap();
	for( Entry<String, String[]> entry : parameterMap.entrySet() )
	{
		final String key = entry.getKey();
		final String keyLower = key.toLowerCase();
		final boolean blankOut = keyLower.contains("password") || keyLower.contains("secret");
		params.append(key);
		params.append("=");

		boolean firstVal = true;
		final String[] values = entry.getValue();
		if( values != null )
		{
			for( String value : values )
			{
				if( !firstVal )
				{
					params.append(",");
				}
				if( blankOut )
				{
					params.append(Strings.padStart("", value.length(), '*'));
				}
				else
				{
					params.append(value);
				}
				firstVal = false;
			}
		}
		params.append("\n");
	}
	REQUEST_LOGGER.trace(params.toString());
}
 
Example 12
Project: smarti   File: RocketChatEndpoint.java   View Source Code Vote up 5 votes
/**
 * Allow conversation-independent search.
 * @param clientName the client id
 * @param request the request to get the query params
 */
@ApiOperation(value = "search for messages", response = SearchResult.class,
        notes = "like solr.")
@RequestMapping(value = "{clientId}/search-message", method = RequestMethod.GET)
public ResponseEntity<?> searchMessage(
        AuthContext authContext,
        @PathVariable(value = "clientId") String clientName,
        HttpServletRequest request
) {
    if (log.isTraceEnabled()) {
        log.debug("{}[{}]: message-search for '{}'", clientName, authContext, request.getParameter("q"));
    } else {
        log.debug("{}: message-search for '{}'", clientName, request.getParameter("q"));
    }

    final Client client = clientService.getByName(clientName);
    if (client == null || !authenticationService.hasAccessToClient(authContext, client.getId())) {
        return ResponseEntity.notFound().build();
    }

    final Map<String, String[]> requestParameterMap = request.getParameterMap();
    if (conversationSearchService != null) {
        try {
            return ResponseEntity.ok(messageSearchService.search(client, requestParameterMap));
        } catch (IOException e) {
            return ResponseEntities.internalServerError(e);
        }
    }

    return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
}
 
Example 13
Project: xq_seckill_microservice   File: LogInterceptor.java   View Source Code Vote up 5 votes
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (LOGGER.isDebugEnabled()) {
        startTime = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();

        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();
        String methodName = method.getName();
        sb.append(ENTER).append(methodName);

        //参数非空则打印参数
        Map<String, String[]> requestMap = request.getParameterMap();
        if (requestMap != null && !requestMap.isEmpty()) {
            sb.append("(");
            for (Map.Entry<String, String[]> entry : requestMap.entrySet()) {
                sb.append("[");
                sb.append(entry.getKey());
                sb.append("=");
                String[] valueArr = entry.getValue();
                sb.append(valueArr[0].toString());
                sb.append("]");
            }
            sb.append(")");
        }

        LOGGER.debug(sb.toString());
    }

    return true;
}
 
Example 14
Project: Hi-Framework   File: MVCReqHandler.java   View Source Code Vote up 5 votes
private Map getValues(HttpServletRequest request){

        Map<String,Object> finalValues = new HashMap<String, Object>();
        Map<String,String[]> map =  request.getParameterMap();

        for(String key : map.keySet()){
            String[] values = map.get(key);
            if(values.length==1)
                finalValues.put(key,values[0]);
            else finalValues.put(key,values);
        }

        return finalValues;

    }
 
Example 15
Project: AppServiceRestFul   File: PayAction.java   View Source Code Vote up 5 votes
/**
 * 支付宝回调接口
 * @param request
 * @param resp
 * @return
 */
@ResponseBody
@RequestMapping(value="/verifyalipayresult.do", method=RequestMethod.POST)
public String verifyAliPayRight(HttpServletRequest request, HttpServletResponse resp)
{
    synchronized (alilock) {
        Map<String,String> params = new HashMap<String,String>();
        Map requestParams = request.getParameterMap();
        for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i]
                        : valueStr + values[i] + ",";
            }
            params.put(name, valueStr);
        }
        try {
            boolean flag = AlipaySignature.rsaCheckV1(params, PayService.ALI_PUBLIC_KEY, "utf-8", "RSA2");
            if(flag)
            {
                if(params.get("trade_status").equals("TRADE_SUCCESS") && params.get("app_id").equals(PayService.ALI_APPID) && params.get("seller_id").equals("2088621136650617"))
                {
                    return payService.verifyAliPay(params);
                }
            }
        } catch (AlipayApiException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "fail";
        }
    }
    return "fail";
}
 
Example 16
Project: lemon   File: MultipartHandler.java   View Source Code Vote up 5 votes
public void handleMultiValueMap(HttpServletRequest request) {
    Map<String, String[]> parameterMap = request.getParameterMap();

    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
        String key = entry.getKey();

        for (String value : entry.getValue()) {
            multiValueMap.add(key, value);
        }
    }
}
 
Example 17
Project: karate   File: SearchController.java   View Source Code Vote up 4 votes
@GetMapping
public Map<String, String[]> search(HttpServletRequest request) {
    return request.getParameterMap();
}
 
Example 18
Project: apache-tomcat-7.0.73-with-comment   File: TestApplicationHttpRequest.java   View Source Code Vote up 4 votes
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    req.setCharacterEncoding("UTF-8");
    resp.setContentType("text/plain");
    resp.setCharacterEncoding("UTF-8");
    PrintWriter w = resp.getWriter();
    Map<String,String[]> actual = req.getParameterMap();

    boolean ok = true;
    for (Entry<String,String[]> entry : actual.entrySet()) {
        String[] expectedValue = expected.get(entry.getKey());
        if (expectedValue == null ||
                expectedValue.length != entry.getValue().length) {
            ok = false;
            break;
        }
        for (int i = 0; i < expectedValue.length; i++) {
            if (!expectedValue[i].equals(entry.getValue()[i])) {
                ok = false;
                break;
            }
        }
        if (!ok) {
            break;
        }
    }

    if (ok) {
        w.print("OK");
        return;
    }
    boolean firstParam = true;
    for (Entry<String,String[]> param : actual.entrySet()) {
        if (firstParam) {
            firstParam = false;
        } else {
            w.print(';');
        }
        w.print(param.getKey());
        w.print(':');
        boolean firstValue = true;
        for (String value : param.getValue()) {
            if (firstValue) {
                firstValue = false;
            } else {
                w.print(',');
            }
            w.print('(');
            w.print(value);
            w.print(')');
        }
    }
}
 
Example 19
Project: logistimo-web-service   File: CreateEntityServlet.java   View Source Code Vote up 4 votes
/**
 *
 * @param req
 * @param resp
 * @param as
 * @throws ServiceException
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private void removeKioskOwner(HttpServletRequest req,
                              HttpServletResponse resp, UsersService as,
                              ResourceBundle backendMessages, ResourceBundle messages)
    throws ServiceException, IOException {
  Map<String, String[]> userDetails = req.getParameterMap();
  userDetails = cleanMap(userDetails);
  String message = "";
  String domainIdStr = req.getParameter(DOMAINID);
  Long domainId = null;
  if (domainIdStr != null && !domainIdStr.isEmpty()) {
    domainId = Long.valueOf(domainIdStr);
  }
  if (userDetails.containsKey(USERID)) {
    String[]
        userIDArr =
        req.getParameterValues(USERID); // userDetails.get("userids")[0].split(",");
    List<String> ids = new ArrayList<String>();
    if (userIDArr != null) {
      for (int i = 0; i < userIDArr.length; i++) {
        try {
          IUserAccount u = as.getUserAccount(userIDArr[i]);
          EntitiesService es = Services.getService(EntitiesServiceImpl.class);
          List results = es.getKioskIdsForUser(u.getUserId(), null, null).getResults();
          if (results !=null && !results.isEmpty()) {
            message +=
                " - " + u.getFullName() + " " + backendMessages.getString("user.cannotdelete")
                    + " " + results.size() + " " + backendMessages
                    .getString("kiosks.lowercase") + MsgUtil.newLine();
          } else {
            ids.add(userIDArr[i]);
          }
        } catch (ObjectNotFoundException e) {
          xLogger.warn("User not found: {0}", e.getMessage());
        }
      }
    }
    // Check if selected users are associated with a kiosk or not
    if (message.length() > 0) {
      message =
          backendMessages.getString("errors.oneormore") + ":<br/><br/>" + message + "<br/><br/>";
    }
    if (ids.size() > 0) {
      as.deleteAccounts(domainId, ids, null);
      message =
          MsgUtil.bold(String.valueOf(ids.size())) + backendMessages.getString("deleted.success") + ". "
              + message;
    }
  }

  message +=
      " &nbsp;[<a href=\"/s/setup/setup.jsp?subview=users\">" + backendMessages
          .getString("users.view") + "</a>]";

  writeToSetupScreen(req, resp, message, Constants.VIEW_USERS);
}
 
Example 20
Project: bumblebee   File: SecurityFilter.java   View Source Code Vote up 4 votes
private boolean validateSign(HttpServletRequest request){
    String sign = request.getParameter("sign");
    String email = request.getParameter("email");
    if(StringUtils.isBlank(sign)||StringUtils.isBlank(email)){
        return false;
    }

    //find user
    BumblebeeService bumblebeeService= SpringContextUtil.getBean(BumblebeeServiceImpl.class);
    BumblebeeUser user =bumblebeeService.queryUser(email);
    if(user==null){
        return false;
    }
    //制作md5
    String signKey=user.getPwd();

    StringBuffer sortUri = new StringBuffer();
    Map<String, String[]> params = request.getParameterMap();
    Set<String> keys = params.keySet();
    List<String> list = new ArrayList<String>();
    list.addAll(keys);
    Collections.sort(list);
    for (String k : list) {
        if (!"sign".equals(k)) {
            sortUri.append(k + "=");
            sortUri.append((params.get(k) != null && params.get(k).length > 0) ? params.get(k)[0] : "");
            sortUri.append("&");
        }
    }
    if(list!=null&&list.size()>0){
        sortUri.deleteCharAt(sortUri.length() - 1);
    }
    String signFinal = Md5Util.MD5(sortUri.toString().trim()+signKey);

    LOG.info("final sign str :" + sortUri + ",signFinal:" + signFinal + ",sign:" + sign);
    // 验签成功
    if (sign.equalsIgnoreCase(signFinal)) {
        LOG.info("Sign Validate success !");
        return true;
    }
    return false;
}