Sample Java Files

In this section:

The following topics describe the sample files associated with the WebFOCUS API Java sample.


Top of page

x
Class Hierarchy

class java.lang.Object


Top of page

x
Interface Hierarchy

Top of page

x
Class Descriptions

In this section:

 



x
com.ibi.ajs.wfapi.Action

The Action class provides the minimum functionality needed to process an action.



Example: Using the Action Class

The following code illustrates the use of Action:

package com.ibi.ajs.wfapi;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibi.ajs.wfapi.samples.WfApiResponseObject;
public interface Action
{
    public WfApiResponseObject execute(
        RequestForm requestContextMap,
        LoginContext lc,
        HttpServletRequest request,
        HttpServletResponse response,
        ServletContext sc);
}


x
com.ibi.ajs.wfapi.ApplController

The ApplController servlet detects and processes the following actions specified in the request:



Example: Using the ApplController Class

The following code illustrates the use of ApplController:

package com.ibi.ajs.wfapi;
import java.io.File;
import java.io.IOException;
 
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.log4j.Logger;
 
import com.ibi.ajs.wfapi.samples.WfApiResponseHandler;
import com.ibi.ajs.wfapi.samples.WfApiResponseObject;
public final class ApplController extends HttpServlet
{
    Logger logger= Logger.getLogger(ApplController.class);
    private ServletContext gSC;
    public ApplController()
    {
        super();
    }
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
    {
        doRequest(req, resp);
    }
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
    {
        doRequest(req, resp);
    }
    public void doRequest(HttpServletRequest req, HttpServletResponse 
resp)
        throws ServletException, IOException
    {
        boolean isLoggedOn= false;
        if (logger.isDebugEnabled())
            logger.info("doRequest...");
        /* check for valid login context */
        LoginAction la= new LoginAction();
        isLoggedOn= la.isSessionValid(req);
        String action= req.getParameter("action");
        if (action != null)
        {
            logger.debug("action=" + action);
            if (action.equals("logon"))
            {
                dispatch(req, resp, Globals.LOGON_JSP);
                return;
            }
            else
                if (action.equals("login"))
                {
                    if (isLoggedOn)
                        la.logout(req);
                    WfApiResponseObject wfrespo= 
la.execute(null,null,req, resp, gSC);
                    if (wfrespo.getStatus() != 0)
                    {
                        req.setAttribute("rr", wfrespo.rr);
                        dispatch(req, resp, Globals.ERROR_JSP);
                    }
                    else
                        redirect(req, resp, Globals.MAINMENU_JSP);
                    return;
                }
                else
                    if (action.equals("logout"))
                    {
                        if (isLoggedOn)
                            la.logout(req);
                        redirect(req, resp, Globals.WELCOME_JSP);
                        return;
                    }
        }
         if (!isLoggedOn)
        {
            if (logger.isDebugEnabled())
                logger.debug("User is not logged in");
            dispatch(req, resp, Globals.LOGON_JSP);
            return;
        }
        else
        {
            if (logger.isDebugEnabled())
                logger.debug("Run Request");
            LoginContext lc= (LoginContext)la.getLoginContext(req);
            RequestForm rf= new RequestForm(req);
            RequestAction ra= new RequestAction();
            WfApiResponseObject wfrespo= ra.execute(rf, lc, req, resp, 
gSC);
            if (wfrespo != null)
            {
                if (wfrespo.getStatus() != 0)
                {
					req.setAttribute("rr", wfrespo.rr);
                    dispatch(req, resp, Globals.ERROR_JSP);
                }
                else
                    WfApiResponseHandler.writeOutputfromStream(resp, 
wfrespo);
            }
        }
    }
    public String getServletInfo()
    {
        return super.getServletInfo();
    }
    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);
        try
        {
            gSC= config.getServletContext();
            /* get webfocus client root */
            String wfClientRoot= 
gSC.getInitParameter(Globals.WFCLIENTROOT);
            Globals.CGILOCATION=
                wfClientRoot + File.separator + "web" + File.separator + 
"cgi";
            if (logger.isInfoEnabled())
                logger.info("Initialized, cfg=" + Globals.CGILOCATION);
        }
        catch (NullPointerException e)
        {
            logger.error(Globals.WFCLIENTROOT + " not defined");
            return;
        }
    }
    public void destroy()
    {
        super.destroy();
        if (logger.isDebugEnabled())
            logger.info("de-initializing");
    }
    private void redirect(
        HttpServletRequest req,
        HttpServletResponse resp,
        String page)
        throws IOException
    {
        if (logger.isDebugEnabled())
            logger.debug("redirecting to: " + page);
        resp.sendRedirect(req.getContextPath() + page);
    }
    private void dispatch(
        HttpServletRequest req,
        HttpServletResponse resp,
        String page)
        throws javax.servlet.ServletException, java.io.IOException
    {
        if (page != null)
        {
            if (logger.isDebugEnabled())
                logger.debug("forwarding to:" + page);
            try
            {
                RequestDispatcher dispatcher= 
gSC.getRequestDispatcher(page);
                dispatcher.forward(req, resp);
            }
            catch (IllegalStateException e)
            {
                logger.error("*** forwarding ERROR:" + e.toString());
            }
        }
        else
            if (logger.isDebugEnabled())
                logger.debug("no page to forwarding to");
    }
}


x
com.ibi.ajs.wfapi.ApplResponse

The ApplResponse Java Bean is used by several of the sample JSPs to retrieve errors when processing a request or authentication information.



Example: Using the ApplResponse Class

The following code illustrates the use of ApplResponse:

public class ApplResponse implements Serializable
{
    private String message;
    private int status;
    private String linkPage;
    public ApplResponse()
    {
        super();
        reset();
    }
    public String getMessage()
    {
        return message;
    }
    public int getStatus()
    {
        return status;
    }
    public void setMessage(String string)
    {
        message= string;
    }
    public void setStatus(int i)
    {
        status= i;
    }
    public void reset()
    {
        setStatus(0);
        setMessage("");
    }
    public String getLinkPage()
    {
        return linkPage;
    }
    public void setLinkPage(String string)
    {
        linkPage= string;
    }
}


x
com.ibi.ajs.wfapi.Globals

The Globals Java class contains values that are made available to the entire sample application as needed. For example, the root directory of the WebFOCUS script files is required by several WebFOCUS API calls. This value can be retrieved passing the Globals.CGILOCATION static variable.



Example: Using the Globals Class

The following code illustrates the use of Globals:

public final class Globals
{
    // webfocus api application values
    public static final String WFCLIENTROOT= "webfocus_client_root";
    public static String CGILOCATION= null;
    // Session keys
    public static final String USER_KEY= "user";
    // JSP files references in this application
    public static final String DISPLAY_JSP= "/display.jsp";
    public static final String INDEX_JSP= "/index.jsp";
    public static final String LOGOFF_JSP= "/logoff.jsp";
    public static final String LOGON_JSP= "/logon.jsp";
    public static final String MAINMENU_JSP= "/mainMenu.jsp";
public static final String WELCOME_JSP="/welcome.jsp";
public static final String ERROR_JSP="/error.jsp";
 }


x
com.ibi.ajs.wfapi.LoginAction

The LoginAction class retrieves the login credentials from the logon.jsp page and validates the values against Managed Reporting and the WebFOCUS Reporting Server. This class integrates the Managed Reporting login with the WebFOCUS Reporting Server user ID. Only the Managed Reporting User ID is validated against the Managed Reporting repository.



Example: Using the LoginAction Class
package com.ibi.ajs.wfapi;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.apache.log4j.Logger;
 
import com.ibi.ajs.wfapi.samples.WfApiRequestHandler;
import com.ibi.ajs.wfapi.samples.WfApiResponseObject;
public final class LoginAction implements Action
{
    Logger logger= Logger.getLogger(LoginAction.class);
    public LoginAction()
    {
        super();
    }
 public WfApiResponseObject execute(
        RequestForm requestContextMap,
        LoginContext lc,
        HttpServletRequest request,
        HttpServletResponse response,
        ServletContext sc)
    {
        String userName= null;
        String password= null;
        String serverNode= null;
        if (logger.isDebugEnabled())
            logger.debug("LogonAction: entering method");
        
// get logon request parameters
        userName= request.getParameter("username");
        password= request.getParameter("password");
        serverNode= request.getParameter("serverNode");
        if (serverNode == null)
            serverNode= "EDASERVE";
        if (logger.isInfoEnabled())
            logger.info("Issue Logon Request");
                WfApiRequestHandler wfa= new WfApiRequestHandler();
        WfApiResponseObject wfLogonResp=
            wfa.webFocusLogOn(request, sc, userName, password, 
serverNode);
        if (wfLogonResp.getStatus() != 0)
            return wfLogonResp;
        LoginContext form= new LoginContext();
        form.setUsername(userName);
        form.setPassword(password);
        form.setServerNode(serverNode);
                String useMR= request.getParameter("useMR");
        if (useMR != null)
        {
            if (useMR.equalsIgnoreCase("true"))
            {
               WfApiRequestHandler wfm= new WfApiRequestHandler();
                WfApiResponseObject mrLogonResp=
                    wfm.webFocMrLogOn(request, sc, userName, password);
             //TODO temp for testing, add code to parse xml, check status
                if (logger.isInfoEnabled())
                    logger.info(
                        "outStream=" + 
mrLogonResp.getOutStreamAsString());
                form.setWfCookies(mrLogonResp.getWFCookies());
            }
        }
        //valid login: Save logged-in user object in the session
        if (logger.isDebugEnabled())
            logger.debug("Save logged-in user object in the session");
        HttpSession session= request.getSession();
        session.setAttribute(Globals.USER_KEY, form);
        if (logger.isDebugEnabled())
        {
            logger.debug(
                "LogonAction: User '"
                    + form.getUsername()
                    + "' logged on in session "
                    + session.getId());
        }
        return wfLogonResp;
    }
    public boolean isSessionValid(HttpServletRequest request)
    {
        if (logger.isDebugEnabled())
            logger.debug("isSessionValid");
        LoginContext lc= (LoginContext) getLoginContext(request);
        return ((lc == null) ? false : true);
    }
    public Object getLoginContext(HttpServletRequest req)
    {
        if (logger.isDebugEnabled())
            logger.debug("getLoginContext");
        if (req == null)
            return null;
        HttpSession session= req.getSession(false);
        if (session == null)
            return null;
        return (session.getAttribute(Globals.USER_KEY));
    }
    public void logout(HttpServletRequest req)
    {
        if (logger.isDebugEnabled())
            logger.debug("logout");
        HttpSession session= req.getSession(false);
        if (session != null)
            session.removeAttribute(Globals.USER_KEY);
        //session.invalidate();
    }
}


x
com.ibi.ajs.wfapi.LoginContext

The LoginContext JavaBean stores the required credentials to sign on to the WebFOCUS Reporting Server and Managed Reporting.



Example: Using the LoginContext Class
package com.ibi.ajs.wfapi;
import java.io.Serializable;
import javax.servlet.http.Cookie;
public class LoginContext implements Serializable
{
    private String username= null;
    private transient String password= null;
    private String serverNode= null;
    private Cookie[] wfCookies= null;
       public LoginContext()
    {
        super();
    }
        public String getPassword()
    {
        return password;
    }
    public String getServerNode()
    {
        return serverNode;
    }
    public String getUsername()
    {
        return username;
    }
    public void setPassword(String string)
    {
        password= string;
    }
     public void setServerNode(String string)
    {
        serverNode= string;
    }
    public void setUsername(String string)
    {
        username= string;
    }
     public Cookie[] getWfCookies()
    {
        return wfCookies;
     public void setWfCookies(Cookie[] cookies)
    {
        wfCookies= cookies;
    }
}


x
com.ibi.ajs.wfapi.RequestAction

The RequestAction class retrieves all of the name-value pairs from the variable tables (which is passed in using the RequestForm and the WfApiRequestObject objects). Additional name-value pairs are then added. The response format for the return code is set to XML, the WebFOCUS Reporting Automatic Signon feature is disabled, and the values needed for the WF_SIGNON action are added to the request.



Example: Using the RequestAction Class
package com.ibi.ajs.wfapi;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.log4j.Logger;
 
import com.ibi.ajs.wfapi.samples.WfApiRequestHandler;
import com.ibi.ajs.wfapi.samples.WfApiRequestObject;
import com.ibi.ajs.wfapi.samples.WfApiResponseObject;
public final class RequestAction implements Action
{
    Logger logger= Logger.getLogger(RequestAction.class);
public WfApiResponseObject execute(
        RequestForm requestContextMap,
        LoginContext lc,
        HttpServletRequest request,
        HttpServletResponse response,
        ServletContext sc)
    {
        if (logger.isDebugEnabled())
            logger.debug("execute");
        WfApiRequestObject wfReq= new WfApiRequestObject();
        wfReq.addParamsToWFRequest(requestContextMap.getWfVarTable());
        wfReq.setWFRequestVar("WF_AUTOSIGNON", "NO");
        wfReq.setWFRequestVar("IBIWF_format", "XML");
        if (lc != null)
        {
            wfReq.setWFRequestVar("IBIC_user", lc.getUsername());
            wfReq.setWFRequestVar("IBIC_pass", lc.getPassword());
            wfReq.setWFRequestVar("IBIC_server", lc.getServerNode());
            wfReq.addWFCookiesToRequest(lc.getWfCookies());
        }
        WfApiRequestHandler wfa= new WfApiRequestHandler();
        WfApiResponseObject wfrespo= wfa.execute(wfReq, request, sc);
        return wfrespo;
    }
}


x
com.ibi.ajs.wfapi.RequestForm

The RequestForm class retrieves all of the form variables and header variables and adds them to a table, which is then processed by the RequestAction class.



Example: Using the RequestForm Class
package com.ibi.ajs.wfapi;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.HashMap;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.log4j.Logger;
public class RequestForm implements Serializable
{
    Logger logger= Logger.getLogger(RequestForm.class);
    private HashMap wfVarTable= null;
     public RequestForm(HttpServletRequest request)
    {
        super();
        wfVarTable= new HashMap(32);
        addFormVarsToWFRequest(request);
    }
    private void addFormVarsToWFRequest(HttpServletRequest request)
    {
        if (logger.isDebugEnabled())
            logger.debug("addVarHtmlForm");
        String values[];
        String value;
        String name;
        Enumeration params= request.getParameterNames();
        while (params.hasMoreElements())
        {
            name= (String) params.nextElement();
            values= request.getParameterValues(name);
            for (int i= 0; i < values.length; i++)
                setWFRequestVar(name, values[i]);
        }
    }
    
public void setWFRequestVar(String name, String value)
    {
        if (logger.isDebugEnabled())
            logger.debug("store var: " + name);
        wfVarTable.put(name, value);
    }
    public String getWFRequestVar(String key)
    {
        if (logger.isDebugEnabled())
            logger.debug("get var: " + key);
        return ((String) wfVarTable.get(key));
    }
       private void clearWfVarTable()
    {
        wfVarTable.clear();
    }
     public HashMap getWfVarTable()
    {
        return wfVarTable;
    }
}


x
com.ibi.ajs.wfapi.samples.WfApiRequestHandler

The WfApiRequestHandler class processes the WebFOCUS request using the WFWorkerUtil.processRequest method. This class is called by the RequestAction class.



Example: Using the WfApiRequestHandler Class
package com.ibi.ajs.wfapi.samples;
import ibi.webfoc.WFApplicationRequest;
import ibi.webfoc.WFApplicationResponse;
import ibi.webfoc.WFServletVariableTableExtension;
import ibi.webfoc.WFWorkerUtil;
import ibi.webfoc.wfutil.WFErrorException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import com.ibi.ajs.util.MsgUtils;
import com.ibi.ajs.wfapi.Globals;
public class WfApiRequestHandler
{
    Logger logger= Logger.getLogger(WfApiRequestHandler.class);
      public WfApiResponseObject execute(
        WfApiRequestObject wfReq,
        HttpServletRequest request,
        ServletContext sc)
    {
        if (logger.isDebugEnabled())
            logger.debug("begin execute...");
        WfApiResponseObject wfResp= new WfApiResponseObject();
		WFApplicationResponse wfWorkerResp= wfResp.getWorkerResp();
        try
        {
            if (logger.isDebugEnabled())
                logger.debug("calling 
WFServletVariableTableExtension...");
            WFServletVariableTableExtension wfSrvTabExt=
                new WFServletVariableTableExtension(request, sc);
                      if (logger.isDebugEnabled())
                logger.debug(
                    "initialize server variables in wf worker 
request...");
            WFApplicationRequest wfWorkerReq= wfReq.getWorkerReq();
            wfWorkerReq.setScheme(request.getScheme());
            wfWorkerReq.setServerName(request.getServerName());
            wfWorkerReq.setServerPort(request.getServerPort());
            wfWorkerReq.setRequestURI(request.getRequestURI());
            /* process webfocus request */
 
if (logger.isDebugEnabled())
                logger.debug("calling processRequest...");
            WFWorkerUtil.processRequest(
                Globals.CGILOCATION,
                wfWorkerReq,
                wfWorkerResp,
                wfSrvTabExt,
                null,
                null,
                request,
                null,
                true,
                "ApiTestApp");
        }
        catch (WFErrorException wfe)
        {
            if (logger.isInfoEnabled())
                logger.info("WFErrorException: " + wfe.toString());
            logger.error("WFErrorException: " + 
MsgUtils.getStackTrace(wfe));
            wfResp.setStatus(wfe.getErrorCode());
            wfResp.setMessage(wfe.getParameter());
        }
        catch (Throwable t)
        {
            logger.error(
                "Exception: "
                    + 
MsgUtils.getStackTrace((Exception)t.fillInStackTrace()));
            wfResp.setStatus(-999);
            wfResp.setMessage(t.toString());
        }
        finally
        {
            if (logger.isDebugEnabled())
                logger.debug("...end execute, Completed");
            return wfResp;
        }
    }
     public WfApiResponseObject webFocusLogOn(
        HttpServletRequest request,
        ServletContext sc,
        String userName,
        String password,
        String serverNode)
    {
        if (logger.isDebugEnabled())
            logger.debug(
                "WebFOCUS logon request for "
                    + userName
                    + " at node "
                    + serverNode);
        WfApiRequestObject wfReq= new WfApiRequestObject();
        wfReq.setWFRequestVar("IBIC_user", userName);
        wfReq.setWFRequestVar("IBIC_pass", password);
        wfReq.setWFRequestVar("IBIC_server", serverNode);
        wfReq.setWFRequestVar("IBIWF_action", "WF_SIGNON");
        wfReq.setWFRequestVar("WF_AUTOSIGNON", "NO");
        wfReq.setWFRequestVar("IBIWF_format", "XML");
        return (execute(wfReq, request, sc));
    }
      public WfApiResponseObject webFocMrLogOn(
        HttpServletRequest request,
        ServletContext sc,
        String userName,
        String password)
    {
        if (logger.isDebugEnabled())
            logger.debug("WF MR logon request for " + userName);
        WfApiRequestObject wfReq= new WfApiRequestObject();
        wfReq.setWFRequestVar("IBIMR_action", "MR_SIGNON");
        wfReq.setWFRequestVar("IBIMR_user", userName);
        wfReq.setWFRequestVar("IBIMR_pass", "");
        wfReq.setWFRequestVar("IBIMR_returntype", "XML");
        return (execute(wfReq, request, sc));
    }
}


x
com.ibi.ajs.wfapi.samples.WfApiRequestObject

The WfApiRequestObject adds all WebFOCUS and non-WebFOCUS variables to the variable table.



Example: Using the WfApiRequestObject Class
package com.ibi.ajs.wfapi.samples;
import ibi.webfoc.WFApplicationRequest;
 
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
 
import javax.servlet.http.Cookie;
 
import org.apache.log4j.Logger;
 
public class WfApiRequestObject
{
    Logger logger= Logger.getLogger(WfApiRequestObject.class);
    private WFApplicationRequest workerReq= null;
    public WfApiRequestObject()
    {
        super();
        if (logger.isDebugEnabled())
            logger.debug("WfApiRequestObject: create");
        workerReq= new WFApplicationRequest();
    }
    public int addParamsToWFRequest(HashMap wfVarTable)
    {
        if (logger.isDebugEnabled())
            logger.debug("addParamsToWFRequest: begin");
        String key;
        String val;
        int nParams= 0;
        Collection myList= wfVarTable.keySet();
        Iterator i= myList.iterator();
        while (i.hasNext())
        {
            key= (String)i.next();
            val= (String)wfVarTable.get(key);
            setWFRequestVar(key, val);
            nParams++;
        }
        if (logger.isDebugEnabled())
            logger.debug("addParamsToWFRequest: end, added=" + nParams);
        return (nParams);
    }
   
 public void setWFRequestVar(String name, String value)
    {
        if (logger.isDebugEnabled())
        {
            if (name.endsWith("_pass"))
                logger.debug("adding var: " + name + "=********");
            else
                logger.debug("adding var: " + name + "=" + value);
        }
        workerReq.addParameter(name, value);
    }
    public void addWFCookiesToRequest(Cookie[] wfCookies)
    {
        if (logger.isDebugEnabled())
            logger.debug("addWFCookiesToRequest");
        if (wfCookies != null)
        {
            if (wfCookies.length > 0)
            {
                workerReq.addCookies(wfCookies);
                if (logger.isDebugEnabled())
                {
                    for (int i= 0; i < wfCookies.length; i++)
                    {
                        logger.debug(
                            wfCookies[i].getName()
                                + " = "
                                + wfCookies[i].getValue());
                    }
                }
            }
        }
    }
    public WFApplicationRequest getWorkerReq()
    {
        return workerReq;
    }
}



x
com.ibi.ajs.wfapi.samples.WfApiResponseHandler

The WfApiResponseHandler writes the streamed output stored in the WfApiResponseObject. The output format used by the client is determined by the content type retrieved from the WFApplicationResponse object.



Example: Using the WfApiResponseHandler Class
package com.ibi.ajs.wfapi.samples;
import ibi.webfoc.WFApplicationResponse;
 
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.log4j.Logger;
 
import com.ibi.ajs.util.MsgUtils;
import com.ibi.ajs.wfapi.ApplResponse;
public class WfApiResponseHandler
{
       public static ApplResponse writeOutputfromStream(
        HttpServletResponse response,
        WfApiResponseObject wfResp)
    {
        Logger logger= Logger.getLogger(WfApiResponseHandler.class);
        if (logger.isDebugEnabled())
            logger.debug("begin writeOutputfromStream...");
        boolean bStatus= true;
        ApplResponse rr= null;
        WFApplicationResponse wfWorkerResp= wfResp.getWorkerResp();
        try
        {
            String wfContentType= wfWorkerResp.getContentType();
            OutputStream outStream= wfWorkerResp.getOutputStream();
            if (logger.isInfoEnabled())
            {
                logger.info("Context Type=" + wfContentType);
                logger.info(
                    "Context Length=" + wfWorkerResp.getContentLength());
                logger.info("Stream Length=" + 
outStream.toString().length());
            }
            if (logger.isDebugEnabled())
                logger.debug(outStream.toString());
            ServletOutputStream httpout= response.getOutputStream();
            response.setContentType(wfContentType);
            ByteArrayOutputStream a= (ByteArrayOutputStream)outStream;
            httpout.write(a.toByteArray());
            httpout.flush();
        }
        catch (IOException e)
        {
            logger.error("IOException: " + MsgUtils.getStackTrace(e));
            rr= new ApplResponse();
            rr.setStatus(-1);
            rr.setMessage(e.getMessage());
        }
        catch (Throwable t)
        {
            logger.error(
                "Exception: "
                    + 
MsgUtils.getStackTrace((Exception)t.fillInStackTrace()));
            rr= new ApplResponse();
            rr.setStatus(-2);
            rr.setMessage(t.getMessage());
        }
        finally
        {
            if (logger.isDebugEnabled())
                logger.debug("...end writeOutputfromStream");
            return rr;
        }
    }
}



x
com.ibi.ajs.wfapi.samples.WfApiResponseObject

The WfApiResponseObject class stores the response that is then processed by the WfApiResponseHandler class.



Example: Using the WfApiResponseObject Class
package com.ibi.ajs.wfapi.samples;
import ibi.webfoc.WFApplicationResponse;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import javax.servlet.http.Cookie;
import org.apache.log4j.Logger;
import com.ibi.ajs.wfapi.ApplResponse;
 
public class WfApiResponseObject
{
    Logger logger= Logger.getLogger(WfApiResponseObject.class);
    private OutputStream outStream;
    private WFApplicationResponse workerResp= null;
private String message;
private int status;
private boolean errorStatus;
public ApplResponse rr=null;
    public WfApiResponseObject()
    {
        super();
if (logger.isDebugEnabled())
logger.debug("WfApiResponseObject: create output stream");
        outStream= new ByteArrayOutputStream(4096);
rr= new ApplResponse();
createWFApplResponse();
    }
    public WfApiResponseObject(OutputStream outStream)
    {
        if (logger.isDebugEnabled())
            logger.debug("WfApiResponseObject: set output stream");
        this.outStream= outStream;
createWFApplResponse();
    }
    private void createWFApplResponse()
    {
        if (logger.isDebugEnabled())
            logger.debug("createWFApiResponse...");
        workerResp= new WFApplicationResponse(outStream);
    }
    public OutputStream getOutStream()
    {
        return outStream;
    }
    public String getOutStreamAsString()
    {
        return (getOutStream().toString());
    }
public Cookie[] getWFCookies()
{
if (logger.isDebugEnabled())
logger.debug("getWFCookies");
return (workerResp.getCookies());
}
    public WFApplicationResponse getWorkerResp()
    {
        return workerResp;
    }
    public String getMessage()
    {
        return rr.getMessage();
    }
    public int getStatus()
    {
        return rr.getStatus();
    }
    public void setMessage(String string)
    {
        rr.setMessage(string);
    }
    public void setStatus(int i)
    {
        rr.setStatus(i);
    }
    public boolean isErrorStatus()
    {
        return errorStatus;
    }
    public void setErrorStatus(boolean b)
    {
        errorStatus= b;
    }
}


WebFOCUS