354 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
Is Converged Infrastructure cure for your data center headaches?
Thu, Apr 17th 2014 33
5 Things That Should Be Keeping CMO’s Up at Night
Thu, Apr 17th 2014 55
IBM Acquires Marketing Automation Player Silverpop
Tue, Apr 15th 2014 70
The Ideal Length of every Tweet, Facebook Post and Headline
Tue, Apr 8th 2014 102
5 Key Strategies for Omni-Channel Marketing
Mon, Apr 7th 2014 127
Liferay Releases SDK to Speed Up Custom Mobile App Development
Tue, Apr 1st 2014 87
Adobe Summit: Designing an integrated customer profile
Thu, Mar 27th 2014 83
Top 10
Official Sitecore Training – Recommendations on Who, What & When
Sun, Dec 23rd 2012 411
SharePoint migrations may cause consternation
Sun, Feb 16th 2014 334
IBM Connect: Demos
Mon, Jan 27th 2014 317
Gartner Magic Quadrant for Horizontal Portals 2013
Wed, Sep 25th 2013 311
IBM Connect: Keynote Guest Speaker: Seth Meyers
Mon, Jan 27th 2014 272
Optimizing Experiences Using IBM TeaLeaf
Tue, Jan 28th 2014 253
IBM Connect: Vision and Direction
Mon, Jan 27th 2014 242
Mobile apps using IBM Worklight and WebSphere Portal: a tutorial
Tue, Sep 4th 2012 233
What’s coming in WebSphere Portal and WCM
Tue, Jan 28th 2014 229
IBM Connect: Social Next What’s Coming to Social
Mon, Jan 27th 2014 218


Using WPS style Resource Environment Providers with Spring
Michael Porter    

Lee Burch, one of our extremely talented architects, gave me a writeup on “Using WPS style Resource Environment Providers with Spring”  He wanted to know where to post something like this and of course, my first thought is this blog.  His justification for posting this is that while it’s a common use case in the WebSphere Portal world, many developers get it wrong.  So thanks to Lee for the post.

Generally a problem most projects face is how to handle configuration information that varies between environments.  Many times you can handle this by using one of WAS built in resources such as a SMTP server or a JDBC connection pool.  However many times the configuration data won’t fit one of these existing WAS resource types, such as an e-mail address, a server name or a URL.  To solve this a lot of approaches are available some use build tools such as Maven to build different EAR files, others use properties files located outside of the EAR.  Unfortunately both of these solutions have their issues and can be difficult to manage.

To solve this problem WAS provides and WPS leverages the resource environment providers. These allow you to specify your settings as a part of the WAS console at the Cell, Node or Server level.  This provides an easy way to maintain values across many servers while also doing away with the need to have special EARs built for each environment.

The following IBM article discusses this

http://www.ibm.com/developerworks/websphere/library/techarticles/0611_totapally/0611_totapally.html

Unfortunately it requires deployment to the App Server lib/ext directory, something that is not always so easily done particularly in a shared enterprise environment.

However WPS uses Resource Environment Providers but does so differently than the above article specifies, it uses the “Custom Properties” of the resource environment provider and requires no deployment to the App Server, an ideal solution.

While it is possible to bind your code directly to the fetches to the Resource Environment Provider I find a more flexible and much more modern way of addressing the problem is to use Spring and its facility for PropertyPlaceholderConfigurer.

This allows for a Spring config something like this

<bean id=”MyBean” class=”com.perficient.sample.MyBean”>
<property name=”${administratorsEmailAddress}” />
</bean>

And the property administratorsEmailAddress will be replaced with the value from the Resource Environment Provider before the context is initialized.

The whole thing would look something like this

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

xmlns=”http://www.springframework.org/schema/beans”

xmlns:util=”http://www.springframework.org/schema/util”

xsi:schemaLocation=”http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd”>

<bean>

<property name=”resourceProviderName” value=”NameOfMyResourceEnvironmentProvider” />

</bean>
<bean id=”MyBean” class=”com.perficient.sample.MyBean”>
<property name=”${administratorsEmailAddress}” />
</bean>

</beans>

 

This will lookup the custom property “administratorsEmailAddress” under the Resource Environment Provider named “NameOfMyResourceEnvironmentProvider” and do the substitution before initializing the context.  Of course it also follows the standard WAS rules allowing for the Node to trump the Cell setting and the Server to trump the Node and Cell settings allowing a lot of flexibility in how the property gets propagated to your configuration.

The code for the WebSphereResourceEnvironmentProviderPlaceHolderConfigurer follows

package com.perficient.spring;

 

import java.util.List;

import java.util.Properties;

 

import javax.management.AttributeList;

import javax.management.AttributeNotFoundException;

import javax.management.ObjectName;

 

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

 

import com.ibm.websphere.management.AdminService;

import com.ibm.websphere.management.AdminServiceFactory;

import com.ibm.websphere.management.Session;

import com.ibm.websphere.management.configservice.ConfigService;

import com.ibm.websphere.management.configservice.ConfigServiceFactory;

import com.ibm.websphere.management.configservice.ConfigServiceHelper;

import com.ibm.websphere.management.exception.ConfigServiceException;

import com.ibm.websphere.management.exception.ConnectorException;

 

 

/**

* The Class WebSphereResourceEnvironmentProviderPlaceHolderConfigurer implements a placeholder that uses WebSphere Application Server

* Resource Environment Provider custom properties as a source.  These will work in the normal way with anythign declared at the server layer

* overriding anything at the node layer which in turns overrides anything at the cell layer.</p>

* For development you may find it useful to either get rid of this definition or use a standard properties file for the placeholders.  As this is

* inherited off the standard placeholder you can still use the normal properties file definition as a fallback.</p>

* To use it simply create a resource environment provider in WAS at whatever level pleases you, and then add the data you want as custom properties]

* to that.  Then in spring specify the name of the resource environment provider as the “resourceProviderName” in the spring configuration

* for this WebSphereResourceEnvironmentProviderPlaceHolderConfigurer.

*

*/

public class WebSphereResourceEnvironmentProviderPlaceHolderConfigurer extends PropertyPlaceholderConfigurer {

 

/** The resource provider name. */

String resourceProviderName;

/** The server properties. */

Properties serverProperties = null;

/** The node properties. */

Properties nodeProperties = null;

/** The cell properties. */

Properties cellProperties = null;

/**

* Gets the resource provider name.

*

* @return the resource provider name

*/

public String getResourceProviderName() {

return resourceProviderName;

}

 

/**

* Sets the resource provider name.

*

* @param resourceProviderName the new resource provider name

*/

public void setResourceProviderName(String resourceProviderName) {

this.resourceProviderName = resourceProviderName;

}

 

/**

* Gets the properties.

*

* @param level the level

* @param providerName the provider name

* @param service the service

* @param session the session

* @return the properties

* @throws ConfigServiceException the config service exception

* @throws ConnectorException the connector exception

* @throws AttributeNotFoundException the attribute not found exception

*/

private Properties getProperties(ObjectName level, ObjectName providerName, ConfigService service, Session session) throws ConfigServiceException, ConnectorException, AttributeNotFoundException {

Properties rv = new Properties();

ObjectName sampleProviderName = null;

ObjectName[] matches;

try {

matches = service.queryConfigObjects(session, level, providerName, null);

} catch (Exception ex) {

ex.printStackTrace();

return rv;

}

if (matches.length > 0) {

sampleProviderName = matches[0]; // use the first provider found

}

if (sampleProviderName != null) {

// search for the repository provider attributes

AttributeList value = service.getAttributes(session, sampleProviderName, new String[] { “propertySet” }, false);

ObjectName propertySet = (ObjectName) ConfigServiceHelper.getAttributeValue(value, “propertySet”);

value = service.getAttributes(session, propertySet, new String[] { “resourceProperties” }, false);

List resourceProperties = (List) ConfigServiceHelper.getAttributeValue(value, “resourceProperties”);

for (int i = 0; i < resourceProperties.size(); i++) {

// load all custom properties

ObjectName on = (ObjectName) resourceProperties.get(i);

String customName = (String) service.getAttribute(session, on, “name”);

String customValue = (String)service.getAttribute(session, on, “value”);

// put it in the property set

rv.put(customName, customValue);

}

}

return rv;

}

 

/**

* Load environment provider properties.

*

* @throws ConfigServiceException the config service exception

* @throws ConnectorException the connector exception

* @throws AttributeNotFoundException the attribute not found exception

*/

private void loadEnvironmentProviderProperties() throws ConfigServiceException, ConnectorException, AttributeNotFoundException {

ConfigService service = ConfigServiceFactory.getConfigService();

Session session = new Session();

AdminService adminService = AdminServiceFactory.getAdminService();

// for some reason the ObjectName returned by the adminService throws a null exception if you try to query with it

// so this is just as well, server names are unique in a cell so this will always return just one server.

ObjectName server = ConfigServiceHelper.createObjectName(null, “Server”, adminService.getLocalServer().getKeyProperty(“name”) );

ObjectName[] matches = service.queryConfigObjects(session, null, server, null);

server = matches[0]; // will be exact match

 

ObjectName node = ConfigServiceHelper.createObjectName(null, “Node”, adminService.getNodeName());

matches = service.queryConfigObjects(session, null, node, null);

node = matches[0]; // will be exact match

 

ObjectName cell = ConfigServiceHelper.createObjectName(null, “Cell”, adminService.getCellName());

matches = service.queryConfigObjects(session, null, cell, null);

cell = matches[0]; // will be exact match

 

// direct search

ObjectName providerName = ConfigServiceHelper.createObjectName(null,  “ResourceEnvironmentProvider”, “SeedlistTransformer”);

 

serverProperties = getProperties(server, providerName, service, session);

nodeProperties = getProperties(node, providerName, service, session);

cellProperties = getProperties(cell, providerName, service, session);

}

 

/**

* Resolve provider value.

*

* @param name the name

* @return the string

*/

private String resolveProviderValue(String name) {

if (serverProperties.containsKey(name) ) {

return serverProperties.getProperty(name);

} else if (nodeProperties.containsKey(name)) {

return nodeProperties.getProperty(name);

} else if (cellProperties.containsKey(name) ) {

return cellProperties.getProperty(name);

} else {

return null;

}

}

 

/* (non-Javadoc)

* @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#resolvePlaceholder(java.lang.String, java.util.Properties)

*/

@Override

protected String resolvePlaceholder(String placeholder, Properties props) {

if (serverProperties == null) {

try {

loadEnvironmentProviderProperties();

} catch (ConfigServiceException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (AttributeNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ConnectorException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

String value = resolveProviderValue(placeholder);

if (value == null) {

return super.resolvePlaceholder(placeholder, props);

} else {

return value;

}

}

 

 

}



---------------------
http://feedproxy.google.com/~r/PortalSolutionsBlog/~3/ZgaV8LmlQpo/
Mar 28, 2012
32 hits



Recent Blog Posts
33


Is Converged Infrastructure cure for your data center headaches?
Thu, Apr 17th 2014 2:12p   Brendon Jones
Oracle recently upgraded their Virtual Compute Appliance (OVCA) to X4-2. It was launched earlier in 2013, with adoption accelerating. It’s particularly useful for consolidating non-workload specific applications into a single managed environment. Applications may be installed on Windows, Linux, or Solaris. OVCA is part of Oracle’s portfolio of Converged Infrastructure, also known as Engineered Systems. This portfolio includes: Exadata Database Machine and Oracle Database Appliance & [read] Keywords: connections ibm application applications database development integration java linux microsoft networking oracle security virtualization
55


5 Things That Should Be Keeping CMO’s Up at Night
Thu, Apr 17th 2014 9:12a   Michael Porter
Thanks to Sharon Suchoval for pointing me to this.  Unless you’ve been hiding under a rock, anyone close to Marketing knows that the digital migration has unleashed a sea of change in the Marketing Department and the CMO.   The Oracle Social Spotlight has an article about 5 Things That Should Be Keeping CMO’s Up at Night. It’s a somewhat light hearted post on a potentially heavy topic.  I’m not going to reveal everything but let me give you the five things. They are su [read] Keywords: oracle
70


IBM Acquires Marketing Automation Player Silverpop
Tue, Apr 15th 2014 1:14p   Michael Porter
The enterprise marketing management space has been heating up for the past couple years.  IBM, Salesforce, Oracle, Adobe, and Microsoft have all made one or more acquisitions here and it hasn’t stopped.  Just a few days ago, IBM bought Silverpop, an Atlanta based cloud marketing automation player with customers in both the B2B and B2C space.  This is in addition to IBM’s Unica and Xtify acquisitions.  As IBM puts in in a Destination CRM article, “Across the board, we’ [read] Keywords: ibm email enterprise interface microsoft mobile oracle
102


The Ideal Length of every Tweet, Facebook Post and Headline
Tue, Apr 8th 2014 6:12a   Mark Polly
I think every writer at one time or another has thought about how long is too long for a post, tweet or headline. As I typed my headline into WordPress, it was kind enough to tell me that my headline is 59 of 65 characters. I never understood if WordPress thought 65 was the max or the ideal size for my headline. Reading through Zite (soon to be Flipboard) today, I came across this article by Kevan Lee at Fast Company: The Proven Ideal Length of Every Tweet, Facebook Post, and Headline Onlin [read] Keywords: facebook google twitter
127


5 Key Strategies for Omni-Channel Marketing
Mon, Apr 7th 2014 11:11a   Mark Polly
IBM recently conducted a webinar titled “5 Key Strategies for Omni-Channel Marketing” in which they discussed the following strategies: Collect data that helps create customer profiles Analyze that customer data to find actionable insights Decide how to allocate your budget across the right channels to reach the right audiences Manage the interactions with customers across the channels Optimize your messages, offers, and capture reactions to feed the data collection process Within [read] Keywords: ibm mac mobile profile
87


Liferay Releases SDK to Speed Up Custom Mobile App Development
Tue, Apr 1st 2014 9:11a   Michael Porter
This just in, Liferay has a new SDK for custom mobile apps.  They will release it to the public on April 2nd.  Here’s the press release. Liferay Releases SDK to Speed Up Custom Mobile App Development New developer toolkit helps Liferay’s customers develop and manage sophisticated mobile apps LOS ANGELES – (April 1, 2014) – Liferay, Inc., which makes open source portal software, is releasing a mobile software development kit today. The Mobile SDK is part of Liferay’s commitment [read] Keywords: collaboration community development eclipse email enterprise integration mobile twitter
83


Adobe Summit: Designing an integrated customer profile
Thu, Mar 27th 2014 4:15p   Mark Polly
Matthew Rawding, a Consulting Manager with Adobe. talked about how to use Adobe Campaign to create an integrated customer profile.  So what is an integrated customer profile? An integrated customer profile is a main pillar of Adobe Campaign.  Also included in Campaign are targeted segmentation, visual campaign orchestration, cross-channel execution, real time interaction management, and operational reporting. The goal is to build the most comprehensive view of a customer possible based on the [read] Keywords: consulting email profile
70


Adobe Summit: New Video Analytics in Adobe Analytics
Thu, Mar 27th 2014 3:12p   Mark Polly
Scott Smith presented a session on video analytics.  Analytics regarding video has been rough to achieve.  There have been few standards and the complexity has been high. Abode has introduced a Video Heartbeat Tracking library where they hope to simplify implementation of video analytics.  They also want to introduce stability into process and help you understand more about your video usage.  This is becoming more and more important as video consumption moves from traditional TV to all of ou [read] Keywords: javascript server
68


Adobe Summit: The Convergence of Search and Social
Thu, Mar 27th 2014 12:12p   Michael Porter
Marc Blinder, Director of Social Marketing at Adobe and Jon Beeston, Director of New Product Innovation at Adobe presented on the trend of search and social convering.  Twitter is a great example of that where we share but also search. Theme: Search and Social platforms are converging – which  means successful marketers musth have one unified team with one set of data. Key takeaways from this session Connect: facebook to offline experience. feed the metadata Bring: search and social teo [read] Keywords: development email facebook google mobile network twitter
101


Amazon Slashes Pricing for Several Cloud Services
Thu, Mar 27th 2014 11:12a   Michael Porter
I recently blogged about Google’s Bigger, Cheaper Cloud and now it looks like Amazon has responded. CRN has an article about Amazon’s announcement of 10%-40% cuts for M1, M2, C1 and CC2 instances.  Amazon didn’t make much reference to Google and they have cut prices a number of times although the timing is suspect. Amazon’s EC2 M3 instances are dropping 38 percent, while C3 instances are being cut by 30 percent. All of these EC2 figures are for instances running Linux, [read] Keywords: database desktop google linux




Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - Mobile Edition