use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class BaseRequestImpl method parseInputNavajo.
protected final Navajo parseInputNavajo(InputStream is) throws IOException {
BufferedReader r;
Navajo in = null;
logger.debug("Parsing using encoding: {}", contentEncoding);
if (contentEncoding != null && contentEncoding.equals(AsyncRequest.COMPRESS_JZLIB)) {
r = new BufferedReader(new java.io.InputStreamReader(new InflaterInputStream(is), StandardCharsets.UTF_8));
} else if (contentEncoding != null && contentEncoding.equals(AsyncRequest.COMPRESS_GZIP)) {
r = new BufferedReader(new java.io.InputStreamReader(new java.util.zip.GZIPInputStream(is), StandardCharsets.UTF_8));
} else {
r = new BufferedReader(new java.io.InputStreamReader(is, StandardCharsets.UTF_8));
}
in = NavajoFactory.getInstance().createNavajo(r);
if (in == null) {
throw new IOException("Invalid request.");
}
Header header = in.getHeader();
if (header == null) {
throw new IOException("Empty Navajo header.");
}
is.close();
return in;
}
use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class ServiceCommand method execute.
@Override
public JsonNode execute(ArticleRuntime runtime, ArticleContext context, Map<String, String> parameters, XMLElement element) throws APIException {
Long startedAt = System.currentTimeMillis();
String name = parameters.get("name");
if (name == null) {
throw new APIException("Command: " + this.getName() + " can't be executed without required parameters: " + name, null, APIErrorCode.InternalError);
}
String refresh = parameters.get("refresh");
if ("false".equals(refresh)) {
Navajo res = runtime.getNavajo(name);
if (res != null) {
runtime.pushNavajo(name, res);
return null;
}
}
String input = parameters.get("input");
Navajo n = null;
if (input != null) {
n = runtime.getNavajo(input);
if (n == null) {
throw new APIException("Command: " + this.getName() + " supplies an 'input' parameter: " + input + ", but that navajo object can not be found" + name, null, APIErrorCode.InternalError);
}
}
if (runtime.getNavajo() != null) {
n = runtime.getNavajo();
} else {
n = NavajoFactory.getInstance().createNavajo();
}
appendTokenAttributes(runtime, n);
final String username = runtime.getUsername();
Header h = NavajoFactory.getInstance().createHeader(n, name, username, "", -1);
if (runtime.getAccess() != null) {
h.setHeaderAttribute("parentaccessid", runtime.getAccess().accessID);
}
n.addHeader(h);
h.setHeaderAttribute("application", "article");
final Navajo result = performCall(runtime, name, n, runtime.getInstance());
statLogger.info("Finished {} ({}) in {}ms", h.getHeaderAttribute("parentaccessid"), name, (System.currentTimeMillis() - startedAt));
runtime.pushNavajo(name, result);
return null;
}
use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class RestTmlServlet method callDirect.
private final void callDirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
String service = request.getParameter("service");
// String type = request.getParameter("type");
String username = request.getParameter("username");
String password = request.getParameter("password");
logger.info(">in callDirect(): service = " + service + ", username = " + username + " class: " + getClass().getName());
if (service == null) {
// logger.info("Empty service specified, request originating from "
// + request.getRemoteHost());
logger.info("thread = " + Thread.currentThread().hashCode());
logger.info("path = " + request.getPathInfo());
logger.info("query = " + request.getQueryString());
logger.info("protocol = " + request.getProtocol());
logger.info("agent = " + request.getRemoteUser());
logger.info("uri = " + request.getRequestURI());
logger.info("method = " + request.getMethod());
logger.info("contenttype = " + request.getContentType());
logger.info("scheme = " + request.getScheme());
logger.info("server = " + request.getServerName());
logger.info("port = " + request.getServerPort());
logger.info("contentlength = " + request.getContentLength());
Enumeration<String> enm = request.getHeaderNames();
while (enm.hasMoreElements()) {
String key = enm.nextElement();
String header = request.getHeader(key);
logger.info(">>" + key + "=" + header);
}
return;
}
Navajo tbMessage;
try {
tbMessage = constructFromRequest(request);
Header header = constructHeader(tbMessage, service, username, password, -1);
tbMessage.addHeader(header);
LocalClient lc = (LocalClient) getServletContext().getAttribute("localClient");
if (lc == null) {
response.sendError(500, "No navajocontext configured (in NavajoFilterServlet)");
return;
}
Navajo resultMessage = lc.call(tbMessage);
response.setContentType("text/xml");
ServletOutputStream outputStream = response.getOutputStream();
java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
response.setContentType("text/xml; charset=UTF-8");
writeOutput(resultMessage, out, service);
// resultMessage.write(out);
out.flush();
out.close();
} catch (NavajoException e) {
logger.error("Error: ", e);
} catch (FatalException e) {
logger.error("Error: ", e);
}
}
use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class TmlHttpServlet method constructFromRequest.
public static final Navajo constructFromRequest(HttpServletRequest request) throws NavajoException {
Navajo result = NavajoFactory.getInstance().createNavajo();
Enumeration<String> all = request.getParameterNames();
// Construct TML document from request parameters.
while (all.hasMoreElements()) {
String parameter = all.nextElement().toString();
if (parameter.indexOf("/") != -1) {
StringTokenizer typedParameter = new StringTokenizer(parameter, "|");
String propertyName = typedParameter.nextToken();
String type = (typedParameter.hasMoreTokens() ? typedParameter.nextToken() : Property.STRING_PROPERTY);
String value = request.getParameter(parameter);
Message msg = com.dexels.navajo.mapping.MappingUtils.getMessageObject(parameter, null, false, result, false, "", -1);
String propName = com.dexels.navajo.mapping.MappingUtils.getStrippedPropertyName(propertyName);
Property prop = null;
if (propName.indexOf(":") == -1) {
prop = NavajoFactory.getInstance().createProperty(result, propName, type, value, 0, "", Property.DIR_IN);
msg.addProperty(prop);
} else {
StringTokenizer selProp = new StringTokenizer(propName, ":");
propertyName = selProp.nextToken();
selProp.nextToken();
prop = msg.getProperty(propertyName);
if (prop == null) {
prop = NavajoFactory.getInstance().createProperty(result, propertyName, "+", "", Property.DIR_IN);
msg.addProperty(prop);
} else {
prop.setType(Property.SELECTION_PROPERTY);
prop.setCardinality("+");
}
StringTokenizer allValues = new StringTokenizer(value, ",");
while (allValues.hasMoreTokens()) {
String val = allValues.nextToken();
Selection sel = NavajoFactory.getInstance().createSelection(result, val, val, true);
prop.addSelection(sel);
}
}
}
}
String service = request.getParameter("service");
String type = request.getParameter("type");
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username == null) {
username = "empty";
password = "";
}
if ((type == null) || (type.equals(""))) {
type = "xml";
}
if (password == null) {
password = "";
}
long expirationInterval = -1;
String expiration = request.getParameter("expiration");
if ((expiration == null) || (expiration.equals(""))) {
expirationInterval = -1;
} else {
try {
expirationInterval = Long.parseLong(expiration);
} catch (Exception e) {
// System.out.println("invalid expiration interval: " +
// expiration);
}
}
Header h = NavajoFactory.getInstance().createHeader(result, service, username, password, expirationInterval);
result.addHeader(h);
return result;
}
Aggregations