Thursday, February 9, 2012

Custom Login Portlet : WPS v6.1.5

IBM WebSPhere Portal Server provides a Login Service that you can use to create a custom login portlet. You may want to create a custom login portlet to IBM WebSphere Portal if the base portlet is not in the format you want, or if you want to add additional checking to the login.


CustomLoginPortlet.java
-----------------------------------------------------------------------------


package com.webspherenotes.services;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.security.auth.login.LoginException;

import com.ibm.portal.auth.exceptions.AuthenticationException;
import com.ibm.portal.auth.exceptions.AuthenticationFailedException;
import com.ibm.portal.auth.exceptions.PasswordInvalidException;
import com.ibm.portal.auth.exceptions.PortletLoginDisabledException;
import com.ibm.portal.auth.exceptions.SessionTimeOutException;
import com.ibm.portal.auth.exceptions.SystemLoginException;
import com.ibm.portal.auth.exceptions.UserAlreadyLoggedInException;
import com.ibm.portal.auth.exceptions.UserIDInvalidException;
import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.portlet.service.login.LoginHome;
import com.ibm.portal.portlet.service.login.LoginService;
import com.ibm.websphere.security.WSSecurityException;

public class CustomLoginPortlet extends GenericPortlet{
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering CustomLoginPortlet.doView()");
response.setContentType("text/html");
getPortletContext().getRequestDispatcher("/login.jsp").include(request, response);
System.out.println("Exiting CustomLoginPortlet.doView()");
}

LoginHome loginHome;
public void init() throws PortletException {
System.out.println("Entering CustomLoginPortlet.init()");
try {
InitialContext ctx = new InitialContext();
PortletServiceHome psh = (PortletServiceHome) ctx.lookup(LoginHome.JNDI_NAME);
loginHome = (LoginHome) psh.getPortletService(LoginHome.class);
//loginHome =(LoginHome) ctx.lookup(LoginHome.JNDI_NAME);
} catch (NamingException e) {
e.printStackTrace();
}
System.out.println("Exiting CustomLoginPortlet.init()");
}

public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
try {
System.out.println("Entering CustomLoginPortlet.processAction()");
String userId = request.getParameter("USER_NAME");
System.out.println("User Id " + userId);
String password = request.getParameter("PASSWORD");
System.out.println("Password " + password);
LoginService loginService = loginHome.getLoginService(request, response);
System.out.println("Login Service " + loginService);
Map contextMap = new HashMap();
contextMap.put(LoginService.DO_RESUME_SESSION_KEY, new Boolean(false));
loginService.login(userId, password.toCharArray(), contextMap, null);
System.out.println("Exiting CustomLoginPortlet.processAction()");
response.sendRedirect("/wpcert/mydemo");
} catch (PasswordInvalidException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserIDInvalidException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthenticationFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SessionTimeOutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PortletLoginDisabledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserAlreadyLoggedInException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemLoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WSSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (com.ibm.portal.auth.exceptions.LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
--------------------------------------------------------------------------
You can refer : http://wpcertification.blogspot.in/2010/06/custom-login-portlet.html

Friday, December 9, 2011

Access HttpSession in IBM WebSphere Portlet ( JSR 168 API)

Below sample method which will returned HttpServlet request.


import javax.portlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;



private HttpServletRequest getHttpServletRequest(PortletRequest request){
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
while(httpServletRequest instanceof HttpServletRequestWrapper){
HttpServletRequestWrapper httpServletRequestWrapper =
(HttpServletRequestWrapper)httpServletRequest;
System.out.println("HttpServletRequestWrapper " + httpServletRequestWrapper);
httpServletRequest = (HttpServletRequest)httpServletRequestWrapper.getRequest();
}
return httpServletRequest;
}



Below code snippet in doview

HttpServletRequest httpServletRequest = getHttpServletRequest(request);
javax.servlet.http.HttpSession httpesesion = httpServletRequest.getSession();
httpesesion.setAttribute("name", "test");


----------------------------------------------------------------
You can access session attribute in servlet. it is helpful in servlet written inside portlet. I have used to render PDF report in servlet.

Sunday, October 2, 2011

JABX2..cool.. Sample example

Steps. Download Binary

xjc exampe\IpopsOperation.xsd -p com.xmlpojo

xjc XSD_location -p Create_pojos_at_package


Simple Main Java

package com.main;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.OutputStream;
import java.io.StringReader;
import java.math.BigDecimal;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import nz.co.equinox.training.domain.booking.*;

public class TestJaxb2 {

/**
* @param args
*/

public static void UmMarshal() {
try {
JAXBContext jaxbContext = JAXBContext
.newInstance("nz.co.equinox.training.domain.booking");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement bookingElement = (JAXBElement) unmarshaller
.unmarshal(new File("C:/Harish/Technical/JAXB2/jaxb-ri-20110512/bin/exampe/Data.xml"));



/*StringBuffer xmlStr = new StringBuffer( "" );
JAXBElement bookingElement = (JAXBElement) unmarshaller.unmarshal(new StreamSource( new StringReader( xmlStr.toString() ) ));*/



CourseBooking booking = bookingElement.getValue();
System.out.println(booking.getCourseReference());
System.out.println(booking.getInvoiceReference());
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void marshal() {

try {

JAXBContext jaxbContext = JAXBContext
.newInstance("nz.co.equinox.training.domain.booking");

CourseBooking booking = new CourseBooking();
booking.setCourseReference("UML-101");
booking.setTotalPrice(new BigDecimal(10000));
booking.setInvoiceReference("123456");
DatatypeFactory datatypes;

datatypes = DatatypeFactory.newInstance();

booking.setCourseDate(datatypes.newXMLGregorianCalendarDate(2006,
06, 15, 0));
booking.setTotalPrice(new BigDecimal(10000));
booking.setInvoiceReference("123456");
booking.getStudent().add(new StudentType());
booking.getStudent().get(0).setFirstName("John");
booking.getStudent().get(0).setSurname("Smith");
booking.setCompany(new CompanyType());
booking.getCompany().setName("Clients inc");
booking.getCompany().setContact(new ContactType());
booking.getCompany().getContact().setName("Paul");
booking.getCompany().getContact().setEmail("paul@clients.inc");
booking.getCompany().getContact().setTelephone("12345678");
booking.getCompany().setAddress("10 client street");


// Marshal to System.out
Marshaller marshaller = jaxbContext.createMarshaller();
JAXBElement bookingElement = (new ObjectFactory())
.createBooking(booking);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);

//StreamResult result = new StreamResult( System.out );

//System.out.println(result.getOutputStream());

ByteArrayOutputStream byteara = new ByteArrayOutputStream();
marshaller.marshal(bookingElement, byteara);
System.out.println("1:"+byteara.toString());

/*DOMResult result = new DOMResult();
marshaller.marshal( bookingElement, result );*/


} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DatatypeConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void main(String[] args) {
marshal();
//UmMarshal();
}

}
------------------------------------------------------------------------

Simple Main

package com.main;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;


import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;


import com.xmlpojo.*;



public class IPOPSTest {

public static void UmMarshal() {
try {
//File f = new File();
InputStream is = new FileInputStream( "C:/Harish/Technical/JAXB2/jaxb-ri-20110512/bin/exampe/OrderResponse.xml" );
JAXBContext jaxbContext = JAXBContext.newInstance(IPOPSOperation.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Object o = unmarshaller.unmarshal(is);
if(o instanceof IPOPSOperation){
//System.out.println("1");
IPOPSOperation operation = (IPOPSOperation) o;
MessageBodyType messageBodyType = operation.getMessageBody();
BusinessInputType businessInputType = messageBodyType.getBusinessInput();
List list = businessInputType.getAPIDETAILS();
System.out.println("----------------businessInput--------------");
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
ApiDetailsType apiDetailsType = (ApiDetailsType) iterator.next();

System.out.println(apiDetailsType.getARGNAME()+":"+apiDetailsType.getARGVALUE());

}
System.out.println("----------------businessOutputData--------------");
BusinessOutputType businessOutputType = messageBodyType.getBusinessOutputData();
List list2 = businessOutputType.getOutputTypes();
for (Iterator iterator = list2.iterator(); iterator.hasNext();) {
OutputType outputType = (OutputType) iterator.next();
System.out.println(outputType.getName()+":"+outputType.getValue());


}
System.out.println("----------------getOutputTypeList--------------");
List list3 = businessOutputType.getOutputTypeList();
for (Iterator iterator = list3.iterator(); iterator.hasNext();) {
OutputTypes outputTypes = (OutputTypes) iterator.next();
List list4 =outputTypes.getOutputTypes();
for (Iterator iterator2 = list4.iterator(); iterator2
.hasNext();) {
OutputType outputType = (OutputType) iterator2.next();
System.out.println(outputType.getName()+":"+outputType.getValue());


}
System.out.println("----------------Type Line Items--------------");
}

}



/*StringBuffer xmlStr = new StringBuffer( "" );
JAXBElement bookingElement = (JAXBElement) unmarshaller.unmarshal(new StreamSource( new StringReader( xmlStr.toString() ) ));*/




//System.out.println(bookingElement.getValue());
//System.out.println(booking.getInvoiceReference());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void marshal() {

try {

JAXBContext jaxbContext = JAXBContext
.newInstance("com.xmlpojo");






// Marshal to System.out
Marshaller marshaller = jaxbContext.createMarshaller();
JAXBElement bookingElement =null ;// (new ObjectFactory()).createIPOPSOperation();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);

//StreamResult result = new StreamResult( System.out );

//System.out.println(result.getOutputStream());

ByteArrayOutputStream byteara = new ByteArrayOutputStream();
marshaller.marshal(bookingElement, byteara);
System.out.println(byteara.toString());

/*DOMResult result = new DOMResult();
marshaller.marshal( bookingElement, result );*/


} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void main(String[] args) {
//marshal();
UmMarshal();
}


}
---------------------------------------------------------------------------------

Friday, September 2, 2011

Run a scheduler automatically on WAS 7 0r 6

https://www-304.ibm.com/support/docview.wss?uid=swg21412991


Startup Beans

Among the WebSphere Application Server extensions, you can find Startup beans. Startup beans expose a start and a stop method, which are invoked by the server if the Startup beans service in enabled (see Related URL: "Startup Beans Service setup").

Startup beans are configured by creating one Stateless Session bean that uses a specific Home and Remote interface, provided by WebSphere Application Server.

There are two names for these interfaces, depending on whether the startup Bean must execute at Application Startup or Module Startup:

1. Application Startup
1. com.ibm.websphere.startupservice.AppStartUpHome (Home)
2. com.ibm.websphere.startupservice.AppStartUp (Remote)
2. Module Startup
1. com.ibm.websphere.startupservice.ModStartUpHome (Home)
2. com.ibm.websphere.startupservice.ModStartUp (Remote)

The bean class must implement the start and stop methods provided by the Remote Interface.

The nature of these Remote interfaces is such that they cannot be used in an EJB 3.0, since the Remote interface extends: javax.ejb.EJBObject.


--------------------------------------------------------------------
 enterprise-beans>

StartupCode
com.ibm.websphere.startupservice.AppStartUpHome
com.ibm.websphere.startupservice.AppStartUp
ejbs.StartupCodeBean
Stateless
Container


--------------------------------------------------------------


package ejbs;

/**
* Bean implementation class for Enterprise Bean: StartupCode
*/
public class StartupCodeBean implements javax.ejb.SessionBean {
public boolean start() throws java.rmi.RemoteException{
System.out.println("Application Start Code "+this);

return true;
};


public void stop() throws java.rmi.RemoteException{

System.out.println("Application Stop Code "+this);

};
static final long serialVersionUID = 3206093459760846163L;
private javax.ejb.SessionContext mySessionCtx;
/**
* getSessionContext
*/
public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* setSessionContext
*/
public void setSessionContext(javax.ejb.SessionContext ctx) {
mySessionCtx = ctx;
}
/**
* ejbCreate
*/
public void ejbCreate() throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}
}

Wednesday, August 24, 2011

Log4J WebSphere Portal

log4j.xml

---------------------------------------------------------------







































-----------------------------------------------------------------


Above file put under src folder

Lib File : log4j-1.2.16.jar , put in WebContent\WEB-INF\lib



Sample code in Java file

import org.apache.log4j.Logger;
private static Logger logger = Logger.getLogger(Test.class);

if (logger.isInfoEnabled()) {
logger.info("Test message"));


Thursday, July 21, 2011

Hashtable data sorting based on Value. Hash table sorting, Java Hashtable: Sorted by Values

package com.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

public class Testing {

public static void main(String[] args) {

//Create a hashtable
Hashtable myhash=new Hashtable();

//Put things in Hashtable
myhash.put("Z", "H");
myhash.put("B", "P");
myhash.put("C", "R");
myhash.put("D", "A");
myhash.put("M", "B");
myhash.put("P", "D");

//Put keys and values in to an arraylist using entryset
ArrayList myArrayList=new ArrayList(myhash.entrySet());

//Sort the values based on values first and then keys.
Collections.sort(myArrayList, new MyComparator());

//Show sorted results
Iterator itr=myArrayList.iterator();
String key="";
String value;
int cnt=0;
LinkedHashMap linkedmap = new LinkedHashMap();
while(itr.hasNext()){

cnt++;
Map.Entry e=(Map.Entry)itr.next();

key = (String)e.getKey();
//value = ((String)e.getValue()).intValue();
value = ((String)e.getValue());

System.out.println(key+","+value);

linkedmap.put(key, value);

}

System.out.println(linkedmap);

}// end of method

static class MyComparator implements Comparator{

public int compare(Object obj1, Object obj2){

int result=0;Map.Entry e1 = (Map.Entry)obj1 ;

Map.Entry e2 = (Map.Entry)obj2 ;//Sort based on values.

String value1 = (String)e1.getValue();
String value2 = (String)e2.getValue();

if(value1.compareTo(value2)==0){

String word1=(String)e1.getKey();
String word2=(String)e2.getKey();

//Sort String in an alphabetical order
result=word1.compareToIgnoreCase(word2);

} else{
//Sort values in a descending order
result=value1.compareTo( value2 );
}

return result;
}

}

}


-------------------------------------
Result :
D,A
M,B
P,D
Z,H
B,P
C,R
{D=A, M=B, P=D, Z=H, B=P, C=R}

Friday, June 24, 2011

Accessing Query String parameter in WebSphere Portal with Dynacache

1) Create a jar of below class

import com.ibm.websphere.cache.DistributedMap;
import java.io.IOException;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class ParameterFilter
implements Filter
{

public static final String PARAMETER_PREFIX = "param.";
public static final String DYNACACHE_NAME = "services/cache/catalog/parameters";
public static final Logger logger = Logger.getLogger(com/ibm/catalog/servlet/filter/ParameterFilter.getName());
private DistributedMap map;

public ParameterFilter()
{
map = null;
}

public void init(FilterConfig arg0)
throws ServletException
{
try
{
InitialContext ic = new InitialContext();
map = (DistributedMap)ic.lookup("services/cache/catalog/parameters");
ic.close();
}
catch(NamingException ne)
{
logger.log(Level.SEVERE, "NamingException error", ne);
}
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpSession session = httpRequest.getSession();
Enumeration parms = httpRequest.getParameterNames();
if(logger.isLoggable(Level.INFO))
logger.log(Level.INFO, "Parameter prefix: param.");
while(parms.hasMoreElements())
{
String key = (String)parms.nextElement();
if(key != null && key.startsWith("param."))
{
String cleanKey = key.substring("param.".length());
StringBuffer sb = new StringBuffer(cleanKey);
String values[] = httpRequest.getParameterValues(key);
sb.append(".count");
map.put(sb.toString(), (new Integer(values.length)).toString());
for(int i = 0; i < values.length; i++)
{
sb = new StringBuffer(cleanKey);
sb.append(".");
sb.append((new Integer(i)).toString());
sb.append(".");
sb.append(session.getId());
map.put(sb.toString(), values[i]);
if(logger.isLoggable(Level.INFO))
logger.log(Level.INFO, (new StringBuilder("Parameter Filter: ")).append(sb.toString()).append(" -- ").append(values[i]).toString());
}

}
}
if(chain != null)
chain.doFilter(request, response);
}

public void destroy()
{
}

}
-------------------------------------------------------------------------------------
2)Create Dynacache
JNDI name: services/cache/catalog/parameters

3)Add the following code to the web.xml file:



<filter>
<filter-name>Parameter Filter
<filter-class>
com.ibm.catalog.servlet.filter.ParameterFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>
Parameter Filter
</filter-name>
<url-pattern>/myportal/*
</filter-mapping>
<filter-mapping>
<filter-name>
Parameter Filter
</filter-name>
<url-pattern>/portal/*
</filter-mapping>


---------------------------------------------------------------------

import com.ibm.websphere.cache.DistributedMap;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;

public class AccessManagerUtils
{

public static final String DYNACACHE_NAME = "services/cache/catalog/parameters";
public static final String PARAMETER_PREFIX = "param.";
private static final String EXTERN_PARAMETERS_GOTTEN = "ExternParametersGotten";
private DistributedMap parameterMap;
public static final Logger logger = Logger.getLogger(com/ibm/fs/bic/accessmanager/AccessManagerUtils.getName());

public AccessManagerUtils()
{
parameterMap = null;
parameterMap = getParameterMap("services/cache/catalog/parameters");
}

protected DistributedMap getParameterMap(String mapName)
{
DistributedMap dm = null;
try
{
InitialContext ic = new InitialContext();
if(logger.isLoggable(Level.INFO))
logger.log(Level.INFO, (new StringBuilder("Opening parameter cache with name: ")).append(mapName).toString());
dm = (DistributedMap)ic.lookup(mapName);
ic.close();
}
catch(NamingException e)
{
logger.log(Level.SEVERE, "NamingException while looking up the distributed map.", e);
}
return dm;
}

protected String getExternParameter(RenderRequest request, String name)
{
getDynacacheMultipleParameters(request);
StringBuffer key = new StringBuffer("param.");
key.append(name);
String values[] = (String[])request.getAttribute(key.toString());
if(values != null)
return values[0];
else
return null;
}

protected String[] getExternParameterValues(RenderRequest request, String name)
{
getDynacacheMultipleParameters(request);
StringBuffer key = new StringBuffer("param.");
key.append(name);
String values[] = (String[])request.getAttribute(key.toString());
if(values != null)
return values;
else
return null;
}

protected int getDynacacheSingleParameters(RenderRequest request)
{
PortletSession session = request.getPortletSession();
int parmCount = 0;
Set keys = parameterMap.keySet();
Iterator iter = keys.iterator();
if(request.getAttribute("ExternParametersGotten") != null || parameterMap.isEmpty())
return -1;
while(iter.hasNext())
{
String key = (String)iter.next();
int dot = key.indexOf('.');
if(dot > 0)
key = key.substring(0, dot);
String values[] = getDynacacheParameterValues(key, request.getPortletSession().getId());
if(values != null)
{
parmCount++;
StringBuffer sb = new StringBuffer("param.");
sb.append(key);
request.setAttribute(sb.toString(), values[0]);
session.setAttribute(sb.toString(), values[0]);
}
}
request.setAttribute("ExternParametersGotten", "done");
return parmCount;
}

private int getDynacacheMultipleParameters(RenderRequest request)
{
if(request.getAttribute("ExternParametersGotten") != null)
return -1;
int parmCount = 0;
Set keys = parameterMap.keySet();
for(Iterator iter = keys.iterator(); iter.hasNext();)
{
String key = (String)iter.next();
int dot = key.indexOf('.');
if(dot > 0)
key = key.substring(0, dot);
String values[] = getDynacacheParameterValues(key, request.getPortletSession().getId());
if(values != null)
{
parmCount++;
StringBuffer sb = new StringBuffer("param.");
sb.append(key);
request.setAttribute(sb.toString(), values);
}
}

request.setAttribute("ExternParametersGotten", "done");
return parmCount;
}

private String[] getDynacacheParameterValues(String key, String sessionId)
{
StringBuffer sb = new StringBuffer(key);
sb.append(".count");
String countStr = (String)parameterMap.get(sb.toString());
if(countStr == null)
{
sb = new StringBuffer(key);
sb.append(".");
sb.append(sessionId);
String value = (String)parameterMap.get(sb.toString());
if(value != null)
{
parameterMap.remove(sb.toString());
String values[] = {
value
};
return values;
} else
{
return null;
}
}
parameterMap.remove(sb.toString());
int count = Integer.parseInt(countStr);
ArrayList valList = new ArrayList(count);
for(int i = 0; i < count; i++)
{
sb = new StringBuffer(key);
sb.append(".");
sb.append(i);
sb.append(".");
sb.append(sessionId);
valList.add(parameterMap.get(sb.toString()));
if(logger.isLoggable(Level.INFO))
logger.log(Level.INFO, (new StringBuilder("Portlet parm: ")).append(sb.toString()).append(" -- ").append((String)parameterMap.get(sb.toString())).toString());
parameterMap.remove(sb.toString());
}

String values[] = new String[valList.size()];
for(int i = 0; i < values.length; i++)
values[i] = (String)valList.get(i);

return values;
}

}
------------------------------------------------------------------------

Accessing in portlets.



import java.io.IOException;
import java.io.PrintWriter;
import javax.portlet.*;


public class AccessManager extends GenericPortlet
{

public static final String JSP_FOLDER = "/_BIC_AccessManager/jsp/";
public static final String ACCESS_MANAGER_SERVLET = "/AccessManagerServlet";
public static final String VIEW_JSP = "AccessManagerView";
public static final String SESSION_BEAN = "AccessManagerSessionBean";
public static final String FORM_SUBMIT = "AccessManagerFormSubmit";
public static final String FORM_TEXT = "AccessManagerFormText";
private AccessManagerUtils utils;

public AccessManager()
{
utils = null;
}

public void init()
throws PortletException
{
super.init();
utils = new AccessManagerUtils();
}

public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
response.setContentType(request.getResponseContentType());
utils.getDynacacheSingleParameters(request);
AccessManagerSessionBean sessionBean = getSessionBean(request);
if(sessionBean == null)
{
response.getWriter().println("NO PORTLET SESSION YET");
return;
} else
{
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, "AccessManagerView"));
rd.include(request, response);
return;
}
}
--------------------------------------------------------------------------------

Followers