[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wsas-java-dev
Subject:    Re: [Dev] How to get web app directly using app name
From:       Anuruddha Liyanarachchi <anuruddhal () wso2 ! com>
Date:       2017-06-30 11:05:10
Message-ID: CAPh8V4mJQCF42Q-ZrE0ePB9VGtyfi8wMu1nrhtGpJYtJrSNBZA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Thusitha,

This worked for me !

Thanks,


On Thu, Jun 29, 2017 at 5:11 PM, Thusitha Thilina Dayaratne <
thusithad@wso2.com> wrote:

> Hi Anuruddha,
> 
> Can you try out the below code segment?
> 
> Map<String, WebApplicationsHolder> webApplicationsHolderMap = \
> WebAppUtils.getAllWebappHolders(getConfigContext()); for (WebApplicationsHolder \
> webApplicationsHolder : webApplicationsHolderMap.values()) { WebApplication \
> webApplication = webApplicationsHolder.getStartedWebapps().get(webappFileName); 
> 
> [1] - https://github.com/wso2/carbon-deployment/blob/4.7.x/
> components/webapp-mgt/org.wso2.carbon.webapp.mgt/src/
> main/java/org/wso2/carbon/webapp/mgt/WebappAdmin.java#L149
> 
> On Thu, Jun 29, 2017 at 7:14 PM, Anuruddha Liyanarachchi <
> anuruddhal@wso2.com> wrote:
> 
> > Hi,
> > 
> > I need to get a web application deployed in carbon. Following is my
> > approach. Is there any other way that I can optimize the following code.
> > 
> > I have to iterate through 2 for loops. Do we have a way to get an
> > application by name without iterating the list?
> > 
> > ConfigurationContext configurationContext = \
> > CarbonConfigurationContextFactory.getConfigurationContext(); \
> > WebApplicationsHolder defaultApplicationsHolder = ((Map<String, \
> > WebApplicationsHolder>) configurationContext. \
> > getProperty(CarbonConstants.WEB_APPLICATIONS_HOLDER_LIST)).get("webapps"); if \
> > (defaultApplicationsHolder != null && \
> > !defaultApplicationsHolder.getStartedWebapps().isEmpty()) { \
> > defaultApplicationsHolder.getStartedWebapps().forEach((appName, webApplication) \
> > -> {
> > > 
> > > if (appName.contains("test-app-wso2")) {
> > 
> > StandardHost applicationHost = (StandardHost) \
> > webApplication.getContext().getParent(); StandardEngine applicationEngine = \
> > (StandardEngine) applicationHost.getParent(); for (Connector connector : \
> > applicationEngine.getService().findConnectors()) { String certWebAppPath = \
> > connector.getScheme() + "://" + applicationHost.getName() + ":" + \
> > connector.getPort() + webApplication.getContext().getEncodedPath(); 
> > }
> > }
> > });
> > }
> > 
> > 
> > 
> > --
> > *Thanks and Regards,*
> > Anuruddha Lanka Liyanarachchi
> > Software Engineer - WSO2
> > Mobile : +94 (0) 712762611
> > Tel      : +94 112 145 345
> > a <thilinad@wso2.com>nuruddhal@wso2.com
> > 
> 
> 
> 
> --
> Thusitha Dayaratne
> WSO2 Inc. - lean . enterprise . middleware |  wso2.com
> 
> Mobile  +94712756809 <+94%2071%20275%206809>
> Blog      alokayasoya.blogspot.com
> About    http://about.me/thusithathilina
> <http://wso2.com/signature>
> 
> 


-- 
*Thanks and Regards,*
Anuruddha Lanka Liyanarachchi
Software Engineer - WSO2
Mobile : +94 (0) 712762611
Tel      : +94 112 145 345
a <thilinad@wso2.com>nuruddhal@wso2.com


[Attachment #5 (text/html)]

<div dir="ltr">Hi Thusitha,<br><br>This worked for me \
!<br><br>Thanks,<br><div><br></div></div><div class="gmail_extra"><br><div \
class="gmail_quote">On Thu, Jun 29, 2017 at 5:11 PM, Thusitha Thilina Dayaratne <span \
dir="ltr">&lt;<a href="mailto:thusithad@wso2.com" \
target="_blank">thusithad@wso2.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Hi Anuruddha,<div><br></div><div>Can you try \
out the below code segment?</div><div><pre \
style="color:rgb(0,0,0);font-family:&quot;DejaVu Sans Mono&quot;;font-size:9pt"><span \
style="background-color:rgb(228,228,255)">Map</span>&lt;String, \
WebApplicationsHolder&gt; webApplicationsHolderMap = WebAppUtils.<span \
style="font-style:italic">getAllWebappHolder<wbr>s</span>(getConfigContext());<br><span \
style="color:rgb(0,0,128);font-weight:bold">for </span>(WebApplicationsHolder \
webApplicationsHolder : webApplicationsHolderMap.<wbr>values()) {<br>    \
WebApplication webApplication = \
webApplicationsHolder.<wbr>getStartedWebapps().get(<wbr>webappFileName);</pre><pre \
style="color:rgb(0,0,0);font-family:&quot;DejaVu Sans \
Mono&quot;;font-size:9pt"><br></pre>[1] - <a \
href="https://github.com/wso2/carbon-deployment/blob/4.7.x/components/webapp-mgt/org.w \
so2.carbon.webapp.mgt/src/main/java/org/wso2/carbon/webapp/mgt/WebappAdmin.java#L149" \
target="_blank">https://github.com/wso2/<wbr>carbon-deployment/blob/4.7.x/<wbr>compone \
nts/webapp-mgt/org.<wbr>wso2.carbon.webapp.mgt/src/<wbr>main/java/org/wso2/carbon/<wbr>webapp/mgt/WebappAdmin.java#<wbr>L149</a></div></div><div \
class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Thu, Jun 29, \
2017 at 7:14 PM, Anuruddha Liyanarachchi <span dir="ltr">&lt;<a \
href="mailto:anuruddhal@wso2.com" target="_blank">anuruddhal@wso2.com</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div dir="ltr">Hi,<br><br>I need to get a web \
application deployed in carbon. Following is my approach. Is there any  other way \
that I can optimize the following code. <br><br>I have to iterate through 2 for \
loops. Do we have a way to get an application by name without iterating the \
list?<br><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt">ConfigurationContext \
configurationContext = CarbonConfigurationContextFact<wbr>ory.<span \
style="font-style:italic">getConfigurationContext</span>();<br>WebApplicationsHolder \
defaultApplicationsHolder = ((Map&lt;String, WebApplicationsHolder&gt;) \
configurationContext.<br>        getProperty(CarbonConstants.<span \
style="color:rgb(102,14,122);font-weight:bold;font-style:italic">WE<wbr>B_APPLICATIONS_HOLDER_LIST</span>)).g<wbr>et(<span \
style="color:rgb(0,128,0);font-weight:bold">&quot;webapps&quot;</span>);<br><span \
style="color:rgb(0,0,128);font-weight:bold">if </span>(defaultApplicationsHolder != \
<span style="color:rgb(0,0,128);font-weight:bold">null </span>&amp;&amp; \
!defaultApplicationsHolder.get<wbr>StartedWebapps().isEmpty()) {<br>    \
defaultApplicationsHolder.getS<wbr>tartedWebapps().forEach((appNa<wbr>me, \
webApplication) -&gt; {  <blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">        <span \
style="color:rgb(0,0,128);font-weight:bold">if </span>(appName.contains(<span \
style="color:rgb(0,128,0);font-weight:bold">&quot;test-app-ws<wbr>o2&quot;</span>)) \
{</blockquote>            StandardHost applicationHost = (StandardHost) \
webApplication.getContext().ge<wbr>tParent();<br>            StandardEngine \
applicationEngine = (StandardEngine) applicationHost.getParent();<br>            \
<span style="color:rgb(0,0,128);font-weight:bold">for </span>(Connector connector : \
applicationEngine.getService()<wbr>.findConnectors()) {<br>               String \
certWebAppPath = connector.getScheme() + <span \
style="color:rgb(0,128,0);font-weight:bold">&quot;://&quot; </span>+<br>              \
applicationHost.getName() + <span \
style="color:rgb(0,128,0);font-weight:bold">&quot;:&quot; </span>+ \
connector.getPort() + webApplication.getContext().ge<wbr>tEncodedPath();<br><br>      \
}<br>        }<br>    });<br>}</pre><span class="m_7006973074227215689HOEnZb"><font \
color="#888888"><br clear="all"><div><br></div>-- <br><div \
class="m_7006973074227215689m_2426865160271049553gmail_signature"><div \
dir="ltr"><div><div><font style="background-color:rgb(255,255,255)" \
color="#000000"><b>Thanks and Regards,</b></font></div><div dir="ltr"><font \
color="#666666">Anuruddha Lanka Liyanarachchi</font><div><font face="arial, \
helvetica, sans-serif" color="#666666">Software Engineer - \
WSO2</font></div><div><font color="#666666">Mobile :  <a value="+94773451194">+94 (0) \
7</a>12762611</font></div><div><font color="#666666"><span \
style="font-family:arial;font-size:small">Tel         :  <a value="+94112145345">+94 \
112 145 345</a></span><br></font></div><div><font color="#666666"><a \
href="mailto:thilinad@wso2.com" target="_blank">a</a><a \
href="mailto:nuruddhal@wso2.com" \
target="_blank">nuruddhal@wso2.com</a></font></div></div></div></div></div> \
</font></span></div> </blockquote></div><br><br \
clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- \
<br><div class="m_7006973074227215689gmail_signature" \
data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div \
dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
dir="ltr"><div style="font-size:12.8000001907349px"><div><font \
color="#444444">Thusitha Dayaratne</font></div><div><span \
style="font-size:12.8px;color:rgb(136,136,136)">WSO2 Inc. - lean . enterprise . \
middleware |    </span><a href="http://wso2.com/" \
style="font-size:12.8px;color:rgb(17,85,204)" \
target="_blank">wso2.com</a><br></div><div><span \
style="color:rgb(153,153,153);font-size:12.8000001907349px"><br></span></div><div><span \
style="color:rgb(153,153,153);font-size:12.8000001907349px">Mobile   <a \
href="tel:+94%2071%20275%206809" value="+94712756809" \
target="_blank">+94712756809</a></span><br></div></div><div><font color="#999999" \
style="font-size:12.8000001907349px">Blog         </font><font color="#999999"><a \
href="http://alokayasoya.blogspot.com" \
target="_blank">alokayasoya.blogspot.com</a></font></div><div><font \
color="#999999">About </font>     <a href="http://about.me/thusithathilina" \
target="_blank">http://about.me/<wbr>thusithathilina</a></div><div><a \
href="http://wso2.com/signature" target="_blank"><img \
src="http://c.content.wso2.com/signatures/wso2-signature-general.png" width="420" \
height="96"></a><br></div><div><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
 </font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div \
class="gmail_signature" data-smartmail="gmail_signature"><div \
dir="ltr"><div><div><font style="background-color:rgb(255,255,255)" \
color="#000000"><b>Thanks and Regards,</b></font></div><div dir="ltr"><font \
color="#666666">Anuruddha Lanka Liyanarachchi</font><div><font face="arial, \
helvetica, sans-serif" color="#666666">Software Engineer - \
WSO2</font></div><div><font color="#666666">Mobile :  <a value="+94773451194">+94 (0) \
7</a>12762611</font></div><div><font color="#666666"><span \
style="font-family:arial;font-size:small">Tel         :  <a value="+94112145345">+94 \
112 145 345</a></span><br></font></div><div><font color="#666666"><a \
href="mailto:thilinad@wso2.com" target="_blank">a</a><a \
href="mailto:nuruddhal@wso2.com" \
target="_blank">nuruddhal@wso2.com</a></font></div></div></div></div></div> </div>



_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic