Sunday, March 23, 2014

Play DVD under Debian Wheezy

Edit /etc/apt/sources.list and add this line....

deb http://www.deb-multimedia.org wheezy main non-free
(refer to this link for more info )

Than give these command from command line....

apt-get update
 apt-get upgrade
apt-get install deb-multimedia-keyring
apt-get upgrade
apt-get update

apt-get install libavcodec54 libdvdcss

Now you are ready.....
Last thing.....
I suggest to use VLC as player
So if you have not installed it, give(from command line):

apt-get install vlc

Bye...


Friday, March 21, 2014

Starting with Web Services(Eclipse Kepler, Tomcat 7)

Here is a small guide to learn how web services run and how Eclipse simplifies the developer job.

The configuration expected is
Java 6
Eclipse Kepler for JavaEE developer
Tomcat 7 (Eclipse embedded configuration)

1) Under Eclipse create a new Dynamic Web Project.
Choose a custom name(remember this will be the server side appl), the target runtime(Tomcat 7 previously configurated) and after in the "Dynamic Web Module Version" combo menu choose the 2.5 specific. Then finish(if you want customize the other fields to choose in the others windows.

2) I create 2 classes.
One is my bean class that is the object that "travel" in the communication between my smalls server and client applications.... 
It's com.test.TestMessage and this is the content:

package com.test;

/**
 * 
 * Test bean class with simple string message property
 * 
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com
 */
public class TestMessage {
   
    private String message ;

    /**
     * @return the message
     */
    public String getMessage() {
        return message;
    }

    /**
     * @param message the message to set
     */
    public void setMessage(String message) {
        this.message = message;
    }
    
} 



3) This is the com.test.TestProvider that is the class that will provide the methods(in this case only one: getMessage) as endpoints for this server side application.


package com.test;

/**
 *
 * Test class, provides a simple method that returns a TestMessage instance.
 *
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com
 */
public class TestProvider {

    public TestMessage getMessage () {
        TestMessage tm = new TestMessage () ;
        tm.setMessage("Prova messaggio di test...");
        return tm ;
    }
   
}



4) Now we are ready to produce the wsdl file that is at the base of the WebServices architecture.
Click on the project and choose New --> Web Service
In the Service implementation we have to choose the TestProvider class
(so put the complete name com.test.TestProvider)
Then we can choose the only Deploy service setting(see the image above) and ensure that under "Configuration:" you have
- Server runtime Tomcat v.7.0 Server (or the server runtime you prefer)
- Web service runtime: Apache Axis (that's the lib Eclipse will use to produce the wsdl)
- Service project: StartingWithWebServices_Server (that's the name of my project, so you select the yours)
Then click on Finish

Well, you have ended the procedure to build your server side application.
Ensure Eclipse have added into Tomcat(embedded) the application into the deployed list. If no add it.
Now we have to create a client side application.

5) Create another Dynamic Web Project with the same specifics of the previously(this will be the client side appl).

6) Point on the TestProvider.wsdl that is in the previously project(the server side application) into WebContent/wsdl folder
Select "Test client", the as hight as possible option and then click on finish.
Ensure you have on the right, under Configuration: Client project: that your project name is correctly indicated(TestWSClient is the current name of my project).
We choose the "Test client" option to produce also, the tests jsp files for quickly try all the "game".





Ensure you have the client application into Tomcat(embedded) deployed applications.

Go under your browser and point to:
http://loaclhost:8080/StartingWithWSClient/sampleTestProviderProxy/TestClient.jsp

where  StartingWithWSClient is the Context name that I give to my project....

Here you can see three methods added as default from wsdl generator, more the method contained into the TestProvider class.
The getMessage method.
If you click on it in the center frame you can see two buttons; clicking on invoke button, in the above frame you can see the result of the method invocation on the server side application.

This should be a quick way to see how to invoke from a jsp file a method, and relative response from the server side application, all through web service architecture.


You can find these small applications(the client and the server sided) under sourceforge.net site, ready to download, via SVN.
The url are:
svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithWebServices/trunk/StartingWithWebServices_Server
svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithWebServices/trunk/StartingWithWebServices_Client
And the istructions from command line are:
svn checkout svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithWebServices/trunk/StartingWithWebServices_Server  mauriziofranco-code
svn checkout svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithWebServices/trunk/StartingWithWebServices_Client  mauriziofranco-code

That's all.....
Bye..

Wednesday, March 19, 2014

JPA and MySQL... quick smart guide(with Eclipse)

Here are to configure a small eclipse project to run JPA capabilities on a mysql database.....

My current configuration is:
JDK 1.6
Eclipse Kepler for JavaEE developer
MySql 5.5
Mysql_jdbc_connector (to connect your java application to mysql db)
EclipseLink 2.5 (provides advanced support for leading relational databases)
all on my Debian Wheezy.....

1)Under Eclipse, create a new "JPA Project".
Insert a custom name. Leaves all the default settings(none target runtime, JPA Version 2.1, Basic JPA Configuration).
Going ahead, setting "EclipseLink 2.5.x" in the Platform combo menu.
Next in the JPA Implementation menu select User Library, then with the button image "Manage Libraries" create twe variables with the relative mapping to three libraries, as above:
-  ECLIPSELINK alias variable that points to $ECLIPSELINK_HOME_DIR/*.jar (where *.jar means some of the libraries under the $ECLIPSELINK_HOME_DIR folder and his subfolders, please see the image above)
- MYSQL_CONNECTOR alias variable that points to $MY_SQL_CONNECTOR_HOME_DIR/mysql-connector-java-5.1.29-bin.jar

Alternatives to the manual mapping of the ECLIPSELINK jars you can click instead on the "Download library..." button and select the version of your Eclipse IDE installed(in this case Eclipse Kepler).
This procedure is automatic and avoids also to download manually the EclipseLink .zip file.



Under the Connection combo menu, click on the "Add connection..."
Select MySQL, Next, Near the Drivers combo menu click on "New Driver Definition".
Under the "Name/Type" tab, select MySQL JDBC Driver, with System Version 5.1.
Under the "JAR List" tab, click on the only showed mysql-connector-java-5.1.0-bin.jar and click on the right on the "Edit JAR Zip..." button.
Select the mysql-connector that you have previously downloaded....
Then click on OK.
Insert your database connection info....:
database name(custom)
URL(complete URL) --> jdbc:mysql://your_database_ip:3306/your_db_name
User name: your db applicative user name
Password: your db applicative password
Click on "Save password" check box
and on the right click on the "Test Connection" button.
Go ahead only if you have a correct response to this db test connection...
If no, solve before this problem. You must have the connection working...


 Then click on "Finish" button.

2) This is an example script used to create my custom table Users
CREATE TABLE Users (
        id INT(5) NOT NULL AUTO_INCREMENT,
        username VARCHAR(20) NOT NULL,
        email    VARCHAR(40) NOT NULL,
        password VARCHAR(20) NOT NULL,               
        PRIMARY KEY(id)
); 

3)This is the content of my persistence.xml(under src/META-INF folder)
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
     version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
     <persistence-unit name="JPATestProject" transaction-type="RESOURCE_LOCAL">
          <class>com.bean.User</class>
          <properties>
              <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/your_db_name"/>
              <property name="javax.persistence.jdbc.user" value="your_db_user_name"/>
              <property name="javax.persistence.jdbc.password" value="db_user_password"/>
              <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
          </properties>
     </persistence-unit>
</persistence>

4)I create 2 classes.
One to map the Users db table.
It is com.bean.User class and contains this:

package com.bean;

import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;

/**
 * Entity implementation class for Entity: User
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com

 */
@Entity
@Table(name="Users")
public class User implements Serializable {

      
    @Id @GeneratedValue
    (strategy=GenerationType.IDENTITY)
    private int id;
   
    private String username;
    private String password;
    private String email;
    private static final long serialVersionUID = 1L;

    public User() {
        super();
    }  
    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }  
    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }  
    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }  
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
  
}

5) The other is the class that tests if all the game works...
com.test.Test is the class and contains this....:

package com.test;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.bean.User;


/**
 *
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com

 *
 */ public class Test {

    private static final String PERSISTENCE_UNIT_NAME = "JPATestProject";
   

    public static void main(String[] args) {
        EntityManagerFactory emf =
                Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
            EntityManager em = emf.createEntityManager();
                        
              //INSER new User
              em.getTransaction().begin();
              User appo = new User () ;
                       
             
              appo.setUsername("username123AAABBB");
              appo.setEmail("provaJPA_123");             
              appo.setPassword("password123");   
              em.persist(appo);            
              em.flush();
              em.getTransaction().commit();
              em.close();
             
              System.out.println("Inserted new User.... with username: " + appo.getUsername() + " - email: " + appo.getEmail());
             
             
//              //SELECT for id.....
//              int userId = 26 ;
//              appo = (User) em.find(User.class, userId);
//             
//              System.out.println("username: " + appo.getUsername() + " - email: " + appo.getEmail());
             
    }

}


Now you are ready to go....:-)

Run Test class and provides to do the insert test of a new User object.

 
Refer to this oracle documentation for other Accessing a JPA Entity using an EntityManager. Or the other Entity Manager capabilities....

Refer to these other links.... Eclipse info, eclipseLink JPA configuration, EclipseLink JPA Examples.


Bye....

PS.: You find the small project of above, available for anonymous download under source forge....
The url to point to checkout is this(ready to run under Eclipse with anonymous username and no password required) :
svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithJPA/trunk/StartingWithJPA
Or you can checkout from command line with this:
svn checkout svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithJPA/trunk/StartingWithJPA mauriziofranco-code

P.P.S.: remember to customize the persistence.xml....

Have a good job.....

Thursday, March 13, 2014

Hibernate quick start guide(with Eclipse).

I used, at now, the latest versions of...
Eclipse Kepler for JavaEE developer
Hibernate ORM 4.3.4
Java 6
MySQL 5.5(more mysql connector... download here)
...all installed on my Debian Wheezy...

Here's a smart guide to create a very small project for Hibernate capabilities.

For Hibernate ORM 4.3.4 resources file, please refer to official site for download latest version.

1) Eclipse: create a new Java Project.

2) Add in the classpath(right click on the project -> properties -> Java Build Path -> Libraries -> Add external libraries) the libraries contained into the hibernate zip file(currently is hibernate-release-4.3.4.Final.zip) you download. You can put only the contents of the "required" folder.

3) Add in the classpath the mysql-connector_XXX.jar(from here) depends of the version of your db version and of connector version....

4) Into src folder create the bean class that maps the persistent object

package com.bean;


import java.io.Serializable;
import java.lang.String;

/**
 * Entity implementation class for Entity: User
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com
 */
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
   
    private int id;
   
    private String username;
    private String password;
    private String email;
   

    public User() {
        super();
    }  
    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }  
    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }  
    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }  
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
  
}


5) Here is the table script....

CREATE TABLE Users (
               id INT(5) NOT NULL AUTO_INCREMENT,
               username VARCHAR(20) NOT NULL,
               email    VARCHAR(40) NOT NULL,
               password VARCHAR(20) NOT NULL,               
               PRIMARY KEY(id) 

);

6) Then the class thats provides to test the insert of data....

package com.test;

import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.Transaction; 
import org.hibernate.cfg.Configuration;

import com.bean.User;



/**
 *
 * Test class, to run simple database operations...
 *
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com
 */
public class StoreData {

    public static void main(String[] args) { 
        System.out.println("StoreData - START");
        //creating configuration object 
        Configuration cfg=new Configuration();
        //populates the data of the configuration file
        cfg.configure("hibernate.cfg.xml"); 
         
        //creating seession factory object 
        SessionFactory factory=cfg.buildSessionFactory(); 
         
        //creating session object 
        Session session=factory.openSession(); 
         
        //creating transaction object 
        Transaction t=session.beginTransaction(); 
             
        User e1=new User(); 
        e1.setUsername("usernamexxx"); 
        e1.setPassword("pwdxxx");
        e1.setEmail("mail@xxxx");
         
        session.persist(e1);//persisting the object 
         
        t.commit();//transaction is committed 
        session.close(); 
         
        System.out.println("StoreData - successfully saved");           
    } 

}




7) Now under the src folder you have to create two configuration files.
The first map the bean/persistent object. It's user.hbm.xml
Note that here we map the com.bean.User to the Users table.

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-mapping PUBLIC   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
 
 <hibernate-mapping> 
  <class name="com.bean.User" table="Users"> 
    <id name="id"> 
     <generator class="assigned"></generator> 
    </id> 
           
    <property name="username"></property> 
    <property name="password"></property>
    <property name="email"></property> 
           
  </class> 
           
 </hibernate-mapping>


8) the other configuration file maps contains database connection info.
Also this is under the src folder. It's hibernate.cfg.xml

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC 
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 

 
<hibernate-configuration> 
 
    <session-factory> 
        <property name="hbm2ddl.auto">update</property> 
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
        <property name="connection.url">jdbc:mysql://localhost:3306/your_db_name</property> 
        <property name="connection.username">your_username</property> 
        <property name="connection.password">your_password</property> 
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
    <mapping resource="user.hbm.xml"/> 
    </session-factory> 
 
</hibernate-configuration>


That's all.... or not?? Remember to customize your hibernate.cfg.xml....
in connection.url, connection.username and connection.password properties....

Execute the main method of StoreData class....
It will provides the simple insert operation...

You can find a small project(contains all you have seen up to here) into a branch of sourceforce.net svn.
It's ready to use...

The url is:
svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithHibernate/trunk/StartingWithHibernate
And the istructions from command line are:
svn checkout svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithHibernate/trunk/StartingWithHibernate  mauriziofranco-code

Bye..

Tuesday, March 11, 2014

HTML: center horizzontally body content(in according to css3)

Insert the content of your body element into this div...

<div style="display: flex;flex-direction: row;flex-wrap: wrap;justify-content: center;align-items: center;">
[..............Your content.......]
</div>

Bye...

Friday, March 7, 2014

Developing JSP: starting with JSTL

For introduce last version of JSTL into your project please download last version of jstl jar file. At the moment the 1.2 version.

Click here to download the 1.2 jstl jar file

Here you can find the JSP Standard Tag Library home page: https://jstl.java.net

Start you eclipse project putting the downloaded jar file into the WEB-INF/lib folder.
No more configuration are needed into web.xml(for servlet container with recently version specifications...).

For starting to use it, into the jsp point to the jstl library that you need...
For example:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
[...]
 <fmt:setBundle basename="resources.messages"/>
//here I put my messages.properties file into my sources folder, into resources package...
[...]
<fmt:message key="homepage.title"/>
//this get the property value with homepage.title key


To start there is this Java EE 5 Online Tutorial(Chapter 7 - JavaServer Pages Standard Tag Library)

Instead refer to the online official javadoc for the full tld information.

Bye...

Installing jdk on 64 bit....: install.sfx.3886 not found

Attempting to install the precompiled Java binaries on a pure 64-bit Linux system fails with the following error message:

install.sfx.3886 not found

Install the ia32-libs package solves the problem.... give:

apt-get install ia32-libs


Be carefull on Ubuntu 13.10. 
Its repository doesn't provides ia32-ibs.
Here you have to install lib32z1


Bye....