use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class RestListenerServlet method service.
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String path = request.getPathInfo();
String restPath = request.getServletPath();
String body = "";
if (restPath.contains("rest-public")) {
response.setHeader("Access-Control-Allow-Origin", "*");
String headers = request.getHeader("Access-Control-Request-Headers");
if (headers != null)
response.setHeader("Access-Control-Allow-Headers", headers);
response.setHeader("Access-Control-Expose-Headers", "ETag, Content-Disposition");
String pattern = sd.findMatchingPattern(path);
if (pattern != null) {
Map methodConfig = sd.getMethodConfig(pattern, "OPTIONS");
if (methodConfig == null) {
// If set, it means the adapter handles the OPTIONS request
Iterator iter = sd.getAvailableMethods(pattern).iterator();
StringBuilder sb = new StringBuilder();
// Append preflight OPTIONS request
sb.append("OPTIONS");
while (iter.hasNext()) {
sb.append(", ").append(iter.next());
}
response.setHeader("Access-Control-Allow-Methods", sb.toString());
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
response.setStatus(200);
// Preflight OPTIONS request should not return any data.
return;
}
}
}
}
String ifNoneMatch = request.getHeader("If-None-Match");
String ifMatch = request.getHeader("If-Match");
String contentType = request.getHeader("accept");
if (log.isTraceEnabled())
log.trace("path [" + path + "] If-Match [" + ifMatch + "] If-None-Match [" + ifNoneMatch + "] contentType [" + contentType + "]");
ISecurityHandler securityHandler = new HttpSecurityHandler(request);
IPipeLineSession messageContext = new PipeLineSessionBase();
messageContext.put(IPipeLineSession.securityHandlerKey, securityHandler);
Enumeration paramnames = request.getParameterNames();
while (paramnames.hasMoreElements()) {
String paramname = (String) paramnames.nextElement();
String paramvalue = request.getParameter(paramname);
if (log.isTraceEnabled())
log.trace("setting parameter [" + paramname + "] to [" + paramvalue + "]");
messageContext.put(paramname, paramvalue);
}
if (!ServletFileUpload.isMultipartContent(request)) {
body = Misc.streamToString(request.getInputStream(), "\n", false);
}
try {
log.trace("RestListenerServlet calling service [" + path + "]");
String result = sd.dispatchRequest(restPath, path, request, contentType, body, messageContext, response, getServletContext());
if (result == null && messageContext.containsKey("exitcode") && messageContext.containsKey("validateEtag")) {
int status = Integer.parseInt("" + messageContext.get("exitcode"));
response.setStatus(status);
// TODO: overbodig?
if (log.isDebugEnabled())
log.trace("aborted request with status [" + status + "]");
return;
}
String etag = (String) messageContext.get("etag");
if (StringUtils.isNotEmpty(etag))
response.setHeader("etag", etag);
int statusCode = 0;
if (messageContext.containsKey("exitcode"))
statusCode = Integer.parseInt("" + messageContext.get("exitcode"));
if (statusCode > 0)
response.setStatus(statusCode);
if (StringUtils.isEmpty(result)) {
log.trace("RestListenerServlet finished with result set in pipeline");
} else {
contentType = (String) messageContext.get("contentType");
if (StringUtils.isNotEmpty(contentType)) {
response.setHeader("Content-Type", contentType);
}
String contentDisposition = (String) messageContext.get("contentDisposition");
if (StringUtils.isNotEmpty(contentDisposition)) {
response.setHeader("Content-Disposition", contentDisposition);
}
String allowedMethods = (String) messageContext.get("allowedMethods");
if (StringUtils.isNotEmpty(allowedMethods)) {
response.setHeader("Allow", allowedMethods);
}
response.getWriter().print(result);
log.trace("RestListenerServlet finished with result [" + result + "] etag [" + etag + "] contentType [" + contentType + "] contentDisposition [" + contentDisposition + "]");
}
} catch (ListenerException e) {
log.warn("RestListenerServlet caught exception, will rethrow as ServletException", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class ServiceClassLoader method reload.
@Override
public void reload() throws ConfigurationException {
super.reload();
if (adapterName == null) {
throw new ConfigurationException("Name of adapter to provide configuration jar not specified");
}
IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
if (adapter != null) {
IPipeLineSession pipeLineSession = new PipeLineSessionBase();
PipeLineResult processResult = adapter.processMessage(getCorrelationId(), configurationName, pipeLineSession);
Object object = pipeLineSession.get("configurationJar");
if (object != null) {
if (object instanceof byte[]) {
readResources((byte[]) object, configurationName);
} else {
throw new ConfigurationException("SessionKey configurationJar not a byte array");
}
} else {
throw new ConfigurationException("SessionKey configurationJar not found");
}
} else {
throw new ConfigurationException("Could not find adapter: " + adapterName);
}
}
use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class InputOutputPipeLineProcessor method processPipeLine.
public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, String message, IPipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
if (pipeLineSession == null) {
pipeLineSession = new PipeLineSessionBase();
}
// reset the PipeLineSession and store the message and its id in the session
if (messageId == null) {
messageId = Misc.createSimpleUUID();
log.error("null value for messageId, setting to [" + messageId + "]");
}
if (message == null) {
throw new PipeRunException(null, "Pipeline of adapter [" + pipeLine.getOwner().getName() + "] received null message");
}
// store message and messageId in the pipeLineSession
pipeLineSession.put(IPipeLineSession.originalMessageKey, message);
pipeLineSession.put(IPipeLineSession.messageIdKey, messageId);
return pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
}
use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class CmisHttpSender method invoke.
public Response invoke(String url, Map<String, String> headers, Output writer, BindingSession session, BigInteger offset, BigInteger length) throws SenderException, TimeOutException {
// Prepare the message. We will overwrite things later...
this.headers = headers;
int responseCode = -1;
IPipeLineSession pls = new PipeLineSessionBase();
pls.put("writer", writer);
pls.put("url", url);
ParameterResolutionContext prc = new ParameterResolutionContext("", pls);
try {
sendMessageWithTimeoutGuarded(null, null, prc);
return (Response) pls.get("response");
} catch (Exception e) {
throw new CmisConnectionException(getUrl(), responseCode, e);
}
}
use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class XslErrorMessageFormatter method format.
@Override
public String format(String message, Throwable t, INamedObject location, String originalMessage, String messageId, long receivedTime) {
String result = super.format(message, t, location, originalMessage, messageId, receivedTime);
if (StringUtils.isNotEmpty(getStyleSheet()) || StringUtils.isNotEmpty(getXpathExpression())) {
try {
Transformer errorTransformer;
if (StringUtils.isNotEmpty(getStyleSheet())) {
errorTransformer = XmlUtils.createTransformer(ClassUtils.getResourceURL(this, styleSheet));
} else {
String xpath = getXpathExpression();
// if (StringUtils.isEmpty(xpath)) {
// xpath="/errorMessage/@message";
// }
errorTransformer = XmlUtils.createTransformer(XmlUtils.createXPathEvaluatorSource(xpath));
}
ParameterList params = getParameterList();
if (params != null) {
try {
params.configure();
} catch (ConfigurationException e) {
log.error("exception while configuring parameters", e);
}
ParameterResolutionContext prc = new ParameterResolutionContext(message, new PipeLineSessionBase());
Map<String, Object> parametervalues = null;
try {
parametervalues = prc.getValueMap(params);
} catch (ParameterException e) {
log.error("got exception extracting parameters", e);
}
XmlUtils.setTransformerParameters(errorTransformer, parametervalues);
}
result = XmlUtils.transformXml(errorTransformer, result);
} catch (IOException e) {
log.error(" cannot retrieve [" + styleSheet + "]", e);
} catch (javax.xml.transform.TransformerConfigurationException te) {
log.error("got error creating transformer from file [" + styleSheet + "]", te);
} catch (Exception tfe) {
log.error("could not transform [" + result + "] using stylesheet [" + styleSheet + "]", tfe);
}
} else
log.warn("no stylesheet defined for XslErrorMessageFormatter");
return result;
}
Aggregations