ServletRequest 参数转Bean

@param <T> Bean类型
@param request ServletRequest
@param bean Bean
@param copyOptions 注入时的设置
@return Bean
@since 3.0.4
496236
public static <T> T fillBean(final ServletRequest request, T bean, CopyOptions copyOptions) {
		final String beanName = StrUtil.lowerFirst(bean.getClass().getSimpleName());
		return BeanUtil.fillBean(bean, new ValueProvider<String>() {
			@Override
			public Object value(String key, Type valueType) {
				String value = request.getParameter(key);
				if (StrUtil.isEmpty(value)) {
					// 使用类名前缀尝试查找值
					value = request.getParameter(beanName + StrUtil.DOT + key);
					if (StrUtil.isEmpty(value)) {
						// 此处取得的值为空时跳过，包括null和""
						value = null;
					}
				}
				return value;
			}

			@Override
			public boolean containsKey(String key) {
				// 对于Servlet来说，返回值null意味着无此参数
				return (null != request.getParameter(key)) || (null != request.getParameter(beanName + StrUtil.DOT + key));
			}
		}, copyOptions);
	}
965517
public static void copyProperties(Object source, Object target, CopyOptions copyOptions) {
		if (null == copyOptions) {
			copyOptions = new CopyOptions();
		}
		BeanCopier.create(source, target, copyOptions).copy();
	}
578843
private byte[] copyBytesFromRequest(HttpServletRequest httpServletRequest) throws IOException {
        InputStream inputStream = httpServletRequest.getInputStream();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int offset=-1;
        while((offset=inputStream.read(buffer,0,1024))>0){
            byteArrayOutputStream.write(buffer,0,offset);
        }
        return byteArrayOutputStream.toByteArray();
    }
638944
protected <T extends HttpRequestBase> T createHttpRequest(Q request) {
    T httpRequest = createHttpRequestBase(request);

    applyHeaders(httpRequest, request.getHeaders());

    applyPayload(httpRequest, request);

    return httpRequest;
  }
1361350
public static <Request> Input create(Request requestBean) {
        if (requestBean == null)
            throw new IllegalArgumentException("request bean should not be null!");
        Class requestClass = requestBean.getClass();
        return create(requestClass);
    }
922334
public void updateJspFromRequest(String servletPath, CmsFlexRequest request) {

        // assemble the RFS name of the requested jsp
        String jspUri = servletPath;
        String pathInfo = request.getPathInfo();
        if (pathInfo != null) {
            jspUri += pathInfo;
        }

        // check the file name
        if ((jspUri == null) || !jspUri.startsWith(m_jspWebAppRepository)) {
            // nothing to do, this kind of request are handled by the CmsJspLoader#service method
            return;
        }

        // remove prefixes
        jspUri = jspUri.substring(m_jspWebAppRepository.length());
        if (jspUri.startsWith(CmsFlexCache.REPOSITORY_ONLINE)) {
            jspUri = jspUri.substring(CmsFlexCache.REPOSITORY_ONLINE.length());
        } else if (jspUri.startsWith(CmsFlexCache.REPOSITORY_OFFLINE)) {
            jspUri = jspUri.substring(CmsFlexCache.REPOSITORY_OFFLINE.length());
        } else {
            // this is not an OpenCms jsp file
            return;
        }

        // read the resource from OpenCms
        CmsFlexController controller = CmsFlexController.getController(request);
        try {
            CmsResource includeResource;
            try {
                // first try to read the resource assuming no additional jsp extension was needed
                includeResource = readJspResource(controller, jspUri);
            } catch (CmsVfsResourceNotFoundException e) {
                // try removing the additional jsp extension
                if (jspUri.endsWith(JSP_EXTENSION)) {
                    jspUri = jspUri.substring(0, jspUri.length() - JSP_EXTENSION.length());
                }
                includeResource = readJspResource(controller, jspUri);
            }
            // make sure the jsp referenced file is generated
            updateJsp(includeResource, controller, new HashSet<String>(8));
        } catch (Exception e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(e.getLocalizedMessage(), e);
            }
        }
    }
696352
public static Map<String, String> getParamMap(ServletRequest request) {
		Map<String, String> params = new HashMap<String, String>();
		for (Map.Entry<String, String[]> entry : getParams(request).entrySet()) {
			params.put(entry.getKey(), ArrayUtil.join(entry.getValue(), StrUtil.COMMA));
		}
		return params;
	}
234672
public static CmsGallerySearchBean getSearch(HttpServletRequest request, CmsGalleryDataBean config) {

        CmsGalleryService srv = new CmsGalleryService();
        srv.setCms(CmsFlexController.getCmsObject(request));
        srv.setRequest(request);
        CmsGallerySearchBean result = null;
        try {
            result = srv.getSearch(config);
        } finally {
            srv.clearThreadStorage();
        }
        return result;
    }
1308319
public static ServiceContext createServiceContext(ServletRequest request) {
        if (!(request instanceof HttpServletRequest)) {
            throw new IllegalArgumentException("Expected HttpServletRequest");
        }
        return createServiceContext((HttpServletRequest) request);
    }
1019164
public Response makeRequest(final Request request) {

        HttpMethod method = request.getMethod();
        RequestBuilder builder = RequestBuilder.create(method.toString())
            .setUri(request.constructURL().toString())
            .setVersion(HttpVersion.HTTP_1_1)
            .setCharset(StandardCharsets.UTF_8);

        if (request.requiresAuthentication()) {
            builder.addHeader(HttpHeaders.AUTHORIZATION, request.getAuthString());
        }

        if (method == HttpMethod.POST) {
            builder.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");

            for (Map.Entry<String, List<String>> entry : request.getPostParams().entrySet()) {
                for (String value : entry.getValue()) {
                    builder.addParameter(entry.getKey(), value);
                }
            }
        }

        HttpResponse response = null;

        try {
            response = client.execute(builder.build());
            HttpEntity entity = response.getEntity();
            return new Response(
                // Consume the entire HTTP response before returning the stream
                entity == null ? null : new BufferedHttpEntity(entity).getContent(),
                response.getStatusLine().getStatusCode()
            );
        } catch (IOException e) {
            throw new ApiException(e.getMessage(), e);
        } finally {

            // Ensure this response is properly closed
            HttpClientUtils.closeQuietly(response);

        }

    }
584928
@Override
	protected void preparePaintComponent(final Request request) {
		assertConfigured();

		List beanList = getBeanList();

		List<Integer> used = new ArrayList<>();

		for (int i = 0; i < beanList.size(); i++) {
			Object rowData = beanList.get(i);

			// Each row has its own context. This is why we can reuse the same
			// WComponent instance for each row.
			UIContext rowContext = getRowContext(rowData, i);

			// Check the context has not been used for another row
			Integer subId = ((SubUIContext) rowContext).getContextId();
			if (used.contains(subId)) {
				Object rowId = ((SubUIContext) rowContext).getRowId();
				String msg = "The row context for row id ["
						+ rowId
						+ "] has already been used for another row. "
						+ "Either the row ID is not unique or the row bean has not implemented equals/hashcode "
						+ "or no rowIdBeanProperty set on the repeater that uniquely identifies the row.";
				throw new SystemException(msg);
			}
			used.add(subId);

			UIContextHolder.pushContext(rowContext);

			try {
				prepareRow(request, i);
			} finally {
				UIContextHolder.popContext();
			}
		}
	}
926407
public static <T> T fillBeanWithMap(Map<?, ?> map, T bean, boolean isToCamelCase, CopyOptions copyOptions) {
		if (MapUtil.isEmpty(map)) {
			return bean;
		}
		if (isToCamelCase) {
			map = MapUtil.toCamelCaseMap(map);
		}
		return BeanCopier.create(map, bean, copyOptions).copy();
	}
563430
public <T extends ApiObject> EntityResponse<T> query(Request<T> request)
    {
        return executeRequest(request, objectMapper.getTypeFactory()
                .constructParametrizedType(EntityResponse.class, EntityResponse.class, request.getEntityType()));
    }
841997
public static <T> T fillBean(T bean, ValueProvider<String> valueProvider, CopyOptions copyOptions) {
		if (null == valueProvider) {
			return bean;
		}

		return BeanCopier.create(valueProvider, bean, copyOptions).copy();
	}
295387
public void copy(CopyRequest request) {
    call(
      new PostRequest(path("copy"))
        .setParam("id", request.getId())
        .setParam("name", request.getName())
        .setParam("organization", request.getOrganization())
        .setMediaType(MediaTypes.JSON)
    ).content();
  }
984325
public String processRequest(HttpServletRequest request){
        Map<String, Object> reqMap = MessageUtil.parseXml(request, getToken(), getCropId(), getAESKey());
        String fromUserName = (String)reqMap.get("FromUserName");
        String toUserName = (String)reqMap.get("ToUserName");
        String msgType = (String)reqMap.get("MsgType");

        LOG.debug("收到消息，消息类型：{}", msgType);

        QYBaseRespMsg msg = null;

        if(msgType.equals(QYReqType.EVENT)){
            String eventType = (String)reqMap.get("Event");
            LOG.debug("收到消息，事件类型：{} " , eventType);

            if(QYEventType.SUBSCRIBE.equalsIgnoreCase(eventType)){
                QYBaseEvent event = new QYBaseEvent();
                buildBasicEvent(reqMap, event);
                msg = handleSubScribe(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }

            }else if(QYEventType.UNSUBSCRIBE.equalsIgnoreCase(eventType)){
                QYBaseEvent event = new QYBaseEvent();
                buildBasicEvent(reqMap, event);
                msg = handleUnsubscribe(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }
            }else if(QYEventType.CLICK.equalsIgnoreCase(eventType)){
                String eventKey = (String)reqMap.get("EventKey");
                LOG.debug("eventKey:{}", eventKey);
                QYMenuEvent event = new QYMenuEvent(eventKey);
                buildBasicEvent(reqMap, event);
                msg = handleMenuClickEvent(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }
            }else if(QYEventType.VIEW.equalsIgnoreCase(eventType)){
                String eventKey = (String)reqMap.get("EventKey");
                LOG.debug("eventKey:{}", eventKey);
                QYMenuEvent event = new QYMenuEvent(eventKey);
                buildBasicEvent(reqMap, event);
                msg = handleMenuViewEvent(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }
            }else if(QYEventType.LOCATION.equalsIgnoreCase(eventType)){
                double latitude = Double.parseDouble((String)reqMap.get("Latitude"));
                double longitude = Double.parseDouble((String)reqMap.get("Longitude"));
                double precision = Double.parseDouble((String)reqMap.get("Precision"));
                QYLocationEvent event = new QYLocationEvent(latitude, longitude, precision);
                buildBasicEvent(reqMap, event);
                msg = handleLocationEvent(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }
            }else if(QYEventType.SCANCODEPUSH.equalsIgnoreCase(eventType) || QYEventType.SCANCODEWAITMSG.equalsIgnoreCase(eventType)){
                String eventKey = (String)reqMap.get("EventKey");
                Map<String, Object> scanCodeInfo = (Map<String, Object>)reqMap.get("ScanCodeInfo");
                String scanType = (String)scanCodeInfo.get("ScanType");
                String scanResult = (String)scanCodeInfo.get("ScanResult");
                QYScanCodeEvent event = new QYScanCodeEvent(eventKey, scanType, scanResult);
                buildBasicEvent(reqMap, event);
                msg = handleScanCodeEvent(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }
            }else if(QYEventType.PICPHOTOORALBUM.equalsIgnoreCase(eventType) || QYEventType.PICSYSPHOTO.equalsIgnoreCase(eventType) || QYEventType.PICWEIXIN.equalsIgnoreCase(eventType)){
                String eventKey = (String)reqMap.get("EventKey");
                Map<String, Object> sendPicsInfo = (Map<String, Object>)reqMap.get("SendPicsInfo");
                int count = Integer.parseInt((String)sendPicsInfo.get("Count"));
                List<Map> picList = (List)sendPicsInfo.get("PicList");
                QYSendPicInfoEvent event = new QYSendPicInfoEvent(eventKey, count, picList);
                buildBasicEvent(reqMap, event);
                msg = handleSendPicsInfoEvent(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }
            }else if(QYEventType.ENTERAGENT.equalsIgnoreCase(eventType)){
                QYEnterAgentEvent event = new QYEnterAgentEvent();
                buildBasicEvent(reqMap, event);
                msg = handleEnterAgentEvent(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }
            }else if(QYEventType.BATCHJOBRESULT.equalsIgnoreCase(eventType)){
                Map<String, Object> batchJob = (Map<String, Object>)reqMap.get("BatchJob");
                String jobId = (String)batchJob.get("JobId");
                String jobType = (String)batchJob.get("JobType");
                int errCode = (Integer)batchJob.get("ErrCode");
                String errMsg = (String)batchJob.get("ErrMsg");
                QYBatchJobEvent event = new QYBatchJobEvent(jobId, jobType, errCode, errMsg);
                buildBasicEvent(reqMap, event);
                msg = handleBatchJobEvent(event);
                if(BeanUtil.isNull(msg)){
                    msg = processEventHandle(event);
                }
            }
        }else{
            if(QYReqType.TEXT.equalsIgnoreCase(msgType)){
                String content = (String)reqMap.get("Content");
                LOG.debug("文本消息内容：{}", content);
                QYTextReqMsg textReqMsg = new QYTextReqMsg(content);
                buildBasicReqMsg(reqMap, textReqMsg);
                msg = handleTextMsg(textReqMsg);
                if(BeanUtil.isNull(msg)){
                    msg = processMessageHandle(textReqMsg);
                }
            }else if(QYReqType.IMAGE.equalsIgnoreCase(msgType)){
                String picUrl = (String)reqMap.get("PicUrl");
                String mediaId = (String)reqMap.get("MediaId");
                QYImageReqMsg imageReqMsg = new QYImageReqMsg(picUrl, mediaId);
                buildBasicReqMsg(reqMap, imageReqMsg);
                msg = handleImageMsg(imageReqMsg);
                if(BeanUtil.isNull(msg)){
                    msg = processMessageHandle(imageReqMsg);
                }
            }else if(QYReqType.VOICE.equalsIgnoreCase(msgType)){
                String format = (String)reqMap.get("Format");
                String mediaId = (String)reqMap.get("MediaId");
                QYVoiceReqMsg voiceReqMsg = new QYVoiceReqMsg(mediaId, format);
                buildBasicReqMsg(reqMap, voiceReqMsg);
                msg = handleVoiceMsg(voiceReqMsg);
                if(BeanUtil.isNull(msg)){
                    msg = processMessageHandle(voiceReqMsg);
                }
            }else if(QYReqType.VIDEO.equalsIgnoreCase(msgType)){
                String thumbMediaId = (String)reqMap.get("ThumbMediaId");
                String mediaId = (String)reqMap.get("MediaId");
                QYVideoReqMsg videoReqMsg = new QYVideoReqMsg(mediaId, thumbMediaId);
                buildBasicReqMsg(reqMap, videoReqMsg);
                msg = handleVideoMsg(videoReqMsg);
                if(BeanUtil.isNull(msg)){
                    msg = processMessageHandle(videoReqMsg);
                }
            }else if(QYReqType.SHORT_VIDEO.equalsIgnoreCase(msgType)){
                String thumbMediaId = (String)reqMap.get("ThumbMediaId");
                String mediaId = (String)reqMap.get("MediaId");
                QYVideoReqMsg videoReqMsg = new QYVideoReqMsg(mediaId, thumbMediaId);
                buildBasicReqMsg(reqMap, videoReqMsg);
                msg = handleShortVideoMsg(videoReqMsg);
                if(BeanUtil.isNull(msg)){
                    msg = processMessageHandle(videoReqMsg);
                }
            }else if(QYReqType.LOCATION.equalsIgnoreCase(msgType)){
                double locationX = Double.parseDouble((String) reqMap.get("Location_X"));
                double locationY = Double.parseDouble((String)reqMap.get("Location_Y"));
                int scale = Integer.parseInt((String)reqMap.get("Scale"));
                String label = (String)reqMap.get("Label");
                QYLocationReqMsg locationReqMsg = new QYLocationReqMsg(locationX, locationY, scale, label);
                buildBasicReqMsg(reqMap, locationReqMsg);
                msg = handleLocationMsg(locationReqMsg);
                if(BeanUtil.isNull(msg)){
                    msg = processMessageHandle(locationReqMsg);
                }
            }
        }

        String result = "";
        if(BeanUtil.nonNull(msg)){
            msg.setFromUserName(toUserName);
            msg.setToUserName(fromUserName);
            result = msg.toXml();
            try{
                WXBizMsgCrypt pc = new WXBizMsgCrypt(getToken(), getAESKey(), getCropId());
                result = pc.encryptMsg(result, request.getParameter("timestamp"), request.getParameter("nonce"));
                LOG.debug("加密后密文：{}", result);
            }catch (AesException e){
                LOG.error("加密异常", e);
            }
        }
        return result;
    }
121810
public static void introspect(Object bean, ServletRequest request) throws JspCoreException {
        Enumeration e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            String value = request.getParameter(name);
            introspecthelper(bean, name, value, request, name, true);
        }
    }