You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@synapse.apache.org by Matthew Shaw <Ma...@ambulance.qld.gov.au> on 2017/08/14 00:05:03 UTC

class mediator and error handling

Hi,

There appears to be a bug in the class mediator when using a try catch. It goes into the catch statement when I force an error, however my code never executes. It jumps straight into ClassMediator catch statement.

Here is my mediator code:

public class GetTimesheetMediator implements Mediator {

    private static final Log log = LogFactory.getLog(GetTimesheetMediator.class);

    public boolean mediate(MessageContext messageContext) {

        boolean success = true;

        String timsheetId = (String) messageContext.getProperty("timesheetId");

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        env.put(Context.PROVIDER_URL, "t3://poldesaps02:5013");
        env.put(Context.SECURITY_PRINCIPAL, "testuser4");
        env.put(Context.SECURITY_CREDENTIALS, "passw0rd");

        Context ic = null;

        try {
            Integer eTimesheetId =  new Integer(timsheetId);
            ic = new InitialContext(env);
            String xml = marshallTimesheet(ic, getTimesheet(ic,eTimesheetId));
            messageContext.setProperty("xmlResponse",xml);
        }catch (Throwable e) {

            success = false;
            log.error("WOWSERS!");
        }


        return success;
    }

I need it to perform the processing in the above catch statement, but it just seems to skip it. Any ideas?

Cheers,
Matt.
This email, including any attachments sent with it, is confidential and for the sole use of the intended recipient(s). This confidentiality is not waived or lost, if you receive it and you are not the intended recipient(s), or if it is transmitted/received in error.

Any unauthorised use, alteration, disclosure, distribution or review of this email is strictly prohibited. The information contained in this email, including any attachment sent with it, may be subject to a statutory duty of confidentiality if it relates to health service matters.

If you are not the intended recipient(s), or if you have received this email in error, you are asked to immediately notify the sender. You should also delete this email, and any copies, from your computer system network and destroy any hard copies produced.

If not an intended recipient of this email, you must not copy, distribute or take any action(s) that relies on it; any form of disclosure, modification, distribution and/or publication of this email is also prohibited.

Although the Queensland Ambulance Service takes all reasonable steps to ensure this email does not contain malicious software, the Queensland Ambulance Service does not accept responsibility for the consequences if any person's computer inadvertently suffers any disruption to services, loss of information, harm or is infected with a virus, other malicious computer programme or code that may occur as a consequence of receiving this email.

Unless stated otherwise, this email represents only the views of the sender and not the views of the Queensland Government.

********************************************************************************

The content presented in this publication is distributed by the Queensland Government as an information source only. The State of Queensland makes no statements, representations or warranties about the accuracy, completeness or reliability of any information contained in this publication. The State of Queensland disclaims all responsibility and all liability (including without limitation for liability in negligence) for all expenses, losses, damages and costs you might incur as a result of the information being inaccurate or incomplete in any way, and for any reason reliance was placed on such information.

RE: class mediator and error handling

Posted by Matthew Shaw <Ma...@ambulance.qld.gov.au>.
Hi All,

Thanks for your replies. My proxy which was invoking the class mediator has a faultsequence, which calls my custom error sequence to send it to a queue and as part of its processing uses payloadfactory mediator to transform it. The payloadfactory mediator was throwing a IllegalGroupException when I passed in the stack trace, which has some < chars in it. The reg expression fails in the doTransform method.

My work around was to bypass the payloadfactory mediator and create the soap body myself.

Thanks again for replying. 

Cheers,
Matt.

-----Original Message-----
From: Rene Schwarb [mailto:rene.schwarb@ipt.ch] 
Sent: Monday, 14 August 2017 2:41 PM
To: user@synapse.apache.org
Subject: Re: class mediator and error handling

Hi Matt

what's in the Exception e?

René


2017-08-14 2:05 GMT+02:00 Matthew Shaw <Ma...@ambulance.qld.gov.au>:

> Hi,
>
> There appears to be a bug in the class mediator when using a try 
> catch. It goes into the catch statement when I force an error, however 
> my code never executes. It jumps straight into ClassMediator catch statement.
>
> Here is my mediator code:
>
> public class GetTimesheetMediator implements Mediator {
>
>     private static final Log log = LogFactory.getLog( 
> GetTimesheetMediator.class);
>
>     public boolean mediate(MessageContext messageContext) {
>
>         boolean success = true;
>
>         String timsheetId = (String) messageContext.getProperty("
> timesheetId");
>
>         Hashtable env = new Hashtable();
>         env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.
> WLInitialContextFactory");
>         env.put(Context.PROVIDER_URL, "t3://poldesaps02:5013");
>         env.put(Context.SECURITY_PRINCIPAL, "testuser4");
>         env.put(Context.SECURITY_CREDENTIALS, "passw0rd");
>
>         Context ic = null;
>
>         try {
>             Integer eTimesheetId =  new Integer(timsheetId);
>             ic = new InitialContext(env);
>             String xml = marshallTimesheet(ic, 
> getTimesheet(ic,eTimesheetId));
>             messageContext.setProperty("xmlResponse",xml);
>         }catch (Throwable e) {
>
>             success = false;
>             log.error("WOWSERS!");
>         }
>
>
>         return success;
>     }
>
> I need it to perform the processing in the above catch statement, but 
> it just seems to skip it. Any ideas?
>
> Cheers,
> Matt.
> This email, including any attachments sent with it, is confidential 
> and for the sole use of the intended recipient(s). This 
> confidentiality is not waived or lost, if you receive it and you are 
> not the intended recipient(s), or if it is transmitted/received in error.
>
> Any unauthorised use, alteration, disclosure, distribution or review 
> of this email is strictly prohibited. The information contained in 
> this email, including any attachment sent with it, may be subject to a 
> statutory duty of confidentiality if it relates to health service matters.
>
> If you are not the intended recipient(s), or if you have received this 
> email in error, you are asked to immediately notify the sender. You 
> should also delete this email, and any copies, from your computer 
> system network and destroy any hard copies produced.
>
> If not an intended recipient of this email, you must not copy, 
> distribute or take any action(s) that relies on it; any form of 
> disclosure, modification, distribution and/or publication of this 
> email is also prohibited.
>
> Although the Queensland Ambulance Service takes all reasonable steps 
> to ensure this email does not contain malicious software, the 
> Queensland Ambulance Service does not accept responsibility for the 
> consequences if any person's computer inadvertently suffers any 
> disruption to services, loss of information, harm or is infected with 
> a virus, other malicious computer programme or code that may occur as 
> a consequence of receiving this email.
>
> Unless stated otherwise, this email represents only the views of the 
> sender and not the views of the Queensland Government.
>
> ************************************************************
> ********************
>
> The content presented in this publication is distributed by the 
> Queensland Government as an information source only. The State of 
> Queensland makes no statements, representations or warranties about 
> the accuracy, completeness or reliability of any information contained 
> in this publication. The State of Queensland disclaims all 
> responsibility and all liability (including without limitation for 
> liability in negligence) for all expenses, losses, damages and costs 
> you might incur as a result of the information being inaccurate or 
> incomplete in any way, and for any reason reliance was placed on such information.
>



--
This email, including any attachments sent with it, is confidential and for the sole use of the intended recipient(s). This confidentiality is not waived or lost, if you receive it and you are not the intended recipient(s), or if it is transmitted/received in error.

Any unauthorised use, alteration, disclosure, distribution or review of this email is strictly prohibited. The information contained in this email, including any attachment sent with it, may be subject to a statutory duty of confidentiality if it relates to health service matters.

If you are not the intended recipient(s), or if you have received this email in error, you are asked to immediately notify the sender. You should also delete this email, and any copies, from your computer system network and destroy any hard copies produced.

If not an intended recipient of this email, you must not copy, distribute or take any action(s) that relies on it; any form of disclosure, modification, distribution and/or publication of this email is also prohibited.

Although the Queensland Ambulance Service takes all reasonable steps to ensure this email does not contain malicious software, the Queensland Ambulance Service does not accept responsibility for the consequences if any person's computer inadvertently suffers any disruption to services, loss of information, harm or is infected with a virus, other malicious computer programme or code that may occur as a consequence of receiving this email.

Unless stated otherwise, this email represents only the views of the sender and not the views of the Queensland Government.

********************************************************************************

The content presented in this publication is distributed by the Queensland Government as an information source only. The State of Queensland makes no statements, representations or warranties about the accuracy, completeness or reliability of any information contained in this publication. The State of Queensland disclaims all responsibility and all liability (including without limitation for liability in negligence) for all expenses, losses, damages and costs you might incur as a result of the information being inaccurate or incomplete in any way, and for any reason reliance was placed on such information.

Re: class mediator and error handling

Posted by Rene Schwarb <re...@ipt.ch>.
Hi Matt

what's in the Exception e?

René


2017-08-14 2:05 GMT+02:00 Matthew Shaw <Ma...@ambulance.qld.gov.au>:

> Hi,
>
> There appears to be a bug in the class mediator when using a try catch. It
> goes into the catch statement when I force an error, however my code never
> executes. It jumps straight into ClassMediator catch statement.
>
> Here is my mediator code:
>
> public class GetTimesheetMediator implements Mediator {
>
>     private static final Log log = LogFactory.getLog(
> GetTimesheetMediator.class);
>
>     public boolean mediate(MessageContext messageContext) {
>
>         boolean success = true;
>
>         String timsheetId = (String) messageContext.getProperty("
> timesheetId");
>
>         Hashtable env = new Hashtable();
>         env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.
> WLInitialContextFactory");
>         env.put(Context.PROVIDER_URL, "t3://poldesaps02:5013");
>         env.put(Context.SECURITY_PRINCIPAL, "testuser4");
>         env.put(Context.SECURITY_CREDENTIALS, "passw0rd");
>
>         Context ic = null;
>
>         try {
>             Integer eTimesheetId =  new Integer(timsheetId);
>             ic = new InitialContext(env);
>             String xml = marshallTimesheet(ic,
> getTimesheet(ic,eTimesheetId));
>             messageContext.setProperty("xmlResponse",xml);
>         }catch (Throwable e) {
>
>             success = false;
>             log.error("WOWSERS!");
>         }
>
>
>         return success;
>     }
>
> I need it to perform the processing in the above catch statement, but it
> just seems to skip it. Any ideas?
>
> Cheers,
> Matt.
> This email, including any attachments sent with it, is confidential and
> for the sole use of the intended recipient(s). This confidentiality is not
> waived or lost, if you receive it and you are not the intended
> recipient(s), or if it is transmitted/received in error.
>
> Any unauthorised use, alteration, disclosure, distribution or review of
> this email is strictly prohibited. The information contained in this email,
> including any attachment sent with it, may be subject to a statutory duty
> of confidentiality if it relates to health service matters.
>
> If you are not the intended recipient(s), or if you have received this
> email in error, you are asked to immediately notify the sender. You should
> also delete this email, and any copies, from your computer system network
> and destroy any hard copies produced.
>
> If not an intended recipient of this email, you must not copy, distribute
> or take any action(s) that relies on it; any form of disclosure,
> modification, distribution and/or publication of this email is also
> prohibited.
>
> Although the Queensland Ambulance Service takes all reasonable steps to
> ensure this email does not contain malicious software, the Queensland
> Ambulance Service does not accept responsibility for the consequences if
> any person's computer inadvertently suffers any disruption to services,
> loss of information, harm or is infected with a virus, other malicious
> computer programme or code that may occur as a consequence of receiving
> this email.
>
> Unless stated otherwise, this email represents only the views of the
> sender and not the views of the Queensland Government.
>
> ************************************************************
> ********************
>
> The content presented in this publication is distributed by the Queensland
> Government as an information source only. The State of Queensland makes no
> statements, representations or warranties about the accuracy, completeness
> or reliability of any information contained in this publication. The State
> of Queensland disclaims all responsibility and all liability (including
> without limitation for liability in negligence) for all expenses, losses,
> damages and costs you might incur as a result of the information being
> inaccurate or incomplete in any way, and for any reason reliance was placed
> on such information.
>



--

Re: class mediator and error handling

Posted by Ravi Undupitiya <ra...@gmail.com>.
Hi Matt, 

What you’re trying should work. I don’t see how anything in the class mediator can cause this as all it does is execute the mediate method of the custom class. If you do not handle exceptions in your custom class, the class mediator wraps the mediate method execution in a try/catch and that should at least throw a SynapseException. 


Thanks, 
Ravi 


> On 14 Aug 2017, at 10:05 am, Matthew Shaw <Ma...@ambulance.qld.gov.au> wrote:
> 
> Hi,
> 
> There appears to be a bug in the class mediator when using a try catch. It goes into the catch statement when I force an error, however my code never executes. It jumps straight into ClassMediator catch statement.
> 
> Here is my mediator code:
> 
> public class GetTimesheetMediator implements Mediator {
> 
>    private static final Log log = LogFactory.getLog(GetTimesheetMediator.class);
> 
>    public boolean mediate(MessageContext messageContext) {
> 
>        boolean success = true;
> 
>        String timsheetId = (String) messageContext.getProperty("timesheetId");
> 
>        Hashtable env = new Hashtable();
>        env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
>        env.put(Context.PROVIDER_URL, "t3://poldesaps02:5013");
>        env.put(Context.SECURITY_PRINCIPAL, "testuser4");
>        env.put(Context.SECURITY_CREDENTIALS, "passw0rd");
> 
>        Context ic = null;
> 
>        try {
>            Integer eTimesheetId =  new Integer(timsheetId);
>            ic = new InitialContext(env);
>            String xml = marshallTimesheet(ic, getTimesheet(ic,eTimesheetId));
>            messageContext.setProperty("xmlResponse",xml);
>        }catch (Throwable e) {
> 
>            success = false;
>            log.error("WOWSERS!");
>        }
> 
> 
>        return success;
>    }
> 
> I need it to perform the processing in the above catch statement, but it just seems to skip it. Any ideas?
> 
> Cheers,
> Matt.
> This email, including any attachments sent with it, is confidential and for the sole use of the intended recipient(s). This confidentiality is not waived or lost, if you receive it and you are not the intended recipient(s), or if it is transmitted/received in error.
> 
> Any unauthorised use, alteration, disclosure, distribution or review of this email is strictly prohibited. The information contained in this email, including any attachment sent with it, may be subject to a statutory duty of confidentiality if it relates to health service matters.
> 
> If you are not the intended recipient(s), or if you have received this email in error, you are asked to immediately notify the sender. You should also delete this email, and any copies, from your computer system network and destroy any hard copies produced.
> 
> If not an intended recipient of this email, you must not copy, distribute or take any action(s) that relies on it; any form of disclosure, modification, distribution and/or publication of this email is also prohibited.
> 
> Although the Queensland Ambulance Service takes all reasonable steps to ensure this email does not contain malicious software, the Queensland Ambulance Service does not accept responsibility for the consequences if any person's computer inadvertently suffers any disruption to services, loss of information, harm or is infected with a virus, other malicious computer programme or code that may occur as a consequence of receiving this email.
> 
> Unless stated otherwise, this email represents only the views of the sender and not the views of the Queensland Government.
> 
> ********************************************************************************
> 
> The content presented in this publication is distributed by the Queensland Government as an information source only. The State of Queensland makes no statements, representations or warranties about the accuracy, completeness or reliability of any information contained in this publication. The State of Queensland disclaims all responsibility and all liability (including without limitation for liability in negligence) for all expenses, losses, damages and costs you might incur as a result of the information being inaccurate or incomplete in any way, and for any reason reliance was placed on such information.