index



modules



license
coding style
to do



Import servlet

The actual data can be sent to the Uni-d generated application using a servlet. Alternatively a web page can be provided (and by default it is), where you can cut and past the import file.

The servlet can be called with code like the following :

URLConnection cnx=url.openConnection();

// Set connection parameters cnx.setDoInput(true); cnx.setDoOutput(true); cnx.setUseCaches(false); cnx.setRequestProperty("Content-Type", "text/plain");

// write the request Writer out=new BufferedWriter(new OutputStreamWriter(cnx.getOutputStream())); // ~~write the data~~ out.flush(); out.close();

// now read the response BufferedInputStream in=new BufferedInputStream(cnx.getInputStream()); // ~~handle the reply~~ in.close();

If the data file starts with "data=” then this is removed from the data (this is done to allow the data to come from a form).

The servlet send a short replies with "OK" if the file was processed properly. If there was a problem during the import, the reply is "FAILED " followed by a human readable reason of failure.

If your servlet is secured (it should be), then it is best to use the be.unid.ymport.ImportClient class. This will handle the login both in case of BASIC and FORM based authentication.

The actual servlet can be generated with a ant task like the following :

<uni-d
        appdir="${rootdir}/build/om"
        definition="test.xml"
        outputdir="${build.generate.dir}"
        package="test.ymport"
        template="import"
        generateAll="${uni-d.generate-all}">
            <config name="extra">
            <attribute name="ejb-package" value="test"/>
        </config>
   </uni-d>

Note that "import” is a reserved word in Java and thus cannot be used as package name.

To use the servlet, a definition like the example which follows has to be added to your web.xml file in your web archive.

<servlet>
      <servlet-name>Import</servlet-name>
      <servlet-class>be.unid.ymport.Servlet</servlet-class>
      <init-param>
        <param-name>DatabaseMap</param-name>
        <param-value>test.ymport.DatabaseMap</param-value>
      </init-param>
   </servlet>

Obviously, this servlet also has to be mapped to a URL, but that’s all there is to it.

Charset issues

On the servlet connection, it is possible to indicate the character encoding which is used in the communication. This can be modified as needed on the client side to match the charset for the text file.