Search in sources :

Example 86 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class NavajoMap method setDoSend.

/**
 * Use this method to call another Navajo webservice. If server is not specified, the Navajo server that is used to handle this request is also used to
 * handle the new request.
 *
 * @param method
 * @throws UserException
 */
public void setDoSend(String method, Navajo od) throws UserException, ConditionErrorException, SystemException {
    if (serviceCalled) {
        logger.warn("DO NOT USE A NAVAJOMAP TO CALL A SECOND WEBSERVICE, USE NEW NAVAJOMAP INSTEAD");
    }
    // Reset current msgPointer when performing new doSend.
    msgPointer = null;
    setMethod(method);
    this.outDoc = od;
    this.username = (username == null) ? this.access.rpcUser : username;
    this.password = (password == null) ? this.access.rpcPwd : password;
    this.method = method;
    if (password == null)
        password = "";
    try {
        if (this.resource != null) {
            serviceCalled = true;
            AsyncClient ac = NavajoClientResourceManager.getInstance().getAsyncClient(this.resource);
            if (ac == null) {
                throw new UserException(-1, "No external resource found for: " + this.resource);
            }
            ac.callService(outDoc, method, this);
        } else if (server != null) {
            // External request.
            try {
                ManualAsyncClient ac = AsyncClientFactory.getManualInstance();
                if (ac == null) {
                    logger.warn("unable to find async client - cannot perform navajomap call!");
                    throw new UserException(-1, "AsyncClient null");
                }
                String server = this.server.startsWith("http") ? this.server : "http://" + this.server;
                Integer timeout = null;
                if (serverTimeout > -1) {
                    timeout = serverTimeout;
                }
                ac.callService(server, username, password, outDoc, method, this, timeout);
            } catch (Exception e) {
                throw new UserException(-1, e.getMessage(), e);
            }
            serviceCalled = true;
        } else // Internal request.
        {
            inDoc = null;
            serviceFinished = false;
            if (block) {
                this.run();
            } else {
                SchedulerRegistry.submit(this, lowPriority);
            }
            serviceCalled = true;
            if (getException() != null) {
                if (getException() instanceof ConditionErrorException) {
                    throw (ConditionErrorException) getException();
                } else if (getException() instanceof UserException) {
                    throw (UserException) getException();
                } else if (getException() instanceof SystemException) {
                    throw (SystemException) getException();
                } else {
                    throw new SystemException(-1, "", getException());
                }
            }
        }
    } catch (NavajoException | IOException e) {
        throw new SystemException("Error connecting to remote server", e);
    }
}
Also used : ConditionErrorException(com.dexels.navajo.server.ConditionErrorException) ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) SystemException(com.dexels.navajo.script.api.SystemException) NavajoException(com.dexels.navajo.document.NavajoException) UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException) AsyncClient(com.dexels.navajo.client.async.AsyncClient) ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException) ConditionErrorException(com.dexels.navajo.server.ConditionErrorException)

Example 87 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class NavajoMap method waitForResult.

protected synchronized void waitForResult() throws UserException {
    // Blocking internal request is ALWAYS synchronous, return immediately.
    if (block && (server == null && resource == null)) {
        return;
    }
    if (!serviceCalled) {
        throw new UserException(-1, "Call webservice before retrieving result.");
    }
    if (!serviceFinished) {
        // 
        synchronized (waitForResult) {
            try {
                waitForResult.wait(MAX_WAITTIME);
            } catch (InterruptedException e) {
                logger.error("WaitForResult interrupted: Error: ", e);
            }
            // We could also be here as a result of a timeout
            if (!serviceFinished) {
                logger.error("waitForResult finished but no serviceFinished! Probably result of timeout. Setting empty navajo as result", new Exception());
                serviceFinished = true;
                serviceCalled = true;
                if (inDoc == null) {
                    inDoc = NavajoFactory.getInstance().createNavajo();
                }
            }
        }
    }
    if (!block && serviceFinished && myException != null) {
        throw new UserException(-1, myException.getMessage());
    }
}
Also used : UserException(com.dexels.navajo.script.api.UserException) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException) ConditionErrorException(com.dexels.navajo.server.ConditionErrorException)

Example 88 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class NavajoMap method getMessages.

/**
 * Try to return messages from using messagePointer, if no messages are found return null.
 *
 * @return
 * @throws UserException
 */
public MessageMap[] getMessages() throws UserException {
    waitForResult();
    if (msgPointer == null)
        return null;
    if (!msgPointer.isArrayMessage())
        throw new UserException(-1, "getMessages can only be used for array messages");
    try {
        List<Message> all = msgPointer.getAllMessages();
        if ((all == null))
            throw new UserException(-1, "Could not find messages: " + messagePointerString + " in response document");
        messages = new MessageMap[all.size()];
        for (int i = 0; i < all.size(); i++) {
            MessageMap msg = new MessageMap();
            msg.setMsg(all.get(i));
            messages[i] = msg;
        }
        return messages;
    } catch (Exception e) {
        throw new UserException(-1, e.getMessage());
    }
}
Also used : Message(com.dexels.navajo.document.Message) UserException(com.dexels.navajo.script.api.UserException) MessageMap(com.dexels.navajo.adapter.navajomap.MessageMap) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException) ConditionErrorException(com.dexels.navajo.server.ConditionErrorException)

Example 89 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class NavajoMap method getNavajo.

/**
 * Gets the Navajo object. If inDoc is present return inDoc, else return inMessage (request Navajo).
 *
 * @return
 * @throws UserException
 */
public Binary getNavajo() throws UserException {
    Binary b = new Binary();
    OutputStream is = b.getOutputStream();
    try {
        if (inDoc != null) {
            inDoc.write(is);
        } else {
            inMessage.write(is);
        }
        is.close();
    } catch (Exception e) {
        throw new UserException(-1, e.getMessage());
    }
    return b;
}
Also used : OutputStream(java.io.OutputStream) Binary(com.dexels.navajo.document.types.Binary) UserException(com.dexels.navajo.script.api.UserException) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException) ConditionErrorException(com.dexels.navajo.server.ConditionErrorException)

Example 90 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class NavajoMap method setPropertyName.

public void setPropertyName(String fullName) throws UserException {
    currentFullName = ((messagePointerString == null || messagePointerString.equals("")) ? fullName : messagePointerString + "/" + ((fullName.length() > 0 && fullName.charAt(0) == '/' ? fullName.substring(1) : fullName)));
    String propName = MappingUtils.getStrippedPropertyName(fullName);
    try {
        if (msgPointer != null)
            currentProperty = msgPointer.getProperty(fullName);
        else
            currentProperty = outDoc.getProperty(fullName);
        if (currentProperty == null) {
            currentProperty = NavajoFactory.getInstance().createProperty(outDoc, propName, Property.STRING_PROPERTY, "", 25, "", Property.DIR_IN);
        }
    } catch (Exception e) {
        e.printStackTrace(Access.getConsoleWriter(access));
        throw new UserException(-1, e.getMessage());
    }
}
Also used : UserException(com.dexels.navajo.script.api.UserException) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException) ConditionErrorException(com.dexels.navajo.server.ConditionErrorException)

Aggregations

UserException (com.dexels.navajo.script.api.UserException)113 MappableException (com.dexels.navajo.script.api.MappableException)54 IOException (java.io.IOException)33 NavajoException (com.dexels.navajo.document.NavajoException)25 Message (com.dexels.navajo.document.Message)22 SQLException (java.sql.SQLException)19 SystemException (com.dexels.navajo.script.api.SystemException)18 Binary (com.dexels.navajo.document.types.Binary)14 ConditionErrorException (com.dexels.navajo.server.ConditionErrorException)13 Property (com.dexels.navajo.document.Property)12 ArrayList (java.util.ArrayList)12 Navajo (com.dexels.navajo.document.Navajo)11 AuthorizationException (com.dexels.navajo.script.api.AuthorizationException)11 ResultSet (java.sql.ResultSet)11 MappingException (com.dexels.navajo.script.api.MappingException)10 ResultSetMetaData (java.sql.ResultSetMetaData)9 Element (org.w3c.dom.Element)8 CompilationException (com.dexels.navajo.script.api.CompilationException)7 File (java.io.File)7 NodeList (org.w3c.dom.NodeList)7