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