Unix Bash Coloured Prompts
| Posted by watashii | Filed under UnixTo display coloured prompts upon user login (on Unix Bash shell, PuTTY client), perform the following modifications:
- Unix login and open the user’s profile in the home directory, eg /home/username/.profile
- In the .profile, add the following entry in a new line to execute the bash shell upon login, eg /usr/bin/bash
- The bash shell will refer to a .bashrc file. If its not there, create it, eg /home/username/.bashrc
- Add following entries in the .bashrc to enable the coloured prompt; showing the username, hostname and working directory:
# Colored Prompts
STARTGREEN='\[\e[0;32m\]';
STARTBLUE='\[\e[1;34m\]';
ENDCOLOR="\[\e[0m\]";
PS1="$STARTGREEN\u@\h$ENDCOLOR:$STARTBLUE\w$ENDCOLOR $ ";
Tags: bash, bashrc, color, profile, prompt
Weblogic Portal – Create Streaming Desktop Page Definition Error
| Posted by watashii | Filed under Programming, WebGot the following error when (re)creating a streaming desktop from an updated .portal file, using the Create Desktop Wizard on Portal Admin Console.
javax.ejb.EJBException: SQL Error while trying to createPageDefinition: SQL [insert into PF_PAGE_DEFINITION ( PAGE_DEFINITION_ID, MARKUP_DEFINITION_ID, IS_PUBLIC, IS_HIDDEN, INTERSECTION_ID, PAGE_LABEL, WEBAPP_NAME) values (?,?,?,?,?,?,?)] database error code [25,222] SQL state [22028] .; nested exception is: java.sql.SQLException: Data exception -- row already exist in index AX1_PAGE_DEF on table PF_PAGE_DEFINITION.
To temporarily bypass this error this so the streaming desktop can be created with the wizard, remove all the Pages manually from the Library.
The problem is one of the Page definition(s) in the .portal file is corrupted which prevents the library page resource from being refreshed. You will need to work out which page is causing the problem, then the redo the page in the .portal file via Weblogic Portal Workshop.
Tags: error, portal, streaming desktop, weblogic
Subversion – Allow Author Name Logging
| Posted by watashii | Filed under Programming, SoftwareTo log the author name when trying to check-in files using Subversive/Eclipse over SVN, switch to SVN Repository Exploring perspective > right-click on your repository > edit the Location Properties > Advanced tab > and enable Override author name:
Tags: eclipse, hook, subversion, subversive, svn
Unix Shell – Check If Directory Is Empty
| Posted by watashii | Filed under Programming, UnixHere is a simple unix shell command to check if a directory, $dir, is empty.
export $dir=/tmp/myfiles/
if [ "$(ls -A $dir)" ];
then
echo "$dir NOT Empty";
else
echo "$dir IS Empty";
fi
Tags: directory, empty, shell, unix
Java Send Email (In a Jar)
| Posted by watashii | Filed under Programming, WebStep 1
Download the JavaMail and Activation Framework library .jar files
• If using Java SE, you’ll need to download JavaMail, eg mail-1.4.3.jar
• If using below Java SE 6, you’ll need to download and include Activation Framework, eg activation-1.1.1.jar
Read the rest of this entry »
Tags: classpath, jar, java, mail
Start & Stop Weblogic Without Username & Password
| Posted by watashii | Filed under Oracle, WebIn a Weblogic Server domain running in production mode, username and password is always prompted during startup and shutdown (admin server and managed servers). To bypass this manual step, we can store the username and password credentials in the boot.properties file (although this is somewhat the same as development mode)…
Tags: encrypt, password, security, weblogic
Weblogic Portal Authorization – Get and Check User’s Roles
| Posted by watashii | Filed under Programming, WebThe Authorization class provides runtime methods for security policies and roles checks. The following code fragment obtains the set of roles the logged-in user belongs to. Note the user must be authenticated first, see Authentication class.
String entAppName = ApplicationHelper.getNonVersionedAppName();
String webAppName = ApplicationHelper.getWebAppName(request);
EnterpriseRoleResource resource = new EnterpriseRoleResource(entAppName,webAppName,EntitlementConstants.P13N_ROLE_POLICY_POOL,"");
Map userRoles = Authorization.getRoles((P13nResource) resource);
if (Authorization.isUserInRole("Admin", userRoles)) {
return true;
}
Global and Enterprise Application roles are obtained using EnterpriseRoleResource. For Global, Enterprise, and Web Application roles, use WebappRoleResource.
com.bea.p13n.security.Authentication
Tags: authentication, authorization, portal, roles, weblogic
Getting the HttpServletRequest from PortletRequest Object
| Posted by watashii | Filed under Programming, WebIn my JSF / icefaces based portlet running on Weblogic Portal, I got the following error:
com.icesoft.faces.webapp.http.portlet.PortletExternalContext cannot be cast to javax.servlet.http.HttpServletRequest
It turned out I cannot simply obtain the HTTPServletRequest object like this:
FacesContext ctx = FacesContext.getCurrentInstance(); HttpServletRequest portletRequest = (HttpServletRequest) ctx.getCurrentInstance().getExternalContext().getRequest();
In a portlet environment, to get the request/response objects, we must obtain the javax.portlet.PortletRequest/PortletResponse objects instead (which inherits methods from java.servlet.HTTPServletRequest/HTTPServletResponse):
FacesContext ctx = FacesContext.getCurrentInstance(); PortletRequest portletReq = (PortletRequest) ctx.getExternalContext().getRequest();
However sometimes we may require the HttpServletRequest / HttpServletResponse object. To obtain this, we must extract an attribute from the PortletRequest / PortletResponse object:
FacesContext ctx = FacesContext.getCurrentInstance();
PortletRequest portletReq = (PortletRequest) ctx.getExternalContext().getRequest();
HttpServletRequest httpServletReq = (HttpServletRequest) portletReq.getAttribute("javax.servlet.request");
Tags: javax, jsf, portlet, request, response, servlet, weblogic portal
Reading Portlet Preferences in Weblogic Portal
| Posted by watashii | Filed under Programming, WebPortlet preferences enables portlets to be associated with external application data. This data should generally be used to store (or update) configuration data in a portlet. For example, to store/update dynamic stock codes in a stock quotes portlet. A portlet preference is basically a name-value pair data structure.
Portlet preferences can be added/updated in the following ways:
- During design-time on Workshop for Weblogic Portal (screenshot above)
- Invoked programmatically at request-time using javax.portlet.* API
- Manually during run-time of a portal (via Portal Administration Console when a portal desktop is created)
When we have added our preferences, we can read them using using the Weblogic Portal API’s. The following sample code fragments are for JSP Portlets, and JSF Portlets:
Tags: java, jsp, portal, portlets, preferences, weblogic
Encrypt Passwords With Weblogic Server
| Posted by watashii | Filed under Oracle, WebIn a Weblogic Server environment, sometimes passwords must be unavoidably stored in text files, for example database connection details within JDBC configuration files. When running Weblogic in production mode, only encrypted password is accepted to ensure that the password is never exposed as clear text. To generate the encrypted password, the weblogic.security.Encrypt utility can be used, which generates a hashed password with a “{3DES}” prepended.
In Unix environment:
$ cd /opt/bea/user_projects/domains/mydomain/bin
$ . setDomainEnv.sh
$ java weblogic.security.Encrypt mycleartextpasswordhere
{3DES}xLLwrOm7asb4imZOYYwxz5TcBqDBEe6S
In Windows environment:
C:\>cd c:\bea\domains\mydomain\bin
C:\bea\domains\mydomain\bin>setDomainEnv.cmd
C:\bea\domains\mydomain\bin>java weblogic.security.Encrypt mycleartextpasswordhere
{3DES}lieJgIkTqg1xSBBoy3YxnHbPuz+tMxhY
Note that running the same command on different environment (or different Weblogic server installation) will produce a different password.






