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.");
}
}
}
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);
}
}
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;
}
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.");
}
}
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());
}
}
Aggregations