Search in sources :

Example 31 with WebMethod

use of javax.jws.WebMethod in project ats-framework by Axway.

the class AgentWsImpl method scheduleActionsInMultipleThreads.

/**
     * Schedule a set of actions (queue) in multiple threads. The actions
     * will not be executed until a call to startQueue is made
     *
     * @param queueName the name of the action queue
     * @param actions the actions in that queue
     * @param serializedThreadingPattern the serialized threading pattern to be used
     * @param testCaseState the test case state
     * @throws AgentException on error
     * @throws InternalComponentException if an exception is thrown while the actions are executed
     */
@WebMethod
public void scheduleActionsInMultipleThreads(@WebParam(name = "name") String queueName, @WebParam(name = "queueId") int queueId, @WebParam(name = "actions") ActionWrapper[] actions, @WebParam(name = "serializedThreadingPattern") byte[] serializedThreadingPattern, @WebParam(name = "serializedLoaderDataConfig") byte[] serializedLoaderDataConfig, boolean isUseSynchronizedIterations) throws AgentException, InternalComponentException {
    final String caller = getCaller();
    ThreadsPerCaller.registerThread(caller);
    try {
        ArrayList<ActionRequest> actionRequests = new ArrayList<ActionRequest>();
        for (ActionWrapper actionWrapper : actions) {
            List<ArgumentWrapper> args = actionWrapper.getArgs();
            int numArguments = args.size();
            Object[] arguments = new Object[numArguments];
            // unwrap the action arguments
            for (int i = 0; i < numArguments; i++) {
                ArgumentWrapper argWrapper = args.get(i);
                ByteArrayInputStream byteInStream = new ByteArrayInputStream(argWrapper.getArgumentValue());
                ObjectInputStream objectInStream = new ObjectInputStream(byteInStream);
                arguments[i] = objectInStream.readObject();
            }
            // construct the action request
            ActionRequest actionRequest = new ActionRequest(actionWrapper.getComponentName(), actionWrapper.getActionName(), arguments);
            actionRequests.add(actionRequest);
        }
        ByteArrayInputStream byteInStream;
        ObjectInputStream objectInStream;
        // de-serialize the threading configuration
        byteInStream = new ByteArrayInputStream(serializedThreadingPattern);
        objectInStream = new ObjectInputStream(byteInStream);
        ThreadingPattern threadingPattern = (ThreadingPattern) objectInStream.readObject();
        // de-serialize the loader data configuration
        byteInStream = new ByteArrayInputStream(serializedLoaderDataConfig);
        objectInStream = new ObjectInputStream(byteInStream);
        LoaderDataConfig loaderDataConfig = (LoaderDataConfig) objectInStream.readObject();
        MultiThreadedActionHandler.getInstance(caller).scheduleActions(caller, queueName, queueId, actionRequests, threadingPattern, loaderDataConfig, isUseSynchronizedIterations);
    } catch (Exception e) {
        handleExceptions(e);
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
}
Also used : ArrayList(java.util.ArrayList) InternalComponentException(com.axway.ats.agent.core.exceptions.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) IOException(java.io.IOException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException) LoaderDataConfig(com.axway.ats.agent.core.threading.data.config.LoaderDataConfig) ThreadingPattern(com.axway.ats.agent.core.threading.patterns.ThreadingPattern) ActionRequest(com.axway.ats.agent.core.action.ActionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) WebMethod(javax.jws.WebMethod)

Example 32 with WebMethod

use of javax.jws.WebMethod in project ats-framework by Axway.

the class AgentWsImpl method getMonitoringResults.

/**
     * @return the latest info about the Agent users activity
     *
     * @throws AgentException
     * @throws InternalComponentException
     */
@WebMethod
public synchronized byte[] getMonitoringResults() throws AgentException, InternalComponentException {
    try {
        ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
        objectOutStream.writeObject(UserActionsMonitoringAgent.getInstance(getCaller()).getMonitoringResults());
        return byteOutStream.toByteArray();
    } catch (Exception e) {
        handleExceptions(e);
        // always throw but the compiler is not aware of this
        return null;
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) InternalComponentException(com.axway.ats.agent.core.exceptions.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) IOException(java.io.IOException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException) WebMethod(javax.jws.WebMethod)

Example 33 with WebMethod

use of javax.jws.WebMethod in project ats-framework by Axway.

the class AgentWsImpl method pushConfiguration.

/**
     * Apply client configuration to the server
     *
     * @param configurators the serialized configurators to be applied
     * @throws AgentException on error
     */
@SuppressWarnings("unchecked")
@WebMethod
public void pushConfiguration(@WebParam(name = "configurators") byte[] serializedConfigurators) throws AgentException {
    final String caller = getCaller();
    ThreadsPerCaller.registerThread(caller);
    ByteArrayInputStream byteInStream = new ByteArrayInputStream(serializedConfigurators);
    ObjectInputStream objectInStream;
    try {
        objectInStream = new ObjectInputStream(byteInStream);
        List<Configurator> configurators = (List<Configurator>) objectInStream.readObject();
        // Check if AgentConfigurator is set. In such case we will need to reload the
        // Agent components as this configuration defines the way Agent components are loaded.
        boolean needToReloadComponents = false;
        for (Configurator configurator : configurators) {
            if (configurator instanceof AgentConfigurator) {
                needToReloadComponents = true;
                break;
            }
        }
        if (needToReloadComponents) {
            // the already loaded Agent components are first unloaded
            MainComponentLoader.getInstance().destroy();
            // the initialization procedure will implicitly apply the new configurations
            // and then will load up again the Agent components
            MainComponentLoader.getInstance().initialize(configurators);
        } else {
            // just apply the configurations
            ConfigurationManager.getInstance().apply(configurators);
        }
    } catch (IOException ioe) {
        final String msg = "IO error while serializing configurators";
        // log on the monitored machine
        log.error(msg, ioe);
        throw new AgentException(msg, ioe);
    } catch (ClassNotFoundException cnfe) {
        final String msg = "Could not deserialize configurators";
        // log on the monitored machine
        log.error(msg, cnfe);
        throw new AgentException(msg, cnfe);
    } catch (Exception e) {
        final String msg = "Error applying configurators";
        // log on the monitored machine
        log.error(msg, e);
        throw new AgentException(msg, e);
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Configurator(com.axway.ats.agent.core.configuration.Configurator) AgentConfigurator(com.axway.ats.agent.core.configuration.AgentConfigurator) AgentException(com.axway.ats.agent.core.exceptions.AgentException) ArrayList(java.util.ArrayList) List(java.util.List) AgentConfigurator(com.axway.ats.agent.core.configuration.AgentConfigurator) IOException(java.io.IOException) InternalComponentException(com.axway.ats.agent.core.exceptions.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) IOException(java.io.IOException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException) ObjectInputStream(java.io.ObjectInputStream) WebMethod(javax.jws.WebMethod)

Example 34 with WebMethod

use of javax.jws.WebMethod in project ats-framework by Axway.

the class AgentWsImpl method executeAction.

/**
     * Web method for execution of Agent actions.
     *
     * @param componentName name of the Agent component
     * @param actionName name of the action to perform
     * @param args arguments - array of ArgumentWrapper
     * @return serialized returned result
     * @throws AgentException if any error occurs
     * @throws InternalComponentException if an exception occurs in the Agent action
     */
@WebMethod
public byte[] executeAction(@WebParam(name = "componentName") String componentName, @WebParam(name = "actionName") String actionName, @WebParam(name = "args") ArgumentWrapper[] args) throws AgentException, InternalComponentException {
    final String caller = getCaller();
    ThreadsPerCaller.registerThread(caller);
    try {
        Object result = executeAction(caller, componentName, actionName, args);
        ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
        objectOutStream.writeObject(result);
        return byteOutStream.toByteArray();
    } catch (Exception e) {
        handleExceptions(e);
        // but the compiler is not aware of this
        return null;
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) InternalComponentException(com.axway.ats.agent.core.exceptions.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) IOException(java.io.IOException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException) WebMethod(javax.jws.WebMethod)

Example 35 with WebMethod

use of javax.jws.WebMethod in project bamboobsc by billchen198318.

the class ApiWebServiceImpl method getScorecard2.

@WebMethod
@GET
@Path("/scorecard2/")
@Override
public BscApiServiceResponse getScorecard2(@WebParam(name = "visionId") @QueryParam("visionId") String visionId, @WebParam(name = "startDate") @QueryParam("startDate") String startDate, @WebParam(name = "endDate") @QueryParam("endDate") String endDate, @WebParam(name = "startYearDate") @QueryParam("startYearDate") String startYearDate, @WebParam(name = "endYearDate") @QueryParam("endYearDate") String endYearDate, @WebParam(name = "frequency") @QueryParam("frequency") String frequency, @WebParam(name = "dataFor") @QueryParam("dataFor") String dataFor, @WebParam(name = "measureDataOrganizationId") @QueryParam("measureDataOrganizationId") String measureDataOrganizationId, @WebParam(name = "measureDataEmployeeId") @QueryParam("measureDataEmployeeId") String measureDataEmployeeId, @WebParam(name = "contentFlag") @QueryParam("contentFlag") String contentFlag) throws Exception {
    HttpServletRequest request = null;
    if (this.getWebServiceContext() != null && this.getWebServiceContext().getMessageContext() != null) {
        request = (HttpServletRequest) this.getWebServiceContext().getMessageContext().get(MessageContext.SERVLET_REQUEST);
    }
    Subject subject = null;
    BscApiServiceResponse responseObj = new BscApiServiceResponse();
    responseObj.setSuccess(YesNo.NO);
    try {
        subject = WsAuthenticateUtils.login();
        @SuppressWarnings("unchecked") IVisionService<VisionVO, BbVision, String> visionService = (IVisionService<VisionVO, BbVision, String>) AppContext.getBean("bsc.service.VisionService");
        @SuppressWarnings("unchecked") IEmployeeService<EmployeeVO, BbEmployee, String> employeeService = (IEmployeeService<EmployeeVO, BbEmployee, String>) AppContext.getBean("bsc.service.EmployeeService");
        @SuppressWarnings("unchecked") IOrganizationService<OrganizationVO, BbOrganization, String> organizationService = (IOrganizationService<OrganizationVO, BbOrganization, String>) AppContext.getBean("bsc.service.OrganizationService");
        String visionOid = "";
        String measureDataOrganizationOid = "";
        String measureDataEmployeeOid = "";
        DefaultResult<VisionVO> visionResult = visionService.findForSimpleByVisId(visionId);
        if (visionResult.getValue() == null) {
            throw new Exception(visionResult.getSystemMessage().getValue());
        }
        visionOid = visionResult.getValue().getOid();
        if (StringUtils.isBlank(measureDataOrganizationId)) {
            measureDataOrganizationOid = BscBaseLogicServiceCommonSupport.findEmployeeDataByEmpId(employeeService, measureDataOrganizationId).getOid();
        }
        if (StringUtils.isBlank(measureDataEmployeeId)) {
            measureDataEmployeeOid = BscBaseLogicServiceCommonSupport.findOrganizationDataByUK(organizationService, measureDataEmployeeId).getOid();
        }
        this.processForScorecard(responseObj, request, visionOid, startDate, endDate, startYearDate, endYearDate, frequency, dataFor, measureDataOrganizationOid, measureDataEmployeeOid, contentFlag);
    } catch (Exception e) {
        responseObj.setMessage(e.getMessage());
    } finally {
        if (!YesNo.YES.equals(responseObj.getSuccess())) {
            responseObj.setMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA));
        }
        WsAuthenticateUtils.logout(subject);
    }
    subject = null;
    return responseObj;
}
Also used : IVisionService(com.netsteadfast.greenstep.bsc.service.IVisionService) IOrganizationService(com.netsteadfast.greenstep.bsc.service.IOrganizationService) BbVision(com.netsteadfast.greenstep.po.hbm.BbVision) OrganizationVO(com.netsteadfast.greenstep.vo.OrganizationVO) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) Subject(org.apache.shiro.subject.Subject) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) HttpServletRequest(javax.servlet.http.HttpServletRequest) BbEmployee(com.netsteadfast.greenstep.po.hbm.BbEmployee) EmployeeVO(com.netsteadfast.greenstep.vo.EmployeeVO) BscApiServiceResponse(com.netsteadfast.greenstep.bsc.vo.BscApiServiceResponse) BbOrganization(com.netsteadfast.greenstep.po.hbm.BbOrganization) IEmployeeService(com.netsteadfast.greenstep.bsc.service.IEmployeeService) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

WebMethod (javax.jws.WebMethod)48 Method (java.lang.reflect.Method)13 WebResult (javax.jws.WebResult)12 Test (org.junit.Test)7 File (java.io.File)6 IOException (java.io.IOException)6 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)6 ActionExecutionException (com.axway.ats.agent.core.exceptions.ActionExecutionException)5 AgentException (com.axway.ats.agent.core.exceptions.AgentException)5 InternalComponentException (com.axway.ats.agent.core.exceptions.InternalComponentException)5 NoCompatibleMethodFoundException (com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException)5 NoSuchActionException (com.axway.ats.agent.core.exceptions.NoSuchActionException)5 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)5 Path (javax.ws.rs.Path)5 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)4 QName (javax.xml.namespace.QName)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3