Search in sources :

Example 1 with MappableException

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

the class NavajoMap method load.

@Override
public void load(Access access) throws MappableException, UserException {
    this.access = access;
    this.config = DispatcherFactory.getInstance().getNavajoConfig();
    this.inMessage = access.getInDoc();
    try {
        outDoc = NavajoFactory.getInstance().createNavajo();
    } catch (Exception e) {
        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)

Example 2 with MappableException

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

the class FileMap method setMessage.

public void setMessage(Object o) throws MappableException {
    if (o instanceof Message) {
        Message arrraymessage = (Message) o;
        if (!arrraymessage.getType().equals(Message.MSG_TYPE_ARRAY)) {
            throw new MappableException("SetMssage only accepts array message");
        }
        for (Message m : arrraymessage.getElements()) {
            FileLineMap fileLineMap = new FileLineMap();
            fileLineMap.setSeparator(separator);
            for (Property p : m.getAllProperties()) {
                fileLineMap.setColumn(p.getTypedValue().toString());
            }
            setLine(fileLineMap);
        }
    } else if (o instanceof List) {
        @SuppressWarnings("rawtypes") List maps = (List) o;
        for (Object mapobject : maps) {
            if (mapobject instanceof com.dexels.navajo.adapter.navajomap.MessageMap) {
                com.dexels.navajo.adapter.navajomap.MessageMap map = (com.dexels.navajo.adapter.navajomap.MessageMap) mapobject;
                FileLineMap fileLineMap = new FileLineMap();
                fileLineMap.setSeparator(separator);
                for (Property p : map.getMsg().getAllProperties()) {
                    if (p.getName().equals("__id")) {
                        continue;
                    }
                    if (p.getTypedValue() != null) {
                        fileLineMap.setColumn(p.getTypedValue().toString());
                    } else {
                        fileLineMap.setColumn("");
                    }
                }
                setLine(fileLineMap);
            }
        }
    } else {
        throw new MappableException("SetMessage only accepts array message or List, but got a " + o.getClass());
    }
}
Also used : MappableException(com.dexels.navajo.script.api.MappableException) Message(com.dexels.navajo.document.Message) FileLineMap(com.dexels.navajo.adapter.filemap.FileLineMap) ArrayList(java.util.ArrayList) List(java.util.List) Property(com.dexels.navajo.document.Property)

Example 3 with MappableException

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

the class IncludeMap method store.

@Override
public void store() throws MappableException, UserException {
    try {
        File f = new File(navajoObject);
        if (type == null || type.equals("tml") || type.equals("tsl")) {
            Navajo n = (type != null && type.equals("tsl") ? NavajoFactory.getInstance().createNavaScript(new FileInputStream(f)) : NavajoFactory.getInstance().createNavajo(new FileInputStream(f)));
            Message current = access.getCurrentOutMessage();
            List<Message> msgList = n.getAllMessages();
            for (int i = 0; i < msgList.size(); i++) {
                Message tbc = msgList.get(i);
                Message copy = tbc.copy(access.getOutputDoc());
                if (current != null) {
                    current.addMessage(copy);
                } else {
                    access.getOutputDoc().addMessage(copy);
                }
            }
        }
    } catch (Exception e) {
        throw new UserException(-1, e.getMessage(), e);
    }
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) UserException(com.dexels.navajo.script.api.UserException) File(java.io.File) FileInputStream(java.io.FileInputStream) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 4 with MappableException

use of com.dexels.navajo.script.api.MappableException 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 5 with MappableException

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

the class RESTAdapter method setupHttpMap.

private void setupHttpMap(HTTPMap http, Binary content) throws UserException {
    // vg
    HashMap<String, String> headers_tr = new HashMap<String, String>();
    try {
        http.load(access);
    } catch (MappableException e) {
        throw new UserException(e.getMessage(), e);
    }
    StringBuilder fullUrl = new StringBuilder(url);
    for (int i = 0; i < parameters.size(); i++) {
        if (i == 0) {
            fullUrl.append("?");
        } else {
            fullUrl.append("&");
        }
        fullUrl.append("&");
        fullUrl.append(parameters.get(i));
    }
    for (Entry<String, String> e : headers.entrySet()) {
        http.setHeaderKey(e.getKey());
        http.setHeaderValue(e.getValue());
        headers_tr.put(e.getKey(), e.getValue());
    }
    http.setUrl(fullUrl.toString());
    http.setHeaderKey("Accept");
    http.setHeaderValue("application/json");
    http.setMethod(method);
    headers_tr.put("Accept", "application/json");
    // if (method.equals("POST") || method.equals("PUT")) { //here it sets the content if the method is only POST or PUT, should I change that?
    // http.setContent(content);
    // http.setContentType("application/json");
    // http.setContentLength(content.getLength());
    // }
    http.setContent(content);
    http.setContentType("application/json");
    http.setContentLength(content.getLength());
    http.trustAll();
    if (username != null && password != null) {
        // Use HTTP Basic auth - should only be used over HTTPS!
        String authString = username + ":" + password;
        byte[] bytes = authString.getBytes(StandardCharsets.UTF_8);
        String encoded = Base64.encode(bytes, 0, bytes.length, 0, "");
        http.setHeaderKey("Authorization");
        http.setHeaderValue("Basic " + encoded);
    }
    http.setReadTimeOut(readTimeOut);
    http.setConnectTimeOut(connectTimeOut);
    if (debug) {
        StringWriter buffer = new StringWriter();
        byte[] em = http.getContent().getData();
        String s_content = new String(em);
        // output all headers, request body and the curl command.
        buffer.append("=======================DEBUG MODE HTTP REQUEST===========================").append("\n");
        buffer.append(">>>>Method: " + http.getMethod()).append("\n");
        buffer.append(">>>>Request body: " + s_content).append("\n");
        buffer.append(">>>>Headers: ").append("\n");
        // curl builder
        String c_url = "curl -X";
        c_url += http.getMethod();
        c_url += " -H \'Content-type:application/json\' ";
        // accessing all headers
        for (Entry<String, String> e : headers_tr.entrySet()) {
            buffer.append(e.getKey() + " : " + e.getValue()).append("\n");
            c_url += "-H \'" + e.getKey() + ": " + e.getValue() + "\' ";
        }
        String no_enter_content = s_content.replace("\n", "").replace("\r", "");
        // http content is a binary
        c_url += "-d \'" + no_enter_content + "\' ";
        c_url += "\'" + http.getUrl() + "\' ";
        buffer.append(">>>>cURL command: " + c_url).append("\n");
        buffer.append("==========================================================================").append("\n");
        logger.info(buffer.toString());
    }
}
Also used : MappableException(com.dexels.navajo.script.api.MappableException) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) UserException(com.dexels.navajo.script.api.UserException)

Aggregations

MappableException (com.dexels.navajo.script.api.MappableException)16 UserException (com.dexels.navajo.script.api.UserException)10 Message (com.dexels.navajo.document.Message)8 NavajoException (com.dexels.navajo.document.NavajoException)5 IOException (java.io.IOException)5 Property (com.dexels.navajo.document.Property)4 Navajo (com.dexels.navajo.document.Navajo)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 FileLineMap (com.dexels.navajo.adapter.filemap.FileLineMap)1 AttachmentMapInterface (com.dexels.navajo.adapter.mailmap.AttachmentMapInterface)1 ConnectionBrokerManager (com.dexels.navajo.adapter.sqlmap.ConnectionBrokerManager)1 RecordMap (com.dexels.navajo.adapter.sqlmap.RecordMap)1 ResultSetMap (com.dexels.navajo.adapter.sqlmap.ResultSetMap)1 SQLMapDatasourceMap (com.dexels.navajo.adapter.sqlmap.SQLMapDatasourceMap)1 ClientInterface (com.dexels.navajo.client.ClientInterface)1 Selection (com.dexels.navajo.document.Selection)1 Binary (com.dexels.navajo.document.types.Binary)1 ElasticSearchResult (com.dexels.navajo.elasticsearch.impl.ElasticSearchResult)1