Index: src/main/java/org/glassfish/admin/rest/Util.java =================================================================== --- src/main/java/org/glassfish/admin/rest/Util.java (revision 47907) +++ src/main/java/org/glassfish/admin/rest/Util.java (working copy) @@ -41,6 +41,7 @@ import com.sun.enterprise.util.LocalStringManagerImpl; import com.sun.enterprise.v3.common.ActionReporter; +import com.sun.jersey.api.client.Client; import org.glassfish.admin.rest.provider.ProviderUtil; import javax.ws.rs.core.UriInfo; import java.io.UnsupportedEncodingException; @@ -63,6 +64,7 @@ */ public class Util { public final static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(Util.class); + private static Client client; private Util() { } @@ -255,6 +257,14 @@ String methodName = upperCaseFirstLetter(elementName); return methodName = prefix + methodName; } + + public static Client getJerseyClient() { + if (client == null) { + client = Client.create(); + } + + return client; + } /** Index: src/main/java/org/glassfish/admin/rest/LazyJerseyInit.java =================================================================== --- src/main/java/org/glassfish/admin/rest/LazyJerseyInit.java (revision 47907) +++ src/main/java/org/glassfish/admin/rest/LazyJerseyInit.java (working copy) @@ -106,6 +106,7 @@ Adapter adapter = null; Reloader r = new Reloader(); + ResourceConfig rc = new DefaultResourceConfig(classes); rc.getMediaTypeMappings().put("xml", MediaType.APPLICATION_XML_TYPE); rc.getMediaTypeMappings().put("json", MediaType.APPLICATION_JSON_TYPE); @@ -121,7 +122,6 @@ rc.getContainerRequestFilters().add(LoggingFilter.class); } if (restConf.getWadlGeneration().equalsIgnoreCase("false")) { //disable WADL - rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE); } } @@ -130,11 +130,9 @@ rc.getClasses().add(ReloadResource.class); //We can only inject these 4 extra classes in Jersey resources... - // rc.getSingletons().add(new SingletonTypeInjectableProvider(Reloader.class, r) {}); rc.getSingletons().add(new SingletonTypeInjectableProvider(ServerContext.class, sc) {}); rc.getSingletons().add(new SingletonTypeInjectableProvider(Habitat.class, habitat) {}); - rc.getSingletons().add(new SingletonTypeInjectableProvider(Client.class, Client.create()) {}); rc.getSingletons().add(new SingletonTypeInjectableProvider(SessionManager.class, habitat.getComponent(SessionManager.class)) {}); //Use common classloader. Jersey artifacts are not visible through @@ -252,7 +250,6 @@ @Override public Set> getResourcesConfigForManagement(Habitat habitat) { - Class domainResourceClass = null;//org.glassfish.admin.rest.resources.generated.DomainResource.class; generateASM(habitat); @@ -265,13 +262,14 @@ final Set> r = new HashSet>(); // uncomment if you need to run the generator: - r.add(GeneratorResource.class); + //r.add(GeneratorResource.class); r.add(StatusGenerator.class); //r.add(ActionReportResource.class); r.add(domainResourceClass); r.add(ManagementProxyResource.class); - r.add(org.glassfish.admin.rest.resources.SessionsResource.class); //TODO this needs to be added to all rest adapters that want to be secured. Decide on it after the discussion to unify RestAdapter is concluded + //TODO this needs to be added to all rest adapters that want to be secured. Decide on it after the discussion to unify RestAdapter is concluded + r.add(org.glassfish.admin.rest.resources.SessionsResource.class); r.add(org.glassfish.admin.rest.resources.StaticResource.class); //body readers, not in META-INF/services anymore Index: src/main/java/org/glassfish/admin/rest/resources/custom/ManagementProxyResource.java =================================================================== --- src/main/java/org/glassfish/admin/rest/resources/custom/ManagementProxyResource.java (revision 47907) +++ src/main/java/org/glassfish/admin/rest/resources/custom/ManagementProxyResource.java (working copy) @@ -40,7 +40,6 @@ package org.glassfish.admin.rest.resources.custom; -import com.sun.jersey.api.client.Client; import org.glassfish.admin.rest.results.ActionReportResult; import org.glassfish.admin.rest.utils.ProxyImpl; import org.glassfish.admin.rest.utils.xml.RestActionReporter; @@ -58,6 +57,7 @@ import java.net.URL; import java.util.List; import java.util.Properties; +import org.glassfish.admin.rest.Util; /** * @author Mitesh Meswani @@ -71,10 +71,6 @@ @Context protected Habitat habitat; - @Context - protected Client client; - - @GET public ActionReportResult proxyRequest() { @@ -84,7 +80,7 @@ ActionReportResult result = new ActionReportResult(ar); - Properties proxiedResponse = new ManagementProxyImpl().proxyRequest(uriInfo, client, habitat); + Properties proxiedResponse = new ManagementProxyImpl().proxyRequest(uriInfo, Util.getJerseyClient(), habitat); ar.setExtraProperties(proxiedResponse); return result; } Index: src/main/java/org/glassfish/admin/rest/resources/MonitoringResource.java =================================================================== --- src/main/java/org/glassfish/admin/rest/resources/MonitoringResource.java (revision 47907) +++ src/main/java/org/glassfish/admin/rest/resources/MonitoringResource.java (working copy) @@ -40,6 +40,7 @@ package org.glassfish.admin.rest.resources; +import org.glassfish.admin.rest.Util; import org.glassfish.admin.rest.utils.ProxyImpl; import org.jvnet.hk2.component.Habitat; @@ -65,7 +66,6 @@ import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.config.serverbeans.Server; -import com.sun.jersey.api.client.Client; import org.glassfish.admin.rest.results.ActionReportResult; import org.glassfish.admin.rest.utils.xml.RestActionReporter; import org.glassfish.external.statistics.Statistic; @@ -92,9 +92,6 @@ @Context protected Habitat habitat; - @Context - protected Client client; - @GET @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML,"text/html;qs=2"}) public Response getChildNodes(@PathParam("path")List pathSegments) { @@ -149,7 +146,7 @@ } else { //firstPathElement != currentInstanceName => A proxy request if(isRunningOnDAS) { //Attempt to forward to instance if running on Das //TODO validate that firstPathElement corresponds to a valid server name - Properties proxiedResponse = new MonitoringProxyImpl().proxyRequest(uriInfo, client, habitat); + Properties proxiedResponse = new MonitoringProxyImpl().proxyRequest(uriInfo, Util.getJerseyClient(), habitat); ar.setExtraProperties(proxiedResponse); responseBuilder.entity(new ActionReportResult(ar)); } else { // Not running on DAS and firstPathElement != currentInstanceName => Reject the request as invalid