From Glassfish to Wildfly - Shared lib dir - part 3

Shared lib dir in Wildfly

In glassifsh I was using a domains/domain1/lib/ directory as shared directory where to put all jars needed by all applications (ear, war, jar)

When install wildfly sure you will search for similiar directory..
Nope..
Wildfly hasn't a shared lib directory, but are using a module concept and other classloading system.

You can install module, global module or follow the next solution.

I make different EAR which group some jars.
For example PdfBoxLibEar where I put pdfbox jar, itext jar, xmlworker jar.

When making the ear be sure that the jar embedded is deployed in lib/ directory of ear.

Then When an application foo needs to PdfBoxLibEar write in manifest.mf the following:

Manifest-Version: 1.0
Dependencies: deployment. LIB_PdfBoxLibEar.ear export, deployment. OTHER_LIB.ear export,

deployment is location where ear is deployed by default.
export is a keyword for make the library available also with internal ear modules(i.e. war or ejb)

From Glassfish to Wildfly - HTTPS - part 5

How to make working https in widfly


Make a keystore with keytool and put it inside standalone/configuration
Take a note for keystore and certificate password.

Make a realm in standalone.xml in security-realms section

Example

               
                   
                       
                   
               
           

Then in web admin console you can make https listener:
Go in configuration - web - http
tab https
Click add and insert socket binding https and realm name MySecurityRealm.

From Glassfish to Wildfly - Mail & Realms - part 4

Mail Resource


Configuring WildFly to send emails with JavaMail is also slightly different from GlassFish. Every inbound and outbound communication through TCP/IP should be declared in the socket binding group. Since SMTP uses TCP/IP to communicate, then we have to create an Outbound Socket Binding for that. To proceed:
  1. In the admin console, go to Profile > General Configuration > Socket Binding.
  2. In standard-sockets, click on View >, select the tab Outbound Remote, and click on Add.
  3. Fill the form with the data to connect to your SMTP server. For instance:
    1. name: mail-smtp-gmail
    2. host: smtp.gmail.com
    3. port: 465
The second step is to create the JavaMail session that uses the socket binding. To proceed:
  1. Go to Profile > Subsytems > Connector > Mail and click on Add.
  2. Define a JNDI name like java:/mail/app and save.
  3. Click on View > in the session you just created and click on Add.
  4. Fill the form with the data to connect to the SMTP server. For instance:
    1. Socket Binding: mail-smtp-gmail
    2. Type: smtp
    3. Use SSL?: true
    4. Username: johnsmith@gmail.com
    5. Password: supersecret


Pay attention to jndi name inside source code update @resource by using java:/resourcename if java:/ is left.

Realms


When using glassfish, for working fast with realm I was using file realms.
In Wildfly I find more easy to work directly with jdbc realm.

create db realms
create in db a users table
create user_roles table
Insert user and roles in the table
Make by using web admin console or editing standalon.xml a datasource for realms db
Edit standalone.xml in order to make a security domain inside security-domains

               
   
       
           
           
           
           
       
       
       
         
         
       
       
   

Finally inside web-inf put file jboss-web.xml contenente

 jdbc-security-domain

edit web.xml roles, login, rules etc.

Notice: If you remove comment from hashalgorithm and choose one algorithm type pay attetion in storing in users table the password hashed version.

If you want to see realms working log you can increase the verbosity log level

    
                ……

Add the following logger..


        
          
      
 
        
          
      
 
        
          
      

   

From Glassfish to Wildfly - Autodeploy directory - part 2

In glassfish you have /autodeploy directory where to put ear, war and jar in order to auto deploy it in application server.

In Wildfly there is also autodeploy dir.. /opt/wildfly/standalone/deployments/

When you put an application in the directory deployment scanner start and deploy automatically the application.

I notice that deployment scanner stop to works when a large file is upload to server.
The deployment scanner see incomplete file and wait for completition.. but in 8.1 wildfly it stops and deployment scanner stop to works until next restart.

In order to avoid this problem

Make other directory for uploading
Put in crontab(i.e. every 2 minute) the following script

#!/bin/bash
WILDFLY_DEPLOY_DIR="/opt/wildfly/standalone/deployments/"
AUTODEPLOY_DIR="/home/myftp/autodeploy/"
#touch "$AUTODEPLOY_DIR"avoid_empty_dir_error
for filename in $AUTODEPLOY_DIR*.*ar; do
#for filename in 'find /home/myftp/autodeploy -name "*.*ar"'; do
if [ "$filename" = "$AUTODEPLOY_DIR*.*ar" ]; then
echo "nofiles"
else
       fuser1=$(/sbin/fuser "$filename")
       if [[ -z "${fuser1}" ]];
       then
               echo "move and rename the file"
                #file non usato da nessun processo, copia terminata
               /bin/cp $filename $WILDFLY_DEPLOY_DIR #uso bin/cp in modo da non chiedere overwrite
               mv $filename $filename.bak
       else echo "copia ftp in corso" #copia in corso
       fi
fi
done

that copy the *.ar file from autodeploy dir to wildfly real autodeploy dir only when the file transfer is complete!

From Glassfish to Wildfly - part 1

How to install wildfly on linux?

Simply by download and launching the following wonderful script:
https://gist.github.com/sukharevd/6087988
Wildfly is installed in /opt/wildfly
You can launch Wildfly by using /etc/init.d/wildfly start


Open Port and Remote Access

Find and launch add-users.sh in order to add user for management realm.
It is necessary for web console admin.

Find and edit standalone.xml in socketbinding section edit the default port if you want.

Enable for web console listener

Root User or not?

By default wildfly is installed and launched as wildfly user.
I think it is the best way.
But I'm migrating from glassfish (i.e. installaed and launched as root user) so all files writed by glassfish applications have root file permission.

So the better solution is to change all file permission from root to wildfly.
Alternative editing /etc/default/wildfly.conf and launch wildfly as root.

MySql Driver

Download from mysql site the connector j.
Access to web admin console and deploy it
(You can also deploy by using autodeploy dir into /opt/wildfly/standalone/deployments/)


Visure Easy - Direttamente sul tuo smartphone

Online il nuovo sito per il reperimento semplice e veloce delle visure direttamente sul tuo cellulare!


Attraverso il browser del tuo smartphone potrai richiedere, pagare e scaricare la tua Visura!!

Visure Easy Mobile

Xcode 4 Tip: Automatically make IBOutlet, property, dealloc and

Xcode 4 Tip:  Automatically make IBOutlet, property, dealloc and synthesize!
G.Morreale

Problem:

Are you bored to write always the same line of code in order to make an IBOutlet, property, synthesize, dealloc and then connect it to the gui in the interface builder?

Solution:

1) Open Xcode 4
2) Open the xib file
3) Split the view so you can see the gui and the header file by clicking in the top on the right the center icon in the editor section.
4) Go to gui element (uibutton, uitextfield etc.) 
5) Menu -> View -> Utilities -> Connection Inspector
6) Select on the Connection Inspector "New referencing outlet"
7) Drag it in your header .h file

In order to make as property drag out outside the interface before the @end!!

Thanks to this answer I find this very very good tip:

Xcode 4 Tip: Automatically make IBOutlet, property, dealloc and

Xcode 4 Tip:  Automatically make IBOutlet, property, dealloc and synthesize!
G.Morreale

Problem:

Are you bored to write always the same line of code in order to make an IBOutlet, property, synthesize, dealloc and then connect it to the gui in the interface builder?

Solution:

1) Open Xcode 4
2) Open the xib file
3) Split the view so you can see the gui and the header file by clicking in the top on the right the center icon in the editor section.
4) Go to gui element (uibutton, uitextfield etc.) 
5) Menu -> View -> Utilities -> Connection Inspector
6) Select on the Connection Inspector "New referencing outlet"
7) Drag it in your header .h file

In order to make as property drag out outside the interface before the @end!!

Thanks to this answer I find this very very good tip:

Mac Os eject cd dvd problem

Mac Os Eject cd/dvd Problem
G.Morreale

Problem:

Your cd/dvd drive can't eject the cd, by keyboard input?
The finder can't show your cd/dvd drive?

Solution:

1) Open Terminal
2) Type drutil tray eject


From Java To Objective-C: String

From Java To Objective C: Strings

My Notes (part 2)


This is a very short introduction from my notes.

A good and complete starting point can be found by google.


The String.


In java we have String Class that represent a string, in objective C there is a NSString object.

Each string constant double quote in objective-c must be prefixed by @

Also in objective C, NSString is immutable like java String.



.objective c version


  • NSString aString = @"hello world";

  • NSString aString2 = [[NSString alloc] initWithString:@"Hello World2"]; 
  • [aString release]; 

  • #define CONSTANT1 @"HELLO";

  • NSLog(@"debug string");

  • NSString *ageString = [NSString stringWithFormat:@"%@ concatenate with %@", "age:", 18];


.java version


  • String aString = "hello world";

  • String aString2 = new String("Hello World 2");

  • public static final String CONSTANT1 = "HELLO";

  • System.out.println("debug string");

  • String ageString = "age:" + " concatenate with " + 18;



From Java To Objective-C

From Java To Objective C 

My Notes (part 1)


This is a very short introduction from my notes.

A good and complete starting point can be found by google.


I'm a java developer and when I'm going to learn objective-c for the iphone development the matching between the 2 languages became automatic.


Objective C is standard ansi C with object oriented extension.

So many OO arguments found in java can be find in objective C.


In objective C the class usually is split in two file:


  • .h file for the class definition.
  • .m file for the class implementation.


Let's go to see some code, this is only my simple notes.


.h file example


#import <UI/Class.h> //like import in java


//interface is a compiler directive, it tell that there is a class definiton

//myClassName the className

//NSObject the parent object

//<aProtocol> it respect the protocol definition (like abstract class in java)

@interface MyClassName: NSObject <aProtocol>

{

    int count; //a simple primitive type

    id *data; //Weak Type

    NSString *aString; 

//String type. *stay for pointer. all the instance object variable

//use this pointer notation


}


//property declare a class property

//nonatomic or atomic value regard the thread safety in the accessor method

//retain in the set accessor the variable value is retained

@property (nonatomic, retain) NSString aString


//this is a method interface definition

-(id)aMethod:(NSString)*paramName;

@end //end interface declaration

.m file example

#import "MyClassName.h"  //import the class interface definition file

@implementation MyClassName

@synthesize aString; 
//It tells to compiler to make automatically get/set method 
//for property aString

-(id)aMethod:(NSString)*paramName
{
    //insert here the method logic
}

@end


.java Equivalent

import ui.Class;

class MyClassName extends NSObject implements aProtocol
{
    private int count;
    private Object data;
    private String aString;

    public void setAVar(String s) { this.aString = s;}
    public String getAString (return this.aString;)

    Object aMethod (String paramName) { //logic }
}


Flex AS3 Webservice Proxy and Object Binding

Flex AS3 Webservice Proxy and Object Binding


Introduction

In the previous article we see how a flex as3 can call webservice simply by using the Webservice class.
Let's see about webservice resultformat and data binding.

The Webservice Client Result Format in AS3

The webservice client result format can be "Object, xml, or e4x".

  • The Object(default resultFormat) return data in form of ObjectProxy. ObjectProxy contains different datatypes like ArrayCollection etc. You would have to handle and parse this result obtaining the data you expect.
  • XML format returns the data as an array of XMLNodes.
  • E4X format gives an XMLList. 



But like jax-ws java client maked with netbeans wizard I wish to search about automatic data binding.

It shows how make the proxy objects by using the wsdl.
This is done by flex builder ide.

Import Webservice into flex builder

The following link show the detailed steps

I write only some notes about this.
First of all, Import webservice inside flex builder project:

Data Menu -> Import Webservice and so on.

Then in order to call the webservice use the

NameService class.
Where Name is the name of webservice.

var ws:NameService = new NameService();

The autogenerate procedure make also one listener for each operation inside the webservice.
So add the listener and make the proper function called by the listener

ws.addOperation1EventListener(onResultOperation1);

the onResultOperation1 definition is like this:

private function onResultOperation1(res:Operation1ResultEvent):void
{
   var value:Operation1ReturnType = res.result._return;
}

The Operation1ResultEvent and Operation1ReturnType is created by flexbuilder during the webservice import.
Note that Operation1ReturnType is the real return type used also in the webservice (server side).
So in this function you obtain directly the returnType Object.

Ok, for calling the webservice, first assign the request variable.

//inside costructor possible parameter to be pass to the webservice //operation
var param:Operation1_request = new Operation1_request(); 
ws.Operation1_request_var = param;

call it

ws.Opearation1_send();


Conclusion

In this way more coding works is done automatic by the ide.

Java Hello World

Java Hello World
G.Morreale

Introduzione:

The simplest programming language example!

//define a class HelloWorld
public class HelloWorld 
{ 
    //define a public static method in the class that make an entry point for the application.
    //It takes an array of String parameter
    public static void main(String[] args) 
    { 
        //Use the base System api to print a "Hello World" string in the standard output.
        System.out.println("Hello World"); 
    } 
}

Conclusion:

In a simple Java Hello World example come into play various topics:

  • the class notion
  • the public modifiers
  • the static method modifiers
  • Array type
  • String type
  • a static method call (System.out.println(String a))

So, You have to start with an object oriented programming tutorial within java tutorial in order to start programming in java.

Maintaining state in Java Webservice(JAX-WS)

Maintaining state in Java Webservice(JAX-WS)


Introduction

This little article start point is the need of get the current session from a flash swf.
I try to explain: The web application has a login form and after the user is authenticated a session is created and mantained, so the need is to access to this value into the session from flash that calls a webservice in the same service.

recapitulate.

Server side: JSP, Servlet etc. for user login.
Server side: Webservice for reporting stuff.

Client side: html form for login
Client side: flash swf (created with flex) for reporting gui. it access the webservice to obtaining reporting data and draw it. when the webservice is called the session data created in login step is required.


The Webservice

The webservice is created like in the previouse article.
But in order to get the current session a MessageContext is required.
So declare it by the @Resouce annotation, and get the HttpSession from it!

@WebService()
public class testWS {

    @Resource
    private WebServiceContext context;
    /**
     * Web service operation
     */
    @WebMethod(operationName = "sayHello")
    public String sayHello(@WebParam(name = "name")
    String name)
    {
        String ret = "";
        MessageContext mc = context.getMessageContext();
        HttpSession session = ((HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST)).getSession(false);
        if (session == null)
        {ret =  "hello: NO SESSION";}
        else
        {
            Enumeration en = session.getAttributeNames();
            while (en.hasMoreElements())
            {
                String key = (String) en.nextElement();
                ret += key + " " + session.getAttribute(key) + "\r\n";
            }
        }
        return ret;

    }

}

That's all.
The client side you can see in the previous article


Conclusion

For a complete discussion about session mantaining

Flex AS3 call a Java Webservice

Flex AS3 call a Java Webservice


Introduction

Webservice is a standard in soa architecture.
Flex is a leading tecnology for client side so let's see how actionscript 3(the flex programming language) can call a java(jax-ws) webservice.


Starting Point

The main step are:

  1. Make a WebProject with a Webservice
  2. Make a MXML in flex side and code the call

The webservice:

Two click with netbeans header and you can obtain this code:

package webservice;

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

@WebService()
public class testWS 
{
    @WebMethod(operationName = "sayHello")
    public String sayHello(@WebParam(name = "name")
    String name)
    {        
        return "hello " + name;
    }

}

The Action Script Side inside mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" click="useWebService()">

<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.WebService;
public function useWebService():void
{
var ws:WebService = new WebService();
 
ws.addEventListener(ResultEvent.RESULT,onResult);
ws.addEventListener(FaultEvent.FAULT,onFault);  
 
ws.loadWSDL("http://yourserver/ws/testWSService?wsdl");
ws.sayHello("pippo");
}
private function onResult(event:ResultEvent):void
{
 trace("result " + event.result);
}
private function onFault(fault:FaultEvent):void
{
 trace("fault " + fault);
}
]]>
</mx:Script>
</mx:Application>

To see the result debug the flex application and see at console only after deploy the webservice.

Conclusion


This is the runtime version.

Translate the blog