IOError: java.nio.channels.ClosedChannelException

55 views
Skip to first unread message

sonawan...@gmail.com

unread,
Sep 9, 2022, 7:00:29 AM9/9/22
to OWASP ZAP User Group
Hello

My HTTPSender script (jython) is getting disabled with this error 

 in sendingRequest
IOError: java.nio.channels.ClosedChannelException


My function is very simple

def sendingRequest(msg, initiator, helper):
token = ScriptVars.getGlobalVar("bearer-token")
msg.getRequestHeader().setHeader('Authorization', 'Bearer ' + token)

I am running entire zap with automations so when with specific one request my HTTPSender script fails and i am not able to continue ahead

How to handle this error and how to keep the HTTPSender script alive even if such errors occurred

sonawan...@gmail.com

unread,
Sep 10, 2022, 5:50:12 AM9/10/22
to OWASP ZAP User Group
Hello 
i fixed this - --- sharing if anyone needs it  (added Try Except block solved my problem)

my  HTTPSender script is 

def sendingRequest(msg, initiator, helper):
try:
token = ScriptVars.getGlobalVar("bearer-token")
msg.getRequestHeader().setHeader('Authorization', 'Bearer ' + token)
except:
return msg;

def responseReceived(msg, initiator, helper):
try:
    print("Response Size = ", msg.getRequestHeader(). getStatusCode  ())
except:
return msg;





thc...@gmail.com

unread,
Sep 10, 2022, 6:08:37 AM9/10/22
to zaprox...@googlegroups.com
Hi.

That doesn't fix it, the mentioned exception is not thrown from the
methods called, those try statements are redundant.
(When reporting exceptions it's better to include the whole stacktrace,
should be in the output/log).

Since you are setting the Authorization header to all requests sent by
ZAP some server is probably not happy with it (e.g. check for updates
requests).
You should just set the header to the required requests.

Best regards.

On 10/09/2022 10:50, sonawan...@gmail.com wrote:
> Hello
> i fixed this - --- sharing if anyone needs it (added Try Except block
> solved my problem)
>
> my HTTPSender script is
>
> *def sendingRequest(msg, initiator, helper):*
>
> *try:*token = ScriptVars.getGlobalVar("bearer-token")
> msg.getRequestHeader().setHeader('Authorization', 'Bearer ' + token)
> except:
> return msg;
>
> *def responseReceived(msg, initiator, helper):*
>
> *try:* print("Response Size = ",
> msg.getRequestHeader(). getStatusCode ())
> *except:*
> return msg;
>
>
>
>
>
> On Friday, September 9, 2022 at 4:30:29 PM UTC+5:30 sonawan...@gmail.com
> wrote:
>
>> Hello
>>
>> My HTTPSender script (jython) is getting disabled with this error
>>
>>
>> * in sendingRequestIOError: java.nio.channels.ClosedChannelException*

sonawan...@gmail.com

unread,
Sep 10, 2022, 6:32:26 AM9/10/22
to OWASP ZAP User Group
Hello,

Thank you for the reply,

understood perfectly :)

sonawan...@gmail.com

unread,
Sep 10, 2022, 6:37:50 AM9/10/22
to OWASP ZAP User Group
@thc202

The same HTTPSender script is used in my other question posted at - https://groups.google.com/g/zaproxy-users/c/WRqt2VjWxaU
So the print statement is getting printed in script console only at first call, and not in next calls

Can you please check that post as well (request)

thc...@gmail.com

unread,
Sep 10, 2022, 7:08:55 AM9/10/22
to zaprox...@googlegroups.com
Done.

Best regards.
Reply all
Reply to author
Forward
0 new messages