Tuesday, July 19, 2016

Add the portlet session bean to the Personalization engine

Add the portlet session bean to the Personalization engine
Register the session bean with the Personalization engine. To enable the Personalization engine to leverage data in session bean:
  1. Export the session bean class as a jar file with full class path.
  2. Copy it to <wp>/pzn/v6.0/collections directory on the WebSphere Portal machine.
  3. Restart WebSphere Portal server to load the jar file.
To register the session bean with Personalization:
  1. Create an application object in Personalization.
  2. Session key and class name are required fields for the creation of the application object
  3. Specify the fully qualified class name
Note: Visibility rule uses caching per session so if the visibility rule is meant to use dynamic data, the results will not change based on the dynamic data. To implement visibility rule on dynamic data you need to disable caching.

Same thing can be done using object cache, we can update values in object cache from application and the stored values can be read from the custom pzn SelfInitializationApplicationObject implementation class.

Different technique can be also used to hide the portlet i.e. portlet eventing.

Hide portlet through external class (SelfInitializationApplicationObject): http://wpcertification.blogspot.com/2011/01/how-to-show-or-hide-portal-or-portlet.html

Issue discussed on setting Personalization Attributes from Portlets:
https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014177630

Friday, June 17, 2016

Portal v7.0 not starting - Previous initialization was not successful

The problem is that now all of a sudden, the wps application starts before the wps_scheduler application, and that is what is causing the problem. To fix it, check the following:

1. Start the WebSphere_Portal server if it is not already started.
2. Try and access the WAS admin console:

http://<portal hostname>:10042/ibm/console

3. Navigate to Applications -> WebSphere Enterprise Applications
4. Pick the 'wps' application and go to 'Startup Behavior'. Check the
Startup Order. The default value is 10. If you have to change this,
do so now.
5. Go back to 'wps' and click Manage Modules.
6. Click 'WebSphere Portal Server'. It's starting weight should be
10000. If you have to change this, do so now.
7. Back in Manage Modules, click 'WebSphere Portal Server WSRP
Facade'. It's starting weight should be 10000. If you have to change
this, do so now.
8. Back in Manage Modules, click 'WebSphere Portal XmlAccess Facade'.
It's starting weight should also be 10000. Again if you have to change
this, do so now.
9. Now back to the list of applications, pick 'wps_scheduler' and go
to 'Startup Behavior'. It's startup order should also be 10. If you
have to change this, do so now.
10. From wps_scheduler, go to Manage Modules.
11. Click 'WPS Task Scheduler'. It's starting weight should be 5000.
If you have to change this, do so now.
12. Save all changes and restart Portal.

Also verify if <portalserver_dir>\wps.propeties file exists and it has required permission. If required rename that to a different file and created a new wps.properties and copied the contents of it and restarted.

If nothing works then try to backup and redeploy wps.ear: http://www-10.lotus.com/ldd/portalwiki.nsf/xpDocViewer.xsp?lookupName=IBM+WebSphere+Portal+8+Product+Documentation#action=openDocument&res_title=Redeploying_the_portal_EAR_file_wp8&content=pdcontent&sa=true

Font Loading issue when installing font in browser is disable

http://ajax.googleapis.com/ajax/libs/webfont/1.5.3/webfont.js
https://github.com/typekit/webfontloader/issues/160
http://www.techrepublic.com/blog/web-designer/how-to-use-the-google-webfont-loader/
http://stackoverflow.com/questions/7973421/detect-if-font-download-in-ie-is-enabledd

Create a url to change language on Portal

You can use following code to change the language on Portal.
<portal-navigation:url command="ChangeLanguage">
  <portal-navigation:urlParam name="locale" value="<language>"/>
</portal-navigation:url>
 
There was a problem with this when navigational state is cleared. 
This happens if  bookmarks to friendly URLs are used for navigation or 
the navigational state is cleared intentionally.
 
You can this technique to store language value in cookie temporarily and 
It sets the locale information, if no locale information can be 
found in the navigational state.
 
Configure cookie support language using this 
url: http://www-01.ibm.com/support/docview.wss?uid=swg1PM17679
 

Content decompress (Base64 + Zlib)

I wanted to decompress data getting send to GSA (google search appliance) to verify the actual content. Google Search Appliance uses Base64 encode and Zlib compress technique which improves performance, because less data is sent across the network.

Here is link on GSA Content Compression: https://www.google.com/support/enterprise/static/gsa/docs/admin/72/gsa_doc_set/feedsguide/feedsguide.html#1074587

There is api provides by Java that can be used to  compress and decompress data using the java.util.zip package. - http://www.oracle.com/technetwork/articles/java/compress-1565076.html

To decode base64 string you can use class org.apache.commons.codec.binary.Base64 provided by apache commons library.

code snippet that follows:  
String string = "SmF2YWNvZGVnZWVrcw==";
// Get bytes from string
byte[] byteArray = Base64.decodeBase64(string.getBytes());
// Print the decoded array
System.out.println(Arrays.toString(byteArray));


To decompress zlib content you can use Java Byte Array Using Inflater
code snippet that follows: 
public static byte[] decompress(byte[] data) throws IOException, DataFormatException {
    Inflater inflater = new Inflater();  
    inflater.setInput(data); 
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); 
    byte[] buffer = new byte[1024]; 
    while (!inflater.finished()) { 
        int count = inflater.inflate(buffer); 
        outputStream.write(buffer, 0, count); 
    } 
    outputStream.close(); 
    byte[] output = outputStream.toByteArray(); 
    LOG.debug("Original: " + data.length); 
    LOG.debug("Compressed: " + output.length); 
    return output; 
}  

Here is the reference link: https://dzone.com/articles/how-compress-and-uncompress


Download complete source code: https://app.box.com/s/w2wyffurcwdpeetouk56kg2tmg40wjtl

Monday, June 13, 2016

How to set Ephox Edit Live editor as default WCM editor?

Below are the simple steps to changes the WCM editor from default rich text to Ephox edit Live. First of all you have to download Ephox edit live from https://greenhouse.lotus.com/ and install the same application on to your portal server if not already installed.
  • Login to WAS Console.
  • Navigate to Applications->Application Types -> WebSphere enterprise applications.
  • Click on Install and select the .ear file you downloaded and click Next. Keep the default options keep going to next pages.
  • Make sure you select websphere_portal as the server not server1 while installing the .ear and finish the installation and save the configuration.
  • Start the application if its not already started.
  • Login to portal as administrator and navigate to WCM Authoring portlet -> Preferences > Configure.
  • Expand the Rich Text Options section , select Custom Editor in the drop down and enter the following in the text box "/wps/ephox/;jsp/html/EditLiveJavaEditor.jsp"and click OK.
  • Now navigate to WCM Authoring portlet -> Preferences > Edit Shared Settings.
  • Expand the RichTextOptions section , select Custom Editor in the drop down and enter the following in the text box "/wps/ephox/;jsp/html/EditLiveJavaEditor.jsp"and click OK.
  • Now go to any content item that uses rich text and you can see its using ephox edit live edit instead of IBM's default RTE.
  •  You can easily toggle between the design view and code view in the bottom left corner.
 Ephox edit Live is a Java Editor and Java Runtime is required on wcm author's machine to be able to use this applet in a browser.

Ephox has also released a javascript based rich text editor that you can apply on WebSphere Portal 8.5.0.0 with CF06 or higher.
Here is some more info on this: https://greenhouse.lotus.com/plugins/plugincatalog.nsf/assetDetails.xsp?action=editDocument&documentId=86189C1DAC5B1D3B85257E4500199F1B

About Rich Text editor options on WCM: https://www.ibm.com/support/knowledgecenter/SS3JLV_8.0.0/wcm/wcm_config_authoringportlet_richtext.html

Thursday, February 4, 2016

OptimizeCacheIdIncrements custom property

Problem statement:
cacheid (first 4char of jsessionid) in cluster env was getting update after 2hours of session inactivity however we had 24hrs of session inactivity set in application server. Due to this some of the applications which were dependent on session was throwing unexpected exception. Users were required to clear their cookies to resolve the issue.
We wanted to know why it was getting updated and if there is a way to stop this activity from occurring?

Solution:
set custom property OptimizeCacheIdIncrements parameter to true

Set the OptimizeCacheIdIncrements custom property to true to make the session manager assess whether the in-memory session for a web module is older than the copy in persistent store. Setting this property resolves the continually increasing cache ID.
If HTTP session management is configured to use session persistence and the user's browser session is moving back and forth across multiple web applications you might see extra persistent store activity as the in-memory sessions for a web module are refreshed from the persistent store. As a result, the cache IDs are continually increasing and the in-memory session attributes are overwritten by those of the persistent copy. Set this property to true if you want to prevent the cache IDs from continually increasing.
If the configuration is a cluster, ensure that the system times of each cluster member is identical as possible.

Reference link: http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.0.0/com.ibm.websphere.nd.doc/info/ae/ae/rprs_custom_properties.html%23OptimizeCacheIdIncrements?lang=en


Using Application Server>URL resources to manage J2EE property files and external service url

Use following code to retrieve url resource using jndi
InitialContext initCtx = new InitialContext();
URL url = (java.net.URL) initCtx.lookup(jndi);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();

With this method you can either enter web service url in resource field or properties file path.

Note: You need to restart the server to lookup the url resource from code.

Reference link: http://www.ibm.com/developerworks/websphere/library/techarticles/0502_botzum/0502_botzum.html

How to access authentication alias from WebSphere Application Server> J2C

You can use the following code to obtain credentials from J2C authentication data entry:

import com.ibm.wsspi.security.auth.callback.Constants;
import com.ibm.wsspi.security.auth.callback.WSMappingCallbackHandlerFactory;
import javax.resource.spi.security.PasswordCredential;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;

Map map = new HashMap();
map.put(Constants.MAPPING_ALIAS, "YOUR_J2C_DATA_ALIAS");
CallbackHandler callbackHandler = WSMappingCallbackHandlerFactory.getInstance().getCallbackHandler(map, null);

LoginContext loginContext = new LoginContext("DefaultPrincipalMapping", callbackHandler);
loginContext.login();

Subject subject = loginContext.getSubject();
Set credentials = subject.getPrivateCredentials();

PasswordCredential passwordCredential = (PasswordCredential) credentials.iterator().next();

String user = passwordCredential.getUserName();
String password = new String(passwordCredential.getPassword());

Reference link: http://stackoverflow.com/questions/4663534/how-to-access-authentication-alias-from-ejb-deployed-to-websphere-6-1/6355992#6355992