357 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
IBM Portlets Running on Liberty Profile on IBM Bluemix
Wed, Jul 23rd 2014 27
Why Social Needs to be Part of Your Portal
Wed, Jul 23rd 2014 29
Consumer Engagement at Florida Blue with IBM Digital Experience
Tue, Jul 22nd 2014 40
IBM Digital Experience in the Cloud: New Options and Capabilities
Tue, Jul 22nd 2014 31
Integrating IBM Digital Experience and Microsoft SharePoint
Tue, Jul 22nd 2014 49
IBM Digital Experience Conf: Developing Portlets Using JQuery
Tue, Jul 22nd 2014 36
IBM Digital Experience Conf: Marketing Integration
Mon, Jul 21st 2014 52
Top 10
Official Sitecore Training – Recommendations on Who, What & When
Sun, Dec 23rd 2012 1238
Gartner Magic Quadrant for Horizontal Portals 2013
Wed, Sep 25th 2013 565
SharePoint migrations may cause consternation
Sun, Feb 16th 2014 471
IBM Connect: Demos
Mon, Jan 27th 2014 441
Mobile apps using IBM Worklight and WebSphere Portal: a tutorial
Tue, Sep 4th 2012 426
Adobe Summit: Top new features in Adobe Experience Manager WCM
Wed, Mar 26th 2014 419
IBM Connect: Keynote Guest Speaker: Seth Meyers
Mon, Jan 27th 2014 405
Optimizing Experiences Using IBM TeaLeaf
Tue, Jan 28th 2014 401
What’s coming in WebSphere Portal and WCM
Tue, Jan 28th 2014 395
IBM Connect: Vision and Direction
Mon, Jan 27th 2014 383


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
64 hits



Recent Blog Posts
27


IBM Portlets Running on Liberty Profile on IBM Bluemix
Wed, Jul 23rd 2014 11:12a   Mark Polly
You may not have heard of the Liberty Profile, unless you are interested in running WebSphere Application Server in a cloud environment like BlueMix.  Saurabh Agarwal and Jaspreet Singh presented this session at the IBM Digital Experience Conference. What is this Liberty Profile? Liberty is a lightweight WebSphere Application Server that is already embedded in IBM Bluemix which runs on Softlayer.  By lightweight, I mean that the install of the server is fast, startup is fast, and it is optimiz [read] Keywords: ibm application database development dojo eclipse interface portlet profile security server websphere websphere portal xml
29


Why Social Needs to be Part of Your Portal
Wed, Jul 23rd 2014 11:12a   Glenn Kline
IBM’s 2014 Digital Experience Conference started Wednesday off with a great session by Mac Guidera, Social Workforce Strategist from IBM, titled “Why Social Needs to be Part of Your Portal.”  The session was very insightful blending a mix of statistics, trends, best practices and insightful thoughts. Social Business Patterns Patterns represent modernized processes with dynamic, repeatable and measurable “people interactions” created by building social into work and [read] Keywords: collaboration connections ibm applications mac mobile websphere websphere portal
40


Consumer Engagement at Florida Blue with IBM Digital Experience
Tue, Jul 22nd 2014 5:13p   Mark Polly
Glenn Kline of Perficient and Phani Kanakala from Florida Blue presented a case study of how Florida Blue, Florida’s largest healthcare payer, uses IBM Digital Experience to engage consumers.  Florida Blue’s mission is “To improve the health and well-being of Floridians and their communities”.  This really is a good reason to engage customers. Florida Blue has been using IBM Digital Experience platforms since 2008.  Every year Florida Blue added new features and new si [read] Keywords: agent ibm application applications mobile properties server websphere websphere portal
31


IBM Digital Experience in the Cloud: New Options and Capabilities
Tue, Jul 22nd 2014 4:12p   Mark Polly
Tony Higham and Paul Kelsey spoke about deploying IBM Digital Experience on both an on-premise and public cloud.  There are 5 properties of the cloud generally recognized in the market.  IBM is fully supporting each of theses properties: On-demand & Self Service – its there when you need it Broad Network Access – a global network with fast access from any device Resource Pooling – customers share computing resources at some level.  IBM is not really embracing shared har [read] Keywords: ibm application database network properties security websphere websphere portal
49


Integrating IBM Digital Experience and Microsoft SharePoint
Tue, Jul 22nd 2014 12:12p   Mark Polly
Jason Cornell spoke at the IBM Digital Experience Conference about how well IBM Digital Experience software integrates with SharePoint. When IBM talks about integration with SharePoint, its usually how to display SharePoint content or apps within WebSphere Portal. There are a bunch of ways that IBM has enabled out-of-the-box integration with SharePoint: IBM has Web Application Bridge to pull in SharePoint sites, libraries, lists, wikis, blogs, announcements and so on.  The Bridge displays cont [read] Keywords: calendaring ibm ldd lotus application applications exchange exchange integration microsoft portlet sharepoint sql websphere websphere portal wiki
36


IBM Digital Experience Conf: Developing Portlets Using JQuery
Tue, Jul 22nd 2014 10:12a   Glenn Kline
jQuery is one of the most pervasive scripting libraries in use today. The session “Developing Portlets Using Javascript and JQuery for Engaging Digital Experiences” by Stephan Hesmer, Web 2.0 Architect, IBM and  Jaspreet Singh, Rational Tools Architect, IBM provided good insight as to how to leverage jQuery in IBM WebSphere Portal. First, a couple of key statistics to indicate why this is important and cannot be ignored: 57.5% of websites use jQuery. jQuery has a 93% marketshare. [read] Keywords: ibm ajax application applications css dojo java javascript mobile portlet properties web 2.0 websphere websphere portal widgets
52


IBM Digital Experience Conf: Marketing Integration
Mon, Jul 21st 2014 5:12p   Mark Polly
Rob Enright, a Digital Experience Strategist with IBM spoke about integrating Marketing Management with IBM Digital Experiences.  Customer expectations are soaring, yet it takes time to build your digital experience to keep up or even get ahead of those expectations. Here are several themes IBM is focusing on: “Insight to Action” with a few clicks – this will require more and more automation of the Manage omni-channel campaigns that are coordinated across the channel.  This [read] Keywords: ibm integration portlet
58


IBM Digital Experience Conf: IBM Web Content Manager Patterns
Mon, Jul 21st 2014 1:13p   Mark Polly
Eric Morentin and Nick Baldwin spoke about WCM Patterns that should be used in content management development in IBM Digital Experience.  Patterns of course are a “canned” way or even best practice for implementing solutions.  There are four themes of patterns they talked about: Better content / component model There are different types of content and Content Manager build a content page by pulling various types of content.  Types can include things like slide shows, lists, bloc [read] Keywords: ibm best practice css development javascript
57


IBM XGX – What’s New in WebSphere Portal and IBM WCM 8.5
Mon, Jul 21st 2014 1:13p   Glenn Kline
Rob Will, chief architect for WebSphere Portal, once again gave a great presentation at IBM’s Digital Experience Conference 2014.  The focus was on the new capabilities delivered in the last year. The focus of the digital experience suite has been to provide a framework with tools and services to be able to deliver a great digital experience.  The focus has shifted from IT building the solutions to the line of business being able to own and deliver content and services themselves.  The [read] Keywords: connections ibm ajax application applications css development dojo mac mobile portlet profile security server websphere websphere portal
54


IBM Digital Experience Conf 2014: Stephen Power’s View
Mon, Jul 21st 2014 11:12a   Mark Polly
Forrester’s Stephen Power spoke about transforming digital strategy. Stephen is Vice President at Forrester and covers the Digital Experience market.  He started by talking about the age of the customer and how we got to this point (customer centricity per Gary Dolsen).  Preceding the age of the customer was Age of Manufacturing, Age of Distribution and the Age of iInformation.  Starting in 2010, he suggests that the Age of Customer started. Complexity is increasing in the Age of the Cu [read] Keywords: ibm




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