Search in sources :

Example 6 with InterlokException

use of com.adaptris.interlok.InterlokException in project interlok by adaptris.

the class InterlokJmxClientTest method testMessageTarget_NoWorkflow.

@Test
public void testMessageTarget_NoWorkflow() throws Exception {
    MyMessageProcessor proc = new MyMessageProcessor();
    DefaultSerializableMessage msg = new DefaultSerializableMessage().withPayload(testName.getMethodName());
    register(createObjectName(new MessageTarget().withAdapter(testName.getMethodName()).withChannel(testName.getMethodName()).withWorkflow(testName.getMethodName())), proc);
    MessageTarget notFound = new MessageTarget().withAdapter(testName.getMethodName()).withChannel(testName.getMethodName()).withWorkflow("abcde");
    InterlokJmxClient client = new InterlokJmxClient(jmxConnectorServer.getAddress());
    try {
        client.connect();
        client.processAsync(notFound, msg);
        fail();
    } catch (InterlokException expected) {
        assertTrue(expected.getMessage().endsWith(" does not narrow to a single workflow"));
    } finally {
        client.disconnect();
    }
}
Also used : MessageTarget(com.adaptris.interlok.client.MessageTarget) InterlokException(com.adaptris.interlok.InterlokException) DefaultSerializableMessage(com.adaptris.interlok.types.DefaultSerializableMessage) Test(org.junit.Test)

Example 7 with InterlokException

use of com.adaptris.interlok.InterlokException in project interlok by adaptris.

the class InterlokJmxClientTest method testMessageTarget_Wildcard.

@Test
public void testMessageTarget_Wildcard() throws Exception {
    MyMessageProcessor proc = new MyMessageProcessor();
    MyMessageProcessor proc2 = new MyMessageProcessor();
    MessageTarget target1 = new MessageTarget().withAdapter(testName.getMethodName()).withChannel(testName.getMethodName()).withWorkflow(testName.getMethodName());
    MessageTarget target2 = new MessageTarget().withAdapter(testName.getMethodName()).withChannel(testName.getMethodName()).withWorkflow(testName.getMethodName() + "2");
    DefaultSerializableMessage msg = new DefaultSerializableMessage().withPayload(testName.getMethodName());
    register(createObjectName(target1), proc);
    register(createObjectName(target2), proc2);
    MessageTarget wildcard = new MessageTarget().withAdapter(testName.getMethodName()).withChannel(testName.getMethodName()).withWorkflow("*");
    InterlokJmxClient client = new InterlokJmxClient(jmxConnectorServer.getAddress());
    try {
        client.connect();
        client.processAsync(wildcard, msg);
        fail();
    } catch (InterlokException expected) {
        assertTrue(expected.getMessage().endsWith(" does not narrow to a single workflow"));
    } finally {
        client.disconnect();
    }
}
Also used : MessageTarget(com.adaptris.interlok.client.MessageTarget) InterlokException(com.adaptris.interlok.InterlokException) DefaultSerializableMessage(com.adaptris.interlok.types.DefaultSerializableMessage) Test(org.junit.Test)

Example 8 with InterlokException

use of com.adaptris.interlok.InterlokException in project interlok by adaptris.

the class ExceptionAsStringReportTest method testDoService_Payload_Exception.

@Test
public void testDoService_Payload_Exception() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception("This is the exception"));
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsString().withTarget(new DataOutputParameter<String>() {

        @Override
        public void insert(String data, InterlokMessage msg) throws InterlokException {
            throw new CoreException();
        }
    }));
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : DataOutputParameter(com.adaptris.interlok.config.DataOutputParameter) MetadataDataOutputParameter(com.adaptris.core.common.MetadataDataOutputParameter) CoreException(com.adaptris.core.CoreException) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InterlokMessage(com.adaptris.interlok.types.InterlokMessage) CoreException(com.adaptris.core.CoreException) ServiceException(com.adaptris.core.ServiceException) InterlokException(com.adaptris.interlok.InterlokException) Test(org.junit.Test)

Example 9 with InterlokException

use of com.adaptris.interlok.InterlokException in project interlok by adaptris.

the class FilesystemRetryStore method getMetadata.

@Override
public Map<String, String> getMetadata(String msgId) throws InterlokException {
    try {
        File dir = validateMsgId(msgId, true);
        File metaFile = FsWorker.isFile(FsWorker.checkReadable(new File(dir, METADATA_FILE_NAME)));
        Properties meta = new Properties();
        try (InputStream in = new FileInputStream(metaFile)) {
            meta.load(in);
        }
        // The compiler works in mysterious ways.
        return (Map) meta;
    } catch (Exception e) {
        throw ExceptionHelper.wrapInterlokException(e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) File(java.io.File) Map(java.util.Map) FileInputStream(java.io.FileInputStream) InterlokException(com.adaptris.interlok.InterlokException) CoreException(com.adaptris.core.CoreException)

Example 10 with InterlokException

use of com.adaptris.interlok.InterlokException in project interlok by adaptris.

the class FilesystemRetryStore method write.

@Override
public void write(AdaptrisMessage msg) throws InterlokException {
    try {
        File dir = validateMsgId(msg.getUniqueId(), false);
        log.trace("Created [{}]", dir.getCanonicalPath());
        File payloadFile = new File(dir, PAYLOAD_FILE_NAME);
        File metadataFile = new File(dir, METADATA_FILE_NAME);
        File exceptionFile = new File(dir, STACKTRACE_FILENAME);
        storePayload(msg, payloadFile);
        storeMetadata(msg, metadataFile);
        storeException(msg, exceptionFile);
    } catch (Exception e) {
        throw ExceptionHelper.wrapInterlokException(e);
    }
}
Also used : File(java.io.File) InterlokException(com.adaptris.interlok.InterlokException) CoreException(com.adaptris.core.CoreException)

Aggregations

InterlokException (com.adaptris.interlok.InterlokException)11 Test (org.junit.Test)6 CoreException (com.adaptris.core.CoreException)5 File (java.io.File)4 IOException (java.io.IOException)3 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)2 MessageTarget (com.adaptris.interlok.client.MessageTarget)2 DefaultSerializableMessage (com.adaptris.interlok.types.DefaultSerializableMessage)2 InterlokMessage (com.adaptris.interlok.types.InterlokMessage)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ServiceException (com.adaptris.core.ServiceException)1 MetadataDataOutputParameter (com.adaptris.core.common.MetadataDataOutputParameter)1 FileBackedMessage (com.adaptris.core.lms.FileBackedMessage)1 ExceptionHelper.rethrowInterlokException (com.adaptris.interlok.client.jmx.ExceptionHelper.rethrowInterlokException)1 RemoteBlob (com.adaptris.interlok.cloud.RemoteBlob)1 DataOutputParameter (com.adaptris.interlok.config.DataOutputParameter)1 MessageProcessor (com.adaptris.interlok.management.MessageProcessor)1 FileOutputStream (java.io.FileOutputStream)1