Hi all,

Isn't it better to handle this error rather than hiding the logs through
log4j.properties? I think option 4 is better and has minimal changes to
existing logic.

ex: We can put a try/catch block and handle below before the XHR request.

var httpClient = new
Packages.org.apache.http.impl.client.DefaultHttpClient();
var httpPost = new
Packages.org.apache.http.client.methods.HttpPost(endpoint);
var response = httpClient.execute(httpPost);
BPSRunning = true;

Thanks,
Lakmali

On 20 March 2015 at 10:33, Rasika Perera <[email protected]> wrote:

> [Please ignore my previous reply, it was incomplete]
>
> Hi Tharindu,
>
> According to chat we had, IMO if your intention is to avoid error messages
> from "XMLHttpRequestHostObject.java" rather than patching XHR, you can
> add following to your log4j property file.
>
> log4j.logger.<your package> = DEBUG|INFO|OFF|WARN...
>
> log4j.logger.org.jaggeryjs.hostobjects.xhr.XMLHttpRequestHostObject = FATAL
>
> Or...
>
> log4j.logger.org.jaggeryjs.hostobjects.xhr= FATAL
>
> Note that i used log level "FATAL" over completely turn off logging using
> "OFF".
>
> Thank you
>
> On Fri, Mar 20, 2015 at 10:27 AM, Rasika Perera <[email protected]> wrote:
>
>> Hi Tharindu,
>>
>> According to chat we had, IMO if your intention is to avoid error
>> messages from "XMLHttpRequestHostObject.java" rather than patching XHR, you
>> can add following to your log4j property file.
>>
>> log4j.logger.<your package> = DEBUG|INFO|OFF|WARN...
>>
>> log4j.logger.org.jaggeryjs.hostobjects.xhr.XMLHttpRequestHostObject =
>> FATAL
>>
>> or
>>
>>
>> Note that i used log level "FATAL" over completely turn off logging using
>> "OFF".
>>
>> Thank you
>>
>>
>> On Thu, Mar 19, 2015 at 6:00 PM, Ruchira Wageesha <[email protected]>
>> wrote:
>>
>>> Following are the possible options that I can think.
>>>
>>> 1. Patching XHR to get rid of the log message
>>> 2. Hiding the error from log4j, but AFAIK, then it will not log any
>>> error from XHR
>>> 3. Using any Java's http-client directly from Jaggery[a] to do the HTTP
>>> calls instead of XHR
>>> 4. Using any Java's http-client to check the endpoint status, and
>>> continue original HTTP call with XHR
>>>
>>> [a]
>>> https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java
>>>
>>> /Ruchira
>>>
>>> On Thu, Mar 19, 2015 at 5:18 PM, Lakmali Baminiwatta <[email protected]>
>>> wrote:
>>>
>>>> Hi Ruchira,
>>>>
>>>> In APIM and APPM we talk to the BPS server and fetch Human Tasks
>>>> available. For that when the user is login to the admin-dashboard jaggery
>>>> app, we do a login call to BPS server using XMLHttpRequest. At this point,
>>>> if the BPS is not running we are getting this connection refused error in
>>>> the logs. We need to handle this.
>>>>
>>>> As Tharindu mentioned, XMLHttpRequestHostObject.java uses 
>>>> log.error(e.getMessage(),
>>>> e); [1]. Therefore we can't get rid of this stack trace in the log by
>>>> just catching the exception.
>>>>
>>>> Is there any method in jaggery that we can use to check whether server
>>>> is up and running before doing the send call and handle this? Appreciate
>>>> any help on this.
>>>>
>>>> [1]
>>>> https://github.com/wso2/jaggery/blob/0.9.0.ALPHA4.wso2v4/components/hostobjects/org.jaggeryjs.hostobjects.xhr/src/main/java/org/jaggeryjs/hostobjects/xhr/XMLHttpRequestHostObject.java
>>>> [2]https://wso2.org/jira/browse/APPM-587
>>>> [3]https://wso2.org/jira/browse/APIMANAGER-3139
>>>>
>>>> Thanks,
>>>> Lakmali
>>>>
>>>> On 18 March 2015 at 08:57, Tharindu Dharmarathna <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Ruchira,
>>>>>
>>>>> We want to carch the exception according to connection refused
>>>>> exception from the jaggery side . Due to logging of this  exception from
>>>>> Hostobject We couldn't remove this exception come from the console.
>>>>>
>>>>> Is there any way of check a server is up and running from jaggery side
>>>>> . If there's a way we can avoid exception come from the console.
>>>>>
>>>>> Thanks
>>>>> Tharindu
>>>>>
>>>>> On Wed, Mar 18, 2015 at 2:06 AM, Ruchira Wageesha <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> What is the issue with going try/catch blocks?
>>>>>>
>>>>>> /Ruchira
>>>>>>
>>>>>> On Tue, Mar 17, 2015 at 5:56 PM, Tharindu Dharmarathna <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>> According to public jira [1]  how can we handle connection refused
>>>>>>> exception come from this issue . This come from the send method.
>>>>>>>
>>>>>>> code snippest for this issue
>>>>>>>
>>>>>>>>
>>>>>>>> try{
>>>>>>>> var xhr = new XMLHttpRequest();
>>>>>>>> var site = require("/site/conf/site.json");
>>>>>>>> var endpoint =
>>>>>>>> site.workflows.applicationWorkFlowServerURL+"AuthenticationAdmin";
>>>>>>>> xhr.open("POST", endpoint);
>>>>>>>> var payload = '<soap:Envelope xmlns:soap="
>>>>>>>> http://www.w3.org/2003/05/soap-envelope"; xmlns:aut="
>>>>>>>> http://authentication.services.core.carbon.wso2.org";><soap:Header/><soap:Body><aut:login><aut:username>'
>>>>>>>> + username + '</aut:username><aut:password>' + password +
>>>>>>>> '</aut:password><aut:remoteAddress>localhost</aut:remoteAddress></aut:login></soap:Body></soap:Envelope>';
>>>>>>>> xhr.send(payload);
>>>>>>>> var cookie = (xhr.getAllResponseHeaders());
>>>>>>>> log.info(xhr.readyState);
>>>>>>>> //session.put("workflowCookie",cookie.split(";")[0].split(":")[1]);
>>>>>>>> var sessionCookie = xhr.getResponseHeader("Set-Cookie");
>>>>>>>> session.put("workflowCookie",sessionCookie);
>>>>>>>> }catch (e) {
>>>>>>>> // log.error(e.message);
>>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> Exception come from the following jaggery hostobject code
>>>>>>>
>>>>>>> private static void executeRequest(Context cx,
>>>>>>>> XMLHttpRequestHostObject xhr) throws ScriptException {
>>>>>>>> try {
>>>>>>>> xhr.httpClient.executeMethod(xhr.method);
>>>>>>>> xhr.statusLine = xhr.method.getStatusLine();
>>>>>>>> xhr.responseHeaders = xhr.method.getResponseHeaders();
>>>>>>>> updateReadyState(cx, xhr, HEADERS_RECEIVED);
>>>>>>>> byte[] response = xhr.method.getResponseBody();
>>>>>>>> if (response.length > 0) {
>>>>>>>> xhr.responseText = new String(response);
>>>>>>>> }
>>>>>>>> Header contentType = xhr.method.getResponseHeader("Content-Type");
>>>>>>>> if (contentType != null) {
>>>>>>>> xhr.responseType = contentType.getValue();
>>>>>>>> }
>>>>>>>> updateReadyState(cx, xhr, DONE);
>>>>>>>> } catch (IOException e) {
>>>>>>>> log.error(e.getMessage(), e);
>>>>>>>> throw new ScriptException(e);
>>>>>>>> } finally {
>>>>>>>> xhr.method.releaseConnection();
>>>>>>>> }
>>>>>>>> }
>>>>>>>
>>>>>>> XMLHttpRequestHostObject.java
>>>>>>>
>>>>>>> [1] - https://wso2.org/jira/browse/APIMANAGER-3139
>>>>>>>
>>>>>>> Thanks and regards
>>>>>>>
>>>>>>>
>>>>>>> *Tharindu Dharmarathna*Associate Software Engineer
>>>>>>> WSO2 Inc.; http://wso2.com
>>>>>>> lean.enterprise.middleware
>>>>>>>
>>>>>>> mobile: *+94779109091 <%2B94779109091>*
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>> *Ruchira Wageesha**Associate Technical Lead*
>>>>>> *WSO2 Inc. - lean . enterprise . middleware |  wso2.com
>>>>>> <http://wso2.com>*
>>>>>>
>>>>>> *email: [email protected] <[email protected]>,   blog:
>>>>>> ruchirawageesha.blogspot.com <http://ruchirawageesha.blogspot.com>,
>>>>>> mobile: +94 77 5493444 <%2B94%2077%205493444>*
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> *Tharindu Dharmarathna*Associate Software Engineer
>>>>> WSO2 Inc.; http://wso2.com
>>>>> lean.enterprise.middleware
>>>>>
>>>>> mobile: *+94779109091 <%2B94779109091>*
>>>>>
>>>>> _______________________________________________
>>>>> Dev mailing list
>>>>> [email protected]
>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Lakmali Baminiwatta
>>>>  Senior Software Engineer
>>>> WSO2, Inc.: http://wso2.com
>>>> lean.enterprise.middleware
>>>> mobile:  +94 71 2335936
>>>> blog : lakmali.com
>>>>
>>>>
>>>
>>>
>>> --
>>>
>>> *Ruchira Wageesha**Associate Technical Lead*
>>> *WSO2 Inc. - lean . enterprise . middleware |  wso2.com
>>> <http://wso2.com>*
>>>
>>> *email: [email protected] <[email protected]>,   blog:
>>> ruchirawageesha.blogspot.com <http://ruchirawageesha.blogspot.com>,
>>> mobile: +94 77 5493444 <%2B94%2077%205493444>*
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> With Regards,
>>
>> *Rasika Perera*
>> Software Engineer
>> M: +94 71 680 9060 E: [email protected]
>> LinkedIn: http://lk.linkedin.com/in/rasika90
>>
>> WSO2 Inc. www.wso2.com
>> lean.enterprise.middleware
>>
>
>
>
> --
> With Regards,
>
> *Rasika Perera*
> Software Engineer
> M: +94 71 680 9060 E: [email protected]
> LinkedIn: http://lk.linkedin.com/in/rasika90
>
> WSO2 Inc. www.wso2.com
> lean.enterprise.middleware
>



-- 
Lakmali Baminiwatta
 Senior Software Engineer
WSO2, Inc.: http://wso2.com
lean.enterprise.middleware
mobile:  +94 71 2335936
blog : lakmali.com
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to