Tuesday, March 20, 2012

Custom variable in WAS, Help in to different env properties

1) Create custom properties in WAS where application deployed.



2) Access custom properties in Java code

System.getProperty("Custom property name");

Actually in J2EE application,in each env access point & log file location is different and maintain in code is very difficult. Best option to have some properties in each env and access in code.

Wednesday, March 14, 2012

CSV DATA LAOD IN ORACLE

Create control file.
--------------------------------------------------------

1) Create table : CHARGE_DEPOSIT_CONFIG_UPE

with following fields

CREATE TABLE CHARGE_DEPOSIT_CONFIG_UPE
(
PART_NUMBER VARCHAR2(100 BYTE),
PARENT_PART_NO VARCHAR2(100 BYTE),
CIRCLE VARCHAR2(100 BYTE),
BILL_PLAN_REF_NUMBER VARCHAR2(100 BYTE),
PRODUCT_NAME VARCHAR2(100 BYTE),
PRODUCT_TYPE VARCHAR2(100 BYTE),
PARENT_PRODUCT_REF_NUMBER VARCHAR2(100 BYTE)
)



For example LoadData.ctl
----------------------------------------------------
options (skip=1)
LOAD DATA
INFILE 'C:\Project\General\Plans\LoadData.csv'
INSERT
INTO TABLE CHARGE_DEPOSIT_CONFIG_UPE
FIELDS TERMINATED BY ','
optionally enclosed by "'"
TRAILING NULLCOLS
(PART_NUMBER,
PARENT_PART_NO,
CIRCLE,
BILL_PLAN_REF_NUMBER,
PRODUCT_NAME,
PRODUCT_TYPE,
PARENT_PRODUCT_REF_NUMBER
)
-----------------------------------------------------

Import data




Choose existing one
select control file
and Click on Finish button

Friday, February 10, 2012

Automatic login with the login URL

http://server:port/wps/portal/cxml/04_SD9ePMtCP1I800I_KydQvyHFUBADPmuQy?userid=userid&password=password

for example

http://localhost:10040/wps/portal/cxml/04_SD9ePMtCP1I800I_KydQvyHFUBADPmuQy?userid=wpsadmin&password=wpsadmin

Show pages only to wpsadmin : WebSphere portal v 6.1

Show pages only to Portal administrator (wpsadmin) ,

Simple steps

1) Create the pages, add some porlets in case required.
2) Remove access right under Allow Inheritance column.

And done.

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();
}


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

Followers