Search in sources :

Example 86 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 87 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
 * @return the agent version
 * @throws AgentException on error
 */
@SuppressWarnings("unchecked")
@WebMethod
public String 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();
    }
    return AtsVersion.getAtsVersion();
}
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 88 with WebMethod

use of javax.jws.WebMethod in project openmeetings by apache.

the class CalendarWebService method save.

/**
 * Save an appointment
 *
 * @param sid
 *            The SID of the User. This SID must be marked as Loggedin
 * @param appointment
 *            calendar event
 *
 * @return - appointment saved
 */
@WebMethod
@POST
@Path("/")
public AppointmentDTO save(@QueryParam("sid") @WebParam(name = "sid") String sid, @FormParam("appointment") @WebParam(name = "appointment") AppointmentDTO appointment) {
    // Seems to be create
    log.debug("save SID: {}", sid);
    return performCall(sid, sd -> {
        User u = userDao.get(sd.getUserId());
        if (!AuthLevelUtil.hasUserLevel(u.getRights())) {
            log.error("save: not authorized");
            return false;
        }
        return AuthLevelUtil.hasWebServiceLevel(u.getRights()) || appointment.getOwner() == null || appointment.getOwner().getId().equals(u.getId());
    }, sd -> {
        User u = userDao.get(sd.getUserId());
        Appointment a = appointment.get(userDao, fileDao, dao, u);
        if (a.getRoom().getId() != null) {
            if (a.getRoom().isAppointment()) {
                a.getRoom().setIspublic(false);
            } else {
                a.setRoom(roomDao.get(a.getRoom().getId()));
            }
        }
        return new AppointmentDTO(dao.update(a, u.getId()));
    });
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) User(org.apache.openmeetings.db.entity.user.User) AppointmentDTO(org.apache.openmeetings.db.dto.calendar.AppointmentDTO) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 89 with WebMethod

use of javax.jws.WebMethod in project openmeetings by apache.

the class FileWebService method getRoom.

/**
 * Get a File Explorer Object by a given Room
 *
 * @param sid
 *            The SID of the User. This SID must be marked as logged in
 * @param roomId
 *            Room Id
 * @return - File Explorer Object by a given Room
 */
@WebMethod
@GET
@Path("/room/{id}")
public FileExplorerObject getRoom(@WebParam(name = "sid") @QueryParam("sid") String sid, @WebParam(name = "id") @PathParam("id") long roomId) {
    log.debug("getRoom::roomId {}", roomId);
    return performCall(sid, User.Right.Room, sd -> {
        FileExplorerObject fileExplorerObject = new FileExplorerObject();
        // Home File List
        List<FileItem> fList = fileDao.getByOwner(sd.getUserId());
        fileExplorerObject.setUser(fList, fileDao.getSize(fList));
        // Public File List
        List<FileItem> rList = fileDao.getByRoom(roomId);
        fileExplorerObject.setRoom(rList, fileDao.getSize(rList));
        return fileExplorerObject;
    });
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) FileExplorerObject(org.apache.openmeetings.db.dto.file.FileExplorerObject) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 90 with WebMethod

use of javax.jws.WebMethod in project openmeetings by apache.

the class RoomWebService method hash.

/**
 * Method to get invitation hash with given parameters
 *
 * @param sid - The SID of the User. This SID must be marked as Loggedin
 * @param invite - parameters of the invitation
 * @param sendmail - flag to determine if email should be sent or not
 * @return - serviceResult object with the result
 */
@WebMethod
@POST
@Path("/hash")
public ServiceResult hash(@WebParam(name = "sid") @QueryParam("sid") String sid, @WebParam(name = "invite") @QueryParam("invite") InvitationDTO invite, @WebParam(name = "sendmail") @QueryParam("sendmail") boolean sendmail) {
    log.debug("[hash] invite {}", invite);
    return performCall(sid, User.Right.Soap, sd -> {
        Invitation i = invite.get(sd.getUserId(), userDao, roomDao);
        i = inviteDao.update(i);
        if (i != null) {
            if (sendmail) {
                try {
                    inviteManager.sendInvitationLink(i, MessageType.Create, invite.getSubject(), invite.getMessage(), false);
                } catch (Exception e) {
                    throw new ServiceException(e.getMessage());
                }
            }
            return new ServiceResult(i.getHash(), Type.SUCCESS);
        } else {
            return new ServiceResult("error.unknown", Type.ERROR);
        }
    });
}
Also used : ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) Invitation(org.apache.openmeetings.db.entity.room.Invitation) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

WebMethod (javax.jws.WebMethod)107 Method (java.lang.reflect.Method)18 Path (javax.ws.rs.Path)17 IOException (java.io.IOException)16 WebResult (javax.jws.WebResult)13 MessageContext (javax.xml.ws.handler.MessageContext)12 WebServiceException (javax.xml.ws.WebServiceException)11 Test (org.junit.Test)10 DataHandler (javax.activation.DataHandler)9 GET (javax.ws.rs.GET)9 Action (javax.xml.ws.Action)9 ArrayList (java.util.ArrayList)8 Oneway (javax.jws.Oneway)8 POST (javax.ws.rs.POST)8 File (java.io.File)7 InputStream (java.io.InputStream)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 QName (javax.xml.namespace.QName)6 RequestWrapper (javax.xml.ws.RequestWrapper)6 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)6