Search in sources :

Example 66 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class ProxyServerConnection method run.

@Override
public void run() {
    Thread.currentThread().setName("Proxy Client Connection Listener to " + serverName + ":" + serverPort);
    while (listening) {
        try {
            if (serverConnection == null)
                connect();
            if (serverConnection != null) {
                BufferedReader request = new BufferedReader(new InputStreamReader(serverConnection.getInputStream()));
                String input = null;
                ProxyMessage thisMessage;
                while (listening && serverConnection != null) {
                    try {
                        input = request.readLine();
                        thisMessage = new ProxyMessage(input);
                        thisMessage.setServer(serverName);
                        manager.processMessage(thisMessage);
                    } catch (InterruptedIOException ex) {
                        // timeout - send a ping
                        sendMessage(ProxyMessage.pingMessage);
                    } catch (InvalidDataException ex) {
                        // invalid proxy message
                        if (input != null)
                            Logger.error("ProxyManager - Invalid proxy message: " + input);
                    }
                }
            }
        } catch (IOException ex) {
            Logger.error("ProxyServerConnection - Disconnected from " + serverName + ":" + serverPort);
            try {
                serverStream.close();
                serverConnection.close();
            } catch (IOException e1) {
            }
            serverStream = null;
            serverConnection = null;
        }
    }
    if (serverStream != null) {
        try {
            Logger.msg(1, "Disconnecting from proxy server on " + serverName + ":" + serverPort);
            serverStream.println(ProxyMessage.byeMessage.toString());
            serverStream.close();
            serverConnection.close();
            serverConnection = null;
        } catch (Exception e) {
            Logger.error("Error disconnecting from proxy server.");
        }
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 67 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class ActivityDataHelper method get.

/**
 * Retrieves the Workflow of the given Item, searches the Activity using the activity path and
 * retrieves a single value based on XPath
 */
@Override
public String get(ItemPath itemPath, String actContext, String dataPath, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
    Logger.msg(5, "ActivityDataHelper.get() - item:" + itemPath + ", actContext:" + actContext + ", dataPath:" + dataPath);
    String[] paths = dataPath.split(":");
    if (paths.length != 2)
        throw new InvalidDataException("Invalid path '" + dataPath + "' it must have one and only one colon (:)");
    String actPath = paths[0];
    String xpath = paths[1];
    if (actPath.startsWith(".")) {
        actPath = actContext + (actContext.endsWith("/") ? "" : "/") + actPath.substring(2);
    }
    // Find the referenced activity, so get the workflow and search
    Workflow workflow = (Workflow) Gateway.getStorage().get(itemPath, ClusterType.LIFECYCLE + "/workflow", locker);
    GraphableVertex act = workflow.search(actPath);
    if (act == null) {
        throw new InvalidDataException("Workflow search failed for actPath:" + actPath + " - item:" + itemPath + ", actContext:" + actContext + ", dataPath:" + dataPath);
    }
    // Get the schema and viewpoint names
    String schemaName = act.getBuiltInProperty(SCHEMA_NAME).toString();
    Integer schemaVersion = Integer.valueOf(act.getBuiltInProperty(SCHEMA_VERSION).toString());
    String viewName = act.getBuiltInProperty(VIEW_POINT).toString();
    if (StringUtils.isBlank(viewName))
        viewName = "last";
    // checks if schema/version was correct
    Schema schema = LocalObjectLoader.getSchema(schemaName, schemaVersion);
    // get the viewpoint and outcome
    Viewpoint view = (Viewpoint) Gateway.getStorage().get(itemPath, ClusterType.VIEWPOINT + "/" + schema.getName() + "/" + viewName, locker);
    Outcome outcome = (Outcome) view.getOutcome(locker);
    // apply the XPath to its outcome
    try {
        return outcome.getFieldByXPath(xpath);
    } catch (XPathExpressionException e) {
        throw new InvalidDataException("Invalid xpath:" + xpath + " - item:" + itemPath + ", actContext:" + actContext + ", dataPath:" + dataPath);
    }
}
Also used : Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Schema(org.cristalise.kernel.persistency.outcome.Schema) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) GraphableVertex(org.cristalise.kernel.graph.model.GraphableVertex) Workflow(org.cristalise.kernel.lifecycle.instance.Workflow)

Example 68 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class Gateway method login.

/**
 * Authenticates the agent using the configured {@link Authenticator}
 *
 * @param agentName the name of the agent
 * @param agentPassword the password of the agent
 * @param resource check {@link Authenticator#authenticate(String, String, String)}
 * @return AgentProxy representing the logged in user/agent
 *
 * @throws InvalidDataException - bad params
 * @throws ObjectNotFoundException - object not found
 */
public static AgentProxy login(String agentName, String agentPassword, String resource) throws InvalidDataException, ObjectNotFoundException {
    Authenticator auth = getAuthenticator();
    if (!auth.authenticate(agentName, agentPassword, resource))
        throw new InvalidDataException("Login failed");
    // find agent proxy
    AgentPath agentPath = mLookup.getAgentPath(agentName);
    AgentProxy agent = (AgentProxy) mProxyManager.getProxy(agentPath);
    agent.setAuthObj(auth);
    return agent;
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) Authenticator(org.cristalise.kernel.process.auth.Authenticator)

Example 69 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class Gateway method connect.

/**
 * Connects to the Lookup server in an administrative context - using the admin username and
 * password available in the implementation of the Authenticator. It shall be
 * used in server processes only.
 *
 * @throws InvalidDataException - bad params
 * @throws PersistencyException - error starting storages
 * @throws ObjectNotFoundException - object not found
 */
public static Authenticator connect() throws InvalidDataException, PersistencyException, ObjectNotFoundException {
    try {
        Authenticator auth = getAuthenticator();
        if (!auth.authenticate("System"))
            throw new InvalidDataException("Server authentication failed");
        if (mLookup != null)
            mLookup.close();
        mLookup = (Lookup) mC2KProps.getInstance("Lookup");
        mLookup.open(auth);
        mStorage = new TransactionManager(auth);
        mProxyManager = new ProxyManager();
        Logger.msg("Gateway.connect() - DONE.");
        return auth;
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        Logger.error(ex);
        throw new InvalidDataException("Cannot connect server process. Please check config.");
    }
}
Also used : TransactionManager(org.cristalise.kernel.persistency.TransactionManager) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ProxyManager(org.cristalise.kernel.entity.proxy.ProxyManager) Authenticator(org.cristalise.kernel.process.auth.Authenticator)

Example 70 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class StandardClient method getRequiredStateMachine.

/**
 * CRISTAL-iSE clients should use the StateMachine information to implement application logic. This method loads the
 * required StateMachine using different cristal-ise configuration.
 *
 * @param propPrefix the Property Name prefix to find client specific configuration
 * @param namesSpaceDefault default value to load bootstrap file if no configuration was provided
 * @param bootfileDefault default value to load bootstrap file if no configuration was provided
 * @return the initialised StateMachine object
 * @throws InvalidDataException Missing/Incorrect configuration data
 */
protected static StateMachine getRequiredStateMachine(String propPrefix, String namesSpaceDefault, String bootfileDefault) throws InvalidDataException {
    if (StringUtils.isBlank(propPrefix))
        throw new InvalidDataException("propertyPrefix must contain a value");
    String smName = Gateway.getProperties().getString(propPrefix + ".StateMachine.name");
    int smVersion = Gateway.getProperties().getInt(propPrefix + ".StateMachine.version");
    try {
        if (StringUtils.isNotBlank(smName) && smVersion != -1) {
            return LocalObjectLoader.getStateMachine(smName, smVersion);
        } else {
            Logger.warning("StandardClient.getRequiredStateMachine() - SM Name and/or Version was not specified, trying to load from bootsrap resource.");
            String stateMachineNS = Gateway.getProperties().getString(propPrefix + ".StateMachine.namespace", namesSpaceDefault);
            String stateMachinePath = Gateway.getProperties().getString(propPrefix + ".StateMachine.bootfile", bootfileDefault);
            return (StateMachine) Gateway.getMarshaller().unmarshall(Gateway.getResource().getTextResource(stateMachineNS, stateMachinePath));
        }
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException(e.getMessage());
    }
}
Also used : StateMachine(org.cristalise.kernel.lifecycle.instance.stateMachine.StateMachine) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Aggregations

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)91 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)40 PersistencyException (org.cristalise.kernel.common.PersistencyException)33 IOException (java.io.IOException)14 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)11 DomainPath (org.cristalise.kernel.lookup.DomainPath)10 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 CannotManageException (org.cristalise.kernel.common.CannotManageException)8 AgentPath (org.cristalise.kernel.lookup.AgentPath)8 Schema (org.cristalise.kernel.persistency.outcome.Schema)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)7 ItemPath (org.cristalise.kernel.lookup.ItemPath)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 MappingException (org.exolab.castor.mapping.MappingException)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 ArrayList (java.util.ArrayList)5 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5