Cal VA
Weblog  
 
March 2017
S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
<Feb Today Apr>
Search
Topics
Personal Personal
Java Java
Syndicate
Links
Referrers Today
 
 
 
 
 
 
   
 
 
 
 
 
God Bless America
 
Saturday, December 31, 2011 Flickr API using OAuth - Jersey and Struts

This is an example of the three steps used to establish the authentication for OAuth with the Flickr site. And an example of using the API to access a photo's information.

First an Action class to use for the OAuth communication and call back - and then a DAO used for OAuth communication and upload

For the struts-config.xml - use this URL for initiating the OAuth process and call back URL on the second step

<action path="/OAuth"
 type="com.holmansite.util.OAuth"
scope="request"
validate="false">
<forward name="success" path="/do/home/home"/>
</action>

Classes


package com.holmansite.util;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.holmansite.controller.HolmanSiteAction;
import com.holmansite.dao.FlickrOAuthDAO;


 public class OAuth extends HolmanSiteAction
 {

     public ActionForward doPerform(ActionMapping       mapping,
                                    ActionForm          form,
                                    HttpServletRequest  request,
                                    HttpServletResponse response) throws Exception
     {
         // Return the session
         HttpSession session = request.getSession();
        
         // Add the DAO object for the OAuth needed
         // Individual security methods are in respective DAO
         FlickrOAuthDAO theDAO = new FlickrOAuthDAO();
        
         String tokenSecret = (String) session.getAttribute("token_secret");
      cat.debug("back from Auth page - toke_secret:" + tokenSecret );
     
         if( tokenSecret == null ) 
         {
          // If no token secret we are in the initial step of three
          //  This method will perform step 1 and step 2
          
          cat.debug("starting step 1 and 2");
          
          tokenSecret = theDAO.getRequestToken();
          session.setAttribute("token_secret", tokenSecret);
         }
         else
         {
          // Third and last step
          
          cat.debug("Starting step 3");
          
          String oauth_token = request.getParameter("oauth_token");
          String oauth_verifier = request.getParameter("oauth_verifier");

       cat.debug("back from Auth page - auth token:" + oauth_token );
       cat.debug("back from Auth page - auth verifier:" + oauth_verifier);
      
          theDAO.performAuthStep(tokenSecret, oauth_token, oauth_verifier);
         }       
        
         // Forward control to the specified success URI
         return (mapping.findForward("success"));
 }

    /** Category definition for this class to log to log4j.  */
    protected Logger cat = Logger.getLogger(this.getClass());  
}

 

package com.holmansite.dao;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;

import com.holmansite.model.Picture;
import com.holmansite.model.PictureCategory;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import com.sun.jersey.multipart.FormDataBodyPart;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;
import com.sun.jersey.oauth.client.OAuthClientFilter;
import com.sun.jersey.oauth.signature.OAuthParameters;
import com.sun.jersey.oauth.signature.OAuthSecrets;


public class FlickrOAuthDAO
{
    /**
     * Creates a new FlickrDAO object.
     */
    public FlickrOAuthDAO()
    {
 
    }

    public String addPhoto( Picture thePicture,
       InputStream instream) throws JSONException
{

 //Turn the keywords into an array for display
 String         thePhotoKeywords    = thePicture.getKeywords();
 String keywords = "";
 
 // initialize by skipping the first *
 int    pos        = thePhotoKeywords.indexOf("*", 1);
 int    oldpos     = 1;
 String theKeyword = "";
 
 while (pos > -1)    //loop through the keywords - separated by *
 {
  if (oldpos !=1)
  {
   keywords = keywords + ",";
  }
  theKeyword = "\"" + thePhotoKeywords.substring(oldpos, pos) + "\"";
  keywords = keywords + theKeyword;
  
  oldpos = pos + 1;
  pos    = thePhotoKeywords.indexOf("*", pos + 1);
 }
 
 PictureCategory item     = null;
 Iterator<PictureCategory>  theItems = thePicture.getCategory().iterator();
 
 while (theItems.hasNext())
 {
  item = (PictureCategory)theItems.next();
 
  keywords = keywords + "," + item.getName();
 }
 keywords = keywords + "," + thePicture.getLocation();
 
 // Create a Jersey client
 Client client = Client.create();
 
 // Create a resource to be used to make  API calls     
 WebResource resource = client.resource("http://api.flickr.com/services/upload/");
 
 // Set the OAuth parameters
 OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(OAUTH_TOKEN_SECRET);
 OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).signatureMethod("HMAC-SHA1").version(
     "1.0").token(OAUTH_TOKEN);
 
 // Create the OAuth client filter
 OAuthClientFilter filter = new OAuthClientFilter(client.getProviders(), params, secrets);
 
 // Add the filter to the resource
 resource.addFilter(filter); 
 
    File thePhotoFile = new File("F:/Pictures/for_site/" + thePicture.getFilename());

 FormDataMultiPart form = new FormDataMultiPart();
 FormDataBodyPart formBody = new FileDataBodyPart("photo", thePhotoFile, MediaType.MULTIPART_FORM_DATA_TYPE);
 form.bodyPart(formBody);
 form.field("title", thePicture.getTitle());
 form.field("description", thePicture.getDescription());
 form.field("tags", keywords);
 
 // Flickr wants signature to have the parameters in signature except for photo
 // Jersey will not add form data to signature - so we trick it
 // by adding the same parameters to the reuest parms - so Jersey will
 // calculate the correct signature - but Flickr will ignore
 // the parameters
 MultivaluedMapImpl requestParams = new MultivaluedMapImpl();
    requestParams.add("title", thePicture.getTitle());
    requestParams.add("description", thePicture.getDescription());
    requestParams.add("tags", keywords);
   
    ClientResponse response = resource.queryParams(requestParams)
      .type("multipart/form-data").post(ClientResponse.class, form);


 String responseBody = response.getEntity(String.class);
 
 cat.debug("POST response:\n" + response.toString() + "\n");
 cat.debug("POST body:\n" + responseBody + "\n");
 
    int oauth_token_index_start = responseBody.indexOf("<photoid>") + 9;
    int oauth_token_index_end = responseBody.indexOf("</photoid>");
    String photoId = responseBody.substring(oauth_token_index_start, oauth_token_index_end);
 
 return photoId;
}
 
 public  void getFlickrInfo(String photo) throws JSONException
 {
        // Create a Jersey client
        Client client = Client.create();
 
        // Create a resource to be used to make  API calls
        WebResource resource = client.resource(URL_API);
 
        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(OAUTH_TOKEN_SECRET);
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).
                signatureMethod("HMAC-SHA1").version("1.0").token(OAUTH_TOKEN);
      
        // Create the OAuth client filter
        OAuthClientFilter filter =
                new OAuthClientFilter(client.getProviders(), params, secrets);
       
        // Add the filter to the resource
        resource.addFilter(filter);
    
     Date today = new Date();
  SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd");
  String todayParsed = format.format(today);
       
     MultivaluedMap<String, String> requestParams = new MultivaluedMapImpl();
     requestParams.add("format", "json");
     requestParams.add("method", "flickr.stats.getPhotoStats");
     requestParams.add("date", todayParsed);
     requestParams.add("photo_id", photo);

     ClientResponse response =  resource.queryParams(requestParams).get(ClientResponse.class);
 
     String responseBody = response.getEntity(String.class);

     cat.debug("back from flickr:\n" + response.toString() + "\n");
     cat.debug("back from flickr:\n" + responseBody + "\n");
 }

 
 public String  getRequestToken() {
 
         // Create a Jersey client
         Client client = Client.create();
 
         // Create a resource to be used to make  API calls
         WebResource resource = client.resource(URL_REQUEST_TOKEN);
 
         // Set the OAuth parameters
         OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET);
         OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY)
                 .signatureMethod("HMAC-SHA1").version("1.0")
                 .callback("http://www.calandva.test/holmansite/do/OAuth");
        
         // Create the OAuth client filter
         OAuthClientFilter filter =
                 new OAuthClientFilter(client.getProviders(), params, secrets);
        
         // Add the filter to the resource
         resource.addFilter(filter);
 
         // make the request
         String response = resource.get(String.class);

      cat.debug("back from request token:" + response );

      // hacked to extract the reuest_token and request_secret from response
      int oauth_token_index_start = 42;
         int oauth_token_index_end = response.indexOf("oauth_token_secret=") - 1;
         String oauth_token = response.substring(oauth_token_index_start, oauth_token_index_end);
 
         int oauth_token_secret_start = response.indexOf("oauth_token_secret=")+ 19;
         String oauth_token_secret = response.substring(oauth_token_secret_start);
        
        
      cat.debug("reuest token:" + oauth_token );
      cat.debug("reuest token secret:" + oauth_token_secret);
 
         // open the browser at the authorization URL to let user authorize
         try {
    Desktop.getDesktop().browse(new URI(URL_AUTHORIZE + "?oauth_token=" + oauth_token + "&perms=write"));
   } catch (IOException e) {
    cat.fatal("Desktop failure");
    e.printStackTrace();
   } catch (URISyntaxException e) {
    cat.fatal("Desktop failure");
    e.printStackTrace();
   }
        
         return oauth_token_secret;
 }
 
 public void performAuthStep(String tokenSecret, String oauth_token, String oauth_verifier)
 {
        // Create a Jersey client
        Client client = Client.create();
 
        // make an API call to request the access token
        WebResource resource = client.resource(URL_ACCESS_TOKEN);
 
      
        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(tokenSecret);
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).
                signatureMethod("HMAC-SHA1").version("1.0");

        // use the request token id and secret to create the request
      
        params.setVerifier(oauth_verifier);
        params.setToken(oauth_token);
       
        // Create the OAuth client filter
        OAuthClientFilter filter =
                new OAuthClientFilter(client.getProviders(), params, secrets);

        // Add the filter to the resource
        resource.addFilter(filter);
   
        // make the request
        String response = resource.get(String.class);
       
        // Print out the result
        // Key and secret will be in this message - copy the message and store the keys
        cat.debug("Access Credentials: " + response);
       
        return;
 }

    // base URL for the API calls
 private static String URL_API =   "http://api.flickr.com/services/rest/";

    // authorization URL
 private static String URL_REQUEST_TOKEN =  "http://www.flickr.com/services/oauth/request_token";
 private static String URL_ACCESS_TOKEN =  "http://www.flickr.com/services/oauth/access_token";
 private static String URL_AUTHORIZE =  "http://www.flickr.com/services/oauth/authorize";
 
 
    String CONSUMER_KEY = "<your api key>";
    String CONSUMER_SECRET = "<your api secret>";
   
    String OAUTH_TOKEN = "<your OAuth token>";
    String OAUTH_TOKEN_SECRET = "<your OAuth secret>";

        /** Category definition for this class to log to log4j.  */
    protected Logger cat = Logger.getLogger(this.getClass());   
 
}



posted at 1131 hrs   | Comments [0]


Friday, December 30, 2011 500px API and OAuth using Jersey and Struts

This is an example of the three steps used to establish the authentication for OAuth with the 500px site. And an example of using the API to access a photo's information.

First an Action class to use for the OAuth communication and call back - and then a DAO used for OAuth communication and upload


For the struts-config.xml - use this URL for initiating the OAuth process and call back URL on the second step

<action path="/OAuth"
 type="com.holmansite.util.OAuth"
scope="request"
validate="false">
<forward name="success" path="/do/home/home"/>
</action>

Classes

package com.holmansite.util;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.holmansite.controller.HolmanSiteAction;
import com.holmansite.dao.FiveHundredPxDAO;


 public class OAuth extends HolmanSiteAction
 {

     public ActionForward doPerform(ActionMapping       mapping,
                                    ActionForm          form,
                                    HttpServletRequest  request,
                                    HttpServletResponse response) throws Exception
     {
         // Return the session
         HttpSession session = request.getSession();
        
         // Add the DAO object for the OAuth needed
         // Individual security methods are in respective DAO
         FlickrOAuthDAO theDAO = new FlickrOAuthDAO();
        
         String tokenSecret = (String) session.getAttribute("token_secret");
      cat.debug("back from Auth page - toke_secret:" + tokenSecret );
     
         if( tokenSecret == null ) 
         {
          // If no token secret we are in the initial step of three
          //  This method will perform step 1 and step 2
          
          cat.debug("starting step 1 and 2");
          
          tokenSecret = theDAO.getRequestToken();
          session.setAttribute("token_secret", tokenSecret);
         }
         else
         {
          // Third and last step
          
          cat.debug("Starting step 3");
          
          String oauth_token = request.getParameter("oauth_token");
          String oauth_verifier = request.getParameter("oauth_verifier");

       cat.debug("back from Auth page - auth token:" + oauth_token );
       cat.debug("back from Auth page - auth verifier:" + oauth_verifier);
      
          theDAO.performAuthStep(tokenSecret, oauth_token, oauth_verifier);
         }       
        
         // Forward control to the specified success URI
         return (mapping.findForward("success"));
 }

    /** Category definition for this class to log to log4j.  */
    protected Logger cat = Logger.getLogger(this.getClass());  
}


   

package com.holmansite.dao;


import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.holmansite.model.FiveHundredPxData;
import com.holmansite.model.Picture;
import com.holmansite.model.PictureComment;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import com.sun.jersey.multipart.FormDataBodyPart;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;
import com.sun.jersey.oauth.client.OAuthClientFilter;
import com.sun.jersey.oauth.signature.OAuthParameters;
import com.sun.jersey.oauth.signature.OAuthSecrets;

 

public class FiveHundredPxDAO
{
   
    public FiveHundredPxDAO()
    {
     
    }


 public  FiveHundredPxData getFiveHundredPxInfo(Integer photo) throws JSONException
 {
        // Create a Jersey client
        Client client = Client.create();
 
        // Create a resource to be used to make  API calls
        WebResource resource = client.resource(URL_API);
 
        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(OAUTH_TOKEN_SECRET);
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).
                signatureMethod("HMAC-SHA1").version("1.0").token(OAUTH_TOKEN);
      
        // Create the OAuth client filter
        OAuthClientFilter filter =
                new OAuthClientFilter(client.getProviders(), params, secrets);
       
        // Add the filter to the resource
        resource.addFilter(filter);
       
     MultivaluedMap<String, String> requestParams = new MultivaluedMapImpl();
     requestParams.add("comments", "1");
     requestParams.add("comments_page", "1");
    

     ClientResponse response =  resource.queryParams(requestParams).path("photos/" + photo).get(ClientResponse.class);
 
     String responseBody = response.getEntity(String.class);

     cat.debug("back from 500px:\n" + responseBody + "\n");
    
     // Extract the date from the Json string
     JSONObject jsonObj;
     FiveHundredPxData theFiveHundredPxData = new FiveHundredPxData();
    
  jsonObj = new JSONObject( responseBody );
  if ( jsonObj != null && jsonObj.has( "photo" ) )
  {
     JSONObject photoJson = (JSONObject) jsonObj.get( "photo" );
 
     theFiveHundredPxData.setNumberOfVotes(photoJson.getInt("votes_count"));
     theFiveHundredPxData.setNumberOfFavorites(photoJson.getInt("favorites_count"));
     theFiveHundredPxData.setNumberOfComments(photoJson.getInt("comments_count"));
     theFiveHundredPxData.setNumberOfViews(photoJson.getInt("times_viewed"));
     theFiveHundredPxData.setRating(photoJson.getDouble("rating"));
     }
  
  PictureComment theComment = null;
  JSONObject commentObj = null;
  JSONObject userObj = null;
  String dateString = "";   
  Date parsed = null;
  SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  
  if ( jsonObj != null && jsonObj.has( "comments" ) )
  {
   JSONArray commentsObj = jsonObj.getJSONArray("comments");
   for (int i = 0; i < commentsObj.length(); i++)
   {
      theComment = new PictureComment();
      commentObj = commentsObj.getJSONObject(i);
      userObj = commentObj.getJSONObject("user");
      theComment.setAuthor(userObj.getString("username"));
      theComment.setText(commentObj.getString("body"));
      dateString = commentObj.getString("created_at");
     
    try
    {
        parsed = format.parse(dateString);
    }
    catch (ParseException e)
    {
        e.printStackTrace();
    }
     
      theComment.setCreated(parsed);
      theFiveHundredPxData.getComments().add(theComment);
   }
  }
    
    return theFiveHundredPxData; 
   
    }

 /*
  * Upload a photo
  */
 public  Integer uploadPhoto(Picture thePicture ) throws JSONException
 {
        // Create a Jersey client
        Client client = Client.create();
 
        // Create a resource to be used to make  API calls
        WebResource resource = client.resource(URL_API);
 
        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(OAUTH_TOKEN_SECRET);
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).
                signatureMethod("HMAC-SHA1").version("1.0").token(OAUTH_TOKEN);
      
        // Create the OAuth client filter
        OAuthClientFilter filter =
                new OAuthClientFilter(client.getProviders(), params, secrets);
       
        // Add the filter to the resource
       resource.addFilter(filter);
        
        // Create parame for URL
     MultivaluedMap<String, String> requestParams = new MultivaluedMapImpl();
     requestParams.add("name", thePicture.getTitle());
     requestParams.add("description", thePicture.getDescription());
     requestParams.add("category", thePicture.getFiveHundredPxCategory());
    
     //  500px does not pick up lens in EXIF
     requestParams.add("lens", thePicture.getLens());
    
     //  500px does not pick up long/lat in EXIF
     requestParams.add("latitude", thePicture.getLatitude());
     requestParams.add("longitude", thePicture.getLongitude());    

     // Make reuest for upload key
     ClientResponse response =  resource.path("photos/").queryParams(requestParams).post(ClientResponse.class);
    
     String responseBody = response.getEntity(String.class);
 
     cat.debug("POST response:\n" + response.toString() + "\n");
     cat.debug("POST body:\n" + responseBody + "\n");
   
     // Extract the date from the Json string
     JSONObject jsonObj;
     String uploadKey = "";   // Needed for second step
     Integer photoId = 0;     // Id to be saved with the picture
    

  jsonObj = new JSONObject( responseBody );
  if ( jsonObj != null && jsonObj.has( "upload_key" ) )
  {
   uploadKey = (String) jsonObj.get( "upload_key");
   JSONObject photo = (JSONObject) jsonObj.get( "photo" );
   photoId = (Integer) photo.getInt("id");
  }
  
     cat.debug("upload_Key:" + uploadKey);
     cat.debug("Photo Id:" + photoId);
    
     // Now that we have upload key need to send photo file
    
     requestParams = new MultivaluedMapImpl();
     requestParams.add("upload_key", uploadKey);
     requestParams.add("photo_id", photoId.toString());
     requestParams.add("consumer_key", CONSUMER_KEY);  // should not be required but is
     requestParams.add("access_key", OAUTH_TOKEN);     // should not be required but is

     File thePhotoFile = new File("F:/Pictures/for_site/" + thePicture.getFilename());

  FormDataMultiPart fdmp = new FormDataMultiPart();
  FormDataBodyPart fdp = new FileDataBodyPart("file", thePhotoFile, MediaType.MULTIPART_FORM_DATA_TYPE);
  fdmp.bodyPart(fdp);
    
     response =  resource.path("upload/").queryParams(requestParams).
            type("multipart/form-data").post(ClientResponse.class, fdmp);

     responseBody = response.getEntity(String.class);
  
     cat.debug("POST response:\n" + response.toString() + "\n");
     cat.debug("POST body:\n" + responseBody + "\n");

     return photoId;
   }


 public String  getRequestToken() {
 
         // Create a Jersey client
         Client client = Client.create();
 
         // Create a resource to be used to make  API calls
         WebResource resource = client.resource(URL_REQUEST_TOKEN);
 
         // Set the OAuth parameters
         OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET);
         OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).
                 signatureMethod("HMAC-SHA1").version("1.0");
        
         // Create the OAuth client filter
         OAuthClientFilter filter =
                 new OAuthClientFilter(client.getProviders(), params, secrets);
        
         // Add the filter to the resource
         resource.addFilter(filter);
 
         // make the request
         String testing = resource.get(String.class);
        
         // hack to extract the reuest token and reuest token secret
         int oauth_token_index_start = 12;
         int oauth_token_index_end = testing.indexOf("oauth_token_secret=") - 1;
         String oauth_token = testing.substring(oauth_token_index_start, oauth_token_index_end);
 
         int oauth_token_secret_start = testing.lastIndexOf("oauth_token_secret=")+ 19;
         int oauth_token_secret_end = testing.indexOf("oauth_callback_confirmed=") - 1;
         String oauth_token_secret = testing.substring(oauth_token_secret_start, oauth_token_secret_end);
        
        
      cat.debug("back from 500px - auth token:" + oauth_token );
      cat.debug("back from 500px - auth token secret:" + oauth_token_secret);
 
         // open the browser at the authorization URL to let user authorize
         try {
    Desktop.getDesktop().browse(new URI(URL_AUTHORIZE + "?oauth_token=" + oauth_token));
   } catch (IOException e) {
    cat.fatal("Desktop failure");
    e.printStackTrace();
   } catch (URISyntaxException e) {
    cat.fatal("Desktop failure");
    e.printStackTrace();
   }
        
         return oauth_token_secret;
 }
 
 public void performAuthStep(String tokenSecret, String oauth_token, String oauth_verifier)
 {
  
        // Create a Jersey client
        Client client = Client.create();
 
        // make an API call to request the access token
        WebResource resource = client.resource(URL_ACCESS_TOKEN);
 
      
        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(tokenSecret);
       
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).
                signatureMethod("HMAC-SHA1").version("1.0").timestamp().nonce();

        // use the request token id and secret to create the request
      
        params.setVerifier(oauth_verifier);
        params.setToken(oauth_token);
       
        // Create the OAuth client filter
        OAuthClientFilter filter =
                new OAuthClientFilter(client.getProviders(), params, secrets);

        // Add the filter to the resource
        resource.addFilter(filter);
       
        // make the request and print out the result
        // Copy response as the access key and secret are returned in the response
        String response = resource.get(String.class);
       
        cat.debug("Access Token and Access Secret: " + response);
 }

    // base URL for the API calls
 private static String URL_API =   "https://api.500px.com/v1/";

    // authorization URL
 private static String URL_REQUEST_TOKEN =  "https://api.500px.com/v1/oauth/request_token";
 private static String URL_ACCESS_TOKEN =  "https://api.500px.com/v1/oauth/access_token";
 private static String URL_AUTHORIZE =  "https://api.500px.com/v1/oauth/authorize";
 
    String CONSUMER_KEY = "<your api key>";

    String CONSUMER_SECRET = "<your api secret>";
    String OAUTH_TOKEN = "<your OAuth token>";

    String OAUTH_TOKEN_SECRET = "<your OAuth secret>";

        /** Category definition for this class to log to log4j.  */
    protected Logger cat = Logger.getLogger(this.getClass());   
 
}

 



posted at 1014 hrs   | Comments [0]


Thursday, December 29, 2011 Smugmug API using Jersey and Struts

Three classes are examples on how to go through the OAuth process and obtain the credentials - then how to access Smugmug for data.

First a standard Action used for many services reuiring OAuth - then a DAO class performing the OAuth methosds, adding a photo, and accessing Smugmug.


For the struts-config.xml - use this URL for initiating the OAuth process and call back URL on the second step

<action path="/OAuth"
 type="com.holmansite.util.OAuth"
scope="request"
validate="false">
<forward name="success" path="/do/home/home"/>
</action>

Classes

package com.holmansite.util;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.holmansite.controller.HolmanSiteAction;
import com.holmansite.dao.SmugmugDAO;


 public class OAuth extends HolmanSiteAction
 {

     public ActionForward doPerform(ActionMapping       mapping,
                                    ActionForm          form,
                                    HttpServletRequest  request,
                                    HttpServletResponse response) throws Exception
     {
         // Return the session
         HttpSession session = request.getSession();
        
         // Add the DAO object for the OAuth needed
         // Individual security methods are in respective DAO
         FlickrOAuthDAO theDAO = new FlickrOAuthDAO();
        
         String tokenSecret = (String) session.getAttribute("token_secret");
      cat.debug("back from Auth page - toke_secret:" + tokenSecret );
     
         if( tokenSecret == null ) 
         {
          // If no token secret we are in the initial step of three
          //  This method will perform step 1 and step 2
          
          cat.debug("starting step 1 and 2");
          
          tokenSecret = theDAO.getRequestToken();
          session.setAttribute("token_secret", tokenSecret);
         }
         else
         {
          // Third and last step
          
          cat.debug("Starting step 3");
          
          String oauth_token = request.getParameter("oauth_token");
          String oauth_verifier = request.getParameter("oauth_verifier");

       cat.debug("back from Auth page - auth token:" + oauth_token );
       cat.debug("back from Auth page - auth verifier:" + oauth_verifier);
      
          theDAO.performAuthStep(tokenSecret, oauth_token, oauth_verifier);
         }       
        
         // Forward control to the specified success URI
         return (mapping.findForward("success"));
 }

    /** Category definition for this class to log to log4j.  */
    protected Logger cat = Logger.getLogger(this.getClass());  
}

 

package com.holmansite.dao;

import java.awt.Desktop;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;

import javax.ws.rs.core.MultivaluedMap;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.holmansite.model.Picture;
import com.holmansite.model.PictureCategory;
import com.holmansite.model.PictureComment;
import com.holmansite.model.SmugmugData;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import com.sun.jersey.oauth.client.OAuthClientFilter;
import com.sun.jersey.oauth.signature.OAuthParameters;
import com.sun.jersey.oauth.signature.OAuthSecrets;

public class SmugmugDAO
{

 
    public SmugmugDAO()
    {

    }

    public String addPhoto( Picture thePicture,
          InputStream instream) throws JSONException
    {
     
        //Turn the keywords into an array for display
        String         theKeywords    = thePicture.getKeywords();
        String smugKeywords = "";

        // initialize by skipping the first *
        int    pos        = theKeywords.indexOf("*", 1);
        int    oldpos     = 1;
        String theKeyword = "";

        while (pos > -1)    //loop through the keywords - separated by *
        {
         if (oldpos !=1)
         {
          smugKeywords = smugKeywords + ",";
         }
            theKeyword = "\"" + theKeywords.substring(oldpos, pos) + "\"";
            smugKeywords = smugKeywords + theKeyword;

            oldpos = pos + 1;
            pos    = theKeywords.indexOf("*", pos + 1);
        }
       
        PictureCategory item     = null;
        Iterator<PictureCategory>  theItems = thePicture.getCategory().iterator();

        while (theItems.hasNext())
        {
            item = (PictureCategory)theItems.next();

            smugKeywords = smugKeywords + "," + item.getName();
        }
        smugKeywords = smugKeywords + "," + thePicture.getLocation();

        // Create a Jersey client
        Client client = Client.create();

        // Create a resource to be used to make  API calls     
        WebResource resource = client.resource("http://upload.smugmug.com/");

        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(OAUTH_TOKEN_SECRET);
       
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).signatureMethod("HMAC-SHA1").version(
                "1.0").token(OAUTH_TOKEN);
       
        // Create the OAuth client filter
        OAuthClientFilter filter = new OAuthClientFilter(client.getProviders(), params, secrets);

        // Add the filter to the resource
        resource.addFilter(filter);  
  
        ClientResponse response = resource.path(thePicture.getFilename())
          .entity(instream)
          .header("X-Smug-AlbumID", 20628810)
          .header("X-Smug-Version", API_VERSION)
          .header("X-Smug-ResponseType", "JSON") 
          .header("X-Smug-Pretty", true)
          .header("X-Smug-Caption", thePicture.getDescription())
          .header("X-Smug-Keywords", smugKeywords )
          .put(ClientResponse.class);   

        String responseBody = response.getEntity(String.class);

        cat.debug("POST response:\n" + response.toString() + "\n");
        cat.debug("POST body:\n" + responseBody + "\n");

     // Extract the photo key from the Json string
     JSONObject jsonObj;
  Integer photoId = 0;
  String photoKey = "";
   
  jsonObj = new JSONObject( responseBody );
  if ( jsonObj != null && jsonObj.has( "Image" ) )
  {
   JSONObject photoJson = (JSONObject) jsonObj.get( "Image" );
   photoId = (Integer) photoJson.get("id");
   photoKey = (String) photoJson.get("Key");
  }
  
  String photoFullKey = photoId  + "_" + photoKey;
  
        return photoFullKey;
    }

    public SmugmugData getSmugmugInfo(String photoId) throws JSONException
    {
     //Deconstruct the key from two parts
     String smugmugId = "";
     String smugmugKey = "";
     
     int dash = photoId.indexOf("_");
     
     smugmugId = photoId.substring(0, dash);
     smugmugKey = photoId.substring(dash + 1);

     // Create a Jersey client
        Client client = Client.create();

        // Create a resource to be used to make  API calls
        WebResource resource = client.resource(URL_API);

        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(OAUTH_TOKEN_SECRET);
       
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).signatureMethod("HMAC-SHA1").version(
                "1.0").token(OAUTH_TOKEN).timestamp().nonce();

        // Create the OAuth client filter
        OAuthClientFilter filter = new OAuthClientFilter(client.getProviders(), params, secrets);

        // Add the filter to the resource
        resource.addFilter(filter);

        // Create parame for URL
        MultivaluedMap<String, String> requestParams = new MultivaluedMapImpl();
        requestParams.add("ImageID", smugmugId);
        requestParams.add("ImageKey", smugmugKey);  
        requestParams.add("method", "smugmug.images.getInfo");
    
     String response =  resource.queryParams(requestParams).get(String.class);

        cat.debug("GET response:\n" + response.toString() + "\n");

     // Extract the data from the Json string
     JSONObject jsonObj = null;
     SmugmugData smugmugPhotoData = new SmugmugData();
 
  jsonObj = new JSONObject( response );
  if ( jsonObj != null && jsonObj.has( "stat" ) )
  {
     if (jsonObj.get("stat").equals("ok"))
     {
      JSONObject photoJson = jsonObj.getJSONObject("Image");
      JSONObject albumJson = photoJson.getJSONObject("Album");
      smugmugPhotoData.setSmugmugURL(albumJson.getString("URL"));
     }
  }

  // Create param for URL to get comments
        requestParams = new MultivaluedMapImpl();
        requestParams.add("ImageID", smugmugId);
        requestParams.add("ImageKey", smugmugKey);  
        requestParams.add("method", "smugmug.images.comments.get");
    
        // Need to bump the nonce because the last request nonce cannot be used
        params.setNonce();

     response =  resource.queryParams(requestParams).get(String.class);

        cat.debug("GET response:\n" + response.toString() + "\n");

     // Extract the date from the Json string
     jsonObj = null;
     JSONObject commentObj = null;
     JSONObject userObj = null;
     PictureComment theComment = null;
     String dateString = "";   
     Date parsed = null;
  SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
  jsonObj = new JSONObject( response );
  if ( jsonObj != null && jsonObj.has( "stat" ) )
  {
     if (jsonObj.getString("stat").equals("ok"))
     {
      JSONObject photoObj = jsonObj.getJSONObject("Image");
      JSONArray commentsObj = photoObj.getJSONArray("Comments");
      for (int i = 0; i < commentsObj.length(); i++)
      {
       theComment = new PictureComment();
       commentObj = commentsObj.getJSONObject(i);
       userObj = commentObj.getJSONObject("User");
       theComment.setAuthor(userObj.getString("Name"));
       theComment.setSmugmugRating(commentObj.getString("Rating"));
       theComment.setText(commentObj.getString("Text"));
       dateString = commentObj.getString("Date");
      
     try
     {
         parsed = format.parse(dateString);
     }
     catch (ParseException e)
     {
         e.printStackTrace();
     }
      
       theComment.setCreated(parsed);
       smugmugPhotoData.getComments().add(theComment);
      }
   }
  }
 
  return smugmugPhotoData;
    }


    public String getRequestToken()
    {

        // Create a Jersey client
        Client client = Client.create();

        // Create a resource to be used to make  API calls
        WebResource resource = client.resource(URL_REQUEST_TOKEN);

        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET);
       
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).signatureMethod("HMAC-SHA1").version(
                "1.0").timestamp().nonce();

        // Create the OAuth client filter
        OAuthClientFilter filter = new OAuthClientFilter(client.getProviders(), params, secrets);

        // Add the filter to the resource
        resource.addFilter(filter);

        // make the request
        String testing = resource.get(String.class);
       
        cat.debug("Response - " + testing);

        // Hack to ectract the reuest token and request secret
        int oauth_token_index_start = 12;
        int oauth_token_index_end = testing.indexOf("oauth_token_secret=") - 1;
        String oauth_token = testing.substring(oauth_token_index_start, oauth_token_index_end);

        int oauth_token_secret_start = testing.indexOf("oauth_token_secret=") + 19;
        int oauth_token_secret_end = oauth_token_secret_start + 64;
        String oauth_token_secret = testing.substring(oauth_token_secret_start, oauth_token_secret_end);

        cat.debug("Request token:" + oauth_token);
        cat.debug("Request token secret:" + oauth_token_secret);

        // open the browser at the authorization URL to let user authorize
        try
        {
            Desktop.getDesktop().browse(new URI(URL_AUTHORIZE + "?oauth_token=" + oauth_token));
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        catch (URISyntaxException e)
        {
            e.printStackTrace();
        }

        return oauth_token_secret;
    }

   
 public void performAuthStep(String tokenSecret, String oauth_token, String oauth_verifier)
 {
  
        // Create a Jersey client
        Client client = Client.create();
 
        // make an API call to request the access token
        WebResource resource = client.resource(URL_ACCESS_TOKEN);
 
        // Set the OAuth parameters
        OAuthSecrets secrets = new OAuthSecrets().consumerSecret(CONSUMER_SECRET).tokenSecret(tokenSecret);
       
        OAuthParameters params = new OAuthParameters().consumerKey(CONSUMER_KEY).
                signatureMethod("HMAC-SHA1").version("1.0").timestamp().nonce();

        // use the request token for the final reuest
        // verifier is not used by Smugmug
        params.setToken(oauth_token);
       
        // Create the OAuth client filter
        OAuthClientFilter filter =
                new OAuthClientFilter(client.getProviders(), params, secrets);

        // Add the filter to the resource
        resource.addFilter(filter);
       
        // make the request and print out the result
        // Copy response as the access key and secret are returned in the response
        String response = resource.get(String.class);
       
        cat.debug("Access Token and Access Secret: " + response);
 }
 
    /** Category definition for this class to log to log4j.  */
    protected Logger cat = Logger.getLogger(this.getClass());
   
   

    String CONSUMER_KEY = "<your api key>";

    String CONSUMER_SECRET = "<your api secret>";
    String OAUTH_TOKEN = "<your OAuth token>";

    String OAUTH_TOKEN_SECRET = "<your OAuth secret>";

    // base URL for the API calls
    String URL_API = "http://api.smugmug.com/services/api/json/1.3.0/";

    String URL_ACCESS_TOKEN = "http://api.smugmug.com/services/oauth/getAccessToken.mg";
    String URL_AUTHORIZE = "http://api.smugmug.com/services/oauth/authorize.mg";
    String URL_REQUEST_TOKEN = "http://api.smugmug.com/services/oauth/getRequestToken.mg";
}

 



posted at 1331 hrs   | Comments [0]


Sunday, September 19, 2004 Bag vs List in Hibernate

Learned a little this weekend - Bag vs List in Hibernate.  I was troubled since i really wanted to have a Java ArrayList in my object so i could index in my jsp and iterate over the list in an update form.  Using a Hibernate Set left me unable to index.  A Hibernate List left the Java ArrayList populated using the primary key - if the keys were 0,1,2,... that would have been ok.  But i only needed a few items from the database in my ArrayList and since the Hibernate List maintains the position of the object in the ArrayList equal to the position in the database the technique was leaving holes in my ArrayList of nulls.  Of course this was not what i wanted.  Now this may be explained in the documentation but after reading it twice i did not fully understand the Hibernate List.  Over the weekend i read the book Hibernate in Action and discovered the Hibernate Bag and it solved my problem.  I can use a Java ArrayList that is loaded simply by adding new objects to the beginning of the ArrayList.

posted at 1759 hrs   | Comments [0]


Saturday, November 15, 2003 Tomcat 5 missing logging JAR

A follow up to the last post.  In configuring a new system I discovered that Tomcat 5.0.14 needs to have the commons-logging-api.jar added to the common\lib directory.  Without it Jasper would not start the org.apache.jasper.JspC class in the jasper2 target.  For some reason Tomcat 5 does not ship with the logging jar.

posted at 2032 hrs   | Comments [0]


Friday, October 31, 2003 Tomcat 5.0 Precompile with Struts and Tiles

Adding precompiled jsps with Tomcat 5 is actually pretty easy to bring into the build process.  First the environment - I was trying to precompile jsps built on Struts 1.1 and Tiles.  My previous attempts in Tomcat 3 were foiled by the complexity of the process.  In Tomcat 5 the documentation provides a good example of setting up the Jasper 2 compiler to precompile your application.

The key is to create the exploded WAR and then invoke the jspc and javac on that structure.  Since they both need all the classes, libraries, and jsps.  My development project structure is below.  The Tomcat example does the precompile on the exploded war in the webapps directory - I use a build directory to pull all the items together prior to making a war file.

First you create the servlets - in following the example I placed them in the WEB-INF directory.  Then you compile the servlets and for me they were compiled into the build/classes directory. Next you need to map all the new servlets to the .jsp requests so I replace a token with the generated_web.xml in my web.xml.  This last step makes the build process automated but means your web.xml is built by ant.  I have not included the compile and war targets.

project
-->src           <-- all .java files

-->build
---->classes     <-- all classes including precompiled jsps
---->WEB-INF 
---->META-INF

-->WebRoot
---->web          <-- html/jsp/css/etc
---->META-INF
---->WEB-INF
------>classes    <-- compiled classes from the project/src the real java classes
------>src        <-- used to store the jsp servlets created in jspc target
------>lib

 <target name="jspc">
  <delete dir="${WEB-INF.dir}/src"/>
 <taskdef    name="jasper2"   classname="org.apache.jasper.JspC" >
  <classpath id="jspc.classpath">
  <pathelement location="${java.home}/../lib/tools.jar"/>
  <fileset dir="${my.catalina.home}/server/lib">
   <include name="*.jar"/>
  </fileset>
  <fileset dir="${my.catalina.home}/common/lib">
     <include name="*.jar"/>
  </fileset>
  </classpath>
 </taskdef>
 
 <jasper2
  validateXml="false"
  uriroot="${WebRoot.dir}"
  webXmlFragment="${WEB-INF.dir}/generated_web.xml"
  outputDir="${WEB-INF.dir}/src" />

</target>
<target name="compilejsp">
 
 <javac  destdir="${build.classes.dir}"
     optimize="off"
     debug="on"
     failonerror="false"
     srcdir="${WEB-INF.dir}/src"
     excludes="**/*.smap">
 
 <classpath>
  <pathelement location="${WEB-INF.dir}/classes"/>
  <fileset dir="${WEB-INF.dir}/lib">
   <include name="*.jar"/>
  </fileset>
  <pathelement location="${my.catalina.home}/common/classes"/>
  <fileset dir="${my.catalina.home}/common/lib">
   <include name="*.jar"/>
  </fileset>
  <pathelement location="${my.catalina.home}/shared/classes"/>
  <fileset dir="${my.catalina.home}/shared/lib">
   <include name="*.jar"/>
  </fileset>
 </classpath>
 <include name="**" />
 <exclude name="tags/**" />
</javac>

    </target>

<target name="compile-jsps" depends="init, compile, jspc,compilejsp">
 <loadfile property="file" srcFile="${WEB-INF.dir}/generated_web.xml"/>
 <copy    file="${ant.template.dir}/web.xml"  
  toFile="${WEB-INF.dir}/web.xml"  filtering="on" overwrite="yes">
  <filterset>
   <filter  token="generated"  value="${file}"/>
  </filterset>
 </copy>  
</target>



posted at 1056 hrs   | Comments []


Sunday, August 10, 2003 Tomcat 4.1.27

Just upgraded to Tomcat 4.1.27 because of the enhancements - or fixes - in the release were jk related.  I noticed the ant task for reload was not working and had substituted a stop and start targets - there is now a patch to correct reload on the Tomcat site.  I am also having problems with httpUnit and jwebUnit and compiling jsps with 27 that were not there in 24.  Still working on that one.  It seems ANT related because Tomcat is using ANT to compile the jsp.

posted at 1309 hrs   | Comments []


Friday, July 11, 2003 Building Bread Crumbs with Tiles and Struts

Let me preface this with the facts: i am not very technical so there are probably many out there that can do what i am demonstrating in a 'better' manner. I used the ideas from the Tiles creator himself - Cedric Dumoulin (thanks for a great tool) and his advanced manual to create my site. This is a small part of the site demonstrating the use of bread crumbs and Tiles. I love Tiles and probably tend to over use the framework. You will need to download the Crumb.war

There are two techniques used in this app for bread crumb generation. The first is to write a Tiles Action that accesses the Tiles definition and the second is a tag that reads the tiles definition. Both have advantages. Using the Tiles Action you can extend the functionality of the class to provide additional Tiles based services. Using the tag is super easy and reduces the overhead of an additional action class.

The three crumb bars on each page display - from the top - the Tiles Action technique, the default (almost - style class added) crumb tag and the third the crumb tag with a different style class and separator. You have probably already clicked about a figured out how they work - but let me describe the Tiles Action first.

The Tiles Action is triggered by adding a controllerUrl attribute to the definition - in this case i am using controllerUrl="/do/renderCrumb". renderCrumb extends Tiles Action and is called whenever the corresponding Tiles Definition is triggered - this includes any controllerUrl that is in a parent definition. Since i attached the controllerUrl to my base definition it will be called for each page (I only link to definitions). Anyway in the renderCrumb action the Tiles Component Context is read giving us access to the current definition - including all the inherited definitions. So the crumb attributes are accessed as well as the page name attribute. This depends on the crumb link and title attributes following a specific naming convention. Each level of the site must inherit it's definition from it's parent and add a set of crumb attributes incrementing the level number on the end of the attribute.

In the Crumbs Action i extended the ability of the Tiles Action to read and load another attribute (of course this is pretty easy to get directly in the jsp as well). This allows some menu styling based on the current Tiles definition. Some additional things you can do in a Tiles Action is play with the definition - change an attribute or even change the template. For an example of this go to my personal site settings page. Here i change the master template used and the stylesheet based on the user's selection.

Tiles Actions are pretty handy - if you select the portal view each of the little list boxes on the right side of the screen are individual jsps with their own action classes. This allows to each to be used on any jsp and the Action Class for the jsp does not need to know the other tile is there. The little tile can load it's own beans without depending on the page it is included in. Additionally i am using osCache to cache the portal tiles since executing 6 or 7 Action Classes per page is a bit much. The support projects page has all the support projects i am using.

The Tiles Action version displays the root (home) crumb but the Crumb Tag does not - you can modify both. The Crumb Tag needs no attributes if you name your crumb link and title crumblink and crumbtitle. If you are inclined you can change the style, separator character, and names of the crumb attributes in the Tiles definition.xml.

The only "bad" part of all this is - you need to use tiles for your site layout in a structured manner. This may make this technique not right for your site. You could get the crumb definitions from another source in the Tiles Action using a page attribute as a key to a database or xml file.

Again - none of this is original, Cedric provided the code for the Tiles Action and Steve Melzer wrote the tag which i extended.

posted at 0948 hrs   | Comments []


Tuesday, June 24, 2003 New Personal Blog

Took a suggestion from Niel Eyde to review the newer version of Personal Blog- wow. I started looking for some source and ideas only two weeks ago and in the last two weeks Personal Blog has really changed. There are some good ideas and Eric is headed in the right direction - moving the HTML to the jsp and Java to the Action Classes. Unfortunately i have already taken the older code and reworked it for my site - so i will continue to improve the code currently running. But i will still watch Personal Blog for great ideas in blog development.

posted at 0822 hrs   | Comments []


Saturday, June 21, 2003 Setting Up a Blogger

To create the blogging section of the site I looked for yet another open source project for code to base my development. I tried both Roller and Personal Blog because they were based on Struts. Roller is quite extensive since it is capable of being set up at a hosting site for several people to use - it is a collection of Struts, Velocity, Hibernate, Castor and others. It was a bit complicated but I may use some of the code.

So I used the code from Personal Blog by Niel Eyde. It is a Struts based weblogger but I changed most of it because it is the opposite design model than the one I use. Most of the java is in the jsp and most the html is in the java - so I wrote my own jsps and am rewriting the Struts action classes. The calendar code is as is - very tough to move the html out of the action class onto the jsp. Also adding DAO objects changing the database layer.



posted at 2107 hrs   | Comments []


Friday, June 13, 2003 Added a Webblog Today

Well I have created a weblog section to the web site - now the real challenge, adding content. I am going to focus on the development of the site in the blog and not many - if any - personal messages.

posted at 2043 hrs   | Comments []


 
 
What's New
12/01 India
09/10 India
11/17 India
09/19 Europe
03/27 Dubai

New Pics
Taylor
Jamming
For the Camera
Piano Player
Swift Paino

Popular Pics
1 Baileys and Sweet...
2 Sweetpea and a Mo...
3 Sleepy
4 Vacation in Highl...
5 A Christmas Jacket
6 Sunrise in Manhattan
7 Washington Hall -...
8 Dinner in Monteverde
9 42nd Street Subway
10 Cozy Fire
11 Sunrise in Manhattan
12 Little Post Office
13 I Can't Believe Y...
14 Salis IT
15 Radio City at Chr...

Top Page Hits
1 GuestBook
2 ScrapbookSearch
3 PictSearch
4 PictDisplayPicture
5


    Top Top    
java struts tomcat log4j DTDns MySQL Ant Apache