use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class NetStorageSender method extractResult.
@Override
public String extractResult(HttpResponseHandler responseHandler, ParameterResolutionContext prc) throws SenderException, IOException {
int statusCode = responseHandler.getStatusLine().getStatusCode();
boolean ok = false;
if (StringUtils.isNotEmpty(getResultStatusCodeSessionKey())) {
prc.getSession().put(getResultStatusCodeSessionKey(), Integer.toString(statusCode));
ok = true;
} else {
if (statusCode == HttpServletResponse.SC_OK) {
ok = true;
} else {
if (isIgnoreRedirects()) {
if (statusCode == HttpServletResponse.SC_MOVED_PERMANENTLY || statusCode == HttpServletResponse.SC_MOVED_TEMPORARILY || statusCode == HttpServletResponse.SC_TEMPORARY_REDIRECT) {
ok = true;
}
}
}
}
if (!ok) {
throw new SenderException(getLogPrefix() + "httpstatus " + statusCode + ": " + responseHandler.getStatusLine().getReasonPhrase() + " body: " + getResponseBodyAsString(responseHandler));
}
XmlBuilder result = new XmlBuilder("result");
HttpServletResponse response = (HttpServletResponse) prc.getSession().get(IPipeLineSession.HTTP_RESPONSE_KEY);
if (response == null) {
XmlBuilder statuscode = new XmlBuilder("statuscode");
statuscode.setValue(statusCode + "");
result.addSubElement(statuscode);
String responseString = getResponseBodyAsString(responseHandler);
responseString = XmlUtils.skipDocTypeDeclaration(responseString.trim());
responseString = XmlUtils.skipXmlDeclaration(responseString);
if (statusCode == HttpURLConnection.HTTP_OK) {
XmlBuilder message = new XmlBuilder("message");
message.setValue(responseString, false);
result.addSubElement(message);
} else {
// Validate Server-Time drift
String dateString = responseHandler.getHeader("Date");
if (!StringUtils.isEmpty(dateString)) {
Date currentDate = new Date();
DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
long responseDate = 0;
try {
Date date = format.parse(dateString);
responseDate = date.getTime();
} catch (Exception e) {
}
if (responseDate != 0 && currentDate.getTime() - responseDate > 30 * 1000)
throw new SenderException("Local server Date is more than 30s out of sync with Remote server");
}
XmlBuilder message = new XmlBuilder("error");
message.setValue(responseString);
result.addSubElement(message);
log.warn(String.format("Unexpected Response from Server: %d %s\n%s", statusCode, responseString, responseHandler.getHeaderFields()));
}
}
return result.toXML();
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class CmisSender method sendMessageForActionGet.
private String sendMessageForActionGet(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
if (StringUtils.isEmpty(message)) {
throw new SenderException(getLogPrefix() + "input string cannot be empty but must contain a documentId");
}
CmisObject object = null;
try {
object = session.getObject(session.createObjectId(message));
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return getResultOnNotFound();
} else {
throw new SenderException(e);
}
}
Document document = (Document) object;
ContentStream contentStream = document.getContentStream();
try {
InputStream inputStream = contentStream.getStream();
if (isStreamResultToServlet()) {
HttpServletResponse response = (HttpServletResponse) prc.getSession().get(IPipeLineSession.HTTP_RESPONSE_KEY);
String contentType = contentStream.getMimeType();
if (StringUtils.isNotEmpty(contentType)) {
log.debug(getLogPrefix() + "setting response Content-Type header [" + contentType + "]");
response.setHeader("Content-Type", contentType);
}
String contentDisposition = "attachment; filename=\"" + contentStream.getFileName() + "\"";
log.debug(getLogPrefix() + "setting response Content-Disposition header [" + contentDisposition + "]");
response.setHeader("Content-Disposition", contentDisposition);
OutputStream outputStream;
outputStream = response.getOutputStream();
Misc.streamToStream(inputStream, outputStream);
log.debug(getLogPrefix() + "copied document content input stream [" + inputStream + "] to output stream [" + outputStream + "]");
return "";
} else if (isGetProperties()) {
if (StringUtils.isNotEmpty(fileInputStreamSessionKey)) {
prc.getSession().put(getFileInputStreamSessionKey(), inputStream);
} else {
byte[] bytes = Misc.streamToBytes(inputStream);
prc.getSession().put(getFileContentSessionKey(), Base64.encodeBase64String(bytes));
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder propertiesXml = new XmlBuilder("properties");
for (Iterator it = document.getProperties().iterator(); it.hasNext(); ) {
Property property = (Property) it.next();
propertiesXml.addSubElement(getPropertyXml(property));
}
cmisXml.addSubElement(propertiesXml);
return cmisXml.toXML();
} else {
return Misc.streamToString(inputStream, null, false);
}
} catch (IOException e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class CmisSender method sendMessageForActionFind.
private String sendMessageForActionFind(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queryElement = null;
try {
if (XmlUtils.isWellFormed(message, "query")) {
queryElement = XmlUtils.buildElement(message);
} else {
queryElement = XmlUtils.buildElement("<query/>");
}
} catch (DomBuilderException e) {
throw new SenderException(e);
}
String statement = XmlUtils.getChildTagAsString(queryElement, "statement");
String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems");
String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount");
String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions");
String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions");
OperationContext operationContext = session.createOperationContext();
if (StringUtils.isNotEmpty(maxItems)) {
operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems));
}
boolean sav = false;
if (StringUtils.isNotEmpty(searchAllVersions)) {
sav = Boolean.parseBoolean(searchAllVersions);
}
if (StringUtils.isNotEmpty(includeAllowableActions)) {
operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions));
}
ItemIterable<QueryResult> q = session.query(statement, sav, operationContext);
if (StringUtils.isNotEmpty(skipCount)) {
long sc = Long.parseLong(skipCount);
q = q.skipTo(sc);
}
if (StringUtils.isNotEmpty(maxItems)) {
q = q.getPage();
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder rowsetXml = new XmlBuilder("rowset");
for (QueryResult qResult : q) {
XmlBuilder rowXml = new XmlBuilder("row");
for (PropertyData<?> property : qResult.getProperties()) {
rowXml.addSubElement(getPropertyXml(property));
}
rowsetXml.addSubElement(rowXml);
}
cmisXml.addSubElement(rowsetXml);
return cmisXml.toXML();
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class CmisSender method sendMessageForActionFetch.
private String sendMessageForActionFetch(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queryElement = null;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
queryElement = XmlUtils.buildElement(message);
} else {
queryElement = XmlUtils.buildElement("<cmis/>");
}
} catch (DomBuilderException e) {
throw new SenderException(e);
}
String objectIdstr = XmlUtils.getChildTagAsString(queryElement, "objectId");
String filter = XmlUtils.getChildTagAsString(queryElement, "filter");
boolean includeAllowableActions = XmlUtils.getChildTagAsBoolean(queryElement, "includeAllowableActions");
boolean includePolicies = XmlUtils.getChildTagAsBoolean(queryElement, "includePolicies");
boolean includeAcl = XmlUtils.getChildTagAsBoolean(queryElement, "includeAcl");
OperationContext operationContext = session.createOperationContext();
if (StringUtils.isNotEmpty(filter))
operationContext.setFilterString(filter);
operationContext.setIncludeAllowableActions(includeAllowableActions);
operationContext.setIncludePolicies(includePolicies);
operationContext.setIncludeAcls(includeAcl);
CmisObject object = null;
try {
object = session.getObject(session.createObjectId(objectIdstr), operationContext);
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return getResultOnNotFound();
} else {
throw new SenderException(e);
}
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder propertiesXml = new XmlBuilder("properties");
for (Iterator it = object.getProperties().iterator(); it.hasNext(); ) {
Property property = (Property) it.next();
propertiesXml.addSubElement(getPropertyXml(property));
}
cmisXml.addSubElement(propertiesXml);
XmlBuilder allowableActionsXml = new XmlBuilder("allowableActions");
Set<Action> actions = object.getAllowableActions().getAllowableActions();
for (Action action : actions) {
XmlBuilder actionXml = new XmlBuilder("action");
actionXml.setValue(action.value());
allowableActionsXml.addSubElement(actionXml);
}
cmisXml.addSubElement(allowableActionsXml);
XmlBuilder isExactAclXml = new XmlBuilder("isExactAcl");
if (object.getAcl() != null)
isExactAclXml.setValue(object.getAcl().isExact().toString());
cmisXml.addSubElement(isExactAclXml);
XmlBuilder policiesXml = new XmlBuilder("policyIds");
List<ObjectId> policies = object.getPolicyIds();
if (policies != null) {
for (ObjectId objectId : policies) {
XmlBuilder policyXml = new XmlBuilder("policyId");
policyXml.setValue(objectId.getId());
policiesXml.addSubElement(policyXml);
}
}
cmisXml.addSubElement(policiesXml);
XmlBuilder relationshipsXml = new XmlBuilder("relationships");
List<Relationship> relationships = object.getRelationships();
if (relationships != null) {
for (Relationship relation : relationships) {
XmlBuilder policyXml = new XmlBuilder("relation");
policyXml.setValue(relation.getId());
relationshipsXml.addSubElement(policyXml);
}
}
cmisXml.addSubElement(relationshipsXml);
return cmisXml.toXML();
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class CreateRestViewPipe method retrieveMenuBarParameter.
private String retrieveMenuBarParameter(String srcPrefix) {
XmlBuilder menuBar = new XmlBuilder("menuBar");
XmlBuilder imagelinkMenu = new XmlBuilder("imagelinkMenu");
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/showConfigurationStatus", "configurationStatus", "Show Configuration Status"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/showConfiguration", "configuration", "Show Configuration"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showLogging.do", "logging", "Show Logging"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "sendJmsMessage.do", "jms-message", "Send a message with JMS"));
if (appConstants.getBoolean("active.ifsa", false)) {
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/testIfsaService", "ifsa-message", "Call an IFSA Service"));
}
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "browseQueue.do", "browsejms", "Browse a queue with JMS"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/testPipeLine", "testPipeLine", "Test a PipeLine of an Adapter"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "testService.do", "service", "Test a ServiceListener"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "rest/webservices", "wsdl", "Webservices"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showSchedulerStatus.do", "scheduler", "Show Scheduler status"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showEnvironmentVariables.do", "properties", "Show Environment Variables"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "executeJdbcQuery.do", "execquery", "Execute a Jdbc Query"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "browseJdbcTable.do", "browsetable", "Browse a Jdbc Table"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "DumpIbisConsole", "dump", "Dump Ibis Console"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showSecurityItems.do", "security", "Show Security Items"));
if (MonitorManager.getInstance().isEnabled()) {
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showMonitors.do", "monitoring", "Show Monitors"));
}
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "showIbisstoreSummary.do", "showsummary", "Show Ibisstore Summary"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "larva", "larva", "Larva Test Tool"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "testtool", "ladybug", "Ladybug Test Tool"));
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "javascript:void(0)", "info", "Information"));
if (appConstants.getBoolean("console.active", false)) {
imagelinkMenu.addSubElement(createImagelinkElement(srcPrefix, "iaf/gui", "theme", "Try our new GUI 3.0 and leave feedback!"));
}
menuBar.addSubElement(imagelinkMenu);
return menuBar.toXML();
}
Aggregations