Lines 45-74
Link Here
|
45 |
package org.netbeans.modules.j2ee.jboss4.nodes; |
45 |
package org.netbeans.modules.j2ee.jboss4.nodes; |
46 |
|
46 |
|
47 |
import java.lang.reflect.Method; |
47 |
import java.lang.reflect.Method; |
|
|
48 |
import java.util.ArrayList; |
48 |
import java.util.Collections; |
49 |
import java.util.Collections; |
49 |
import java.util.HashSet; |
50 |
import java.util.HashSet; |
50 |
import java.util.Iterator; |
51 |
import java.util.Iterator; |
|
|
52 |
import java.util.List; |
51 |
import java.util.Set; |
53 |
import java.util.Set; |
52 |
import java.util.Vector; |
|
|
53 |
import java.util.concurrent.ExecutionException; |
54 |
import java.util.concurrent.ExecutionException; |
54 |
import java.util.logging.Level; |
55 |
import java.util.logging.Level; |
55 |
import java.util.logging.Logger; |
56 |
import java.util.logging.Logger; |
|
|
57 |
import javax.enterprise.deploy.shared.ModuleType; |
58 |
import javax.enterprise.deploy.spi.Target; |
59 |
import javax.enterprise.deploy.spi.TargetModuleID; |
60 |
import javax.enterprise.deploy.spi.exceptions.TargetException; |
56 |
import javax.management.MBeanServerConnection; |
61 |
import javax.management.MBeanServerConnection; |
57 |
import javax.management.ObjectInstance; |
62 |
import javax.management.ObjectInstance; |
58 |
import javax.management.ObjectName; |
63 |
import javax.management.ObjectName; |
59 |
import javax.management.QueryExp; |
64 |
import javax.management.QueryExp; |
|
|
65 |
import org.netbeans.modules.j2ee.jboss4.JB7RemoteAction; |
60 |
import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; |
66 |
import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; |
61 |
import org.netbeans.modules.j2ee.jboss4.JBRemoteAction; |
67 |
import org.netbeans.modules.j2ee.jboss4.JBRemoteAction; |
62 |
import org.netbeans.modules.j2ee.jboss4.JBoss5ProfileServiceProxy; |
68 |
import org.netbeans.modules.j2ee.jboss4.JBoss5ProfileServiceProxy; |
63 |
import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable; |
69 |
import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable; |
64 |
import org.openide.nodes.Children; |
70 |
import org.openide.nodes.Children; |
65 |
import org.openide.nodes.Node; |
71 |
import org.openide.nodes.Node; |
|
|
72 |
import org.openide.util.Exceptions; |
66 |
import org.openide.util.Lookup; |
73 |
import org.openide.util.Lookup; |
67 |
import org.openide.util.RequestProcessor; |
74 |
import org.openide.util.RequestProcessor; |
68 |
|
75 |
|
69 |
/** |
76 |
/** |
70 |
* It describes children nodes of the Web Applications node. Implements |
77 |
* It describes children nodes of the Web Applications node. Implements |
71 |
* Refreshable interface and due to it can be refreshed via ResreshModulesAction. |
78 |
* Refreshable interface and due to it can be refreshed via |
|
|
79 |
* ResreshModulesAction. |
72 |
* |
80 |
* |
73 |
* @author Michal Mocnak |
81 |
* @author Michal Mocnak |
74 |
*/ |
82 |
*/ |
Lines 92-175
Link Here
|
92 |
this.abilitiesSupport = new JBAbilitiesSupport(lookup); |
100 |
this.abilitiesSupport = new JBAbilitiesSupport(lookup); |
93 |
} |
101 |
} |
94 |
|
102 |
|
95 |
public void updateKeys(){ |
103 |
public void updateKeys() { |
96 |
setKeys(new Object[] {Util.WAIT_NODE}); |
104 |
setKeys(new Object[]{Util.WAIT_NODE}); |
|
|
105 |
RequestProcessor.getDefault().post(abilitiesSupport.isJB7x() ? new JBoss7WebNodeUpdater() : new JBossWebNodeUpdater(), 0); |
106 |
} |
97 |
|
107 |
|
98 |
RequestProcessor.getDefault().post(new Runnable() { |
108 |
class JBossWebNodeUpdater implements Runnable { |
99 |
Vector keys = new Vector(); |
|
|
100 |
|
109 |
|
101 |
public void run() { |
110 |
List keys = new ArrayList(); |
102 |
try { |
|
|
103 |
lookup.lookup(JBDeploymentManager.class).invokeRemoteAction(new JBRemoteAction<Void>() { |
104 |
|
111 |
|
105 |
@Override |
112 |
@Override |
106 |
public Void action(MBeanServerConnection connection, JBoss5ProfileServiceProxy profileService) throws Exception { |
113 |
public void run() { |
107 |
// Query to the jboss server |
114 |
try { |
108 |
ObjectName searchPattern; |
115 |
final JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); |
109 |
if (abilitiesSupport.isRemoteManagementSupported() |
116 |
dm.invokeRemoteAction(new JBRemoteAction<Void>() { |
110 |
&& (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { |
117 |
|
111 |
searchPattern = new ObjectName("jboss.management.local:j2eeType=WebModule,J2EEApplication=null,*"); // NOI18N |
118 |
@Override |
|
|
119 |
public Void action(MBeanServerConnection connection, JBoss5ProfileServiceProxy profileService) throws Exception { |
120 |
// Query to the jboss server |
121 |
ObjectName searchPattern; |
122 |
if (abilitiesSupport.isRemoteManagementSupported() |
123 |
&& (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { |
124 |
searchPattern = new ObjectName("jboss.management.local:j2eeType=WebModule,J2EEApplication=null,*"); // NOI18N |
112 |
} |
125 |
} |
113 |
else { |
126 |
else { |
114 |
searchPattern = new ObjectName("jboss.web:j2eeType=WebModule,J2EEApplication=none,*"); // NOI18N |
127 |
searchPattern = new ObjectName("jboss.web:j2eeType=WebModule,J2EEApplication=none,*"); // NOI18N |
|
|
128 |
} |
129 |
|
130 |
Method method = connection.getClass().getMethod("queryMBeans", new Class[] {ObjectName.class, QueryExp.class}); |
131 |
method = Util.fixJava4071957(method); |
132 |
Set managedObj = (Set) method.invoke(connection, new Object[] {searchPattern, null}); |
133 |
|
134 |
// Query results processing |
135 |
for (Iterator it = managedObj.iterator(); it.hasNext();) { |
136 |
try { |
137 |
ObjectName elem = ((ObjectInstance) it.next()).getObjectName(); |
138 |
String name = elem.getKeyProperty("name"); |
139 |
String url = "http://" + dm.getHost() + ":" + dm.getPort(); |
140 |
String context = null; |
141 |
|
142 |
if (name.endsWith(".war")) { |
143 |
name = name.substring(0, name.lastIndexOf(".war")); |
144 |
} |
145 |
|
146 |
if (abilitiesSupport.isRemoteManagementSupported() |
147 |
&& (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { |
148 |
if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package |
149 |
continue; |
150 |
} |
151 |
String descr = (String) Util.getMBeanParameter(connection, "jbossWebDeploymentDescriptor", elem.getCanonicalName()); // NOI18N |
152 |
context = Util.getWebContextRoot(descr, name); |
153 |
} else { |
154 |
if (name.startsWith("//localhost/")) { // NOI18N |
155 |
name = name.substring("//localhost/".length()); // NOI18N |
156 |
} |
157 |
if ("".equals(name)) { |
158 |
name = "ROOT"; // NOI18N // consistent with JBoss4 |
159 |
} |
160 |
if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package |
161 |
continue; |
162 |
} |
163 |
|
164 |
context = (String) Util.getMBeanParameter(connection, "path", elem.getCanonicalName()); // NOI18N |
165 |
} |
166 |
|
167 |
name += ".war"; // NOI18N |
168 |
keys.add(new JBWebModuleNode(name, lookup, (context == null ? null : url + context))); |
169 |
} catch (Exception ex) { |
170 |
LOGGER.log(Level.INFO, null, ex); |
115 |
} |
171 |
} |
|
|
172 |
} |
173 |
return null; |
174 |
} |
175 |
}); |
116 |
|
176 |
|
117 |
Method method = connection.getClass().getMethod("queryMBeans", new Class[] {ObjectName.class, QueryExp.class}); |
177 |
} catch (ExecutionException ex) { |
118 |
method = Util.fixJava4071957(method); |
178 |
LOGGER.log(Level.INFO, null, ex); |
119 |
Set managedObj = (Set) method.invoke(connection, new Object[] {searchPattern, null}); |
179 |
} |
120 |
|
180 |
|
121 |
JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); |
181 |
setKeys(keys); |
|
|
182 |
} |
183 |
} |
122 |
|
184 |
|
123 |
// Query results processing |
185 |
class JBoss7WebNodeUpdater implements Runnable { |
124 |
for (Iterator it = managedObj.iterator(); it.hasNext();) { |
|
|
125 |
try { |
126 |
ObjectName elem = ((ObjectInstance) it.next()).getObjectName(); |
127 |
String name = elem.getKeyProperty("name"); |
128 |
String url = "http://" + dm.getHost() + ":" + dm.getPort(); |
129 |
String context = null; |
130 |
|
186 |
|
|
|
187 |
List keys = new ArrayList(); |
188 |
|
189 |
@Override |
190 |
public void run() { |
191 |
|
192 |
try { |
193 |
final JBDeploymentManager dm = (JBDeploymentManager) lookup.lookup(JBDeploymentManager.class); |
194 |
dm.invokeRemoteAction(new JB7RemoteAction<Void>() { |
195 |
|
196 |
@Override |
197 |
public Void execute() { |
198 |
try { |
199 |
Target[] targets = dm.getTargets(); |
200 |
ModuleType moduleType = ModuleType.WAR; |
201 |
|
202 |
//Get all deployed WAR files. |
203 |
TargetModuleID[] modules = dm.getAvailableModules(moduleType, targets); |
204 |
// Module list may be null if nothing is deployed. |
205 |
if (modules != null) { |
206 |
String url = "http://" + dm.getHost() + ":" + dm.getPort(); |
207 |
for (int intModule = 0; intModule < modules.length; intModule++) { |
208 |
String name = modules[intModule].getModuleID(); |
131 |
if (name.endsWith(".war")) { |
209 |
if (name.endsWith(".war")) { |
132 |
name = name.substring(0, name.lastIndexOf(".war")); |
210 |
name = name.substring(0, name.lastIndexOf(".war")); |
133 |
} |
211 |
} |
134 |
|
212 |
if ("".equals(name)) { |
135 |
if (abilitiesSupport.isRemoteManagementSupported() |
213 |
name = "ROOT"; // NOI18N // consistent with JBoss4 |
136 |
&& (abilitiesSupport.isJB4x() || abilitiesSupport.isJB6x())) { |
|
|
137 |
if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package |
138 |
continue; |
139 |
} |
140 |
String descr = (String) Util.getMBeanParameter(connection, "jbossWebDeploymentDescriptor", elem.getCanonicalName()); // NOI18N |
141 |
context = Util.getWebContextRoot(descr, name); |
142 |
} else { |
143 |
if (name.startsWith("//localhost/")) { // NOI18N |
144 |
name = name.substring("//localhost/".length()); // NOI18N |
145 |
} |
146 |
if ("".equals(name)) { |
147 |
name = "ROOT"; // NOI18N // consistent with JBoss4 |
148 |
} |
149 |
if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package |
150 |
continue; |
151 |
} |
152 |
|
153 |
context = (String) Util.getMBeanParameter(connection, "path", elem.getCanonicalName()); // NOI18N |
154 |
} |
214 |
} |
155 |
|
215 |
if (SYSTEM_WEB_APPLICATIONS.contains(name)) { // Excluding it. It's system package |
|
|
216 |
continue; |
217 |
} |
156 |
name += ".war"; // NOI18N |
218 |
name += ".war"; // NOI18N |
157 |
keys.add(new JBWebModuleNode(name, lookup, (context == null ? null : url + context))); |
219 |
keys.add(new JBWebModuleNode(name, lookup, url)); |
158 |
} catch (Exception ex) { |
|
|
159 |
LOGGER.log(Level.INFO, null, ex); |
160 |
} |
220 |
} |
161 |
} |
221 |
} |
162 |
return null; |
222 |
} catch (TargetException ex) { |
|
|
223 |
Exceptions.printStackTrace(ex); |
224 |
} catch (IllegalStateException ex) { |
225 |
Exceptions.printStackTrace(ex); |
163 |
} |
226 |
} |
164 |
}); |
227 |
return null; |
165 |
|
228 |
} |
166 |
} catch (ExecutionException ex) { |
229 |
}); |
167 |
LOGGER.log(Level.INFO, null, ex); |
230 |
} catch (Exception ex) { |
168 |
} |
231 |
LOGGER.log(Level.INFO, null, ex); |
|
|
232 |
} |
169 |
|
233 |
|
170 |
setKeys(keys); |
234 |
setKeys(keys); |
171 |
} |
235 |
} |
172 |
}, 0); |
|
|
173 |
} |
236 |
} |
174 |
|
237 |
|
175 |
protected void addNotify() { |
238 |
protected void addNotify() { |