Developing the Staf Extension

Source: Internet
Author: User

Development of STAF plug-ins, mainly to implement the STAFServiceInterfaceLevel30 interface, the implementation of INIT, term, acceptrequest three methods, according to the name can be learned: one for the initialization method, one for the destruction method, One to process the request method.

For example, we can initialize a handle in init and then destroy the handle in the term.
try {fservicename =;fhandle = new Stafhandle ("staf/service/" +;} catch (Stafexception e) {return new Stafresult (Stafresult.stafregistrationerror, e.tostring ());}


In Init, we can also use Stafcommandparser to define the list of parameters that request receives, as follows:
QUERY parser fqueryparser = new Stafcommandparser (); Stafcommandparser.valuenotallowed indicates that a value cannot be passed to query when requested fqueryparser.addoption ("query", 1,                                    stafcommandparser.valuenotallowed);    Stafcommandparser.valuerequired      indicates that a value can be passed to NAME when requested, but not required fqueryparser.addoption ("name", 1,                                    stafcommandparser.valueallowed);//stafcommandparser.valuerequired      indicates that a value must be passed to education when requested Fqueryparser.addoption ("Education", 1,                                    stafcommandparser.valuerequired);//This indicates that you need name and education      , But not both have Fqueryparser.addoptiongroup ("name      Education", 0, 1);//If you specify NAME      or education, Query is a must fqueryparser.addoptionneed ("Name      Education", "Query");//If you specify QUERY, you need NAME      or Educationfqueryparser.addoptionneed ("QUERY", "NAME      

the initialization function and the Destroy function are basically finished, and the rest is the Acceptrequest function, which handles the request function

This function receives the Requestinfo parameter, obtains the request by obtaining the requested type, in order to determine how to handle the request

In the handler function, you can use the initialized Fqueryparser in init to convert the request requests so that the incoming parameters can be checked

Once you get the incoming parameters, you can handle them according to your own ideas, and in the end, you need to return to Stafresult as the result of processing.

When your extension class is complete, the next step is to package, you can refer to the "Ant package deployment Staf Plug-in" for deployment, which is no longer detailed

Sample Download:

Reprint Please specify: Http://

Explore test art, Exchange test technology, Welcome to the "Sogou test"

Developing the Staf Extension

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.