Error handling
A word about error handling
When working with the error handling inside ConnectPlaza, you have to be aware how this mechanism works. Otherwise you can get quite unexpected
behaviour. For example, in some cases the disk will fill up quite quickly, with all problems accordingly.
You can define the error handling at two levels, at the interface and at the flow level.
Interface Look
Flow look
In both cases the following two fields determine which error flow is used:
Select the default error flow, storeChannel, of type the error flow of your choice. Both fields are internally the same value.
What is the storeChannel
If you select the default storeChannel as your error flow, the exceptions will be saved as a file in the <connectplaza agent directory>/temp/storechannel directory. These files are exceptions that occur in ConnectPlaza and do not have an error handling created by the user.
In this directory you will see the files containing the exception.
If you open these files you can read the exception. This looks like this
<ConnectMessage>
<props>
<prop name="myesb-channel-id" value="storeChannel"/>
<prop name="connectmessageTimestamp" value="1658492644733"/>
<prop name="flowstart" value="3075724875528933"/>
<prop name="myesb-adapter-id" value="commonMyESBAdapter"/>
<prop name="id" value="b88a7139-df80-a5c1-b6a3-17385dfbeab2"/>
<prop name="contentType" value="application/x-www-form-urlencoded"/>
<prop name="timestamp" value="1658492644796"/>
<prop name="http_requestMethod" value="POST"/>
<prop name="myesb-component-id" value="storeProxy"/>
<prop name="connectmessageID" value="fe8069da-7cfb-4f0c-bd2b-8e84baf3f8db"/>
<prop name="history" value="connectplaza-deploy-backend-adapter.backend-channel.httpconsumer.HttpInboundGateway,connectplaza-deploy-backend-adapter.backend-channel.httpconsumer.InboundChannel,connectplaza-deploy-backend-adapter.backend-channel.InboundServiceChannel,connectplaza-deploy-backend-adapter.backend-channel.Service,errorRoutingChannel,storeChannel"/>
<prop name="myesb-componenttype-id" value="Consumer"/>
<prop name="http_requestUrl" value="http://test.connectplaza.com:8088/deploy-backend"/>
</props>
<parts>
<part id="msgprt0" index="0" type="TEXT">
<props>
</props>
<content><![CDATA[{{"controller":"DeployController","method":"getAllAgentSpecificBundles","parameters":[{"value":"agenturl","type":"java.lang.String"},{"value":"148","type":"java.lang.String"},{"value":"https://test.connectplaza.com:8444/gw/K9GA-J5R7-5EZI-9SPR-TPSM","type":"java.lang.String"}, {"value":"314","type":"java.lang.String"}],"body":null}=[]}]]></content>
</part>
<part id="exception" index="1" type="OBJECT">
<props>
<prop name="myesb-channel-id" value="backend-channel"/>
<prop name="errorChannel" value="null"/>
<prop name="flowstart" value="null"/>
<prop name="myesb-adapter-id" value="connectplaza-deploy-backend-adapter"/>
<prop name="id" value="null"/>
<prop name="contentType" value="null"/>
<prop name="timestamp" value="null"/>
<prop name="http_requestMethod" value="POST"/>
<prop name="myesb-component-id" value="__myesb-component-id__"/>
<prop name="myesb-componenttype-id" value="Service"/>
<prop name="history" value="null"/>
<prop name="replyChannel" value="null"/>
<prop name="http_requestUrl" value="http://test.connectplaza.com:8088/deploy-backend"/>
</props>
<content><![CDATA[
nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('{' (code 123)): was expecting double-quote to start field name
at [Source: (String)"{{"controller":"DeployController","method":"getAllAgentSpecificBundles","parameters":[{"value":"agenturl","type":"java.lang.String"},{"value":"148","type":"java.lang.String"},{"value":"https://test.connectplaza.com:8444/gw/K9GA-J5R7-5EZI-9SPR-TPSM","type":"java.lang.String"}, {"value":"314","type":"java.lang.String"}],"body":null}=[]}"; line: 1, column: 3]
org.springframework.messaging.MessagingException: nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('{' (code 123)): was expecting double-quote to start field name
at [Source: (String)"{{"controller":"DeployController","method":"getAllAgentSpecificBundles","parameters":[{"value":"agenturl","type":"java.lang.String"},{"value":"148","type":"java.lang.String"},{"value":"https://test.connectplaza.com:8444/gw/K9GA-J5R7-5EZI-9SPR-TPSM","type":"java.lang.String"}, {"value":"314","type":"java.lang.String"}],"body":null}=[]}"; line: 1, column: 3], failedMessage=GenericMessage [payload=ConnectMessageImpl [parts={exception=ConnectMessagePartObjectImpl [content=org.springframework.messaging.MessagingException, id=exception, partNumber=1, properties=myesb-channel-id=backend-channel,errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@671d3043,flowstart=3075724875528933,myesb-adapter-id=connectplaza-deploy-backend-adapter,id=72e0c209-9f0c-466e-6e9e-db2d309cf3e9,contentType=application/x-www-form-urlencoded,timestamp=1658492644734,http_requestMethod=POST,myesb-component-id=__myesb-component-id__,myesb-componenttype-id=Service,history=connectplaza-deploy-backend-adapter.backend-channel.httpconsumer.HttpInboundGateway,connectplaza-deploy-backend-adapter.backend-channel.httpconsumer.InboundChannel,connectplaza-deploy-backend-adapter.backend-channel.InboundServiceChannel,connectplaza-deploy-backend-adapter.backend-channel.Service,replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@671d3043,http_requestUrl=http://test.connectplaza.com:8088/deploy-backend,], msgprt0=ConnectMessagePartStringImpl [content={{"controller":"DeployController","method":"getAllAgentSpecificBundles","parameters":[{"value":"agenturl","type":"java.lang.String"},{"value":"148","type":"java.lang.String"},{"value":"https://test.connectplaza.com:8444/gw/K9GA-J5R7-5EZI-9SPR-TPSM","type":"java.lang.String"}, {"value":"314","type":"java.lang.String"}],"body":null}=[]}, id=msgprt0, partNumber=0, properties=], exception_message=ConnectMessagePartStringImpl [content=Unexpected character ('{' (code 123)): was expecting double-quote to start field name
Etc....
You can delete these files if you need to free up some space. It is wise to check these files before deleting them to check if there are unexpected exceptions and if you can do something about it with you own created error handling.
What you also need to know
What you need to know is that the error handling assigned to the interface is active for all the flows active in this interface. This is not a problem for most cases, but if you have defined the error handling to a flow present in this interface you can have issues if the error handling flow is producing errors. You will get a loop. The error handling flow is assigned the error handling flow for errors, but there are errors...... etc.
Imagine that your error handling flow has an Analyze Wiretap, all the data is written to the Analyze database, and because of the looping effect, this is a serious issue.
In the aforementioned case, it is better to set the error handling at flow level.
Sending exceptions (Objects) to your email via scripting
If you catch your error and send it to a special error_flow, you can send your exceptions to your emailaddress for instance. In this chapter I want to give you an example how to do this.
If you catch the error you check analyze, you will see a view messageparts representing the error. But the exception is an Object. This causes a problem, because you cannot email yourself an Object.
So your message is now arrived in your error flow (via de flow gateway). We send it via email to an emailadres.
To convert the java exception to a string, you can use this code:
(function(){
var StringWriter = Java.type('java.io.StringWriter');
var PrintWriter = Java.type('java.io.PrintWriter');
var sw = new StringWriter();
var pw = new PrintWriter(sw);
connectmsg.getPartById('exception').getContent().printStackTrace(pw);
return sw.toString();
})();
This looks a bit different than the Javascript you probably normally use. That is because with our Javascript Engine, you can use the JAVA library. The engine is build within the JAVA software and you can use parts of the JAVA library. This is very powerfull.
As you can see, we use the java.io.StringWriter and java.io.PrintWriter, to convert our object to a String. This string value we return and we can put this in a messagepart to be used in our email.