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)