use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class IdentityResponseWrapper method processResponse.
@Override
public void processResponse(HttpServletRequest originalRequest, Navajo indoc, Navajo outDoc, HttpServletResponse originalResponse) throws IOException {
String sendEncoding = originalRequest.getHeader("Accept-Encoding");
boolean useSendCompression = ((sendEncoding != null) && (sendEncoding.indexOf("zip") != -1));
if (useSendCompression) {
originalResponse.setContentType("text/xml; charset=UTF-8");
originalResponse.setHeader("Content-Encoding", "gzip");
java.util.zip.GZIPOutputStream gzipout = new java.util.zip.GZIPOutputStream(originalResponse.getOutputStream());
Document laszlo = NavajoLaszloConverter.createLaszloFromNavajo(outDoc, indoc.getHeader().getRPCName());
XMLDocumentUtils.write(laszlo, new OutputStreamWriter(gzipout), false);
gzipout.close();
} else {
originalResponse.setContentType("text/xml; charset=UTF-8");
OutputStream out = originalResponse.getOutputStream();
try {
outDoc.write(out);
} catch (NavajoException e) {
logger.error("Error: ", e);
}
out.close();
}
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class BareTestCase method addProperty.
protected final Property addProperty(Navajo n, String path, Object value) {
if (path.indexOf("/") == -1) {
fail("Illegal path: " + path);
}
String messagePath = path.substring(0, path.lastIndexOf("/"));
Message parent = addMessage(n, messagePath);
assertNotNull(parent);
String propertyName = path.substring(path.lastIndexOf("/") + 1, path.length());
Property p;
try {
p = NavajoFactory.getInstance().createProperty(n, propertyName, Property.STRING_PROPERTY, "", 99, "", Property.DIR_IN);
parent.addProperty(p);
p.setAnyValue(value);
return p;
} catch (NavajoException e) {
logger.error("Error: ", e);
fail(e.getMessage());
}
return null;
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class QueryMap method store.
@Override
public void store() throws MappableException, UserException {
// Construct Navajo message.
try {
Message recordSet = NavajoFactory.getInstance().createMessage(outputDoc, "RecordSet", Message.MSG_TYPE_ARRAY);
try {
outputDoc.addMessage(recordSet);
} catch (NavajoException ex) {
throw new UserException(-1, ex.getMessage(), ex);
}
ResultSetMap[] resultSet = getResultSet();
for (int i = 0; i < resultSet.length; i++) {
Message record = NavajoFactory.getInstance().createMessage(outputDoc, "RecordSet", Message.MSG_TYPE_ARRAY_ELEMENT);
recordSet.addElement(record);
RecordMap[] columns = resultSet[i].getRecords();
for (int j = 0; j < columns.length; j++) {
try {
Object value = columns[j].getRecordValue();
String type = (value != null ? MappingUtils.determineNavajoType(value) : "unknown");
Property prop = NavajoFactory.getInstance().createProperty(outputDoc, columns[j].recordName, type, null, 0, "", Property.DIR_IN);
prop.setAnyValue(value);
record.addProperty(prop);
} catch (Exception ex1) {
throw new UserException(-1, ex1.getMessage(), ex1);
}
}
}
} finally {
super.store();
}
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class NavajoMap method setAppend.
/**
* Set this to a valid message path if the result of the webservices needs to be appended. If messageOffset = "/" the entire result will be appended to the
* current output message pointer.
*
* @param b
* @throws UserException
*
* TODO: FINISH THIS. IMPLEMENT CLONE METHOD IN MESSAGE IMPLEMENTATION(!!)
*
* (!)if messageOffset is '', the received inDoc document will become the new output document for the Navajo service. if messageOffset is '/',
* the messages of the received inDoc will be appended to the output document.
*/
public final void setAppend(String messageOffset) throws UserException {
waitForResult();
if (messageOffset.equals("")) {
access.setOutputDoc(inDoc);
return;
}
try {
Navajo currentDoc = access.getOutputDoc();
Message currentMsg = access.getCurrentOutMessage();
List<Message> list = null;
// If append message equals '/'.
if (messageOffset.equals(Navajo.MESSAGE_SEPARATOR)) {
list = inDoc.getAllMessages();
} else if (inDoc.getMessage(messageOffset) == null) {
return;
} else if (!inDoc.getMessage(messageOffset).getType().equals(Message.MSG_TYPE_ARRAY)) {
list = new ArrayList<>();
list.add(inDoc.getMessage(messageOffset));
} else {
// For array messages...
list = new ArrayList<>();
list.add(inDoc.getMessage(messageOffset));
}
// If no messages were found, there is nothing to append
if (list.isEmpty()) {
return;
}
/**
* appendTo logic. If appendTo ends with '/' append the entire append message to the defined appendTo message. If appendTo does not end with '/',
* merge the append message with the defined appendTo message.
*/
boolean appendToComplete = (appendTo != null && !appendTo.equals(Navajo.MESSAGE_SEPARATOR) && appendTo.endsWith(Navajo.MESSAGE_SEPARATOR));
if (appendToComplete) {
// Strip last "/".
appendTo = appendTo.substring(0, appendTo.length() - 1);
}
// Check whether incoming array message needs to be expanded: if not
// appendToComplete and if appendTo is defined and
// appendTo is array message.
boolean appendToIsArray = false;
if (appendTo != null && currentMsg != null && currentMsg.getMessage(appendTo) != null && currentMsg.getMessage(appendTo).getType().equals(Message.MSG_TYPE_ARRAY)) {
appendToIsArray = true;
}
if (appendTo != null && currentDoc.getMessage(appendTo) != null && currentDoc.getMessage(appendTo).getType().equals(Message.MSG_TYPE_ARRAY)) {
appendToIsArray = true;
}
if (!appendToComplete && appendTo != null && list != null && list.get(0) != null && list.get(0).getType().equals(Message.MSG_TYPE_ARRAY) && appendToIsArray) {
// Expand list if it contains an array message.
list = list.get(0).getAllMessages();
}
if (list == null) {
logger.warn("Can not append: appendTo target can not be found");
return;
}
for (int i = 0; i < list.size(); i++) {
Message inMsg = list.get(i);
// Clone message and append it to currentMsg if it exists, else
// directly under currentDoc.
// currentDoc.importMessage(inMsg)
Message clone = inDoc.copyMessage(inMsg, currentDoc);
if (currentMsg != null) {
if (appendTo != null) {
if (appendTo.equals(Navajo.MESSAGE_SEPARATOR)) {
if (clone.getName().equals(currentMsg.getName())) {
currentMsg.merge(clone);
} else {
currentDoc.addMessage(clone, true);
}
} else if (currentMsg.getMessage(appendTo) != null) {
if (currentMsg.getMessage(appendTo).getType().equals(Message.MSG_TYPE_ARRAY)) {
// For
// array
// messages
// do
// not
// overwrite.
currentMsg.getMessage(appendTo).addMessage(clone);
} else {
if (appendToComplete) {
currentMsg.getMessage(appendTo).addMessage(clone);
} else {
currentMsg.getMessage(appendTo).merge(clone);
}
}
} else {
throw new UserException(-1, "Unknown appendTo message: " + appendTo);
}
} else {
// Merge message with existing message.
if (clone.getName().equals(currentMsg.getName())) {
currentMsg.merge(clone);
} else {
currentMsg.addMessage(clone, true);
}
}
} else {
if (appendTo != null) {
if (appendTo.equals(Navajo.MESSAGE_SEPARATOR)) {
currentDoc.addMessage(clone, true);
} else if (currentDoc.getMessage(appendTo) != null) {
if (currentDoc.getMessage(appendTo).getType().equals(Message.MSG_TYPE_ARRAY)) {
// For
// array
// messages
// do
// not
// overwrite.
currentDoc.getMessage(appendTo).addMessage(clone);
} else {
if (appendToComplete) {
currentDoc.getMessage(appendTo).addMessage(clone);
} else {
currentDoc.getMessage(appendTo).merge(clone);
}
}
} else {
throw new UserException(-1, "Unknown appendTo message: " + appendTo);
}
} else {
// existing message.
if (currentDoc.getMessage(clone.getName()) != null) {
currentDoc.getMessage(clone.getName()).merge(clone);
} else {
currentDoc.addMessage(clone, true);
}
}
}
}
} catch (NavajoException ne) {
throw new UserException(-1, ne.getMessage());
}
}
use of com.dexels.navajo.document.NavajoException 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);
}
}
Aggregations