コード例 #1
0
ファイル: ViewService.java プロジェクト: mattdrees/jboss-as
    public ComponentViewInstance createInstance(Map<Object, Object> contextData) {
      final SimpleInterceptorFactoryContext factoryContext = new SimpleInterceptorFactoryContext();
      final Map<Method, InterceptorFactory> viewInterceptorFactories =
          ViewService.this.viewInterceptorFactories;
      final Map<Method, Interceptor> viewEntryPoints =
          new IdentityHashMap<Method, Interceptor>(viewInterceptorFactories.size());
      factoryContext.getContextData().put(Component.class, component);
      factoryContext.getContextData().putAll(contextData);
      // the post construct interceptors currently MUST be created first
      // and in some cases the instance is attached in this create process
      // TODO: this is probably not a good thing. {@see ManagedBeanCreateInterceptorFactory}
      final Interceptor postConstructInterceptor = viewPostConstruct.create(factoryContext);

      for (Method method : viewInterceptorFactories.keySet()) {
        viewEntryPoints.put(method, viewInterceptorFactories.get(method).create(factoryContext));
      }
      final Interceptor preDestroyInterceptor = viewPreDestroy.create(factoryContext);

      final ComponentViewInstance instance =
          new ViewInstance(viewEntryPoints, preDestroyInterceptor);
      try {
        InterceptorContext context = new InterceptorContext();
        context.putPrivateData(ComponentView.class, this);
        context.putPrivateData(Component.class, component);
        postConstructInterceptor.processInvocation(context);
      } catch (Exception e) {
        // TODO: What is the best exception type to throw here?
        throw new RuntimeException("Failed to instantiate component view", e);
      }
      return instance;
    }
コード例 #2
0
  @Override
  public void callTimeout(final TimerImpl timer, final Method timeoutMethod) throws Exception {
    final Interceptor interceptor;
    synchronized (this) {
      if (!started) {
        // this can happen if an invocation has been triggered as the deployment is shutting down
        throw EjbLogger.ROOT_LOGGER.timerInvocationFailedDueToInvokerNotBeingStarted();
      }
      interceptor = timeoutInterceptors.get(timeoutMethod);
    }
    if (interceptor == null) {
      throw EjbLogger.ROOT_LOGGER.failToInvokeTimeout(timeoutMethod);
    }
    final InterceptorContext context = new InterceptorContext();
    context.setContextData(new HashMap<String, Object>());
    context.setMethod(timeoutMethod);
    if (timeoutMethod.getParameterTypes().length == 0) {
      context.setParameters(new Object[0]);
    } else {
      final Object[] params = new Object[1];
      params[0] = timer;
      context.setParameters(params);
    }
    context.setTimer(timer);

    if (timer.getPrimaryKey() != null) {
      context.putPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY, timer.getPrimaryKey());
    }
    context.putPrivateData(Component.class, ejbComponent.getValue());
    context.putPrivateData(MethodIntf.class, MethodIntf.TIMER);
    context.putPrivateData(InvocationType.class, InvocationType.TIMER);
    interceptor.processInvocation(context);
  }
コード例 #3
0
ファイル: ViewService.java プロジェクト: mattdrees/jboss-as
 public void destroy() {
   try {
     InterceptorContext interceptorContext = new InterceptorContext();
     interceptorContext.putPrivateData(ComponentView.class, View.this);
     interceptorContext.putPrivateData(ComponentViewInstance.class, this);
     interceptorContext.putPrivateData(Component.class, component);
     preDestroyInterceptor.processInvocation(interceptorContext);
   } catch (Exception e) {
     logger.warn(
         "Exception while invoking pre-destroy interceptor for component class: "
             + this.getComponent().getComponentClass(),
         e);
   }
 }
コード例 #4
0
ファイル: ViewService.java プロジェクト: mattdrees/jboss-as
      public Object createProxy() {
        final SimpleInterceptorFactoryContext factoryContext =
            new SimpleInterceptorFactoryContext();
        factoryContext.getContextData().put(Component.class, component);
        factoryContext.getContextData().put(ComponentView.class, View.this);
        factoryContext.getContextData().put(ComponentViewInstance.class, this);

        final Map<Method, InterceptorFactory> clientInterceptorFactories =
            ViewService.this.clientInterceptorFactories;
        final Map<Method, Interceptor> clientEntryPoints =
            new IdentityHashMap<Method, Interceptor>(clientInterceptorFactories.size());
        for (Method method : clientInterceptorFactories.keySet()) {
          clientEntryPoints.put(
              method, clientInterceptorFactories.get(method).create(factoryContext));
        }
        final Interceptor postConstructInterceptor = clientPostConstruct.create(factoryContext);
        try {
          Object object =
              proxyFactory.newInstance(
                  new ProxyInvocationHandler(clientEntryPoints, component, View.this, this));
          InterceptorContext interceptorContext = new InterceptorContext();
          interceptorContext.putPrivateData(ComponentView.class, View.this);
          interceptorContext.putPrivateData(ComponentViewInstance.class, this);
          interceptorContext.putPrivateData(Component.class, component);
          try {
            postConstructInterceptor.processInvocation(interceptorContext);
          } catch (Exception e) {
            InstantiationException exception =
                new InstantiationException("Post-construct lifecycle failed");
            exception.initCause(e);
            throw exception;
          }
          return object;
        } catch (InstantiationException e) {
          InstantiationError error = new InstantiationError(e.getMessage());
          Throwable cause = e.getCause();
          if (cause != null) error.initCause(cause);
          throw error;
        } catch (IllegalAccessException e) {
          IllegalAccessError error = new IllegalAccessError(e.getMessage());
          Throwable cause = e.getCause();
          if (cause != null) error.initCause(cause);
          throw error;
        }
      }
コード例 #5
0
  /**
   * Invokes WS endpoint.
   *
   * @param endpoint WS endpoint
   * @param wsInvocation web service invocation
   * @throws Exception if any error occurs
   */
  public void invoke(final Endpoint endpoint, final Invocation wsInvocation) throws Exception {
    try {
      // prepare for invocation
      onBeforeInvocation(wsInvocation);
      // prepare invocation data
      final ComponentView componentView = getComponentView();
      Component component = componentView.getComponent();
      // for spring integration and @FactoryType is annotated we don't need to go into ee's
      // interceptors
      if (wsInvocation.getInvocationContext().getTargetBean() != null
              && (endpoint.getProperty("SpringBus") != null)
          || wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null) {
        this.reference =
            new ManagedReference() {
              public void release() {}

              public Object getInstance() {
                return wsInvocation.getInvocationContext().getTargetBean();
              }
            };
        if (component instanceof WSComponent) {
          ((WSComponent) component).setReference(reference);
        }
      }
      final Method method =
          getComponentViewMethod(wsInvocation.getJavaMethod(), componentView.getViewMethods());
      final InterceptorContext context = new InterceptorContext();
      prepareForInvocation(context, wsInvocation);
      context.setMethod(method);
      context.setParameters(wsInvocation.getArgs());
      context.putPrivateData(Component.class, component);
      context.putPrivateData(ComponentView.class, componentView);
      if (wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null) {
        context.putPrivateData(ManagedReference.class, reference);
      }
      // invoke method
      final Object retObj = componentView.invoke(context);
      // set return value
      wsInvocation.setReturnValue(retObj);
    } catch (Throwable t) {
      handleInvocationException(t);
    } finally {
      onAfterInvocation(wsInvocation);
    }
  }
コード例 #6
0
ファイル: EjbCorbaServant.java プロジェクト: manovotn/wildfly
 private void prepareInterceptorContext(
     final SkeletonStrategy op, final Object[] params, final InterceptorContext interceptorContext)
     throws IOException, ClassNotFoundException {
   if (!home) {
     if (componentView.getComponent() instanceof StatefulSessionComponent) {
       final SessionID sessionID = (SessionID) unmarshalIdentifier();
       interceptorContext.putPrivateData(SessionID.class, sessionID);
     } else if (componentView.getComponent() instanceof EntityBeanComponent) {
       final Object pk = unmarshalIdentifier();
       interceptorContext.putPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY, pk);
     }
   }
   interceptorContext.setContextData(new HashMap<String, Object>());
   interceptorContext.setParameters(params);
   interceptorContext.setMethod(op.getMethod());
   interceptorContext.putPrivateData(ComponentView.class, componentView);
   interceptorContext.putPrivateData(Component.class, componentView.getComponent());
 }
コード例 #7
0
 @Override
 public Object processInvocation(InterceptorContext context) throws Exception {
   final Method invokedMethod = context.getMethod();
   final ComponentViewInstance componentViewInstance =
       context.getPrivateData(ComponentViewInstance.class);
   // For a lifecycle interception, the ComponentViewInstance (and the invoked business interface)
   // will be null.
   // On a normal method invocation, the invoked business interface will be obtained from the
   // ComponentViewInstance
   final Class<?> invokedBusinessInterface =
       componentViewInstance == null ? null : componentViewInstance.getViewClass();
   Object[] parameters = context.getParameters();
   SessionInvocationContext sessionInvocationContext =
       new CustomSessionInvocationContext(
           lifecycleCallback, context, invokedBusinessInterface, invokedMethod, parameters);
   context.putPrivateData(InvocationContext.class, sessionInvocationContext);
   CurrentInvocationContext.push(sessionInvocationContext);
   try {
     return context.proceed();
   } finally {
     CurrentInvocationContext.pop();
     context.putPrivateData(InvocationContext.class, null);
   }
 }
コード例 #8
0
ファイル: EjbCorbaServant.java プロジェクト: manovotn/wildfly
  /**
   * Receives IIOP requests to this servant's <code>EJBObject</code>s and forwards them to the bean
   * container, through the JBoss <code>MBean</code> server.
   */
  public OutputStream _invoke(
      final String opName, final InputStream in, final ResponseHandler handler) {

    if (logger.isTraceEnabled()) {
      logger.trace("EJBObject invocation: " + opName);
    }

    SkeletonStrategy op = methodInvokerMap.get(opName);
    if (op == null) {
      logger.debugf(
          "Unable to find opname '%s' valid operations:%s", opName, methodInvokerMap.keySet());
      throw new BAD_OPERATION(opName);
    }
    final NamespaceContextSelector selector =
        componentView.getComponent().getNamespaceContextSelector();
    final ClassLoader oldCl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    NamespaceContextSelector.pushCurrentSelector(selector);
    try {
      WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
      SecurityContext sc = null;
      org.omg.CORBA_2_3.portable.OutputStream out;
      try {
        Object retVal;

        if (!home && opName.equals("_get_handle")) {
          retVal = new HandleImplIIOP(orb.object_to_string(_this_object()));
        } else if (home && opName.equals("_get_homeHandle")) {
          retVal = homeHandle;
        } else if (home && opName.equals("_get_EJBMetaData")) {
          retVal = ejbMetaData;
        } else {
          Transaction tx = null;
          if (inboundTxCurrent != null) tx = inboundTxCurrent.getCurrentTransaction();
          if (tx != null) {
            transactionManager.resume(tx);
          }
          try {
            SimplePrincipal principal = null;
            Object credential = null;

            if (sasCurrent != null) {
              final byte[] incomingName = sasCurrent.get_incoming_principal_name();

              if (incomingName != null && incomingName.length > 0) {
                // we have an identity token, which is a trust based mechanism
                if (incomingName.length > 0) {
                  String name = new String(incomingName, StandardCharsets.UTF_8);
                  int domainIndex = name.indexOf('@');
                  if (domainIndex > 0) name = name.substring(0, domainIndex);
                  principal = new SimplePrincipal(name);
                  // we don't have any real way to establish trust here
                  // we just use the SASCurrent as a credential, and a custom login
                  // module can make a decision for us.
                  credential = sasCurrent;
                }
              } else {
                // the client has just sent a username and password
                final byte[] username = sasCurrent.get_incoming_username();
                final byte[] incomingPassword = sasCurrent.get_incoming_password();
                if (username.length > 0) {
                  String name = new String(username, StandardCharsets.UTF_8);
                  int domainIndex = name.indexOf('@');
                  if (domainIndex > 0) {
                    name = name.substring(0, domainIndex);
                  }
                  principal = new SimplePrincipal(name);
                  credential = new String(incomingPassword, StandardCharsets.UTF_8).toCharArray();
                }
              }

              if (securityDomain != null) {
                sc = SecurityContextFactory.createSecurityContext(securityDomain);
                sc.getUtil().createSubjectInfo(principal, credential, null);
              }
            }
            final Object[] params = op.readParams((org.omg.CORBA_2_3.portable.InputStream) in);

            if (!home && opName.equals("isIdentical") && params.length == 1) {
              // handle isIdentical specially
              Object val = params[0];
              if (val instanceof org.omg.CORBA.Object) {
                retVal = handleIsIdentical((org.omg.CORBA.Object) val);
              } else {
                retVal = false;
              }
            } else {

              if (sc != null) {
                setSecurityContextOnAssociation(sc);
              }
              try {
                final InterceptorContext interceptorContext = new InterceptorContext();

                if (sc != null) {
                  interceptorContext.putPrivateData(SecurityContext.class, sc);
                }
                prepareInterceptorContext(op, params, interceptorContext);
                retVal = componentView.invoke(interceptorContext);
              } finally {
                if (sc != null) {
                  clearSecurityContextOnAssociation();
                }
              }
            }
          } finally {
            if (tx != null) {
              if (transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
                transactionManager.suspend();
              }
            }
          }
        }
        out = (org.omg.CORBA_2_3.portable.OutputStream) handler.createReply();
        if (op.isNonVoid()) {
          op.writeRetval(out, retVal);
        }
      } catch (Exception e) {
        if (logger.isTraceEnabled()) {
          logger.trace("Exception in EJBObject invocation", e);
        }
        if (e instanceof MBeanException) {
          e = ((MBeanException) e).getTargetException();
        }
        RmiIdlUtil.rethrowIfCorbaSystemException(e);
        out = (org.omg.CORBA_2_3.portable.OutputStream) handler.createExceptionReply();
        op.writeException(out, e);
      }
      return out;
    } finally {
      NamespaceContextSelector.popCurrentSelector();
      WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldCl);
    }
  }