Hi all,
I think I found the root cause here.

Actually there are two scenarios,
scenario1 - webapp is loaded
scenario2 - webapp is unloaded

(Reason for getting this reproduced when the tenant is unloaded; is that
when tenant is unloaded , the webapp gets unloaded too.But actual effect is
unloading the webapp)

Simply the cause is InitialContext not being set properly.

In *ApplicationAwareCarbonJavaURLContextFactory* class, before we get the
initial context we check whether the request coming from a webapp.
If yes we return the *CarbonServerSelectorContext* else we just send the
*NamingContext.*
We have used following code to check whether the request is coming from a
webapp or not, As I can see its checking with class loader.

*if (ContextBindings.isClassLoaderBound())*

when the webapp is unloaded above code returns false.


values of contexts are as follows,
*CarbonServerSelectorContext* -
org.wso2.carbon.appfactory.ext.jndi.Context.CarbonServerSelectorContext
*NamingContext* - org.apache.naming.NamingContext

Our datasource is available only in *CarbonServerSelectorContext. *So
whenever the *NamingContext* is returned , datasource appears to be null.
So application is unable to show data. Thats pretty much the case.

I have one question.

*Is there any other way to check the request whether its coming from a
webapp or not ?* If yes we can easily solve this issue.





On Mon, Mar 9, 2015 at 12:12 PM, Mahesh Chinthaka <[email protected]> wrote:

> Hi Harsha,
>
> Frankly I dont have much idea why its happenning like that, and this
> happens in that way after the fix for APPFAC -2195 [1]
>
> This is the exact code segment im talking about.
>
>
> try {
>      context.startTenantFlow();
>
>  
> context.getThreadLocalCarbonContext().setTenantId(tenantManager.getTenantId(tenantDomain));
>      context.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
>      context.getThreadLocalCarbonContext().setUsername(userName);
>      accessUrl =
> server.osgiService('org.wso2.carbon.appfactory.application.mgt.service.ApplicationManagementService')
>
> .getApplicationUrl(applicationKey, version, stage, tenantDomain);
>      status =
> server.osgiService('org.wso2.carbon.appfactory.application.mgt.service.ApplicationManagementService')
>
>  .getApplicationStatus(applicationKey, version, stage, tenantDomain);
>
>      if(!status){
>        //fix for APPFAC-2195
>        //load the tenant
>        if(accessUrl){
>                    var xhr = new XMLHttpRequest();
>                    xhr.open("GET",accessUrl + "",false);
>                    xhr.send("");
>                    }
>
>        status =
> server.osgiService('org.wso2.carbon.appfactory.application.mgt.service.ApplicationManagementService')
>
> .getApplicationStatus(applicationKey, version, stage, tenantDomain);
>       }
>       if(status){
>                 url=accessUrl;
>                  }
>
>   } finally {
>             context.endTenantFlow();
>   }
>
>
>
> [1] - https://wso2.org/jira/browse/APPFAC-2195
>
>
> On Mon, Mar 9, 2015 at 11:59 AM, Harsha Thirimanna <[email protected]>
> wrote:
>
>> Hi Mahesh,
>>
>> One question,
>> What is the meaning of deploy status false and why it try to retrieve URl
>> if it is not deploy ? Is that the behavior we are doing or are there any
>> logic behind the seen ?
>>
>> If it is required then, I think you suggestion may be good. But how it
>> load the tenant ?
>>
>>
>> *Harsha Thirimanna*
>> Senior Software Engineer; WSO2, Inc.; http://wso2.com
>> * <http://www.apache.org/>*
>> *email: **[email protected]* <[email protected]>* cell: +94 71 5186770  ,
>> +94 *
>> *774617784twitter: **http://twitter.com/
>> <http://twitter.com/afkham_azeez>*
>> *harshathirimannlinked-in: **http:
>> <http://lk.linkedin.com/in/afkhamazeez>**//www.linkedin.com/pub/harsha-thirimanna/10/ab8/122
>> <http://www.linkedin.com/pub/harsha-thirimanna/10/ab8/122>*
>>
>> *Lean . Enterprise . Middleware*
>>
>>
>> On Sun, Mar 8, 2015 at 11:21 PM, Mahesh Chinthaka <[email protected]>
>> wrote:
>>
>>> Hi all,
>>>
>>> Found that when the "Launch" button is clicked in Repos n builds page it
>>> checks for the application deployed status,
>>> If deployed status is false, then  it loads the tenant again and get
>>> access url for the app.
>>> If deployed status is true, then it just access the app url without
>>> loading the tenant.
>>>
>>> When I tried with removing the if statement and tried loading the tenant
>>> each time fixed the issue.
>>>
>>> What are the bad/good effects of solving this issue with above mentioned
>>> change ?
>>>
>>> On Sat, Mar 7, 2015 at 10:08 AM, Harsha Thirimanna <[email protected]>
>>> wrote:
>>>
>>>> ​Hi Mahesh,
>>>>
>>>> You can set tenant unloading time for few minutes. And check that.
>>>>
>>>>
>>>> *Harsha Thirimanna*
>>>> Senior Software Engineer; WSO2, Inc.; http://wso2.com
>>>> * <http://www.apache.org/>*
>>>> *email: **[email protected]* <[email protected]>* cell: +94 71 5186770  ,
>>>> +94 *
>>>> *774617784twitter: **http://twitter.com/
>>>> <http://twitter.com/afkham_azeez>*
>>>> *harshathirimannlinked-in: **http:
>>>> <http://lk.linkedin.com/in/afkhamazeez>**//www.linkedin.com/pub/harsha-thirimanna/10/ab8/122
>>>> <http://www.linkedin.com/pub/harsha-thirimanna/10/ab8/122>*
>>>>
>>>> *Lean . Enterprise . Middleware*
>>>>
>>>>
>>>> On Fri, Mar 6, 2015 at 8:35 PM, Mahesh Chinthaka <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Danushka,
>>>>>
>>>>> Tenant domain and tenant Id are set properly at everytime. other
>>>>> parameters are null. ok, lets see on Monday.
>>>>> @Harsha,
>>>>> Could be, have any idea of overcoming that ??
>>>>>
>>>>> On Fri, Mar 6, 2015 at 10:08 PM, Danushka Fernando <[email protected]
>>>>> > wrote:
>>>>>
>>>>>> May be this is due to some missing patch. Lets discuss this monday.
>>>>>>
>>>>>> Thanks & Regards
>>>>>> Danushka Fernando
>>>>>> Software Engineer
>>>>>> WSO2 inc. http://wso2.com/
>>>>>> Mobile : +94716332729
>>>>>>
>>>>>> On Fri, Mar 6, 2015 at 9:43 PM, Harsha Thirimanna <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi Mahesh,
>>>>>>> Is this may be tenant loading delay for the first time ?
>>>>>>> On Mar 6, 2015 6:51 AM, "Danushka Fernando" <[email protected]>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> When you say "CarbonContext data are empty" are they null or are
>>>>>>>> they not tenant data?
>>>>>>>> What's the value of tenant domain and tenant id of carbon context?
>>>>>>>>
>>>>>>>> Thanks & Regards
>>>>>>>> Danushka Fernando
>>>>>>>> Software Engineer
>>>>>>>> WSO2 inc. http://wso2.com/
>>>>>>>> Mobile : +94716332729
>>>>>>>>
>>>>>>>> On Fri, Mar 6, 2015 at 8:10 PM, Mahesh Chinthaka <[email protected]>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hi All,
>>>>>>>>>
>>>>>>>>> Im working on [1]. This is regarding appfactory sample "Customer
>>>>>>>>> Portal".
>>>>>>>>>
>>>>>>>>> We have a webapp that uses a datasource/database.
>>>>>>>>> When we deploy it and access for the first time , context data
>>>>>>>>> doesn't get loaded. When refreshed the browser or try to access the 
>>>>>>>>> app for
>>>>>>>>> the second time (click again in 'open' url)  it works fine.
>>>>>>>>>
>>>>>>>>> When I analyzed and debugged the code I found that CarbonContext
>>>>>>>>> data are empty.
>>>>>>>>> But in ApplicationAwareDataSourceRepository.java class and
>>>>>>>>> in CarbonContextCreatorValve.java class those context details are 
>>>>>>>>> being set
>>>>>>>>> properly.
>>>>>>>>>
>>>>>>>>> When our sample webapp tries to read those values it returns null
>>>>>>>>> for the first time.
>>>>>>>>>
>>>>>>>>> What can be the reason for this ?
>>>>>>>>>
>>>>>>>>> [1] - https://wso2.org/jira/browse/APPFAC-2998
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> *Mahesh Chinthaka Vidanagama* | Software Engineer
>>>>>>>>> WSO2, Inc | lean. enterprise. middleware.
>>>>>>>>> #20, Palm Grove, Colombo 03, Sri Lanka
>>>>>>>>> Mobile: +94 71 63 63 083 | Work: +94 112 145 345
>>>>>>>>> Email: [email protected] | Web: www.wso2.com
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Dev mailing list
>>>>>>>>> [email protected]
>>>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> Dev mailing list
>>>>>>>> [email protected]
>>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> *Mahesh Chinthaka Vidanagama* | Software Engineer
>>>>> WSO2, Inc | lean. enterprise. middleware.
>>>>> #20, Palm Grove, Colombo 03, Sri Lanka
>>>>> Mobile: +94 71 63 63 083 | Work: +94 112 145 345
>>>>> Email: [email protected] | Web: www.wso2.com
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> *Mahesh Chinthaka Vidanagama* | Software Engineer
>>> WSO2, Inc | lean. enterprise. middleware.
>>> #20, Palm Grove, Colombo 03, Sri Lanka
>>> Mobile: +94 71 63 63 083 | Work: +94 112 145 345
>>> Email: [email protected] | Web: www.wso2.com
>>>
>>
>>
>
>
> --
> *Mahesh Chinthaka Vidanagama* | Software Engineer
> WSO2, Inc | lean. enterprise. middleware.
> #20, Palm Grove, Colombo 03, Sri Lanka
> Mobile: +94 71 63 63 083 | Work: +94 112 145 345
> Email: [email protected] | Web: www.wso2.com
>



-- 
*Mahesh Chinthaka Vidanagama* | Software Engineer
WSO2, Inc | lean. enterprise. middleware.
#20, Palm Grove, Colombo 03, Sri Lanka
Mobile: +94 71 63 63 083 | Work: +94 112 145 345
Email: [email protected] | Web: www.wso2.com
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to