OpenLSD ENOpenLSD

Download at SourceForge.net

ConceptLogic Technical Aspects Future Plan Howto Benchmarks
Home OpenLSD OpenLSM OpenR66

HowTo Use OpenLSD Framework-Web

In this story example, You will find the database step, then the Data structure step, the Functions step, the Web step, the Jar Implementation Step and the final step.

 

 

Web step

Here you find some hits on how to include OpenLSD support in your servlets.

I will take the option that Oracle is your database software support. The same can be done using MySQL.

By default, one Tomcat instance has to have only one database for OpenLSD Server instance. Many OpenLSD Server can be used within one database, but from one Tomcat server, only one database can be access since there are some global data that are shared within the OpenLSD Framework.

Another way to say that, you can use only one LSDBusiness implementation in one database within one Tomcat instance.

You have then two choices, using a pool of database connections or not.

 

WEB GET

You can optimize the initialization part in the init part of the servlet, which is executed only once. By this way, the xml configuration step is done once and not each time there is a connection. (1 and 2a)

If you use no database pool of connections, then you have to use the second solution to create the connection by OpenLSD itself. (1 and 2b)

Obviously, the best solution is to use a database pool of connections.

 

INIT only once

1) Init global context: in the general initialization of the servlet (done only once)

Load log4j config file and openlsd-db config file from file real path and execute the initialization step.

The third argument contains the class that will be used as the default prefix class name in the logger.

LSDWebCommon.initialize(prefix+log4jfile, prefix+conflsddb, servletClassName.class);

INIT Database from existant connection from a pool of database connections

2a) Init LSD and Database context:

Set Oracle as default driver

LSDConstants.typeDriver = LSDConstants.typeOracle;

Once you get your own database connection, you can pass it trough the initAdmin call, such that OpenLSD will use this connection and so as to not open a new one.

If the Web function is in read mode (get), the first argument must be filled with the connection.

If in write mode (import), the second argument must be filled, the first one should be null.

The third argument contains a default ArrayList<String> that will contain plain text in case of error.

LSDDbAdmin admin = LSDWebCommon.initAdmin(connread,null,erreurs);

if (admin == null) {

    // There is an error since admin is null so you can take an action.

    return;

}

No call to admin.close() is necessary since the connection is not create by LSD. But if you want that OpenLSD take care of closing and getting the exception for you, you can still call admin.close().

INIT without a pool of database connections

2b) Init LSD and Database context:

Set Oracle as default driver

LSDConstants.typeDriver = LSDConstants.typeOracle;

As you don't get your own database connection, the initAdmin call will take one for you, such that OpenLSD can use this connection and so open a new one each time.

The first argument contains a default ArrayList<String> that will contain plain text in case of error.

LSDDbAdmin admin = LSDWebCommon.initAdmin(erreurs);

if (admin == null) {

    // There is an error since admin is null so you can take an action.

    return;

}

A call to admin.close() is necessary since the connection is create by LSD before the servlet is done (take care of error handling calling admin.close()).

Continue with dynamic part

3) Init OpenLSD Server identification:

Here you get the IpPort object that represents the OpenLSD Server on which you want to interact.

First arg is the ArrayList<String> for error handling.

Second arg is the previous LSDDbAdmin object if not null.

Third arg is the Legacy id (long number) on which you want to interact (id of the OpenLSD Server)

Fourth arg is the type of client you want (user, compressed, admin or protected)

LSDDbIpPort ipport = LSDWebCommon.getIpPort(erreurs, admin, legacy,

   LSDDbIpPort.fuser); // or fusercomp

if (ipport == null) {

   // There is an error since ipport is null

   return;

}

4) Init LSDBusiness object:

Here you create the LSDBusiness object as your implementation needs it.

You need to value for Get only the business index.

LSDBusinessImpl lsdb = new LSDBusinessImpl();

lsdb.idb = sidm;

5) Call to the LSD Web support function:

Here you call the real function.

Get: ArrayList<String> for error handling, LSDDbAdmin object, legacy id, LSDBusiness object, the LSDDbIpPort object and the HttpServletResponse object.

Behind, from the HttpServletResponse object, we get the ServletOutputStream.

All blocks of the needed file are returns directly to the user.

If everything is OK, it returns true.

if (! LSDWebGet.getDocument(erreurs, admin, legacy, lsdb,

   ipport, response)) {

   // There is an error since return is false

   return;

}

PoolGet: Same Get but from an internal pool of LSD Server connections to minimize connections.

if (! LSDWebGet.getPoolDocument(erreurs, admin, legacy, lsdb,

   ipport, response)) {

   // There is an error since return is false

   return;

}

Or either pooled or not pooled version using Exception return:

try {

   if (LSDWebGet.getPoolDocumentException(erreurs, admin, legacy, lsdb, ipport, response) == 0)

   {

      ipport = null;

      // Closing the database Connection (can be done elsewhere in the servlet part)

      admin.close();

      admin = null;

      return;

   }

} catch (LSDNoConnexionException e) { quitInError(request,response,"No Connecxion to OpenLSD Server");

} catch (LSDServletOutputStreamException e) { quitInError(request,response,"Servlet Error");

} catch (LSDBadRequestException e) { quitInError(request,response,"Bad Request Error");

} catch (LSDInternalException e) { quitInError(request,response,"Internal Error");

} catch (LSDNotFoundException e) { quitInError(request,response,"No document found");

} catch (LSDUnknownException e) { quitInError(request,response,"Unknown Error");

}

6) Enable shutdown in case of Pool of OpenLSD connections (LSDWebGet.getPoolDocument):

In destroy() function, you have to call the destructor of the OpenLSD connections pool.

public void destroy() {

            LSDWebGet.closeAll();

            super.destroy();

}

WEB PUT

Most of the things are the same. Scenario 1b-2b is exactly the same, so only the 1a-2a is show again.

 

1a) Init global context: in the general initialization of the servlet (done only once)

Load log4j config file and openlsd-db config file from file real path and execute the initialization step.

The fourth argument contains the class that will be used as the default prefix class name in the logger.

LSDWebCommon.initialize(prefix+log4jfile, prefix+conflsddb, servletClassName.class);

2a) Init LSD and Database context:

Set Oracle as default driver

LSDConstants.typeDriver = LSDConstants.typeOracle;

Once you get your own database connection, you can pass it trough the initAdmin call, such that OpenLSD will use this connection and so as to not open a new one.

As the mode is in write (import), the second argument must be filled, the first one should be null.

The third argument contains a default ArrayList<String> that will contain plain text in case of error.

LSDDbAdmin admin = LSDWebCommon.initAdmin(null,connwrite,erreurs);

if (admin == null) {

    // There is an error since admin is null so you can take an action.

    return;

}

No call to admin.close() is necessary since the connection is not create by LSD. But if you want that OpenLSD take care of closing and getting the exception for you, you can still call admin.close().

 

3) Init OpenLSD Server identification:

Here you get IpPort objects that represent the OpenLSD Server on which you want to interact, based on two client: either (admin,protected) or (compressed,protected) according to the not compressed/compressed protocol you want.

LSDDbIpPort ipport = LSDWebCommon.getIpPort(erreurs, admin, legacy,

   LSDDbIpPort.fadmin); // or fusercomp

if (ipport == null) {

   // There is an error since ipport is null

   return;

}

LSDDbIpPort ipport = LSDWebCommon.getIpPort(erreurs, admin, legacy,

   LSDDbIpPort.fprotected);

if (ipport == null) {

   // There is an error since ipport is null

   return;

}

4) Init LSDBusiness object:

Here you create the LSDBusiness object as your implementation needs it.

For Put you should include all the values that are needed according to your business logic during import.

int [] rank = { LSDBusinessImpl.ridb,LSDBusinessImpl.ridbunit,

   LSDBusinessImpl.ridowner, LSDBusinessImpl.rlimitdate};

String [] args = {sidm,sidbunit,sidowner,slimitdate};

LSDBusinessImpl lsdb = new LSDBusinessImpl(rank, args);

5) Call to the LSD Web support function:

Here you call the real function.

Put: ArrayList<String> for error handling, LSDDbAdmin object, legacy id, the LSDDbIpPort object for put, the LSDDbIpPort object for control (protected), LSDBusiness object, and the file path.

Behind, the file is imported though a local access from OpenLSD Server (Servlet server is installed on the same server than OpenLSD Server).

If everything is OK, it returns true.

boolean result = LSDWebImport.putFileFromWeb(erreurs, admin, legacy,

   ipport1, ipport2, lsdb, uploadedFile);

if (result) {

   //OK, go for inform the user

   …

} else {

   //KO

   return;

}

PutNet: Same Put but the file is imported from the net, i.e. the Servlet server is not on the same server than OpenLSD Server.

boolean result = LSDWebImportNet.putFileFromWeb(erreurs, admin, legacy,

   ipport1, ipport2, lsdb, uploadedFile);

if (result) {

   //OK, go for inform the user

   …

} else {

   //KO

   return;

}