List of usage examples for org.apache.commons.beanutils BeanUtils populate
public static void populate(Object bean, Map properties)
From source file:com.adito.properties.actions.AbstractPropertiesAction.java
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Initialise form AbstractPropertiesForm pf = (AbstractPropertiesForm) form; pf.clearValues();//from w ww. ja v a2s . c om pf.setUpdateAction(mapping.getPath() + ".do"); pf.setInput(mapping.getInput()); // Now try the struts supplied action mapping parameter if (mapping.getParameter() != null && !mapping.getParameter().equals("")) { PropertyList pl = new PropertyList(mapping.getParameter()); Properties pr = pl.getAsNameValuePairs(); BeanUtils.populate(pf, pr); } if ("changeSelectedCategory".equalsIgnoreCase(pf.getActionTarget())) { pf.setSelectedCategory(pf.getNewSelectedCategory()); } // Build and display return rebuildItems(mapping, pf.getParentCategory(), pf, request, getSessionInfo(request).getUser()); }
From source file:com.liusoft.dlog4j.velocity.VelocityTool.java
/** * Call by VelocityViewServlet/*from ww w . j av a 2s.c o m*/ */ public void configure(Map arg0) { this.params = arg0; try { BeanUtils.populate(this, arg0); } catch (Exception e) { log.error("Populate parameters to " + getClass().getName() + " failed.", e); } }
From source file:de.hybris.platform.chinesepspwechatpay.controllers.misc.ChineseWeChatPayResponseController.java
@RequestMapping(value = "/paymentresponse/notify", method = RequestMethod.POST) public void handlePaymentResponse(final HttpServletRequest request, final HttpServletResponse response) throws CMSItemNotFoundException, IOException { final String requestBody = getPostRequestBody(request); if (requestBody.isEmpty()) { LOG.error("Notify body is empty"); } else {//from w w w .j a va 2s. co m final Map<String, String> unifyResponseMap; try { final Node notifyXml = new XmlParser().parseText(requestBody); unifyResponseMap = (Map<String, String>) notifyXml.children().stream().collect( Collectors.toMap(k -> ((Node) k).name(), k -> ((Node) k).children().get(0).toString())); final SignVerificationProcessor signVerificationProcessor = new SignVerificationProcessor( weChatPayConfiguration, unifyResponseMap); if (!signVerificationProcessor.process().booleanValue()) { LOG.warn("Invalid notify from WeChatPay"); response.setContentType("text/xml"); response.getWriter().write(XSSEncoder.encodeXML("FAIL")); } final WeChatRawDirectPayNotification weChatPayNotification = new WeChatRawDirectPayNotification(); final Map<String, String> camelCaseMap = WeChatPayUtils.convertKey2CamelCase(unifyResponseMap); BeanUtils.populate(weChatPayNotification, camelCaseMap); weChatPayNotificationService.handleWeChatPayPaymentResponse(weChatPayNotification); response.setContentType("text/xml"); response.getWriter().write(XSSEncoder.encodeXML("SUCCESS")); } catch (IOException | SAXException | ParserConfigurationException | IllegalAccessException | InvocationTargetException e) { LOG.error("Problem in handling WeChatPay's notify message", e); } } }
From source file:com.feedzai.fos.impl.weka.utils.WekaThreadSafeScorerPool.java
/** * Creates a new thread safe scorer from the given configuration parameters. * * @param wekaModelConfig the configuration of the model * @param wekaManagerConfig the global configurations * @throws FOSException when the underlying classifier could not be instantiated *//* w ww . j a v a 2 s . co m*/ public WekaThreadSafeScorerPool(WekaModelConfig wekaModelConfig, WekaManagerConfig wekaManagerConfig) throws FOSException { checkNotNull(wekaModelConfig, "Model config cannot be null"); checkNotNull(wekaManagerConfig, "Manager config cannot be null"); checkNotNull(wekaModelConfig.getAttributess(), "Model instances fields cannot be null"); checkArgument(wekaModelConfig.getAttributess().size() > 0, "Model must have at least one field"); this.poolConfig = new GenericObjectPoolConfig(); this.wekaManagerConfig = wekaManagerConfig; this.wekaModelConfig = wekaModelConfig; this.attributes = WekaUtils.instanceFields2Attributes(wekaModelConfig.getClassIndex(), wekaModelConfig.getAttributess()); this.instanceSetters = WekaUtils.instanceFields2ValueSetters(wekaModelConfig.getAttributess(), InstanceType.SCORING); this.instances = new Instances(Integer.toString(this.wekaModelConfig.hashCode()), attributes, 0 /*this set is for scoring only*/); this.instances.setClassIndex(wekaModelConfig.getClassIndex()); try { BeanUtils.populate(poolConfig, this.wekaModelConfig.getPoolConfiguration()); final Cloner<Classifier> cloner = new Cloner<Classifier>(wekaModelConfig.getModelDescriptor()); // check that the profided file is in fact a valid classifier object. cloner.get(); this.pool = new AutoPopulateGenericObjectPool<>(new ClassifierFactory(cloner), poolConfig); } catch (Exception e) { throw new FOSException(e); } }
From source file:fr.paris.lutece.plugins.workflow.modules.notifycrm.web.NotifyCRMTaskComponent.java
/** * {@inheritDoc}//from w w w .java2s. c o m */ @Override public String doSaveConfig(HttpServletRequest request, Locale locale, ITask task) { // In case there are no errors, then the config is created/updated boolean bCreate = false; TaskNotifyCRMConfig config = _taskNotifyCRMConfigService.findByPrimaryKey(task.getId()); if (config == null) { config = new TaskNotifyCRMConfig(); config.setIdTask(task.getId()); bCreate = true; } try { BeanUtils.populate(config, request.getParameterMap()); } catch (IllegalAccessException e) { AppLogService.error("NotifyCRMTaskComponent - Unable to fetch data from request", e); } catch (InvocationTargetException e) { AppLogService.error("NotifyCRMTaskComponent - Unable to fetch data from request", e); } String strApply = request.getParameter(NotifyCRMConstants.PARAMETER_APPLY); // Check if the AdminUser clicked on "Apply" or on "Save" if (StringUtils.isEmpty(strApply)) { // Check mandatory fields Set<ConstraintViolation<TaskNotifyCRMConfig>> constraintViolations = BeanValidationUtil .validate(config); if (constraintViolations.size() > 0) { return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP); } } if (bCreate) { _taskNotifyCRMConfigService.create(config); } else { _taskNotifyCRMConfigService.update(config); } return null; }
From source file:fr.paris.lutece.plugins.extend.business.extender.ResourceExtenderDTOFilter.java
/** * Init.//from ww w . ja va 2 s .c om * * @param request the request */ public void init(HttpServletRequest request) { try { BeanUtils.populate(this, request.getParameterMap()); } catch (IllegalAccessException e) { AppLogService.error("Unable to fetch data from request", e); } catch (InvocationTargetException e) { AppLogService.error("Unable to fetch data from request", e); } }
From source file:com.liusoft.dlog4j.db.DataSourceConnectionProvider.java
/** * Initialize the datasource/*from www . j a va2s. com*/ * @param props * @throws HibernateException */ protected synchronized void initDataSource(Properties props) throws HibernateException { String dataSourceClass = null; Properties new_props = new Properties(); Iterator keys = props.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); //System.out.println(key+"="+props.getProperty(key)); if (ENCODING_KEY.equalsIgnoreCase(key)) { encoding = "true".equalsIgnoreCase(props.getProperty(key)); useProxy = true; } else if (DATASOURCE_KEY.equalsIgnoreCase(key)) { dataSourceClass = props.getProperty(key); } else if (key.startsWith(BASE_KEY)) { String value = props.getProperty(key); value = StringUtils.replace(value, "{DLOG4J}", Globals.WEBAPP_PATH); new_props.setProperty(key.substring(BASE_KEY.length()), value); } } if (dataSourceClass == null) throw new HibernateException("Property 'dscp.datasource' no defined."); try { dataSource = (DataSource) Class.forName(dataSourceClass).newInstance(); BeanUtils.populate(dataSource, new_props); } catch (Exception e) { throw new HibernateException(e); } }
From source file:fr.paris.lutece.plugins.workflow.modules.notifymylutece.web.NotifyMyLuteceTaskComponent.java
/** * {@inheritDoc}/*from w w w . j a va2 s .c o m*/ */ @Override public String doSaveConfig(HttpServletRequest request, Locale locale, ITask task) { // In case there are no errors, then the config is created/updated boolean bCreate = false; TaskNotifyMyLuteceConfig config = _taskNotifyMyLuteceConfigService.findByPrimaryKey(task.getId()); if (config == null) { config = new TaskNotifyMyLuteceConfig(); config.setIdTask(task.getId()); bCreate = true; } try { BeanUtils.populate(config, request.getParameterMap()); String strApply = request.getParameter(PARAMETER_APPLY); // Check if the AdminUser clicked on "Apply" or on "Save" if (StringUtils.isEmpty(strApply)) { String strJspError = validateConfig(config, request); if (StringUtils.isNotBlank(strJspError)) { return strJspError; } } // The method is overrided becaus of the following setter config.setListUserGuid(getSelectedUsers(request, config)); if (bCreate) { _taskNotifyMyLuteceConfigService.create(config); } else { _taskNotifyMyLuteceConfigService.update(config); } } catch (IllegalAccessException e) { AppLogService.error(e.getMessage(), e); } catch (InvocationTargetException e) { AppLogService.error(e.getMessage(), e); } return null; }
From source file:com.mirth.connect.connectors.jms.JmsDispatcherTests.java
@BeforeClass public static void beforeClass() throws Exception { JmsDispatcherProperties properties = getInitialProperties(); if (properties.isUseJndi()) { connectionFactory = lookupConnectionFactoryWithJndi(properties); } else {/*w w w . ja v a2 s . co m*/ String className = properties.getConnectionFactoryClass(); connectionFactory = (ConnectionFactory) Class.forName(className).newInstance(); } BeanUtils.populate(connectionFactory, properties.getConnectionProperties()); Connection connection = connectionFactory.createConnection(properties.getUsername(), properties.getPassword()); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
From source file:io.fabric8.api.registry.rules.CamelEndpointFinder.java
@Override protected void appendObjectNameEndpoints(List<ApiDTO> list, ApiSnapshot snapshot, Pod pod, Container container, J4pClient jolokia, ObjectName objectName) throws MalformedObjectNameException, J4pException { String httpUrl = getHttpUrl(pod, container, jolokia); String urlPrefix = snapshot.getUrlPrefix(); if (httpUrl != null) { URL url = null;//from ww w .ja va2 s . c o m try { url = new URL(httpUrl); } catch (MalformedURLException e) { LOG.warn("Failed to parse http URL: " + httpUrl + ". " + e, e); return; } ApiDeclaration apiDeclaration = new ApiDeclaration(); apiDeclaration.setModels(new Models()); // lets find the rest services... J4pResponse<J4pExecRequest> results = jolokia .execute(new J4pExecRequest(objectName, "listRestServices")); Object value = results.getValue(); if (value instanceof Map) { Map<String, Object> map = (Map<String, Object>) value; Set<Map.Entry<String, Object>> entrySet = map.entrySet(); for (Map.Entry<String, Object> entry : entrySet) { String uriPattern = entry.getKey(); Object entryValue = entry.getValue(); if (entryValue instanceof Map) { Map<String, Object> entryMap = (Map<String, Object>) entryValue; Set<Map.Entry<String, Object>> operations = entryMap.entrySet(); for (Map.Entry<String, Object> operation : operations) { String operationName = operation.getKey(); Object operationValue = operation.getValue(); if (operationValue instanceof Map) { Map operationMap = (Map) operationValue; CamelRestService restService = new CamelRestService(); try { BeanUtils.populate(restService, operationMap); } catch (Exception e) { LOG.warn("Failed to populate " + restService + " from " + operationMap + ". " + e, e); return; } restService.setUrl(replaceHostAndPort(url, restService.getUrl())); restService.setBaseUrl(replaceHostAndPort(url, restService.getBaseUrl())); addToApiDescription(apiDeclaration, restService, objectName); } } } } } List<Api> apis = apiDeclaration.getApis(); if (apis != null && apis.size() > 0) { // TODO where should we get the API version from? // lets add a default version if (Strings.isNullOrBlank(apiDeclaration.getApiVersion())) { apiDeclaration.setApiVersion("1.0"); } if (apiDeclaration.getSwaggerVersion() == null) { apiDeclaration.setSwaggerVersion(ApiDeclaration.SwaggerVersion._1_2); } String podId = getName(pod); // TODO this is not the container id... String containerId = getName(pod); PodAndContainerId key = new PodAndContainerId(podId, containerId); snapshot.putPodAndContainerSwagger(key, apiDeclaration); String basePath = apiDeclaration.getResourcePath(); URI basePathUri = apiDeclaration.getBasePath(); String fullUrl = null; if (basePathUri != null) { fullUrl = basePathUri.toString(); } String swaggerPath = "/swagger/pod/" + podId + "/" + containerId; String swaggerUrl = null; if (Strings.isNotBlank(urlPrefix)) { swaggerUrl = urlPathJoin(urlPrefix, swaggerPath); } String wadlPath = null; String wadlUrl = null; String wsdlPath = null; String wsdlUrl = null; int port = url.getPort(); String state = "RUNNING"; String jolokiaUrl = jolokia.getUri().toString(); String serviceId = null; ApiDTO api = new ApiDTO(pod, container, serviceId, objectName.toString(), basePath, fullUrl, port, state, jolokiaUrl, swaggerPath, swaggerUrl, wadlPath, wadlUrl, wsdlPath, wsdlUrl); list.add(api); } } }