@Override
  public <T> T getBusinessObject(SessionContext ctx, Class<T> businessInterface)
      throws IllegalStateException {
    if (businessInterface == null) {
      throw new IllegalStateException("Business interface type cannot be null");
    }

    final Serializable sessionId =
        ((SessionBeanComponentInstance.SessionBeanComponentInstanceContext) ctx).getId();

    if (viewServices.containsKey(businessInterface.getName())) {
      final ServiceController<?> serviceController =
          CurrentServiceRegistry.getServiceRegistry()
              .getRequiredService(viewServices.get(businessInterface.getName()));
      final ComponentView view = (ComponentView) serviceController.getValue();
      final ComponentViewInstance instance;
      if (sessionId != null) {
        instance =
            view.createInstance(
                Collections.<Object, Object>singletonMap(
                    StatefulSessionComponent.SESSION_ATTACH_KEY, sessionId));
      } else {
        instance = view.createInstance();
      }
      return (T) instance.createProxy();
    } else {
      throw new IllegalStateException(
          "View of type " + businessInterface + " not found on bean " + this);
    }
  }
 public void stop(final StopContext stopContext) {
   final ServiceController<?> serviceController =
       stopContext
           .getController()
           .getServiceContainer()
           .getService(CommonDeploymentService.getServiceName(jndiName));
   if (serviceController != null) {
     serviceController.setMode(ServiceController.Mode.REMOVE);
   }
   ExecutorService executorService = executor.getValue();
   Runnable r =
       new Runnable() {
         @Override
         public void run() {
           try {
             stopService();
           } finally {
             stopContext.complete();
           }
         }
       };
   try {
     executorService.execute(r);
   } catch (RejectedExecutionException e) {
     r.run();
   } finally {
     stopContext.asynchronous();
   }
 }
 /**
  * @see org.jboss.wsf.spi.ioc.IoCContainerProxy#getBean(java.lang.String, java.lang.Class)
  * @param <T> bean type
  * @param beanName bean name inside IoC registry
  * @param clazz bean type class
  * @return bean instance
  * @throws IllegalArgumentException if bean is not found
  */
 @SuppressWarnings("unchecked")
 public <T> T getBean(final String beanName, final Class<T> clazz) {
   ServiceController<T> service =
       (ServiceController<T>)
           WSServices.getContainerRegistry().getService(ServiceName.parse(beanName));
   return service != null ? service.getValue() : null;
 }
Exemplo n.º 4
0
  /**
   * Test configuration
   *
   * @throws Throwable Thrown if case of an error
   */
  @Test
  public void testRegistryConfiguration() throws Throwable {
    ServiceController<?> controller =
        serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE);
    assertNotNull(controller);
    ResourceAdapterRepository repository = (ResourceAdapterRepository) controller.getValue();
    assertNotNull(repository);
    Set<String> ids = repository.getResourceAdapters(javax.jms.MessageListener.class);

    assertNotNull(ids);
    int pureInflowListener = 0;
    for (String id : ids) {
      if (id.indexOf("PureInflow") != -1) {
        pureInflowListener++;
      }
    }
    assertEquals(1, pureInflowListener);

    String piId = ids.iterator().next();
    assertNotNull(piId);

    Endpoint endpoint = repository.getEndpoint(piId);
    assertNotNull(endpoint);

    List<MessageListener> listeners = repository.getMessageListeners(piId);
    assertNotNull(listeners);
    assertEquals(1, listeners.size());

    MessageListener listener = listeners.get(0);

    ActivationSpec as = listener.getActivation().createInstance();
    assertNotNull(as);
    assertNotNull(as.getResourceAdapter());
  }
  /*
   * In order to test this specific scenario, we use Byteman to insert a monitor in the specific moment
   *  where the transition from STOP_REQUESTED to the next state is going to occur.
   *  This monitor will force the thread to wait until upperCount is incremented to 1.
   */
  @Test
  public void test() throws Exception {
    ServiceName serviceName = ServiceName.of("service");
    TestServiceListener serviceListener = new TestServiceListener();

    // install service as usual
    Future<ServiceController<?>> serviceStart = serviceListener.expectServiceStart(serviceName);
    serviceContainer.addService(serviceName, Service.NULL).addListener(serviceListener).install();
    ServiceController<?> serviceController = assertController(serviceName, serviceStart);

    Future<ServiceController<?>> serviceStopping =
        serviceListener.expectNoServiceStopping(serviceName);
    Future<ServiceController<?>> serviceStop = serviceListener.expectNoServiceStop(serviceName);
    serviceStart = serviceListener.expectNoServiceStart(serviceName);
    // set the mode to NEVER, so that serviceController enters STOP_REQUESTED state
    serviceController.setMode(ServiceController.Mode.NEVER);
    // set the mode to ACTIVE, so that serviceController transitions to UP state
    serviceController.setMode(ServiceController.Mode.ACTIVE);
    // no notifications are expected
    assertNull(serviceStop.get());
    assertNull(serviceStopping.get());
    assertNull(serviceStart.get());
    // service should still be in the up state
    assertSame(ServiceController.State.UP, serviceController.getState());
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    ModelNode newValue = operation.require(CacheContainerResource.PROTO_URL.getName());
    String urlString = newValue.asString();

    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String cacheContainerName = address.getElement(address.size() - 1).getValue();
    final ServiceController<?> controller =
        context
            .getServiceRegistry(false)
            .getService(EmbeddedCacheManagerService.getServiceName(cacheContainerName));

    EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) controller.getValue();
    ProtobufMetadataManager protoManager =
        cacheManager.getGlobalComponentRegistry().getComponent(ProtobufMetadataManager.class);
    if (protoManager != null) {
      try {
        URL url = new URL(urlString);
        protoManager.registerProtofile(url.openStream());
      } catch (Exception e) {
        throw new OperationFailedException(
            new ModelNode().set(MESSAGES.failedToInvokeOperation(e.getLocalizedMessage())));
      }
    }
    context.stepCompleted();
  }
    @Override
    public synchronized Reference getInstance(final String className) {
      Reference instance = cache.get(className);
      if (instance != null) return instance;

      if (!className.equals(endpointClass)) {
        // handle JAXWS handler instantiation
        final ServiceName handlerComponentName = getHandlerComponentServiceName(className);
        final ServiceController<BasicComponent> handlerComponentController =
            getComponentController(handlerComponentName);
        if (handlerComponentController != null) {
          // we support initialization only on non system JAXWS handlers
          final BasicComponent handlerComponent = handlerComponentController.getValue();
          final ComponentInstance handlerComponentInstance =
              handlerComponent.createInstance(delegate.getInstance(className).getValue());
          final Object handlerInstance = handlerComponentInstance.getInstance();
          // mark reference as initialized because JBoss server initialized it
          final Reference handlerReference =
              ReferenceFactory.newInitializedReference(handlerInstance);
          return cacheAndGet(handlerReference);
        }
      }
      // fallback for system JAXWS handlers
      final Reference fallbackInstance = delegate.getInstance(className);
      final Reference fallbackReference =
          ReferenceFactory.newUninitializedReference(fallbackInstance);
      return cacheAndGet(fallbackReference);
    }
  public ModelController createController(final ModelNode model, final Setup registration)
      throws InterruptedException {
    final ServiceController<?> existingController =
        serviceContainer.getService(ServiceName.of("ModelController"));
    if (existingController != null) {
      final CountDownLatch latch = new CountDownLatch(1);
      existingController.addListener(
          new AbstractServiceListener<Object>() {
            public void listenerAdded(ServiceController<?> serviceController) {
              serviceController.setMode(ServiceController.Mode.REMOVE);
            }

            public void transition(
                ServiceController<?> serviceController, ServiceController.Transition transition) {
              if (transition.equals(ServiceController.Transition.REMOVING_to_REMOVED)) {
                latch.countDown();
              }
            }
          });
      latch.await();
    }

    ServiceTarget target = serviceContainer.subTarget();
    ControlledProcessState processState = new ControlledProcessState(true);
    ModelControllerService svc = new ModelControllerService(processState, registration, model);
    ServiceBuilder<ModelController> builder =
        target.addService(ServiceName.of("ModelController"), svc);
    builder.install();
    svc.latch.await();
    ModelController controller = svc.getValue();
    ModelNode setup = Util.getEmptyOperation("setup", new ModelNode());
    controller.execute(setup, null, null, null);
    processState.setRunning();
    return controller;
  }
  @Override
  public void unregisterService(ServiceState serviceState) {
    List<ServiceName> serviceNames = serviceState.getServiceNames();
    log.debug("Unregister service: " + serviceNames);

    AbstractBundle serviceOwner = serviceState.getServiceOwner();

    // This event is synchronously delivered before the service has completed unregistering.
    eventsPlugin.fireServiceEvent(serviceOwner, ServiceEvent.UNREGISTERING, serviceState);

    // Remove from using bundles
    for (AbstractBundle bundleState : serviceState.getUsingBundlesInternal()) {
      while (ungetService(bundleState, serviceState)) ;
    }

    // Remove from owner bundle
    serviceOwner.removeRegisteredService(serviceState);

    // Unregister name associations
    for (ServiceName serviceName : serviceNames) {
      String[] clazzes = (String[]) serviceState.getProperty(Constants.OBJECTCLASS);
      for (String clazz : clazzes) unregisterNameAssociation(clazz, serviceName);
    }

    // Remove from controller
    ServiceName rootServiceName = serviceNames.get(0);
    try {
      ServiceController<?> controller = serviceContainer.getService(rootServiceName);
      controller.setMode(Mode.REMOVE);
    } catch (RuntimeException ex) {
      log.error("Cannot remove service: " + rootServiceName, ex);
    }
  }
Exemplo n.º 10
0
 public void undeploy(DeploymentUnit context) {
   final ServiceName moduleContextServiceName = ContextServiceNameBuilder.module(context);
   final ServiceController<?> serviceController =
       context.getServiceRegistry().getService(moduleContextServiceName);
   if (serviceController != null) {
     serviceController.setMode(ServiceController.Mode.REMOVE);
   }
 }
  @SuppressWarnings("unchecked")
  @Override
  public final Object getObjectInstance(
      Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    final Reference reference = asReference(obj);
    final ServiceNameRefAdr nameAdr = (ServiceNameRefAdr) reference.get("srof");
    if (nameAdr == null) {
      throw new NamingException("Invalid context reference.  Not a 'srof' reference.");
    }
    final ServiceName serviceName = (ServiceName) nameAdr.getContent();
    final ServiceController<?> controller;
    try {
      controller = serviceRegistry.getRequiredService(serviceName);
    } catch (ServiceNotFoundException e) {
      throw new NamingException("Could not resolve service " + serviceName);
    }

    ServiceReferenceListener listener = new ServiceReferenceListener();
    controller.addListener(listener);
    synchronized (listener) {
      // if we are interrupted just let the exception propagate for now
      while (!listener.finished) {
        try {
          listener.wait();
        } catch (InterruptedException e) {
          throw new NamingException(
              "Thread interrupted while retrieving service reference for service " + serviceName);
        }
      }
    }
    switch (listener.getState()) {
      case UP:
        return getObjectInstance(listener.getValue(), obj, name, nameCtx, environment);
      case START_FAILED:
        throw new NamingException(
            "Could not resolve service reference to "
                + serviceName
                + " in factory "
                + getClass().getName()
                + ". Service was in state START_FAILED.");
      case REMOVED:
        throw new NamingException(
            "Could not resolve service reference to "
                + serviceName
                + " in factory "
                + getClass().getName()
                + ". Service was in state START_FAILED.");
    }
    // we should never get here, as the listener should not notify unless the state was one of the
    // above
    throw new NamingException(
        "Could not resolve service reference to "
            + serviceName
            + " in factory "
            + getClass().getName()
            + ". This is a bug in ServiceReferenceObjectFactory. State was"
            + listener.getState());
  }
Exemplo n.º 12
0
 /**
  * Rollback runtime changes made in {@link #performRuntime(OperationContext,
  * org.jboss.dmr.ModelNode, org.jboss.dmr.ModelNode, ServiceVerificationHandler, java.util.List)}.
  *
  * <p>This default implementation removes all services in the given list of {@code controllers}.
  * The contents of {@code controllers} is the same as what was in the {@code newControllers}
  * parameter passed to {@code performRuntime()} when that method returned.
  *
  * @param context the operation context
  * @param operation the operation being executed
  * @param model persistent configuration model node that corresponds to the address of {@code
  *     operation}
  * @param controllers holder for the {@link ServiceController} for any new services installed by
  *     {@link #performRuntime(OperationContext, org.jboss.dmr.ModelNode, org.jboss.dmr.ModelNode,
  *     ServiceVerificationHandler, java.util.List)}
  */
 protected void rollbackRuntime(
     OperationContext context,
     final ModelNode operation,
     final ModelNode model,
     List<ServiceController<?>> controllers) {
   for (ServiceController<?> controller : controllers) {
     context.removeService(controller.getName());
   }
 }
 /**
  * @return
  * @deprecated {@link EJBUtilities} is deprecated post 7.2.0.Final version.
  */
 @Deprecated
 protected EJBUtilities getEJBUtilities() {
   // constructs
   final DeploymentUnit deploymentUnit = getDeploymentUnitInjector().getValue();
   final ServiceController<EJBUtilities> serviceController =
       (ServiceController<EJBUtilities>)
           deploymentUnit.getServiceRegistry().getRequiredService(EJBUtilities.SERVICE_NAME);
   return serviceController.getValue();
 }
  @Override
  public synchronized void start(StartContext context) throws StartException {
    ServiceController<?> controller = context.getController();
    LOGGER.tracef("Starting: %s in mode %s", controller.getName(), controller.getMode());
    try {
      ServiceContainer serviceContainer = context.getController().getServiceContainer();

      // Setup the OSGi {@link Framework} properties
      SubsystemState subsystemState = injectedSubsystemState.getValue();
      Map<String, Object> props = new HashMap<String, Object>(subsystemState.getProperties());
      setupIntegrationProperties(context, props);

      // Register the URLStreamHandlerFactory
      Module coreFrameworkModule =
          ((ModuleClassLoader) FrameworkBuilder.class.getClassLoader()).getModule();
      Module.registerURLStreamHandlerFactoryModule(coreFrameworkModule);
      Module.registerContentHandlerFactoryModule(coreFrameworkModule);

      ServiceTarget serviceTarget = context.getChildTarget();
      JAXPServiceProvider.addService(serviceTarget);
      ResolverService.addService(serviceTarget);
      RepositoryService.addService(serviceTarget);

      Activation activation = subsystemState.getActivationPolicy();
      Mode initialMode = (activation == Activation.EAGER ? Mode.ACTIVE : Mode.LAZY);

      // Configure the {@link Framework} builder
      FrameworkBuilder builder = FrameworkBuilderFactory.create(props, initialMode);
      builder.setServiceContainer(serviceContainer);
      builder.setServiceTarget(serviceTarget);

      builder.createFrameworkServices(serviceContainer, true);
      builder.registerIntegrationService(FrameworkPhase.CREATE, new BundleLifecycleIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.CREATE, new FrameworkModuleIntegration(props));
      builder.registerIntegrationService(FrameworkPhase.CREATE, new ModuleLoaderIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.CREATE, new SystemServicesIntegration(resource, extensions));
      builder.registerIntegrationService(FrameworkPhase.INIT, new BootstrapBundlesIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.INIT, new PersistentBundlesIntegration(deploymentTracker));

      // Install the services to create the framework
      builder.installServices(FrameworkPhase.CREATE, serviceTarget, verificationHandler);

      if (activation == Activation.EAGER) {
        builder.installServices(FrameworkPhase.INIT, serviceTarget, verificationHandler);
        builder.installServices(FrameworkPhase.ACTIVE, serviceTarget, verificationHandler);
      }

      // Create the framework activator
      FrameworkActivator.create(builder);

    } catch (Throwable th) {
      throw MESSAGES.startFailedToCreateFrameworkServices(th);
    }
  }
 void setServiceMode(ServiceController<?> controller, Mode mode) {
   try {
     LOGGER.tracef("Set mode %s on service: %s", mode, controller.getName());
     controller.setMode(mode);
   } catch (IllegalArgumentException rte) {
     // [MSC-105] Cannot determine whether container is shutting down
     if (rte.getMessage().equals("Container is shutting down") == false) throw rte;
   }
 }
Exemplo n.º 16
0
 public Class<?> getEjbLocalObjectType() {
   if (ejbLocalObjectViewServiceName == null) {
     return null;
   }
   final ServiceController<?> serviceController =
       currentServiceContainer().getRequiredService(ejbLocalObjectViewServiceName);
   final ComponentView view = (ComponentView) serviceController.getValue();
   return view.getViewClass();
 }
Exemplo n.º 17
0
 protected <T> T createViewInstanceProxy(
     final Class<T> viewInterface,
     final Map<Object, Object> contextData,
     final ServiceName serviceName) {
   final ServiceController<?> serviceController =
       CurrentServiceContainer.getServiceContainer().getRequiredService(serviceName);
   final ComponentView view = (ComponentView) serviceController.getValue();
   final ManagedReference instance = view.createInstance(contextData);
   return viewInterface.cast(instance.getInstance());
 }
Exemplo n.º 18
0
 private void testCustomFilters(KernelServices mainServices) {
   ServiceController<FilterService> customFilter =
       (ServiceController<FilterService>)
           mainServices.getContainer().getService(UndertowService.FILTER.append("custom-filter"));
   customFilter.setMode(ServiceController.Mode.ACTIVE);
   FilterService connectionLimiterService = customFilter.getService().getValue();
   HttpHandler result =
       connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
   Assert.assertNotNull("handler should have been created", result);
 }
Exemplo n.º 19
0
 public static TransactionManager getTransactionManager(StartContext context) {
   @SuppressWarnings("unchecked")
   ServiceController<TransactionManager> service =
       (ServiceController<TransactionManager>)
           context
               .getController()
               .getServiceContainer()
               .getService(TxnServices.JBOSS_TXN_TRANSACTION_MANAGER);
   return service == null ? null : service.getValue();
 }
Exemplo n.º 20
0
  private synchronized ContainerStateChangeReport createContainerStateChangeReport() {

    final Map<ServiceName, Set<ServiceName>> missingDeps =
        new HashMap<ServiceName, Set<ServiceName>>();
    for (ServiceController<?> controller : servicesWithMissingDeps) {
      for (ServiceName missing : controller.getImmediateUnavailableDependencies()) {
        Set<ServiceName> dependents = missingDeps.get(missing);
        if (dependents == null) {
          dependents = new HashSet<ServiceName>();
          missingDeps.put(missing, dependents);
        }
        dependents.add(controller.getName());
      }
    }

    final Set<ServiceName> previousMissing = previousMissingDepSet;

    // no longer missing deps...
    final Map<ServiceName, Boolean> noLongerMissingServices = new TreeMap<ServiceName, Boolean>();
    for (ServiceName name : previousMissing) {
      if (!missingDeps.containsKey(name)) {
        ServiceController<?> controller = serviceRegistry.getService(name);
        noLongerMissingServices.put(name, controller == null);
      }
    }

    // newly missing deps
    final Map<ServiceName, MissingDependencyInfo> missingServices =
        new TreeMap<ServiceName, MissingDependencyInfo>();
    for (Map.Entry<ServiceName, Set<ServiceName>> entry : missingDeps.entrySet()) {
      final ServiceName name = entry.getKey();
      if (!previousMissing.contains(name)) {
        ServiceController<?> controller = serviceRegistry.getService(name);
        boolean unavailable = controller != null;
        missingServices.put(name, new MissingDependencyInfo(name, unavailable, entry.getValue()));
      }
    }

    final Map<ServiceController<?>, String> currentFailedControllers =
        new HashMap<ServiceController<?>, String>(failedControllers);

    previousMissingDepSet = new HashSet<ServiceName>(missingDeps.keySet());

    failedControllers.clear();

    boolean needReport =
        !missingServices.isEmpty()
            || !currentFailedControllers.isEmpty()
            || !noLongerMissingServices.isEmpty();
    return needReport
        ? new ContainerStateChangeReport(
            missingServices, currentFailedControllers, noLongerMissingServices)
        : null;
  }
 private void handleStateChange(ServiceController controller) {
   state = controller.getState();
   if (state == State.UP) {
     value = controller.getValue();
   }
   if (state == State.UP || state == State.START_FAILED || state == State.REMOVED) {
     controller.removeListener(this);
     finished = true;
     notifyAll();
   }
 }
 /**
  * Returns the name of the resource adapter which will be used as the default RA for MDBs (unless
  * overridden by the MDBs).
  *
  * @param serviceRegistry
  * @return
  */
 private String getDefaultResourceAdapterName(final ServiceRegistry serviceRegistry) {
   if (appclient) {
     // we must report the MDB, but we can't use any MDB/JCA facilities
     return "n/a";
   }
   final ServiceController<DefaultResourceAdapterService> serviceController =
       (ServiceController<DefaultResourceAdapterService>)
           serviceRegistry.getRequiredService(
               DefaultResourceAdapterService.DEFAULT_RA_NAME_SERVICE_NAME);
   return serviceController.getValue().getDefaultResourceAdapterName();
 }
Exemplo n.º 23
0
 /** {@inheritDoc} */
 public void serviceFailed(
     ServiceController<? extends Object> serviceController, StartException reason) {
   final ServiceName serviceName = serviceController.getName();
   log.errorf(reason, "Service [%s] start failed", serviceName);
   serviceFailures.put(serviceName, reason);
   if (!expectedOnDemandServices.contains(serviceController.getName())
       && countUpdater.decrementAndGet(this) == 0) {
     batchComplete();
   }
   serviceController.removeListener(this);
 }
Exemplo n.º 24
0
 /** {@inheritDoc} */
 public void serviceStarted(final ServiceController<? extends Object> serviceController) {
   startedServicesUpdater.incrementAndGet(this);
   if (expectedOnDemandServices.contains(serviceController.getName())) {
     startedOnDemandServicesUpdater.incrementAndGet(this);
   }
   if (!expectedOnDemandServices.contains(serviceController.getName())
       && countUpdater.decrementAndGet(this) == 0) {
     batchComplete();
   }
   serviceController.removeListener(this);
 }
Exemplo n.º 25
0
 private AddressControl getAddressControl(
     final OperationContext context, final ModelNode operation) {
   final String addressName =
       PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();
   final ServiceName hqServiceName =
       MessagingServices.getHornetQServiceName(
           PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
   ServiceController<?> hqService = context.getServiceRegistry(false).getService(hqServiceName);
   HornetQServer hqServer = HornetQServer.class.cast(hqService.getValue());
   return AddressControl.class.cast(
       hqServer.getManagementService().getResource(ResourceNames.CORE_ADDRESS + addressName));
 }
Exemplo n.º 26
0
  private void initializeModeShapeEngine(
      final OperationContext context,
      final ModelNode operation,
      ModelNode model,
      final List<ServiceController<?>> newControllers) {
    ServiceTarget target = context.getServiceTarget();

    final JBossLifeCycleListener shutdownListener = new JBossLifeCycleListener();

    engine = buildModeShapeEngine(model);

    // Engine service
    ServiceBuilder<JcrEngine> engineBuilder =
        target.addService(ModeShapeServiceNames.ENGINE, engine);
    engineBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    ServiceController<JcrEngine> controller = engineBuilder.install();
    controller.getServiceContainer().addTerminateListener(shutdownListener);
    newControllers.add(controller);

    // JNDI Binding
    final ReferenceFactoryService<JcrEngine> referenceFactoryService =
        new ReferenceFactoryService<JcrEngine>();
    final ServiceName referenceFactoryServiceName =
        ModeShapeServiceNames.ENGINE.append("reference-factory"); // $NON-NLS-1$
    final ServiceBuilder<?> referenceBuilder =
        target.addService(referenceFactoryServiceName, referenceFactoryService);
    referenceBuilder.addDependency(
        ModeShapeServiceNames.ENGINE, JcrEngine.class, referenceFactoryService.getInjector());
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

    final ContextNames.BindInfo bindInfo =
        ContextNames.bindInfoFor(ModeShapeJndiNames.JNDI_BASE_NAME);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder =
        target.addService(bindInfo.getBinderServiceName(), binderService);
    binderBuilder.addDependency(
        ModeShapeServiceNames.ENGINE,
        JcrEngine.class,
        new ManagedReferenceInjector<JcrEngine>(binderService.getManagedObjectInjector()));
    binderBuilder.addDependency(
        bindInfo.getParentContextServiceName(),
        ServiceBasedNamingStore.class,
        binderService.getNamingStoreInjector());
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);

    Logger.getLogger(getClass())
        .debug("Binding ModeShape to JNDI name '{0}'", bindInfo.getAbsoluteJndiName());

    newControllers.add(referenceBuilder.install());
    newControllers.add(binderBuilder.install());
  }
Exemplo n.º 27
0
  private AuthorizingCallbackHandler getAuthorizingCallbackHandler(final String realmName) {
    SecurityRealm realm;
    if (TEST_REALM.equals(realmName)) {
      realm = securityRealm;
    } else {
      ServiceContainer container = getContainer();
      ServiceController<?> service =
          container.getRequiredService(SecurityRealm.ServiceUtil.createServiceName(realmName));

      realm = (SecurityRealm) service.getValue();
    }

    return realm.getAuthorizingCallbackHandler(AuthMechanism.PLAIN);
  }
Exemplo n.º 28
0
  @Test
  public void testMetadataConfiguration() throws Throwable {
    ServiceController<?> controller =
        serviceContainer.getService(ConnectorServices.IRONJACAMAR_MDR);
    assertNotNull(controller);
    MetadataRepository repository = (MetadataRepository) controller.getValue();
    assertNotNull(repository);
    Set<String> ids = repository.getResourceAdapters();

    assertNotNull(ids);

    String piId = ids.iterator().next();
    assertNotNull(piId);
    assertNotNull(repository.getResourceAdapter(piId));
  }
Exemplo n.º 29
0
 protected <T> T createViewInstanceProxy(
     final Class<T> viewInterface,
     final Map<Object, Object> contextData,
     final ServiceName serviceName) {
   final ServiceController<?> serviceController =
       currentServiceContainer().getRequiredService(serviceName);
   final ComponentView view = (ComponentView) serviceController.getValue();
   final ManagedReference instance;
   try {
     instance = view.createInstance(contextData);
   } catch (Exception e) {
     // TODO: do we need to let the exception propagate here?
     throw new RuntimeException(e);
   }
   return viewInterface.cast(instance.getInstance());
 }
Exemplo n.º 30
0
 public EJBHome getEJBHome() throws IllegalStateException {
   if (ejbHomeViewServiceName == null) {
     throw MESSAGES.beanHomeInterfaceIsNull(getComponentName());
   }
   final ServiceController<?> serviceController =
       currentServiceContainer().getRequiredService(ejbHomeViewServiceName);
   final ComponentView view = (ComponentView) serviceController.getValue();
   final String locatorAppName = earApplicationName == null ? "" : earApplicationName;
   return EJBClient.createProxy(
       new EJBHomeLocator<EJBHome>(
           (Class<EJBHome>) view.getViewClass(),
           locatorAppName,
           moduleName,
           getComponentName(),
           distinctName));
 }