Sunday, April 27, 2014

Goodbye Blogger, Hello Flogger

My blog moved to http://sidmorad.herokuapp.com.

and my first post[1] explains why ?

[1] http://sidmorad.herokuapp.com/app/file?name=startMyBlog.xml

p.s. I got a feeling that I did publish a post like this before!

Tuesday, July 31, 2012

Configuring InfraRED 2.6-rc1 in your java web project

InfraRED is a Java profiler [1].

There is a good post here [2], that compares all different available open source profilers, include infraRED.

There is an installation guide [3], that is last available document for infraRED version 2.4.1-BETA, You could follow that installation guide and check my guide here to see the differences in version 2.6-rc1.
Note: I was not able to find any document for version 2.6-rc1.

Step1: download the infraRED 2.6-rc1 from SourceForge [4].

Step2: preparing the application

1. Include infrared-agent.properties to your WEB-INF/classes directory of your web project.
2. Include infrared jar file to your WEB-INF/lib directory of your web project.

3. Add infraRED application startup listener and filter to your web.xml

Step 3: install web GUI of InfraRED

Find infrared-web-2.6-rc1.war file and copy it to your application server (e.g tomcat/webapps).

Step 4 (optional): customizing application layers using Aspectj
Note: this step worked for me with exact following configuration

1. Add aspectjrt.jar to your project classpath
Note: If you are using Eclipse and Aspectj plugin then right-click in your project -> Configure -> Convert to Aspectj project

2. Create a java class file like this one, WebLayerAspect.java:

  package infraredprofiler;

  import net.sf.infrared.aspects.aj.AbstractApiAspect;
  import org.aspectj.lang.annotation.Aspect;
  import org.aspectj.lang.annotation.Pointcut;

  @Aspect
  public class WebLayerAspect extends AbstractApiAspect {
  
    // Pointcut for all classes and all methods
    @Pointcut(value= "call(* *(..) )")
    public void apiExecution() {}
  
    public String getLayer() {
      return "Layer_name_e_g_001";
    }
  }

3. Create aop.xml under META-INF directory, by following content:

Sorry this blogger.com it didn't make it easy for me to past XML content!!
It's been a while that I am not happy with blogger.com anymore..
So I start my own blogging software in following address:
https://github.com/smoradi/flogger
and my own example of using this software is available in
http://sidmorad.herokuapp.com/
Want to know why I am not happy with blogger ? read following page
http://sidmorad.herokuapp.com/app/file?name=startMyBlog.xml
http://sidmorad.herokuapp.com/data/startMyBlog.xml

Oh about aop.xml, just see another aop.xml of InfraRED examples, it should be easy to figure out.

4. Make sure your code compiled with Aspectj compiler (In my case I had aspectj-maven-plugin from org.codehaus.mojo version 1.3).

That's all, you should be able to browse your app and open infraRED GUI and see the statistics.



Note: for some reason adding second layer didn't worked for me, I had only one layer and only one pointcut to work with!

[1] http://infrared.sourceforge.net
[2] sorry I was not able to find that post in Google search engine again! and I am using duckduckgo.com right now! ;-)
[3] http://infrared.sourceforge.net/versions/latest/installation.html
[4] http://sourceforge.net/project/showfiles.php?group_id=92904

Sunday, December 19, 2010

Celery stew

Living on the cheapest available food would be very unhealthy. Rice, beans and vegetables are a better source of food. "Start by investing in a rice cooker, if you don't have one.". I've read above text from Paul Graham (Ramen Profitable essay[1]) at 2009. 

His advise was very useful for me in last semester at university. After I moved to university campus, I had to cook for myself. I bought a rice cooker and I was using beans and vegetables a lot. At the same time, it was another easy, cheap and common food available for students: "Instant Noodles". Please don't use this type of food often and instead of that try to cook something healthy like "Celery stew".

As I am in holiday at home with my family. I've decided to learn some new recipe from my mom. My mom's cooking is the best (and famous) between our friends and relatives. I've asked many times from her about her secrets in cooking, she is always answering me with the detailed recipe. Let's use my mom's recipe for cooking celery stew and see how much you may enjoy ;-)
  • Rice
  • Oil 
  • Yellow onions
  • Fresh Celery 
  • Red meat or chicken or mushroom (form left to right is better to use)
  • Red chili, salt and turmeric (turmeric is for changing food's color, Saffron can be use instead of that too but it is much more expensive)
  • Sour water  
First put rice in rice cooker. Add water as specified on rice cooker. Add salt and a little bit of oil if you want to. Turn on rice cooker now and forget about it (Ideally rice and celery stew would be ready at same time, but usually celery stew takes more time to cook).

  1. Cut and fried the onions until their color changed to bright yellow. 
  2. Add small pieces of celery plus it's leafs (Celery stalk should be between 1.5 cm to 2.5 cm. Wash and chop chop celery leafs before adding). Fried celery for 4 to 6 minutes (until the green color of leafs became darker).
  3. Add pieces of meat and fried them until they changed the color too (not cooked neither row).
  4. Add nearly twice as much as all of the food water to the container. Or add water until it cover food plus 5cm above it. 
  5. Add red chili, salt and turmeric.
  6. Then increase the fire level to high to boil the water until it lost half of it.
  7. Add a little by little sour water and taste the food.
  8. Decrease the fire level to low and wait for food to cook slowly.

That's all, when celeries are soft and nice to eat, you could eat the celery stew with the rice.
Enjoy the food and share your feedback :-)

P.S. if you are using Saffron then it's better to add it at the end (after #8).

Thursday, February 11, 2010

Beach Walk #2 (Fishing tips)

After writing Beach Walk #1 on 11th July 2009 I went to the beach, on average one times a week. Walking, Running and Swimming are activities that interest me. But last night I went fishing, and it was my second time to go to this spot at Boambee and I guess my fifth time in my whole life!

Yeah and I am quite new in fishing and last night something magical happened! ;-) , I went home with two fish(a flat head and another type!) How did this happen? I was lucky to meet David and Kerin (I hope i spelled that right) . They told me a lot of tips about fishing. Then I thought it would be nice if I shared tips in my Blog. Maybe someone like me can use these tips and go back home happy and excited ! :D

Tips that I remember are :

* After heavy rain more fish will come from sea to river.
* After sun goes down , you have more chance to catch bigger fish .
* We used fish meat for bait , they told me cheap/fresh fish will do the job , in our case I guess it was Mullet fish.
* David showed me how put bait onto the hook,and make sure you go pierce through the skin twice and hook with bait.
* David showed me how to drop line to water and leave line in ground until fish bite the bait properly, yeah it's time to be patient.
* If you didn't feel much bite with fish then it's time to check your hook again.
* last tip is about being positive and lucky, good luck ;-)

Another interesting thing about last night was the talk that we had together. Australian's are famous for being friendly and that is really true, they treated me like their close friend and taught me a lot of tricks and tips about fishing. The only things they asked me was sharing these tips with others ,and that I think it's a great thing and I am doing it right now! ;-)
I also talked about my nationality and they were interested to know more about my culture and politics in Iran (formally Persia). I explained to them Why I wore GREEN last night(11th February 2010)? And I saw their support and interest in Green movements all over the world.

I noticed about one pattern in my life that is about the 11th of each month, for example I was born on the 11th of March and I arrived to Australia on the 11th of March as well,and I caught two fish on the 11th of February ;-) and I'd like to post in my blog after this day :-) Anyway there are many 11th days in front , let's see what will happen in the future.
Cheers,
Sid
PS. I caught one fish(flat head) and David gave another one to me , thanks David ;-)

Sunday, January 3, 2010

Configure Jasperreports 3.x Spring 3.x Maven 2.x by Roo 1.x

In this post we are going to see how easy and fast we could integrate Jasperreports to the Spring-MVC based projects by Spring-Roo. Spring Roo is a next-generation rapid application development tool for Java developers.
Note: Spring Roo uses Maven2 as a default build tool for generated projects.


In the first step we will create sample project with Spring-Roo and in the second step we will add required configurations manually.
Before going to steps, have a look at my test environment :
jasperreports-3.5.2
springframework-3.0.0.RELEASE
spring-roo-1.0.0.RELEASE
apache-maven-2.2.1
sun-jdk1.6.0_16 (64bit)
linux-ubuntu-8.04 (64bit)

And don't worry about the differences to yours , you just need to have Spring-Roo-1.0.0.RELEASE installed, then you can expect same result as me.

Step one: create sample project with Spring Roo
$mkdir sample
$cd sample
$roo
roo> project --topLevelPackage com.company.sample
roo> persistence setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT
roo> entity --class ~.domain.Customer
roo> field string --fieldName name --class ~.domain.Customer
roo> controller scaffold --class ~.web.CustomerController --entity ~.domain.Customer 
roo> quit
$mvn clean tomcat:run


Now you can go to http://localhost:8080/sample/ and check the CRUD functionality that you have created with 'controller scaffold' add-ons.

Step two: modify files manually:
You may want to edit files in Eclipse IDE or STS :
Note: STS has all required plugins installed.
$cd sample
$mvn eclipse:eclipse

sample/pom.xml
      <dependencies>
...
        <dependency>
            <groupid>org.springframework</groupId>
            <artifactId>org.springframework.context.support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>3.5.3</version>
        </dependency>
      </dependencies>

You may ask why jasperreports version 3.5.3? while last stable version is 3.7.0? the answer is I couldn't find any higher version in mvnrepository.com . If you could find a higher version in any other Maven2 repositories, please let me know.

sample/src/main/webapp/WEB-INF/spring/webmvc-config.xml

<beans ...>
...
    <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
       <property name="basename" value="views"/>
    </bean>
</beans>


sample/src/main/webapp/WEB-INF/classes/views.properties
customerReportList.(class)=org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView
customerReportList.url=/WEB-INF/reports/customerReportList.jasper
customerReportList.reportDataKey=customerReportList

sample/src/main/webapp/WEB-INF/reports/customerReportList.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="customerList" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
  <field name="name" class="java.lang.String"/>
  <columnHeader>
    <band height="31" splitType="Stretch">
      <staticText>
        <reportElement x="0" y="0" width="100" height="20"/>
        <text><![CDATA[NAME]]></text>
      </staticText>
    </band>
  </columnHeader>
  <detail>
    <band height="24" splitType="Stretch">
      <textField>
        <reportElement x="0" y="0" width="100" height="20"/>
        <textElement/>
        <textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>
      </textField>
    </band>
  </detail>
</jasperReport>


sample/src/main/webapp/WEB-INF/reports/customerReportList.jasper
You have different options to compile this file, in my case jasperreports-maven-plugin from mojo.codehaus.org
sample/pom.xml
...
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jasperreports-maven-plugin</artifactId>
    <configuration>
      <sourceDirectory>src/main/webapp/WEB-INF/reports</sourceDirectory>
      <outputDirectory>src/main/webapp/WEB-INF/reports</outputDirectory>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>compile-reports</goal>
        </goals>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>3.5.3</version>
      </dependency>
      <dependency>
        <groupId>org.apache.log4j</groupId>
        <artifactId>com.springsource.org.apache.log4j</artifactId>
        <version>1.2.15</version>
      </dependency>                    
     </dependencies>
  </plugin>
</plugins>
</build>


sample/src/main/java/com/company/sample/web/CustomerController.java
package com.company.sample.web;

import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import com.company.sample.domain.Customer;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.stereotype.Controller;

@RooWebScaffold(path = "customer", automaticallyMaintainView = true, formBackingObject = Customer.class)
@RequestMapping("/customer/**")
@Controller
public class CustomerController {

 @RequestMapping(value ="/customer/report/pdf", method = RequestMethod.GET)
 public String fireReport(ModelMap modelMap) {
  JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(Customer.findAllCustomers(),false);
  modelMap.put("customerReportList", jrDataSource);
  return "customerReportList";
 }
}

That's all, add some customers and check 'http://localhost:8080/sample/customer/report/pdf' .

What else?
I also tried to get multiple report format + changing report name at runtime:
sample/src/main/webapp/WEB-INF/spring/webmvc-config.xml
<beans ...>
...
  <bean id="jasperReportsMultiFormatView" name="jasperReportsMultiFormatViewBean"
class="com.company.sample.web.report.CustomJasperReportsMultiFormatView">

    <!-- The value _rep_name_ will be replaced with the report name -->
    <property name="contentDispositionMappings">
      <props>
        <prop key="html">attachment; filename=_rep_name_.html</prop>
        <prop key="pdf">attachment; filename=_rep_name_.pdf</prop>
        <prop key="xls">attachment; filename=_rep_name_.xls</prop>
        <prop key="csv">attachment; filename=_rep_name_.csv</prop>
      </props>
    </property>
  </bean>
</beans>

sample/src/main/webapp/WEB-INF/classes/views.properties
customerReportList.(class)=com.company.sample.web.report.CustomJasperReportsMultiFormatView

sample/src/main/java/com/company/sample/web/report/CustomJasperReportsMultiFormatView.java
package com.company.sample.web.report;

import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JasperPrint;
import org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView;

/**
 * This calss override renderReport() method for replace report name .
 */
public class CustomJasperReportsMultiFormatView extends JasperReportsMultiFormatView {

 protected void renderReport(JasperPrint populatedReport, Map model, HttpServletResponse response) throws Exception {
        super.renderReport(populatedReport,model,response);
        
        // replace content disposition header filename with the report names.
        Properties contentDispositions = this.getContentDispositionMappings();
        
        Enumeration enumContDispKeys = contentDispositions.keys();
        // iterate over all disposition mappings and replace the word _rep_name_ with the reportName
        while(enumContDispKeys.hasMoreElements()){
            Object contDispKey = enumContDispKeys.nextElement();
            // check whether string before cast.
            if(contDispKey instanceof String){
                // get the disposition string
                String dispositionStr = contentDispositions.getProperty((String)contDispKey);
                // set the new value in the properties
                contentDispositions.setProperty((String)contDispKey,dispositionStr.replace("_rep_name_",populatedReport.getName()));
            }
        }
    }
}

I found the above code from this post . But I got no success to change report name.I also moved super.renderReport(..) to the bottom of method but there was no difference. Maybe it is not working because of my jasperreports version, If you find the problem please let me know, thanks.

And finally sample/src/main/java/com/company/sample/web/CustomerController.java
 @RequestMapping(value ="/customer/report/{format}", method = RequestMethod.GET)
 public String fireReport(ModelMap modelMap, @PathVariable("format") String format) {
  JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(Customer.findAllCustomers(),false);
  modelMap.put("customerReportList", jrDataSource);
  modelMap.put("format", format);
  return "customerReportList";
 }

Now you could see different formats like this:
http://localhost:8080/sample/customer/report/pdf
http://localhost:8080/sample/customer/report/csv
http://localhost:8080/sample/customer/report/html
http://localhost:8080/sample/customer/report/xls

Note: for xls format we need to add below dependency to pom.xml
<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi</artifactId>
  <version>3.2-FINAL</version>
</dependency>


What last?
Spring-Roo is awesome ;-) give it a try and join it's community. I really had a good time with Roo in my recent project. Actually reading Roo's forum and Roo's twittes are my favorite reads now! :-)
I could feel Roo's potential, for example look at this post and what we have done in step two , All of these could be done with Roo add-ons in the near future. If you want to make that happen sooner please vote for this issue : https://jira.springsource.org/browse/ROO-228.

Hopefully this will help you to integrate jasperreports to your Spring-Roo based project. If you have any suggestions to make these configurations better, please let me know.

Thursday, September 10, 2009

Donate Blood

Today I went to one blood donor center near to my place . It was my first time in Australia . They give me 2 forms : 1_personal information 2_questions about health background.

I answered most of questions and I left two questions without answer because I was not sure about answers. After that I had a interview with a doctor (one nice lady) , she check some questions with me and help me to answer those two questions . To make story short , I was alright with all questions expect one , and that one was: did you have contact with blood of somebody else ?, and my answer was Yes!! how did happened !? , well we were playing rugby in lismore and one guy get hurt and he washed his blood with one bottle of water . I did not have contact with that guy but my mistake was I washed my tooth protection with water of that bottle !oops! I know, I saw that after washing ! I feel Ok because that guy was their best player :-)

The doctor told me it could be risky if they take my blood and I have to wait until 27 Nov 2009.
At the end I like to add donating blood is a nice thing to do and is a sign of thinking about other people not only yourself!
I read this some where : only one in 30 donate blood but one in 3 will need blood in their lifetime . hope more people became motivated to donate blood ... thanks for reading.

Friday, August 28, 2009

August 2009 - Move out, Rugby, Assignments

Move out :
I move out to the new house on 11th august . At first i was a little bit sad but after passing a week I understand, that was good and necessary action for me. Now i am living with two Chinese friends . They can cook good and I can wash the dishes !:-) We sharing our budget and result for me is less budget than before.

Rugby :
Last week we traveled to Lismore (Southern Cross University (main campus)) for playing rugby with their team . They win the game ! :-( but we had lot of fun ! :-) for example after game there was a party : free food , free drinks and happy people. Next day in the bus was another enjoyable time for us (drinks + funny friends). After arriving to Coffs Harbour we went to the pub (Green house) then we had drinks+playing billiard . Finally we had party in campus's accommodation (drinks and dancing!) . In summery I could say Australian drinks a lot ! ;-)

Assignments :
I am studying BIT in SCU .Assignments could be divide to two groups , group 1 writing , group 2 coding . Group 2 are easier for me and takes less time + enjoyment ! :-) . On the other hand Group 1 is a little bit of pain for me! ;-)
anyway I realize that, you can do the perfect things if you could enjoy from it.