Tuesday, December 2, 2014

Mysql: execute sql file from command line.

If you need to execute some commands from command line,as in this case, all stored into a .sql file give this:

> mysql -u _your_username_ -p

after inserted the password

> use _your_database_ ;

(in case of your_database is not existent remember to create it before. )
then

> source /home/_your_userhome_/_your_file.sql


Bye....

Mysql: quick backup with mysqldump

You need to do a quick backup of a mysql table?
Give this command:

mysqldump database_to_backup_name -u root -p > ./filename_with_dumped_db.sql

this will produce a file(filename_with_dumped_db.sql) with all the backupped db(database_to_backup_name).

Please refer here to the mysql manual pages.

Bye..

Monday, December 1, 2014

linux: make a symbolic link to a directory

From command line this give you a link to a folder:

ln -s /home/user/workspace/original_folder_to_link/ /var/www/linked_folder

Bye...

Thursday, October 23, 2014

Debian, gnome3: system settings menu icon disappeared....

We are under gnome3.
If for any reason the System settings menu icon under
Applications menu --> System Tools menu --> Preferences menu
is disappeared;
you need to install the gnome-control-center
by giving simply...:

apt-get install gnome-control-center 

Bye..

Saturday, October 18, 2014

Debian Wheezy 64 bit: installing correctly skype

I assume you've downloaded skype from site.
The Debian 7 multiarch package.

I have some problem during skype installation on my 64 bit architecture.
Something like this:

package architecture (i386) does not match system (amd64)
Errors were encountered while processing:
skype

So, I need to do these steps:

dpkg --add-architecture i386
apt-get update
apt-get install qt-at-spi:i386
dpkg -i  skype-debian_4.3.0.37-1_i386.deb
(where skype-debian_4.3.0.37-1_i386.deb is the file version I currently downloaded..)

Now It goes like a charm....

Bye...

Debian Wheezy a good cd ripper(but not with default installation): setup asunder

Hi all,

I need to rip some old cds.
But I don't like the default installed sound-juicer.
It cannot give me(easly) the way to set the bitrate.

So I remove it and I try another: asunder
Very very simply and good!!!
apt-get remove sound-juicer
apt-get install asunder
dmesg | grep CD
give me this output
[    2.229627] scsi 1:0:0:0: CD-ROM            HL-DT-ST DVDRAM GUA0N     AL00 PQ: 0 ANSI: 5
[    2.252941] cdrom: Uniform CD-ROM driver Revision: 3.20
[    2.253162] sr 1:0:0:0: Attached scsi CD-ROM sr0
You see the last word..? Is sr0.
It's indicate where asunder have to read the cd
So after the installation launch asunder, go under Preferences
General tab, and insert /dev/sr0 (or what is for you) in the CD-ROM device text field.

All is done.

Bye....

Debian Wheezy and Lenovo G50: setup sound card

One of the problem I have after debian installation is that it seems controller and sound card seems to be recognize.
Giving the commands:

lspci | grep audio
lsmod | grep snd
speaker-test  
 
may help you to see what has been recognized.
In my case all seems to be recognized, but I hear no sounds.

From gdm right-clicking up on the right, on the volume control and choosing sound preferences I see only this voice:
Built-in Audio Digital Stereo(HDMI)
and above in the combo menu list I see only
HDMI / Display port

This not give me assurances.
So after some try I install some other modules:

apt-get install firmware-linux-nonfree
dpkg-reconfigure alsa-base
aslactl init
alsamixer

Into alsamixer giving F6 key I see that there were 2 sound card.
Now I see that I have two sounds card(exactly the same I see with the other commands by sheel).

Now clicking on the volume icon(sound preferences) I see also here(and I select it(under Output and Hardware tabs)) the view on the correct sound card(in my case Built-in Analog Stereo, and under connector the possibility to choose among Headphones or Speakers).

Now all seems solved....

Bye

Monday, October 13, 2014

Dual Boot: Windows 8 and Debian 7.6.0 Wheezy in Legacy Mode under my new Lenovo G50

Hi all, I want to share with all my hard experience to find the correct way to have Windows 8 and Debian Wheezy correctly installed on my new laptop Lenovo G50.
All in correct dual boot, rigorously with Grub 2, and in Legacy Mode(NO UEFI).

Premise: I bought the laptop with Windows 8 pre-installed. I just copy the product key(right click on my computer, see on the right frame, down) of my Windows 8 version. For laziness I forgot to do the correctly procedure to download the Windows 8 distribution(recover dvd) from the site....
So when I run Easus Partition to resize my partitions(I only resized the major, where windows 8 was installed), after rebooting, no o.s. was found....
It's the begin of my "some days of madness".
Why?
Beacause I'll never "played" before with windows 8 installation and UEFI technology....
Well(and I end my premise) I reinstalled windows 8 and debian 7, I don't know how much time.....
I don't know how much isos of different distribution I downloaded....
How many repair tools and other.....
At the end..... I will use only what already were in my possession... an old distribution of parted magic, that's now is no more a free distribution...
But we see also how to do all without this really magic distribution....

Are you ready?

1)Go under your bios and disable Secure Boot and UEFI boot. Choose Legacy mode. Choose dvd reader as first boot option.
2)Insert a copy of your PartedMagic or any other live distribution. We need to backup the system reserved data(on another hard disk, an external..).
In my case I backup completely all the data contained in the other partition pre-created by the manufacter.
The most important: the reserved partition were UEFI files are stored.
But most of all the reserved partition of all drivers for windows 8(so when I reinstall the windows 8 I already have all drivers ready to install...)
3)Ended the backup(really is a copy on another hard disk) we need to have 2 things to download:
- the windows 8 distribution(that you can download from here; it's a magnet link for torrent; It's a Windows 8 enterprise).
- the debian 7 live distribution
4) Now we can install Windows 8. Insert dvd, I prefere to don't connect the pc to the net. It will be a more quickly installation.
During the setup you have to erase all the hard disk.
You can do this also before starting installation with another partitioner tool.
5) Ended the windows 8 installation, you have to disable the windows 8 fast startup.
Next you need to modify(erase) the GPT table; so you have 2 chances:
first one is to go with gparted cd and start the partitioner tool.
second one is to start the live cd of debian. Install the gparted and start it.
When gparted starts, a message will show to you:

/dev/sda contains GPT signatures, indicating that it has a GPT table. However, it does not have a valid fake msdos partition table, as it should. Perhaps it was corrupted - possibly by a program that doesn't understand GPT partition tables. Or perhaps you deleted the GPT table, and are now using an msdos partition table. Is this a GPT partition table?

Where /dev/sda depends of your system. It should be /dev/sdb or anything other...
Yes we have to erase GPT table. To do this give this command:
sgdisk --zap /dev/sda

sgdisk is equipped already from gparted distribution.
If we proceeded with the live distribution(as in our case Debian live) we have also to install it(from 7.6 it is in debian repository)
apt-get install gdisk

6)Now we removed the gpt table. Now our debian live distribution will be able to see windows partition.
Start it and proceed with a normal installation.
Preserve(do not move or resize) windows partitions.
Install(as default) grub boot loader into master boot record.

At the end of installation, reboot and you will have a "normal" dual boot with Windows 8 and Debian 7 Wheezy.

P.S.: only in this moment I proceed with Windows 8 activation(after I replace the product serial id with mine).

Bye..




Friday, October 10, 2014

DRAFT - Installing Debian on Lenovo G50.... configuring wi-fi

Here is a temporany procedure to configure the wi-fi on your Lenovo G50.
First of all you need to install the correctly firmware.
Download it from here(firmware-realtek_0.43_all.deb) and install it giving:

dpkg -i firmware-realtek_0.43_all.deb

Then add to the sources list file the backports repository.
We are going to install a new kernel. No panic!!!
So open /etc/apt/sources.list file and add this line:

deb http://ftp.debian.org/debian wheezy-backports main contrib non-free

Then:

apt-get update
apt-get upgrade

I read that about 3.16, kernel starting to support the realtek_0.4* firmware family....

So after searching(apt-cache search) the last one available... install the

linux-image-3.16-0.bpo.2-amd64
and
linux-headers-3.16-0.bpo.2-amd64
giving these commands:

apt-get install linux-image-3.16-0.bpo.2-amd64 linux-headers-3.16-0.bpo.2-amd64 -t wheezy-backports

Now we need to reboot and to select in the boot menu the new installed kernel.

Now if all it's gone well our wifi card should be recognized.


Monday, October 6, 2014

Encoding a DVD under Debian

Need to encode a dvd under your Debian distribution?
Edit /etc/apt/sources.list and add this line....

deb http://www.deb-multimedia.org wheezy main non-free

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 h264enc

Now you are ready to encode your first dvd.
This to facilitate you to encode the first time:

h264enc -1p -p vhq

There will prompted to you a series of settings to apply to your encoding operation...

+=============================================================+
|<<<<<<< h264enc - the interactive shell script ripper >>>>>>>|
|-------------------------------------------------------------|
|<<<<<< version: 9.4.9 - (C) 2006-2012, Grozdan Nikolov >>>>>>|
+=============================================================+

Select the Input type [file/dir/dvd/vcd]: dvd

Input Selection
~~~~~~~~~~~~~~~
0 -> Encode from a DVD disc/drive
1 -> Encode from a DVD ISO image
2 -> Encode from a DVD VIDEO_TS directory

Select the input [default is 0]: 0


See the h264enc manual to see all features....

Bye

Thursday, October 2, 2014

Installing Debian on Lenovo G50...

I'm currently installing Debian 7.6.0 on my new Laptop Lenovo G50.
I execute the normal installation process starting from the net-inst distribution.

During the installation I needed to connect the net cable.
The wi-fi desn't been recognized.
Argh!!!!! (but this is another story in another post!!!)...
At the end of the installation a warning message notify me that gdm3 isn't started for some problems.

I see after, in a rapid check that also the the webcam in video modality has some problem(test with cheese application).

At the end of the process we have three problems to solve:
- wi-fi card unrecognized
- web-cam or video card to optimize
- gdm3 doesn't start

Next posts we try to solve these....

Bye..

P.S.: 18/10/14 review....: also audio doesn't funtcion.....[SOLVED see here]

Thursday, March 27, 2014

Starting with EJB3(Eclipse Kepler and JBoss 7.1.1 embedded)


Here are to configure an eclipse project to run a small EJB3 example....

My current configuration is:
JDK 1.7
JBoss AS 7.1.1.Final(jboss Eclipse embedded configuration, see here)
JBoss Tools 4.1.2.Final installed in Eclipse(see here)
Eclipse Kepler for JavaEE developer
all on my Debian Wheezy....

We configure two project. One for the server side application. The other one for the client; we create a Dynamic Web Project for this last one. With a jsp file, within a button that starts all the process flow.

Let's we start with the server side application.

1) Under Eclipse File --> New --> EJB Project
I choose the name StartingWithEJB3_ServerSideAppl


Choose "JBoss 7.1 Runtime"(or what JBoss version you have) under "Target runtime" combo menu.
Choose "3.1" under "EJB module version" combo menu.

Then you can click on Finish.

2) Now we have to created two classes. All under "ejbModule" folder.
The first one will be our Stateless Session Bean.
The logic business class.
So, right click on the ejbModule folder --> New --> Other --> Session Bean (EJB 3.x)


Choose a new Java package, that will be created... I give com.test.server.business
Than choose the class name, I give StatelessServerBean
At State type choose Stateless,
and into "Create business interface" section select the "Remote" check field, and I put as name StatelessServerBeanInterface
This field will create the remote Interface for the stateless bean we have created.

This is the content of the com.test.server.business.StatelessServerBean class

package com.test.server.business;

import javax.ejb.Stateless;

/**
 * Session Bean implementation class StatelessServerBean
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com
 */
@Stateless
public class StatelessServerBean implements StatelessServerBeanInterface {
    public StatelessServerBean() {
    }

    public String executeTestMethod() {
        return "executeTestMethod invoked!!!";
    }
}


This is the content of the com.test.server.business.StatelessServerBeanInterface interface

package com.test.server.business;

import javax.ejb.Remote;

/**
 * StatelessServerBean interface
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com
 */
@Remote
public interface StatelessServerBeanInterface {
    public String executeTestMethod();
}



3) Now we provide to create the second application. The client side application. With a Dynamic Web Project.

Click on New --> Dynamic Web Project


I Choose StartingWithEJB3_ClientAppl as project name.
"JBoss 7.1 Runtime" as "Target runtime"
and "3.0" as Dynamic web module version.
In configuration I had leaved "Default Configuration for JBoss 7.1 Runtime".

Than click on Finish.

4) Under project root create a new folder, I call it resources.
Under it, create a new properties file, I named it jboss-ejb-client.properties
This is its content:

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default

remote.connection.default.host=localhost
remote.connection.default.port = 4447


remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

After create it, we have to put it into the class path.
So right-click on the project, Properties --> Java Build Path --> Libraries
Click on the button, on the right, "Add Class Folder" and we have to flag the check button for resources folder under our project.



5) Under src folder now we have to create to packages.
com.ejb3.client.test and com.ejb3.client.test.servlet

6) Under com.ejb3.client.test we have to create to classes.
First one is ContextProvider.
It contains:

package com.ejb3.client.test;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class ContextProvider {

    private static Context initialContext;

    private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";

    public static Context getInitialContext() throws NamingException {
        if (initialContext == null) {
            Properties properties = new Properties();
            properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);

            initialContext = new InitialContext(properties);
        }
        return initialContext;
    }
}

7) The other one is EJBApplicationTestClient
It contains:

package com.ejb3.client.test;

import javax.naming.Context;
import javax.naming.NamingException;


import com.test.server.business.StatelessServerBean;
import com.test.server.business.StatelessServerBeanInterface;

public class EJBApplicationTestClient {
   
    public static void main(String[] args) {
        System.out.println(EJBApplicationTestClient.class.getName() + ".main - START");
        StatelessServerBeanInterface bean = doLookup();
        System.out.println(EJBApplicationTestClient.class.getName() + ".main - DEBUG - Call server business logic method: " + bean.executeTestMethod());
    }

    public static StatelessServerBeanInterface doLookup() {
        System.out.println(EJBApplicationTestClient.class.getName() + ".doLookup - START");
        Context context = null;
        StatelessServerBeanInterface bean = null;
        try {
            System.out.println(EJBApplicationTestClient.class.getName() + ".doLookup - DEBUG - Obtaining Context");
            context = ContextProvider.getInitialContext();
            System.out.println(EJBApplicationTestClient.class.getName() + ".doLookup - DEBUG - Generate JNDI Lookup name");
            String lookupName = getLookupName();
            System.out.println(EJBApplicationTestClient.class.getName() + ".doLookup - DEBUG - Lookup and cast");
            bean = (StatelessServerBeanInterface) context.lookup(lookupName);
            System.out.println(EJBApplicationTestClient.class.getName() + ".doLookup - DEBUG - remote server bean successfully looked up..");
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return bean;
    }

    private static String getLookupName() {
        System.out.println(EJBApplicationTestClient.class.getName() + ".getLookupName - START");
        //The app name is the EAR name of the deployed EJB without .ear suffix.
        //Since we haven't deployed the application as a .ear, the app name for us will be an empty string
      
        String appName = "";

        //The module name is the JAR name of the deployed EJB without the .jar suffix - in this case is the name of the Project..
       
        String moduleName = "StartingWithEJB3_ServerSideAppl";

        //AS7 allows each deployment to have an (optional) distinct name.
        //This can be an empty string if distinct name is not specified.
        String distinctName = "";

        System.out.println(EJBApplicationTestClient.class.getName() + ".getLookupName - DEBUG - Get EJB bean implementation class name");
        String beanName = StatelessServerBean.class.getSimpleName();
        System.out.println(EJBApplicationTestClient.class.getName() + ".getLookupName - DEBUG - beanName: " + beanName);
       
        System.out.println(EJBApplicationTestClient.class.getName() + ".getLookupName - DEBUG - Get fully qualified remote interface name");
        final String interfaceName = StatelessServerBeanInterface.class.getName();
        System.out.println(EJBApplicationTestClient.class.getName() + ".getLookupName - DEBUG - interfaceName: " + interfaceName);
       
        System.out.println(EJBApplicationTestClient.class.getName() + ".getLookupName - DEBUG - Create a look up string name");
        String name = "ejb:" + appName + "/" + moduleName + "/" + distinctName    + "/" + beanName + "!" + interfaceName;
        System.out.println(EJBApplicationTestClient.class.getName() + ".getLookupName - DEBUG - lookup up name: " + name);
       
        return name;
    }
}

WARNING!!!! I pick the background to red to pay attention to the moduleName, it must be the server module name(normally the name of the server application gived to the eclipse project)

8) Next, under com.ejb3.client.test.servlet we create a Servlet class.
Its name is TestServlet and it contains:

package com.ejb3.client.test.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ejb3.client.test.EJBApplicationTestClient;
import com.test.server.business.StatelessServerBeanInterface;

/**
 * Servlet implementation class TestServlet
 */
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {       
        System.out.println(TestServlet.class.getName() + ".main - START");
        StatelessServerBeanInterface bean = EJBApplicationTestClient.doLookup();
        //Call server business logic method
        System.out.println(TestServlet.class.getName() + ".main - DEBUG - " + bean.executeTestMethod());        
    }


}




9) Now we have surely some errors on the Servlet and on the EJBApplicationTestClient class. Some classes used are not resolved.
So we have to import the jar file of the Server application.
So we do it right clicking on the Server Side Application, in my case on the 
StartingWithEJB3_ServerSideAppl project, (remember the Java EE perspective) go under "Export" --> EJB JAR file  

Our server application project selected in the EJB Project text field.
Than in the Destination text filed we have(with "Browse.." button) to point to:
%ECLIPSE_WORKSPACE_FOLDER/StartingWithEJB3_ClientAppl/WebContent/WEB-INF/lib






After give an F5 on the client project. Only with this forced refresh the project will see the server application jar.


10) We have at the last point. Create a simple jsp file to invoke all the process. A simple page that through the button pression will call the
TestServlet thats using the EJBApplicationTestClient class will invoke the remote(on the server) instance of StatelessServerBean to call the executeTestMethod()
The index.jsp contains:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Jsp test page for invoke ejb3 test client class...</title>
</head>
<body>
    <form action="${pageContext.request.contextPath}/TestServlet">
        <h1>After clicking see the server console output....</h1>
        <input type="submit" value="invoke ejb3 client application"/>
    </form>
</body>
</html> 



That's all. 
You can find all this small example in a branch of sourceforge.net ready for download.
The urls for Anonymous download(no password required) are:

svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithEJB3/trunk/StartingWithEJB3_Server 

svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithEJB3/trunk/StartingWithEJB3_Client

Or for checkout directly from command line give these:

svn checkout svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithEJB3/trunk/StartingWithEJB3_Server  mauriziofranco-code

svn checkout svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithEJB3/trunk/StartingWithEJB3_Client  mauriziofranco-code

Bye...

Wednesday, March 26, 2014

Eclipse Kepler: configure JBoss 7 Application Server(Community version) as local instance. The quick developer configuration.

Current environment is
JDK 1.7
Eclipse Kepler 4.3.0
JBoss Tools already installed(version 4.1.2.Final)(if not yet installed please see here)
JBoss Application Server 7.1.1 (COMMUNITY VERSION)downloaded(from here) and installed.

1) Under Eclipse go under Java EE Perspective(in the high on the right, or click on "Window" --> "Open Perspective" --> "Other" --> and here find and choose Java EE)

2) In the low area, in the "Servers" tab, right click and choose New --> Server

3) Here choose your JBoss AS version, under JBoss Community menu folder, in this case "JBoss AS 7.1"


4) Than point to the right home directory of your JBoss installation.


5) Than finish.

That's all. You have now a local instance of the JBoss Community Server into Eclipse Kepler correctly configured...

6) Tests it: right click on the server --> "Start"
Once JBoss is started, from browser point to http://localhost:8080


Bye...

Eclipse Kepler: installing JBoss Tools 4.1.2.Final

My target is that of install only the necessary to execute the local/embedded(to Eclipse) version of JBoss Application Server, and to create and develop a EJB3 project.
This post is only for the installation of the JBoss Tools plugin for Eclipse Kepler.
At now the JBoss Tools version is the 4.1.2.Final for Kepler.

1) Under Eclipse click on "Window" --> "Install New Software" --> "Add" (on the right)
Put JBOSS_TOOLS(or what you want) as alias
and the url:
http://download.jboss.org/jbosstools/updates/stable/kepler


 2) From the list of additional plugins to install choose(it's the minimal requirements for my target...):

- JBoss Application Development
- JBoss Tools And Java EE Development

Then click on Next, Accept the Licenses and click on Finish to starting the downloading and installation of all....(P.S.: different windows will prompted to advise that unsigned software will be installed.... obviously click on "Yes to All"). And yes also to the restart of Eclipse.

That's all...

Bye...

Tuesday, March 25, 2014

Starting with Struts 2(Eclipse Kepler and Tomcat 7 embedded)

Here are to configure a small eclipse project to run a small Struts 2 example project....

My current configuration is:
JDK 1.6
Tomcat 7(eclipse embedded configuration)
Eclipse Kepler for JavaEE developer
Struts 2.3.16.1(refer to Struts Project Home Page)
all on my Debian Wheezy.....

1) Download from Struts site the latest(at now the 2.3.16.1 version) version of .zip file available. Unzip it.

2) Under Eclipse create a new Dynamic Web Project.
Choose a custom name(I choose StartingWithStruts), the target runtime(Tomcat 7 previously configurated) and after in the "Dynamic Web Module Version" combo menu choose the 2.5 specific.
Then next, and choose click on the generate web deployment descriptor(web.xml file) radio button.
Then Finish.

3)Copy into WEB-INF/lib folder these libraries that you find under struts_home_resources_folder directory that you created when you downloaded and unzipped the struts zip file.

commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.16.1.jar
xwork-core-2.3.16.1.jar

Ensure you have into your classpath(right click on the project, Properties, Java Build Path, libraries)  "Web App Libraries" library setted.



4) Add in web.xml the filter StrutsPrepareAndExecuteFilter class in every time a page is called. Update web.xml in this way:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>StartingWithStruts</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>      
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>


5)Create a package com.test within our first class LoginAction
that maps our first jsp page, a login form.
Note the execute method, that is the action called when form button is performed...
Note the extension of ActionSupport class that will allow us to use the getText method(to get properties from resource bundle file)

package com.test;

import com.opensymphony.xwork2.ActionSupport;

/**
 * Class that maps our first jsp page, a simple login form
 * @author Maurizio Franco
 *         http://maurizio-franco.blogspot.it
 *         maurizio.franco@ymail.com
 */
public class LoginAction extends ActionSupport {

    private String username ;
    private String password ;
    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }
    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }
    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }
    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
   
    /*
     * Performs a simple check if username.equals(password)
     * It returns a String that maps the next page where the flow is redirected.
     */
    public String executeLogin () {
        String returnValue = "" ;       
        if (username.equals(password)) {
            returnValue = "loginOK" ;
        } else {
            addActionError(getText("error.login"));
            returnValue = "loginKO" ;
        }
        return returnValue ;
    }

}



 6) Under WebContent I create a two jsp files.
First one is index.jsp file that contains:

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
    <head>
        <title>StartingWithStruts</title>
    </head>
   
    <body>
        <h2>StartingWithStruts - Simple Login Form</h2>
        <s:actionerror />
        <s:form action="login.action" method="post">
            <s:textfield name="username" key="label.username" size="20" />
            <s:password name="password" key="label.password" size="20" />
            <s:submit method="executeLogin" key="label.login" align="center" />
        </s:form>
    </body>
</html>

Then loginOK.jsp, that contains a simple page to give the success login message.

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Welcome page...</title>
</head>

<body>
    <h2>User <s:property value="username" /> logged successfully!!!</h2>
</body>
</html>

7) Then we have to add in the classpath two files. The resources bundle file, that I call messages.properties and I add it under src folder
It contains this:

label.username= Username
label.password= Password
label.login= Login
error.login= Invalid Username/Password. Please try again.

Then directly under src folder I create a struts.xml file with this:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.custom.i18n.resources" value="messages" />

    <package name="default" extends="struts-default" namespace="/">
        <action name="login" method="executeLogin" class="com.test.LoginAction">
            <result name="loginOK">loginOK.jsp</result>
            <result name="loginKO">index.jsp</result>
        </action>
    </package>
</struts>



That's all.
Start the embedded Tomcat and point to http://loaclhost:8080/YOUR_PROJECT_NAME/index.jsp

You can fine this smaill project illustreted by me, under a sourceforge.net branch. Ready for download via SVN.
This is the direct url:
svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithStruts/trunk/StartingWithStruts
or this is command for shell:
svn checkout svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithStruts/trunk/StartingWithStruts  mauriziofranco-code



For other documentation and examples refer to http://struts.apache.org/release/2.2.x/docs/home.html

Bye....

 

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..