358 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
A Day in the Life of a Social Media Manager
Mon, Sep 29th 2014 31
How to Implement Lighter Weight Portals, Part 3: Knockout Portlet
Thu, Sep 18th 2014 130
How to Implement Lighter Weight Portals, Part 2: Portlets
Tue, Sep 16th 2014 94
Using Mapping to Show Up-to-Date Content
Thu, Sep 4th 2014 178
How to Implement Lighter Weight Portals
Wed, Sep 3rd 2014 115
Why Patient Portals Remain Healthcare’s Enigma
Wed, Sep 3rd 2014 97
Forrester Digital Experience Wave
Wed, Jul 30th 2014 188
Top 10
IBM Digital Experience v8.5 – What’s Been Removed or Deprecated
Mon, May 12th 2014 873
Official Sitecore Training – Recommendations on Who, What & When
Sun, Dec 23rd 2012 742
Perficient discusses Salesforce Communities
Mon, Jun 9th 2014 297
Gartner Magic Quadrant for Horizontal Portals 2013
Wed, Sep 25th 2013 252
Are Portals Really Dead?
Mon, Jun 30th 2014 244
Adobe Summit: The Convergence of Search and Social
Thu, Mar 27th 2014 241
Adobe Summit: Top new features in Adobe Experience Manager WCM
Wed, Mar 26th 2014 234
Google: Reasons Why Nobody Uses Your App, Your Site, Your…
Thu, Jul 17th 2014 234
Hilton Changes The Game, Mobile Enables It
Tue, Jul 29th 2014 230
WebSphere Portal and UI Myths and Facts
Wed, Jul 30th 2014 222


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



Recent Blog Posts
31


A Day in the Life of a Social Media Manager
Mon, Sep 29th 2014 11:11a   Mark Polly
In the BufferSocial blog, Kevan Lee posted an article for Social Media Managers.  The post takes a look a “typical” social media manager’s day and breaks down that day into many different activities, represented in the info graphic here.    Mr. Lee also provides several different views on how other people spend their days managing social media.  One person, Finola Howard, manages to compress all her daily activities into just one hour per day. Her tasks include: Use Socia [read] Keywords: connections ibm networking twitter
130


How to Implement Lighter Weight Portals, Part 3: Knockout Portlet
Thu, Sep 18th 2014 5:15p   Mark Polly
In this series, I’m showing how Portals don’t have to be heavyweight.  In Part 1, I wrote about how to make the infrastructure lighter by using cloud or IBM’s Pure System.  In Part 2, I introduced the concept of using IBM’s Web Content Manager system to build very simple portlets. Now in this final installment, I am going to extend the concepts introduced in Part 2 to show how we can build more complex portlets, but still keep everything lightweight.  To review quickly [read] Keywords: ibm application css dojo interface java javascript network portlet widget
94


How to Implement Lighter Weight Portals, Part 2: Portlets
Tue, Sep 16th 2014 12:11p   Mark Polly
In part 1 of this series, How to Implement Lighter Weight Portals, I talked wrote about the infrastructure and installation aspects of Portals. To make the tasks of managing and installing portals, I recommended cloud solutions and for IBM, their PureApplication system both in the cloud and on-premise. In Part 2, I turn my attention to applications and how to make task of developing portal applications more lightweight. The goal of a portal is to combine applications and content at the glass fo [read] Keywords: admin ibm application applications interface java javascript portlet websphere websphere portal xml
178


Using Mapping to Show Up-to-Date Content
Thu, Sep 4th 2014 11:12a   Michael Porter
Sometimes I’m amazed with what some of our developers do.  I’ve seen so many examples of code just thrown together. I’ve seen that code produce infinite loops, slow down load time by a factor of 10, and take down servers.  So when I see an example of someone thinking through how to efficiently create code, I’m amazed.  Anyway, Parshva Vora, a Sitecore developer here at Perficient, just blogged on how you can use mapping to create agile code and more efficiently get at [read] Keywords: database microsoft
115


How to Implement Lighter Weight Portals
Wed, Sep 3rd 2014 9:11a   Mark Polly
One of the complaints we often hear about horizontal portal systems is they are complicated and feel “heavy”. What makes a system feel heavy and how can we lighten the load? In a typical portal application we have to integrate multiple applications, content and document management systems, security, search, personalization, page management, etc, etc. is it any wonder why a portal would feel heavy when you try to bolt together all these systems? Some vendors have taken the approach th [read] Keywords: ibm application applications database db2 development portlet security server websphere websphere portal
97


Why Patient Portals Remain Healthcare’s Enigma
Wed, Sep 3rd 2014 9:11a   Michael Porter
CIO.com has an interesting article about why patient portals just aren’t popular.  I think the author, Brian Eastwood, gets some things right but also misses some key reasons or challenges.  Here’s what he got right. Adoption just isn’t very high. No one is using the patient portals that are out there. Doctors don’t use portals………….and they don’t have patients who use portals.  In other words, if a medical provider still thinks the best w [read] Keywords: applications office security server
188


Forrester Digital Experience Wave
Wed, Jul 30th 2014 3:12p   Mark Polly
Last week Forrester published their first Wave on Digital Experience Platforms.   I was at the IBM Digital Experience Conference and it sounded like IBM was expecting good news from Forrester in this wave.   In fact, Stephen Powers from Forrester was the Keynote speaker at the conference and one of the principal authors of the Wave.   Much to every one’s surprise, the Wave came out with nobody listed as a Leader.  Adobe, hybris (SAP), IBM and Sitecore came out as the Strong Performers [read] Keywords: ibm development sap
222


WebSphere Portal and UI Myths and Facts
Wed, Jul 30th 2014 12:12p   Michael Porter
I don’t know how I missed it but Harish Bhavinachikar has a nice post on what you can do with modern UI tools in WebSphere Portal.  It’s on our Spark Blog but addresses something that keeps coming up again and again.  Frankly, the front-end tools have changed considerably in the last couple years.  Modern UI tools / frameworks like AngularJS, Bootstrap, JQuery, and a host of others make it easier to manage the UI and to further enforce separation of the front-end from the back-end [read] Keywords: ibm css javascript mobile portlet websphere websphere portal
158


Google Search With Sales Force
Wed, Jul 30th 2014 9:12a   Michael Porter
Brendan Callum, a director and whiz extraordinaire in our Salesforce practice, has a video out about what they did with Google Search and Salesforce. The video doesn’t go into a lot of detail but I find it extremely interesting that an appliance (older trend) searches the cloud (ongoing trend) in a secure fashion.  Of course, why do you need detail when someone developed a connector for it and all you have to do it buy, install, and go. [read] Keywords: google
161


Migrating Web Content Using Kapow (Part 3)
Wed, Jul 30th 2014 9:12a   Michael Porter
I’ve blogged about this before with Candace’s Part 1 and Part 2. She just published Part 3 in the series.  Here she focuses on what to do once you’ve extracted and transformed the content.  In other words, getting that web content into the target system. In this case it’s Sitecore, a popular .NET based WCM.  I think it’s great Candace took the time to walk through a step by step approach to this.  Go to her post for the full set of steps and details. Once data [read] Keywords: database microsoft




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