Search in sources :

Example 11 with ServerContext

use of org.glassfish.internal.api.ServerContext in project Payara by payara.

the class AbstractRestResourceProvider method getResourceConfig.

@Override
public ResourceConfig getResourceConfig(Set<Class<?>> classes, final ServerContext sc, final ServiceLocator habitat, final Set<? extends Binder> additionalBinders) throws EndpointRegistrationException {
    final Reloader r = new Reloader();
    ResourceConfig rc = new ResourceConfig(classes);
    rc.property(ServerProperties.MEDIA_TYPE_MAPPINGS, getMimeMappings());
    rc.register(CsrfProtectionFilter.class);
    // TODO - JERSEY2
    // RestConfig restConf = ResourceUtil.getRestConfig(habitat);
    // if (restConf != null) {
    // if (restConf.getLogOutput().equalsIgnoreCase("true")) { //enable output logging
    // rc.getContainerResponseFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getLogInput().equalsIgnoreCase("true")) { //enable input logging
    // rc.getContainerRequestFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getWadlGeneration().equalsIgnoreCase("false")) { //disable WADL
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // }
    // else {
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // 
    rc.register(r);
    rc.register(ReloadResource.class);
    rc.register(new MultiPartFeature());
    // rc.register(getJsonFeature());
    rc.register(new AbstractBinder() {

        @Override
        protected void configure() {
            AbstractActiveDescriptor<Reloader> descriptor = BuilderHelper.createConstantDescriptor(r);
            descriptor.addContractType(Reloader.class);
            bind(descriptor);
            AbstractActiveDescriptor<ServerContext> scDescriptor = BuilderHelper.createConstantDescriptor(sc);
            scDescriptor.addContractType(ServerContext.class);
            bind(scDescriptor);
            LocatorBridge locatorBridge = new LocatorBridge(habitat);
            AbstractActiveDescriptor<LocatorBridge> hDescriptor = BuilderHelper.createConstantDescriptor(locatorBridge);
            bind(hDescriptor);
            RestSessionManager rsm = habitat.getService(RestSessionManager.class);
            AbstractActiveDescriptor<RestSessionManager> rmDescriptor = BuilderHelper.createConstantDescriptor(rsm);
            bind(rmDescriptor);
        }
    });
    for (Binder b : additionalBinders) {
        rc.register(b);
    }
    rc.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
    return rc;
}
Also used : Binder(org.glassfish.hk2.utilities.Binder) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServerContext(org.glassfish.internal.api.ServerContext) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) RestSessionManager(org.glassfish.common.util.admin.RestSessionManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) AbstractActiveDescriptor(org.glassfish.hk2.utilities.AbstractActiveDescriptor)

Example 12 with ServerContext

use of org.glassfish.internal.api.ServerContext in project Payara by payara.

the class ActiveJmsResourceAdapter method isDBEnabled.

private boolean isDBEnabled() {
    Domain domain = Globals.get(Domain.class);
    ServerContext serverContext = Globals.get(ServerContext.class);
    Server server = domain.getServerNamed(serverContext.getInstanceName());
    AvailabilityService as = server.getConfig().getAvailabilityService();
    if (as != null) {
        JmsAvailability jmsAvailability = as.getExtensionByType(JmsAvailability.class);
        if (jmsAvailability.getAvailabilityEnabled() != null && Boolean.parseBoolean(jmsAvailability.getAvailabilityEnabled())) {
            return true;
        } else if (jmsAvailability.getConfigStoreType() != null && !"MASTERBROKER".equalsIgnoreCase(jmsAvailability.getConfigStoreType()))
            return true;
    }
    return false;
}
Also used : AvailabilityService(com.sun.enterprise.config.serverbeans.AvailabilityService) ServerContext(org.glassfish.internal.api.ServerContext) Server(com.sun.enterprise.config.serverbeans.Server) JmsAvailability(com.sun.enterprise.connectors.jms.config.JmsAvailability) Domain(com.sun.enterprise.config.serverbeans.Domain)

Example 13 with ServerContext

use of org.glassfish.internal.api.ServerContext in project Payara by payara.

the class ActiveJmsResourceAdapter method getClusterName.

private String getClusterName() {
    ServerContext serverctx = Globals.get(ServerContext.class);
    String instanceName = serverctx.getInstanceName();
    Domain domain = Globals.get(Domain.class);
    Server server = domain.getServerNamed(instanceName);
    return server.getCluster() != null ? server.getCluster().getName() : null;
/*ClusterHelper.getClusterForInstance(this.serverContxt.
                       .getConfigContext(),
                        serverContxt.getInstanceName()).getName();*/
}
Also used : ServerContext(org.glassfish.internal.api.ServerContext) Server(com.sun.enterprise.config.serverbeans.Server) Domain(com.sun.enterprise.config.serverbeans.Domain)

Example 14 with ServerContext

use of org.glassfish.internal.api.ServerContext in project Payara by payara.

the class ActiveJmsResourceAdapter method startResourceAdapter.

@Override
protected void startResourceAdapter(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
    JmsService jmsService = getJmsService();
    if (jmsService != null && jmsService.getType().equals("DISABLED")) {
        return;
    }
    try {
        if (this.moduleName_.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER)) {
            if (connectorRuntime.isServer()) {
                Domain domain = Globals.get(Domain.class);
                ServerContext serverContext = Globals.get(ServerContext.class);
                Server server = domain.getServerNamed(serverContext.getInstanceName());
                try {
                    initializeLazyListener(jmsService);
                } catch (Throwable ex) {
                    Logger.getLogger(ActiveJmsResourceAdapter.class.getName()).log(Level.SEVERE, null, ex);
                    throw new ResourceAdapterInternalException(ex);
                }
            }
            // System.setProperty("imq.jmsra.direct.clustered", "true");
            AccessController.doPrivileged(new java.security.PrivilegedExceptionAction() {

                public Object run() throws ResourceAdapterInternalException {
                    // set the JMSRA system property to enable XA JOINS
                    // disabling this due to issue - 8727
                    // System.setProperty(XA_JOIN_ALLOWED, "true");
                    // to prevent classloader leaks in new threads clear invocation manager before bootstrapping JMS
                    resourceadapter_.start(bootStrapContextImpl);
                    return null;
                }
            });
        // setResourceAdapter(resourceadapter_);
        } else {
            resourceadapter_.start(bootStrapContextImpl);
        }
    } catch (PrivilegedActionException ex) {
        throw new ResourceAdapterInternalException(ex);
    }
}
Also used : JmsService(com.sun.enterprise.connectors.jms.config.JmsService) ServerContext(org.glassfish.internal.api.ServerContext) Server(com.sun.enterprise.config.serverbeans.Server) PrivilegedActionException(java.security.PrivilegedActionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) Domain(com.sun.enterprise.config.serverbeans.Domain) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 15 with ServerContext

use of org.glassfish.internal.api.ServerContext in project Payara by payara.

the class OpenAPISupplier method getServerURL.

private List<URL> getServerURL(String contextRoot) {
    List<URL> result = new ArrayList<>();
    ServerContext context = Globals.get(ServerContext.class);
    String hostName;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException ex) {
        hostName = "localhost";
    }
    String instanceType = Globals.get(ServerEnvironment.class).getRuntimeType().toString();
    List<Integer> httpPorts = new ArrayList<>();
    List<Integer> httpsPorts = new ArrayList<>();
    List<NetworkListener> networkListeners = context.getConfigBean().getConfig().getNetworkConfig().getNetworkListeners().getNetworkListener();
    String adminListener = context.getConfigBean().getConfig().getAdminListener().getName();
    networkListeners.stream().filter(networkListener -> Boolean.parseBoolean(networkListener.getEnabled())).forEach(networkListener -> {
        int port;
        try {
            // get the dynamic config port
            port = Globals.get(GrizzlyService.class).getRealPort(networkListener);
        } catch (MultiException ex) {
            // get the port in the domain xml
            port = Integer.parseInt(networkListener.getPort());
        }
        // Check if this listener is using HTTP or HTTPS
        boolean securityEnabled = Boolean.parseBoolean(networkListener.findProtocol().getSecurityEnabled());
        List<Integer> ports = securityEnabled ? httpsPorts : httpPorts;
        // If this listener isn't the admin listener, it must be an HTTP/HTTPS listener
        if (!networkListener.getName().equals(adminListener)) {
            ports.add(port);
        } else if (instanceType.equals("MICRO")) {
            // micro instances can use the admin listener as both an admin and HTTP/HTTPS port
            ports.add(port);
        }
    });
    for (Integer httpPort : httpPorts) {
        try {
            result.add(new URL("http", hostName, httpPort, contextRoot));
        } catch (MalformedURLException ex) {
        // ignore
        }
    }
    for (Integer httpsPort : httpsPorts) {
        try {
            result.add(new URL("https", hostName, httpsPort, contextRoot));
        } catch (MalformedURLException ex) {
        // ignore
        }
    }
    return result;
}
Also used : StructuredDeploymentTracing(org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing) OpenApiConfiguration(fish.payara.microprofile.openapi.impl.config.OpenApiConfiguration) ConfigPropertyProcessor(fish.payara.microprofile.openapi.impl.processor.ConfigPropertyProcessor) Enumeration(java.util.Enumeration) Globals(org.glassfish.internal.api.Globals) URL(java.net.URL) ApplicationProcessor(fish.payara.microprofile.openapi.impl.processor.ApplicationProcessor) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) FileProcessor(fish.payara.microprofile.openapi.impl.processor.FileProcessor) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Collectors.toSet(java.util.stream.Collectors.toSet) Types(org.glassfish.hk2.classmodel.reflect.Types) MalformedURLException(java.net.MalformedURLException) ApplicationLifecycle(com.sun.enterprise.v3.server.ApplicationLifecycle) Set(java.util.Set) IOException(java.io.IOException) OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) Logger(java.util.logging.Logger) UnknownHostException(java.net.UnknownHostException) Parser(org.glassfish.hk2.classmodel.reflect.Parser) Objects(java.util.Objects) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) ServerContext(org.glassfish.internal.api.ServerContext) List(java.util.List) FilterProcessor(fish.payara.microprofile.openapi.impl.processor.FilterProcessor) GrizzlyService(com.sun.enterprise.v3.services.impl.GrizzlyService) MultiException(org.glassfish.hk2.api.MultiException) BaseProcessor(fish.payara.microprofile.openapi.impl.processor.BaseProcessor) ModelReaderProcessor(fish.payara.microprofile.openapi.impl.processor.ModelReaderProcessor) Collections(java.util.Collections) Type(org.glassfish.hk2.classmodel.reflect.Type) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) URL(java.net.URL) ServerContext(org.glassfish.internal.api.ServerContext) MultiException(org.glassfish.hk2.api.MultiException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

ServerContext (org.glassfish.internal.api.ServerContext)15 Domain (com.sun.enterprise.config.serverbeans.Domain)7 Server (com.sun.enterprise.config.serverbeans.Server)6 File (java.io.File)4 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)3 IOException (java.io.IOException)3 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)3 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 AvailabilityService (com.sun.enterprise.config.serverbeans.AvailabilityService)2 JmsAvailability (com.sun.enterprise.connectors.jms.config.JmsAvailability)2 ExecException (com.sun.enterprise.util.ExecException)2 ProcessExecutor (com.sun.enterprise.util.ProcessExecutor)2 GrizzlyService (com.sun.enterprise.v3.services.impl.GrizzlyService)2 PrintStream (java.io.PrintStream)2 InetAddress (java.net.InetAddress)2 PrivilegedActionException (java.security.PrivilegedActionException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Properties (java.util.Properties)2 Test (org.junit.Test)2