Monday, November 29, 2010

Facebook Tracking Your Every Move

I've recently become aware that facebook tracks all of my browsing activities, even when I'm not on the facebook site. It turns out that every web page that contains a facebook 'like' button is also capable of tracking your visit to the page if you're logged into facebook, even if you haven't explicitly clicked that button.

Blocking Facebook

I'm not a big fan of giving away information, particularly to large corporations that have loose privacy policies, so I do what I can to prevent this kind of tracking. Step one in this case is always logging out of facebook when I'm done with a session (I've largely stopped posting to facebook anyways), but I've also gone the extra step and added it to my firefox ad blocking plugin. The ad blocker works by filtering out a list predefined URLs in an HTML document that refer to ads, the net result is an ad-free web browsing experience.

Adding *facebook* to the list of URLs enables me to ultimately block any communication with facebook servers unless I explicitly allow it. I suppose this technique could be used for any website.

Wednesday, November 17, 2010

Finding a Missing Java Class at Compile Time

As a developer I've run into this scenario many times - my code won't compile because of a missing reference to some third party class in some JAR file that I can't possibly find.

On many occasions I've used findjar. Just pop in the class name that the compiler is complaining about and this handy site will not only tell you which JAR it lives in, but will also provide a link to the location it can be downloaded.

But today I ran into a more difficult case. Findjar doesn't work well with proprietary JARs like those found in IBM's Websphere Portal Server. I remember a long time ago reading about a utility that could find a JAR file by loading up a given classpath and quickly finding a class on that path.

A quick google search yielded something even better, Jarscan. Jarscan is a utility that will scour a given path on your filesystem, collecting all the JARs it finds and then tells you where your elusive class lives.

Monday, November 15, 2010

Using The Repeated Region builder

I recently encountered a case where I needed to display some repeating xml data that was embedded in a larger xml structure, something that the data page builder doesn't do well. So I decided to take a look at the repeated region builder, and found out that as with many builders, the correct inputs aren't so easy to figure out.

The data in a variable builder (varData) :
       <descr>Item one</descr>  
       <descr>Item two</descr>  
       <descr>Item three</descr>  

Note that <contact> is a sibling element of <order>, but we're not interested in that. What we want is just a list of orders with the ID hyperlinked to a URL which uses the UPC code as a parameter.

Page builder contents:
   <head><title>Default Test Page</title></head>  
                <tr name="repeatRow">  
                     <td><span name="id"/></td>  
                     <td name="descr"/>  


1234 Item one
3456 Item two
3458 Item three

The repeated region builder is designed to handle this exact scenario, the difficulty comes in defining the correct input values for the builder.

Note that the source data input field points to varData/dsixe/order and not varData/dsixe/order/item. The key piece of information here is the loop variable name (dsixeLoopVar) which is used in other builders to refer to values which are repeated. I think the reason this builder is difficult to use is due to the fact that this variable name doesn't show up as expanded in the variable pickers, it has to be manually typed in.
Also note how the page location repeatRow is a table row and identifies what chunk of HTML will be repeated.

Let's add a text builder to display the descr element:

In this case I was able to select ${Variables/dsixeLoopVar} from the picker and then type /item/descr on the end.

Hope someone finds this useful!

Creating Web Services for Portlet Factory

The heart of any SOA strategy involves web services and the document that makes it happen is a WSDL. Websphere Portlet Factory is an excellent tool for putting together a SOA presentation layer since it easily accepts a WSDL and quickly exposes its operations in a developer friendly IDE (Eclipse/RAD).

In previous WPF projects I'd start by building out schema that represent the data needed for display in the tool, but when working with web services the schema is defined in the WSDL document. Since I dislike working with schema, I typically create a sample XML and then use a tool to generate a schema from it. But what about the schema that are in the WSDL? What if I'm also developing the web services that will be ultimately consumed by WPF? I sure don't want to create a schema when something else can do the dirty work.

Enter web services metadata annotations (JSR 181).

Using annotations and a compatible runtime container like Apache's Axis2, I can throw together a web service in no time by just adding some annotations to a regular POJO. Suppose I have a need to retrieve contact information, but no implementation is available yet and I just need something stubbed out so I can get going. Someone else can follow up later and code in an implementation.

Let's start with a bean that will hold our contact information:

 public class ContactBean {  
      private String name;  
      private String phone;  
      public String getName() {  
           return name;  
      public void setName(String name) {  
  = name;  
      public String getPhone() {  
           return phone;  
      public void setPhone(String phone) {  
  = phone;  

The only code needed here is the declaration of the name and phone, the rest (class definition, getters/setters) is generated by Eclipse. Now let's create a POJO that will ultimately contain the implementation of the operation, but for right now it will just return a static instance of ContactBean:

 public class ContactInfo {  
      public ContactBean getContact(String uid){  
           ContactBean cb = new ContactBean();  
           cb.setPhone("678 555-1212");  
           return cb;  

Nothing magical about this class, but it can be turned into a web service operation by adding 3 annotations:

 import javax.jws.WebMethod;  
 import javax.jws.WebService;  
 import javax.jws.soap.SOAPBinding;  

 @WebService(serviceName="ContactService", targetNamespace="")  

 public class ContactInfo {  
      public ContactBean getContact(String uid){  
           ContactBean cb = new ContactBean();  
           cb.setPhone("678 555-1212");  
           return cb;  

Believe it or not, that's it! I package it into a JAR (not a WAR) and deploy to Axis2 and I'm ready to pull a WSDL into a WPF web service builder.

In the time it probably would have taken me to build an XSD schema using some fancy editor, I've not only created a WSDL with the required schema but also a functional base implementation of a service operation.