webservice interfaces

OBEROn (since version 1.3) employes Apache CXF to generate the WSDL and to expose/execute the webservice methods.

A webservice source code has a structure like this:

package com.oberon.webservices;
public
class <CLASSNAME> {
  @WebMethod
public
.... exposeMethod1(@WebParam(name="...") .... ) {
    .... CODE ....
  }
  public .... Method2(.... ) {
    .... CODE ....
  }
  @WebMethod
public
.... exposeMethod3(@WebParam(name="...") .... ) {
    .... CODE ....
  }
}


The <CLASSNAME> tag is automatically replaced with the webservice name during the compilation.
Inside the webservice class you can declare public or private methods / parameters; only public methods with annotation @WebMethod are exposed as conseguence of the webservice publication.
Moreover, if you want specify the parameter names inside the generated WSDL you should add the
@WebParam (name="<parameter name>") annotation for each exposed method parameter. If you don't add these annotations, method parameters will be named with the general "arg0", "arg1" ... names.



The following example shows how to implement a webservice class. It's very important to note that if the application server connects to the database indirectly through a RMI interface all java API methods with the "framework" input argument don't work properly. In this case (is best practice to do it always) you MUST use the JRClient class methods to perform the operations.

package com.oberon.webservices;

import
com.oberon.ooql.sdk.*;
import com.oberon.ooql.rmi.*;
import java.util.*;
import javax.servlet.http.*;
import javax.xml.ws.WebServiceContext;
import javax.annotation.*;
import javax.jws.*;

public
class <CLASSNAME> {
 
@Resource
private WebServiceContext context;

private
HttpSession getSession( ) {
    // Retrive the HttpSession from the CXF WebServiceContext
try {
      return JRClient.getCXFHttpSession(context) ;
    } catch (Exception e) {
      return null;
    }
  }
 
// Perform the OBEROn Login and return the session ID for next calls
// Clients must authenticate themselves to services that they are calling
@WebMethod
public String doLogin(@WebParam(name="user") String user ,
       @WebParam(name="password") String password ) throws Exception {

String
sReturn="";
try {
      // Try to open the framework with the input userName and Password
Framework
framework = JRClient.doLogin(user,password,getSession());
// Generate the session ID
sReturn = JRClient.generateSessionId(user,password);
    } catch (Exception e) {
      sReturn = " EXCEPTION: " + e.toString();
    }
return sReturn;
  }
 
// Perform a OBEROn query: retrieve all object of a specific class

@WebMethod
public String doQuery(@WebParam(name="sessionId") String sessionId ,
       @WebParam(name="classname") String classname ) throws Exception {

String
sReturn="";
try {
      HttpSession session = getSession( ) ;
// Try to open the framework with the input session ID
Framework framework = JRClient.doLogin( sessionId , session);
// Perform the query
Vector vRes = JRClient.performOOQLCommands("query immediate object "+classname+" * * get { name description currentstage } token | ;",session);
sReturn = (String) vRes.elementAt(0) ;
    } catch (Exception e) {
      sReturn = " EXCEPTION: " + e.toString();
    }
return sReturn;
  }
 
// Get the image icon for a specific class

@WebMethod
public byte[] getImage(@WebParam(name="sessionId") String sessionId ,
      @WebParam(name="classname") String classname ) throws Exception {

try
{
      // Try to open the framework with the input session ID
Framework
framework = JRClient.doLogin( sessionId , getSession());
// Retrieve the class image-icon
return JRClient.getImage("Class",classname);
    } catch (Exception e) {
      System.out.println( e.getMessage() );
return
new byte[0];
    }
  }
}

If a webservice is defined as a FileSpace interface, it must implement all the methods (login, download, upload, rename, ...) of the com.oberon.webservices.WebServiceSpaceCode java interface. This is a sample:

package com.oberon.webservices;

import
com.oberon.ooql.sdk.*;
import com.oberon.ooql.rmi.JRClient;
import javax.servlet.http.HttpSession;
import javax.xml.ws.WebServiceContext;
import javax.annotation.*;
import javax.jws.*;
import java.io.File;
import java.util.Vector;

public class <CLASSNAME> {
  @Resource
private WebServiceContext context;

private
void checkSessionId( String sessionId ) throws Exception {
    HttpSession session = JRClient.getCXFHttpSession(context) ;
Framework framework = JRClient.doLogin( sessionId , session);
  }
 
// Perform the Login and return the session ID for next calls
@WebMethod
public String login(@WebParam(name="account") String account,
       @WebParam(name="password") String password ) throws Exception {

HttpSession session = JRClient.getCXFHttpSession(context) ;
Framework framework = JRClient.doLogin(account,password,session);
    return JRClient.generateSessionId(account,password);
  }
 
// Download a file

@WebMethod
public byte[] download(@WebParam(name="sessionId") String sessionId ,
       @WebParam(name="filepath") String filepath ) throws Exception {

checkSessionId(sessionId);
return JRClient.getBytesFromFile(filepath);
  }
 
// Upload a file

@WebMethod
public void
upload(@WebParam(name="sessionId") String sessionId ,
       @WebParam(name="filedata") byte[] filedata ,
   @WebParam(name="filepath") String filepath ) throws Exception {

checkSessionId(sessionId);
File file = new File(filepath);
JRClient.saveBytesToFile(file.getParent(),file.getName(),filedata);
  }
 
// Rename a file

@WebMethod
public void
rename(@WebParam(name="sessionId") String sessionId ,
       @WebParam(name="filepath") String filepath ,
   @WebParam(name="newname") String newname ) throws Exception {

checkSessionId(sessionId);
JRClient.copyFile( new File(filepath),new File(newname), true );
  }
 
// Delete a file

@WebMethod
public void delete( @WebParam(name="sessionId") String sessionId ,
       @WebParam(name="filepath") String filepath ) throws Exception {

checkSessionId(sessionId);
File file = new File(filepath);
file.delete();
  }
 
// Return the list of file inside a directory or recursively on its sub-directories

@WebMethod
public String[] list(@WebParam(name="sessionId") String sessionId ,
       @WebParam(name="path") String path ,
   @WebParam(name="subfolders") boolean subfolders) throws Exception {

checkSessionId(sessionId);
Vector vFiles = JRClient.listFiles( path, subfolders );
String[] files = new String[vFiles.size()];
for (int i=0;i<vFiles.size();i++) {
      files[i]=(String)vFiles.elementAt(i); }
    }
    return files;
  }
 
// Remove all empty directories recursively starting from the given path

@WebMethod
public void clean(@WebParam(name="sessionId") String sessionId ,
       @WebParam(name="path") String path ) throws Exception {

checkSessionId(sessionId);
JRClient.cleanDirs(path);
  }
 
// Create a directory tree for a given path

@WebMethod
public void
createdir(@WebParam(name="sessionId") String sessionId ,
       @WebParam(name="path") String path ) throws Exception {

checkSessionId(sessionId);
JRClient.createLocalDir(path);
  }
}

 



© 2008-2015 MS Enterprise Solutions | Website Templates by IceTemplates.com
Please Read: Privacy Policy and Terms of Use