Wednesday, August 7, 2013

Cyg box

Apt like command for cygwin.
 # svn --force export http://apt-cyg.googlecode.com/svn/trunk/ /bin/
  # chmod +x /bin/apt-cyg
  # apt-cyg install nano
 OS X like open command for cygwin. In the home folder of cygwin type:
echo "alias open='cygstart'" >> .bash_profile 
source .bash_profile
 usage example: 
  open file.pdf
It will open the default OS program for reading PDF files.

Wednesday, February 20, 2013

Linux Box

To update jars in a WAR file without new deployment, stop the running Application and find the expanded WAR file location. Find the JAR file that contains the file [plugin.xml, MANIFEST.MF for example]. To see the Structure of the JAR files and the files that it contains, type
unzip -l jarfilename.jar
You are likely to get output of the format:
Archive:  jarfilename.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2013-02-20 13:35   META-INF/
      868  2013-02-20 13:35   META-INF/MANIFEST.MF
     1476  2013-02-20 13:26   plugin.xml
To view the content of an file type:
unzip -p jarfilename.jar plugin.xml
or the content of a file that is placed in a folder:
unzip -p jarfilename.jar META-INF/MANIFEST.MF

Now that the file to be edited is found, make a copy of it by typing the following:
mkdir META-INF

unzip -p jarfilename.jar META-INF/MANIFEST.MF > META-INF/MANIFEST.MF
nano META-INF/MANIFEST.MF
Edit the MANIFEST.MF file, and save it to the disk. Now to update the file in the jar file, type the following lines:
zip -u jarfilename.jar META-INF/MANIFEST.MF
All zip and unzip operations can be piped out to an file that can be examined at later time. And don't forget to clean up by removing your working files and directories. In this case:
rm -rf META-INF

Wednesday, February 3, 2010

Custom Portlet Scope for Spring, JSF, RichFaces portlet Applications

It is all to usual scenario. Create a Portlet, create a Spring bean with the scope="session" or scope="globalSession" and hope that everything works just fine. And it does, until you don't have the scenario where the user creates two separate instance of the same portlet definition.

In that case, all you get is two portlets which display the same informations. Why? Because both of the portlet instances are getting their data from the same Backing Bean instance.

One would wonder, should one use the Spring DispatcherPortlet. If yes, how do I put all that together with JSF, RichFaces etc. At least I did not manage to find any tutorial or example how to put all that technologies together.

So, are we using the right technologies? Still the Answear is most probably yes!

Looking for a soulution, I came accross the information, that one can define his own scope for the Spring Beans.

So I decidet to create own custom scope that saves the Spring Beans per portlet Instance. In other words, each Spring Bean Instance is saved in the PortletSession.PORTLET_SCOPE of the session.

Here is the Custom Scope definition.


public class PortletSessionScope extends AbstractRequestAttributesScope {

private final int scope;


public PortletSessionScope() {
this.scope = PortletSession.PORTLET_SCOPE;
}

@Override
protected int getScope() {
return this.scope;
}

public String getConversationId() {
String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId();
return sessionId;
}


@Override
public Object get(String name, ObjectFactory objectFactory) {
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
Object mutex = requestAttributes.getSessionMutex();
synchronized (mutex) {
ExternalContext external = FacesContext.getCurrentInstance().getExternalContext();
Object scopedObject = null;
Object session = null;
if (null != external) {
session = external.getSession(false);
if (null != session && session instanceof PortletSession) {

scopedObject = ((PortletSession) session).getAttribute(name, PortletSession.PORTLET_SCOPE);
if (scopedObject == null) {
scopedObject = objectFactory.getObject();
((PortletSession) session).setAttribute(name, scopedObject, PortletSession.PORTLET_SCOPE);
}
else if (null != session && session instanceof ServletSessionWrapper) {

scopedObject = ((ServletSessionWrapper) session).getAttribute(name);
if (scopedObject == null) {
scopedObject = objectFactory.getObject();
((ServletSessionWrapper) session).setAttribute(name, scopedObject);
}
}
}

return scopedObject;
}
}

@Override
public Object remove(String name) {

Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex();
synchronized (mutex) {
Object scopedObject = super.remove(name);
return scopedObject;
}
}
}
So now that you have the scoped bean, all it takes is to make it known to Spring. That is streight process.

In your applicationContext.xml, where all the beans are ceclared, do the following:














So, with that done, all it takes to get Spring Bean in PorltetSession.PORTLET_SCOPE is a deffinition of a Bean with the above scope, something like this:






That was it. Hope it works for you!