Blogs

Using jtweet portlet behind a proxy for twittering #liferay contents

Recently Sandeep Nair developed a portlet that commits the blog entries and other contents in a Twitter account. This portlet is configurable by groupId and it can manage several Twitter accounts by Group (Organization,Community etc..). The portlet use the jtweet library to interact with api.tweeter.com.

We are testing this portlet and we find a problem if Liferay is behind a proxy. The reason is that jtweet uses the java.net.Connection instead of the HttpImpl provided by Liferay, which is clear because jtweet is a general purpose library. So, if you want to use this cool portlet you have to configure the JVM for the proxy and set the user credentials.

http.proxyHost=proxy.server.com
http.nonProxyHosts=localhost
http.proxyPort=8080



To set the user and password, you have to register an Authenticator, and set it as default.

package net.zylk.proxy.auth;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;

public class StartupAction extends SimpleAction{

    @Override
    public void run(String[] arg0) throws ActionException {
        // TODO Auto-generated method stub
        Authenticator.setDefault(new SimpleAuthenticator("PROXY_USER","PROXY_PASSWORD"));
    }

    public class SimpleAuthenticator extends Authenticator {
        private String username, password;

        public SimpleAuthenticator(String username, String password) {
            this.username = username;
            this.password = password;
        }

        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password.toCharArray());
        }
    }
}


On liferay startup:

global.startup.events=com.liferay.portal.events.GlobalStartupAction, net.zylk.proxy.auth.StartupAction

It is also useful for the RSS portlet behind proxy with authentication. I don't know if this is the best way to do this but is one way.
 

More Blog Entries

How to link portlets located on different pages in Liferay Portal

Following with the IPC (inter portlet communication) , let's go with an example that...

Usando parametros publicos de renderizado desde velocity CMS en #liferay

Siguiendo con el tema de IPC y render public params , vamos a explicar una forma de hacer...

0 Comments