Search in sources :

Example 56 with UserException

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

the class ProxyMap method store.

@Override
public void store() throws MappableException, UserException {
    if (server == null)
        throw new UserException(-1, "ProxyMap error: no server URI specified, e.g. localhost/servlet/Postman");
    try {
        ClientInterface nc = NavajoClientFactory.createClient();
        inMessage.removeHeader();
        nc.setUsername(username == null ? access.rpcUser : username);
        nc.setPassword(password == null ? access.rpcPwd : password);
        nc.setAllowCompression(true);
        nc.setServerUrl(server);
        Navajo out = nc.doSimpleSend(inMessage, (method == null ? access.rpcName : method));
        access.setOutputDoc(out);
    } catch (Exception e) {
        throw new UserException(-1, e.getMessage());
    }
}
Also used : UserException(com.dexels.navajo.script.api.UserException) ClientInterface(com.dexels.navajo.client.ClientInterface) Navajo(com.dexels.navajo.document.Navajo) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 57 with UserException

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

the class RESTAdapter method setDoSend.

@Override
public void setDoSend(String method) throws UserException, ConditionErrorException, SystemException {
    if (messagesPerRequest < 1 || useCurrentMessages == null) {
        setDoSend(method, prepareOutDoc());
        serviceCalled = true;
    } else {
        String[] messages = useCurrentMessages.split(",");
        Navajo copy = outDoc.copy();
        Navajo indoc = null;
        if (inDoc == null) {
            indoc = NavajoFactory.getInstance().createNavajo();
        } else {
            indoc = inDoc.copy();
        }
        for (String msgName : messages) {
            Message msg = access.getOutputDoc().getMessage(msgName);
            if (msg != null && msg.isArrayMessage()) {
                Message outMsg = NavajoFactory.getInstance().createMessage(outDoc, msgName);
                outMsg.setType("array");
                int counter = 0;
                int totalCounter = 0;
                for (Message element : msg.getElements()) {
                    outMsg.addElement(element);
                    counter++;
                    totalCounter++;
                    if (counter >= messagesPerRequest || totalCounter >= msg.getArraySize()) {
                        outDoc.addMessage(outMsg);
                        setDoSend(method, outDoc);
                        indoc.merge(inDoc);
                        // Going to clear data
                        outDoc = copy.copy();
                        outMsg = NavajoFactory.getInstance().createMessage(outDoc, msgName);
                        outMsg.setType("array");
                        counter = 0;
                    }
                }
                inDoc = indoc.copy();
            } else {
                throw new UserException(2, "Message " + msgName + "not found or not array message!");
            }
        }
        serviceCalled = true;
    }
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) UserException(com.dexels.navajo.script.api.UserException)

Example 58 with UserException

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

the class AsyncProxyMap method run.

@Override
public void run() throws UserException {
    Header h = outDoc.getHeader();
    if (h == null) {
        h = NavajoFactory.getInstance().createHeader(outDoc, method, username, password, -1);
        outDoc.addHeader(h);
    } else {
        h.setRPCName(method);
        h.setRPCPassword(password);
        h.setRPCUser(username);
    }
    // Clear request id.
    h.setRequestId(null);
    try {
        inDoc = DispatcherFactory.getInstance().handle(outDoc);
    } catch (Exception e) {
        throw new UserException(-1, e.getMessage(), e);
    } finally {
        logger.info("Setting set is finished.");
        setIsFinished();
    }
}
Also used : Header(com.dexels.navajo.document.Header) UserException(com.dexels.navajo.script.api.UserException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 59 with UserException

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

the class AccessMap method setAccessId.

public void setAccessId(String id) throws UserException {
    this.accessId = id;
    if (accessId == null) {
        throw new UserException(-1, "Set accessId first");
    }
    Set<Access> all = com.dexels.navajo.server.DispatcherFactory.getInstance().getAccessSet();
    Iterator<Access> iter = all.iterator();
    while (iter.hasNext()) {
        Access a = iter.next();
        if (a.accessID.equals(accessId)) {
            this.myAccess = a;
            showDetails = true;
        }
    }
    if (!(showDetails)) {
        // Try async store
        myAccess = com.dexels.navajo.mapping.AsyncStore.getInstance().accessStore.get(id);
        if (myAccess != null) {
            showDetails = true;
        }
    }
}
Also used : Access(com.dexels.navajo.script.api.Access) UserException(com.dexels.navajo.script.api.UserException)

Example 60 with UserException

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

the class CSVMap method store.

@Override
public void store() throws MappableException, UserException {
    if (draftEntries != null) {
        entries = new CSVEntryMap[draftEntries.size()];
        int i = 0;
        for (CSVEntryMap ce : draftEntries) {
            entries[i++] = ce;
        }
    }
    if (update && entries != null) {
        try (FileWriter writer = new FileWriter(fileName)) {
            // Write CSV.
            for (int i = 0; i < entries.length; i++) {
                CSVEntryMap e = entries[i];
                for (int j = 0; j < e.entries.length; j++) {
                    writer.write(e.getEntry(Integer.valueOf(j)));
                    if (j < (e.entries.length - 1))
                        writer.write(separator);
                }
                if (i < (entries.length - 1))
                    writer.write("\n");
            }
            writer.close();
        } catch (IOException ioe) {
            throw new UserException(-1, ioe.getMessage());
        }
    }
}
Also used : CSVEntryMap(com.dexels.navajo.adapter.csvmap.CSVEntryMap) FileWriter(java.io.FileWriter) IOException(java.io.IOException) UserException(com.dexels.navajo.script.api.UserException)

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