Wednesday, November 30, 2016

How to quickly convert type of Spring Data (JPA) Page content...

Suppose you have the current dto class

public class AbcDto {

private Long id;
private String description;
private Timestamp creationDate;

[.......]

}

and the model/bean to send as response via REST service that returns the pagination instance of Abc instances....

public class AbcView {

private Long id;
private String descriptionInUpperCase;
private String creationDateTruncated;

[.......]

}

That you use the repository to asking for data within "Pageable" form...
So you could have something like this...

Page<AbcDto> tmp = abcDtoRepository.findAll(new PageRequest(page, size));

So you can quickly convert the content, preserving the Page instance details in this way:

Page<AbcView > returnList = tmp.map(new Converter<AbcDto, AbcView> () {
                    @Override
                    public AbcView convert(AbcDto v) {
                        return new AbcView(v.getId(), v.getDesciption().toUpperCase(),
                                sdf.format(v.getCreationDate()));
                    }
                });

Simply and quick...
I hope this help you....

Bye..

Thursday, October 27, 2016

Starting with EJB3(Eclipse and WildFly 10 embedded)


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

My current configuration is:
JDK 1.8.0_91
WildFly 10(WildFly embedded configuration for Eclipse, see here)
JBoss Tools 4.3.1.Final installed in Eclipse(see here)
Eclipse 4.5.1 Mars for JavaEE developer
all on Windows 10....

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 "WildFly 10.0 Runtime"(or whatever WildFly version you have) under "Target runtime" combo menu.
Leaves default "3.2" 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...

Monday, May 30, 2016

Eclipse (4.5.2 "Mars"): configure WildFly 10 Application Server as local instance. The quick developer configuration.

My current environment is
JDK 1.8.0_91
Eclipse Mars 4.5.2
JBoss Tools 4.3.1.Final already installed(if not yet installed please see here)
WildFly 10 Application Server 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 WildFly 10.0 version, under JBoss Community menu folder:





4) Select the adapter options, as the image, type of server and as you want to control it:




5) Than point to the right home directory of your WildFly installation.






6) Then finish.

That's all. You have now a local instance of the WildFly 10 into Eclipse correctly configured...

7) Test it: right click on the server --> "Start"
Once WildFly is started, from browser point to http://localhost:9990


You should see something like this....(of course the screenshot above tells you how to create users to access administration console correctly.....)


Bye...

Eclipse 4.5.2 (Mars), installing JBoss Tools 4.3.1.Final for WildFly 10

Here we see how to configure JBoss Tools 4.3.1 under Eclipse(currently at 4.5.2 version, "Mars").
All for configure a WildFly 10 eclipse embedded environment setup.
Currently configuration has been done with JDK 1.8 version.

1) Under Eclipse, go on "Help" --> "Eclipse Market Place"

2)Fill with "jboss tools" the search text field, and search for JBoss Tools, currently I found 4.3.1.Final version as the image....


3) Go ahead throught the setup wizard...

4) After you restart Eclipse you are ready to setup the WildFly 10 embedded configuration...

Bye...


Friday, May 6, 2016

Starting with: REST web services, server and client examples.

1) Open Eclipse IDE
2) Create dynamic web project named "startingWithRESTWebServiceServer" (and set 3 at dynamic module version)
3)Download from jersey download page last available JAX-RS 2.0 API jar distribution
4)Unzip it and copy all jars under api, ext and lib folders under WEB-INF/lib
5)Ensure that you have your "Web App Libraries" configured in your project build path.
6) right-click on src folder and create a new package name com.webservices
7)Then create User class with this content:

package com.webservices;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "user")
public class User implements Serializable {

   private static final long serialVersionUID = 1L;
   private int id;
   private String name;
   private String profession;

   public User(){}
  
   public User(int id, String name, String profession){
      this.id = id;
      this.name = name;
      this.profession = profession;
   }

   public int getId() {
      return id;
   }

   @XmlElement
   public void setId(int id) {
      this.id = id;
   }
   public String getName() {
      return name;
   }
   @XmlElement
   public void setName(String name) {
      this.name = name;
   }
   public String getProfession() {
      return profession;
   }
   @XmlElement
   public void setProfession(String profession) {
      this.profession = profession;
   }       
}


8)Then create UserDao class with this content:

package com.webservices;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class UserDao {
   public List<User> getAllUsers(){
      List<User> userList = null;
      try {
         File file = new File("Users.dat");
         if (!file.exists()) {
            User user = new User(1, "Maurizio", "Fisherman");
            userList = new ArrayList<User>();
            userList.add(user);
            saveUserList(userList);       
         }
         else{
            FileInputStream fis = new FileInputStream(file);
            ObjectInputStream ois = new ObjectInputStream(fis);
            userList = (List<User>) ois.readObject();
            ois.close();
         }
      } catch (IOException e) {
         e.printStackTrace();
      } catch (ClassNotFoundException e) {
         e.printStackTrace();
      }       
      return userList;
   }

   private void saveUserList(List<User> userList){
      try {
         File file = new File("Users.dat");
         FileOutputStream fos;

         fos = new FileOutputStream(file);

         ObjectOutputStream oos = new ObjectOutputStream(fos);
         oos.writeObject(userList);
         oos.close();
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }  
}


9)Then create UserService class with this content:
10)Then create or update web.xml file(under WebContent folder) with this content:

<?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_3_0.xsd"
   id="WebApp_ID" version="3.0">
   <display-name>startingWithRESTWebServiceServer</display-name>
   <servlet>
      <servlet-name>REST Wer Service server example</servlet-name>
      <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
         <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.webservices</param-value>
         </init-param>
      </servlet>
   <servlet-mapping>
   <servlet-name>REST Wer Service server example</servlet-name>
      <url-pattern>/rest/*</url-pattern>
   </servlet-mapping> 
</web-app>




11)Now we are ready to deploy the application.
So deploy the exported project as war file under tomcat or configure it internal bundled and add the project to it.
Then we can use a chrome plugin extension(as SimpleRestClient) to test it.
Pointing to url:
http://localhost:8080/startingWithRESTWebServiceServer/rest/UserService/users

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

Thursday, May 5, 2016

Starting with: JAX-WS web services, server and client examples.

1) Open Eclipse IDE
2) Create java project named "startingWithJAXWSServer"
3) right-click on src folder and create a new package name com.webservices
4) create into an interface named WebServiceDefinition with this content:
package com.webservices;

import javax.jws.WebMethod; 
import javax.jws.WebService; 

@WebService
public interface WebServiceDefinition {
 
    @WebMethod
    public String getYourName(String name);
   
}
5) create always in the same package a new class named WebServiceImplementation with this content:

package com.webservices;

import javax.jws.WebService;

@WebService(endpointInterface="com.webservices.WebServiceDefinition")
public class WebServiceImplementation implements WebServiceDefinition {

    public String getYourName (String name) { 
        return "My name is " + name ; 
    }
 
6) Create always in the same class another class named WebServicePublisher, that will be the endpoint publisher, with this content:

package com.webservices;
 
import javax.xml.ws.Endpoint; 
 
public class WebServicePublisher { 
    public static void main(String[] args) { 
        Endpoint.publish("http://localhost:8080/WS/WebServiceDefinition", new WebServiceImplementation() ); 
    } 
}

7) The server is ready. Now we have to run the server(right click on the class or on the project, then "Run As Java Application")
So we have to open a new browser and check under this url:
http://localhost:8080/WS/WebServiceDefinition?wsdl
we'll find the wsdl rapresentation.

Now we can proceed with the client.
8) Create java project named "startingWithJAXWSClient"
9) open a shell and move under $WORKSPACE_HOME_DIR/startingWithJAXWSClient/src
10) give this command: 
wsimport -s . http://localhost:8080/WS/WebServiceDefinition?wsdl
This will generate all stub classes.
(Remember to give F5 on src eclipse folder to refresh its content).
11) Then we have to create a new class named TestWS with this content:
package com.webservices;

public class TestWS {

     
    public static void main(String[] args) { 
             
        WebServiceImplementationService wsServiceImpl = new WebServiceImplementationService (); 
        WebServiceDefinition wsDef = wsServiceImpl.getWebServiceImplementationPort(); 
        System.out.println(wsDef.getYourName("Maurizio"));          
    } 
}

12) Now we can test all running also this class.....

That's all...

Bye...

Wednesday, May 4, 2016

Starting with: a dynamic web project with Spring 3 MVC

Now we can see a rapid guide to quickly see how to run a simple dynamic web project using project Spring MVC 3. The very essential to see how it works.

- open eclipse
- create a new dynamic web project(in my case I set 2.5 value into Dynamic web module version combo selection)
- this is the content of web.xml:

<?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>Spring3 MVC Application</display-name>

    <servlet>
        <servlet-name>spring-web</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring-web</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>


- always here, under WEB-INF, create a new spring-web-servlet.xml
(note that name first part"spring-web" have to be the same of what you declared as servlet-name in the web.xml mapping to the DispatcherServlet)
with this content:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:component-scan base-package="com.web" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/jsp/" />          
        <property name="suffix" value=".jsp" />      
    </bean>

    <mvc:annotation-driven />
  
</beans>


- under src folder, create a new package named: com.web.controller

- and put into WebController.java:

package com.web.controller;

import org.springframework.stereotype.Controller;
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.web.servlet.ModelAndView;

@Controller
public class WebController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Spring 3 MVC Example");
        return "home";
    }

    @RequestMapping(value = "/main/{name:.+}", method = RequestMethod.GET)
    public ModelAndView hello(@PathVariable("name") String name) {
        ModelAndView model = new ModelAndView();
        model.setViewName("main");
        model.addObject("msg", name);
        return model;
    }

}

- under WEB-INF/lib put into these libs(you need to search and download all of them):
aopalliance-1.0.jar
commons-logging-1.1.3.jar
jstl-1.2.jar
spring-aop-3.2.13.RELEASE.jar
spring-beans-3.2.13.RELEASE.jar
spring-context-3.2.13.RELEASE.jar
spring-core-3.2.13.RELEASE.jar
spring-expression-3.2.13.RELEASE.jar
spring-web-3.2.13.RELEASE.jar
spring-webmvc-3.2.13.RELEASE.jar

- create the folder path WEB-INF/views/jsp
- put into these two jsp: home.jsp(welcome page)
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Spring MVC 3 example</title>
    </head>
    <body>
        <div>
            <div>              
                <p>
                    <c:if test="${not empty name}">
                        Welcome to main menu ${name}
                    </c:if>
                </p>
            </div>
            <a href="${pageContext.request.contextPath}/main/maurizio">go to main menu</a>
        </div>
    </body>
</html>


- and main.jsp(target page, only to see the navigation):

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Spring MVC 3 example</title>
    </head>
    <body>
        <div>
            <p>
                <c:if test="${not empty name}">
                    Welcome! Please click above for the main menu... ${name}
                </c:if>       
            </p>           
        </div>
    </body>
</html>


So now you can try all:
- building a war file through right clicking on the project, then Export --> find and select War file, and moving the war file under an active application server.
- configuring an application server inbound to eclipse and adding the entire project to it.

Indipendently to the choosen way open a browser and point to:
http://localhost:8080/startingWithSpringMVC3
and test if all is ok....

You checkout the entire project(under sourceforge.net) from command line with this:
svn checkout svn://svn.code.sf.net/p/mauriziofranco/code/StartingWithSpringMVC3/trunk/startingWithSpringMVC3 mauriziofranco-code

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


Tuesday, May 3, 2016

Shopping List 0.6.0 version released.

Shopping List 0.6.0 version released(click on image to try it)


0.6.0 beta version commitment details:
- introduced batch script to one shot convert logo.png image(under www/images) to android res images to different resolution (96x96, 72x72, 36x36, 48x48).
- scripts refactoring.
- created build.xml for project handling via ant.
- removed hooks, platforms and plugins directories and slbuild.sh, setupIcons.sh and slruntest.sh from project committed resources(implemented ant task for re-initializing the project structure).
- refactorized dynamical size for items and addImageButton.
- added resources folder; it contains resources used in building, signing and publication processes.
- added images to resources folder for publication process.
- added first version of all tasks to build.xml. Now it possible to handle all initializing, building and signing processes via ant.
- setted blog url into sourceforge.net application profile(support url location).
- apk signing
- google market publication

Incoming features(and general to do):
- splash screen
- "how to start" project documentation.
- change items font
- confirm dialog on exiting
- introduce a new categorized order(capability)
- intoduce a settings menu
- change font at runtime(into settins menu)
- change language(into setting menu)

Wednesday, April 27, 2016

Shopping List 0.5.2 version released

Shopping List 0.5.2 version released(click on image to try it)


0.5.2 beta version commitment details:
- replaced app icon with a new one(removed old logo.png file).
- improvement for addItemModal dialog graphic.
- reduced font size for list items.
- introduced ng-cordova js lib.
- general js code refactoring.
- introducing vibration on add item modal function calling.
- prevent stand-by/sleeping mode during app activity.
- introduced heading bar.


Incoming features(and general to do):
- set blog url into sourceforge.net application profile(support url location).
- splash screen
- apk signing
- google market publication
- "how to start" project documentation.
- change items font
- confirm dialog on exiting
- introduce a new categorized order(capability)
- intoduce a settings menu
- change font at runtime(into settins menu)
- change language(into setting menu)

Friday, April 22, 2016

Cordova/PhoneGap inhibit/prevent sleeping mode

If you need to prevent the sleeping mode here is a plugin that does this..

Install it:
cordova plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git

or

phonegap plugin add https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git

than to use it this is the code; to prevent sleep mode use:

window.plugins.insomnia.keepAwake()

instead to re-allow the sleeping mode again use:


window.plugins.insomnia.allowSleepAgain()

Please refer here to full documentation.....

 Bye..

Tuesday, April 5, 2016

Cordova/PhoneGap force the calling to the virtual keyboard - how to

I've spent some days to search a solution to an issue I have when a input text in my ui needs to show the android virtual keyboard.
The only way I found, is to add a plugin to my cordova-phonegap project via command line interface.
First, ensure you have cordova.js included/imported in your html page.
Move into the project directory and type:
cordova plugin add ionic-plugin-keyboard

the in your code(javascript) when you need call this:
cordova.plugins.Keyboard.show();

...and the virtual keyboard show up.

Note that during development if you are testing your app in the browser, probably you'll be notified by this error:

"Cannot read property 'Keyboard' of undefined"

It's depends by the cordova.js that you have included into the page, but it is imported only when application is built for the devices.
So you will really see it in the device or in device emulator.

It's all.

I try it only in Android. Please notify me(also with a simple comment) if it correctly works on other platforms.

Here you can find some documentation.

Bye...





Thursday, March 17, 2016

Angular translate in few steps

Next steps allow you to introduce i18n and l10n support to your frontend application.
First of all download angular-translate.js (also for no bower use) from https://angular-translate.github.io/

You can download directly last source code zip you found. Explode it in and put directly the angular-translate.js or the angular-translate.min.js in your WebContent dir.
Then import it into your html code with this:

<script src="js/angular-translate.min.js"></script>

In my case all the code needed for the translation has been moved into a separeted file....

<script src="js/translations.js"></script>

This is its content:

angular.module('shoppingListApp').config(function($translateProvider) {
      $translateProvider.translations('en', {
        APP_TITLE: 'SHOPPING LIST',
        ADD_ITEM_TEXT: 'Add shopping items here...'
      }).translations('it', {
        APP_TITLE: 'LA TUA SPESA!!',
        ADD_ITEM_TEXT: 'Aggiungi un nuovo articolo...'
      });
      $translateProvider.preferredLanguage('en');
    });



Now in my html file(or js code)......

<span>{{ 'APP_TITLE' | translate }}</span>

and.....

<span>({{ 'ADD_ITEM_TEXT' | translate }}</span>

do what you need....

The last three things:
1) This instruction

$translateProvider.preferredLanguage('en');

set what's the starting language to use



2) This instruction avoids xss(cross-site scripting) dangers for your application, as you can see http://angular-translate.github.io/docs/#/guide/19_security
// Enable escaping of HTML
$translateProvider.useSanitizeValueStrategy('escape');


3)Change at runtime your app language(defining the changeLanguage function in the controller..... and calling it..:-)): 

app.controller('TranslateController', function($translate, $scope) {
  $scope.changeLanguage = function (langKey) {
    $translate.use(langKey);
  };
});
 
 Please refer here for complete documentation: 
That's all.
Bye
 

Monday, February 22, 2016

Oracle Java /JDK on (a vergin) Debian Jessie 8.3

Add in sources.list at the end:

deb http://httpredir.debian.org/debian/ jessie main contrib

then give these commands..:

apt-get update
apt-get install java-package


download the .tar.gz package from the oracle site. Choose the .tar.gz file

then, as non root, create the dpkg package

fakeroot make-jpkg jdk-8u73-linux-i586.tar.gz

At the end, as root, you are ready to install:

dpkg --install oracle-java8-jdk_8u73_i386.deb

At the end you are ready to use jdk... type for try>:

java -version

Pay attention, PATH and CLASSPATH have not been touched.
If you need you will have to update them.

Bye..

Kodi on (a vergin) Debian Jessie 8.3


We do it throught the debian multimedia repository.
So open in editing the /etc/apt/sources.list file and add at the end this row

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

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

Finally:
apt-get install kodi

Optional
if you know that you will use your kobi also for live tv you need to install a PVR add-on that in linux installer there aren't bundled.
Here is an example for iptv addon

apt-get install kodi-pvr-iptvsimple

Please refere here for the pvr addons available.. 
Bye..