use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class DecodingService method transcodeMessage.
@Override
public void transcodeMessage(AdaptrisMessage msg) throws ServiceException {
try (InputStream msgIn = msg.getInputStream();
OutputStream msgOut = msg.getOutputStream()) {
AdaptrisMessage decodedMsg = getEncoder().readMessage(msgIn);
for (MetadataElement me : decodedMsg.getMetadata()) {
if (!isOverrideMetadata() && msg.headersContainsKey(me.getKey())) {
continue;
}
msg.addMetadata(me);
}
StreamUtil.copyAndClose(decodedMsg.getInputStream(), msgOut);
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class MultipartMessageBuilder method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
MultiPartOutput output = createOutputPart(msg);
for (MimePartBuilder builder : getMimeParts()) {
MimeBodyPart part = builder.build(msg);
output.addPart(part, part.getContentID());
}
try (OutputStream out = msg.getOutputStream()) {
output.writeTo(out);
}
msg.addMetadata(CoreConstants.MSG_MIME_ENCODED, Boolean.TRUE.toString());
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class XPathService method doService.
// @Override
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
NamespaceContext namespaceContext = SimpleNamespaceContext.create(getNamespaceContext(), msg);
try {
DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(namespaceContext);
Document document = buildDocument(builder, this.getXmlSource().extract(msg));
XPath xPathHandler = XPath.newXPathInstance(builder, namespaceContext);
for (Execution execution : this.getExecutions()) {
String result = this.serializeNode(xPathHandler.selectNodeList(document, execution.getSource().extract(msg)));
execution.getTarget().insert(result, msg);
}
} catch (Exception ex) {
throw new ServiceException(ex);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class XpathNodeIdentifier method isThisSyntax.
/**
* @see SyntaxIdentifier#isThisSyntax(java.lang.String)
*/
@Override
public boolean isThisSyntax(String message) throws ServiceException {
boolean rc = true;
try {
Document d = createDocument(message);
if (d == null) {
return false;
}
XPath xp = createXPath();
for (String xpath : getPatterns()) {
Object result = null;
if (resolveAsNodeset()) {
result = xp.selectNodeList(d, xpath);
} else {
result = xp.selectSingleNode(d, xpath);
}
if (result == null) {
rc = false;
break;
}
}
} catch (Exception e) {
throw new ServiceException(e);
}
return rc;
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class AggregatingFtpConsumeServiceTest method testService_SingleFile_Failure.
@Test
public void testService_SingleFile_Failure() throws Exception {
int count = 1;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener();
FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
try {
// should be ftp://localhost/home/user/work/file0 which is created when you
// create the filesystem.
String ftpConsumeUrl = "ftp://localhost" + DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + 0;
FtpConnection conn = createConnection(server);
AggregatingFtpConsumer consumer = createConsumer(ftpConsumeUrl, null, new ReplaceWithFirstMessage());
AggregatingFtpConsumeService service = new AggregatingFtpConsumeService(conn, consumer);
AdaptrisMessage msg = new DefectiveMessageFactory().newMessage();
try {
execute(service, msg);
fail();
} catch (ServiceException expected) {
}
} finally {
server.stop();
}
}
Aggregations