Search in sources :

Example 91 with ServiceException

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);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) MetadataElement(com.adaptris.core.MetadataElement) ServiceException(com.adaptris.core.ServiceException)

Example 92 with ServiceException

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);
    }
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) OutputStream(java.io.OutputStream) MimeBodyPart(javax.mail.internet.MimeBodyPart) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 93 with ServiceException

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);
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) Execution(com.adaptris.core.common.Execution) ServiceException(com.adaptris.core.ServiceException) NamespaceContext(javax.xml.namespace.NamespaceContext) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) ServiceException(com.adaptris.core.ServiceException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 94 with ServiceException

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;
}
Also used : XPath(com.adaptris.util.text.xml.XPath) ServiceException(com.adaptris.core.ServiceException) Document(org.w3c.dom.Document) ServiceException(com.adaptris.core.ServiceException)

Example 95 with ServiceException

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();
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7