示例#1
0
 /** Serialize to an XML File. */
 public void writeXML(File f) {
   OutputStream out = null;
   try {
     Marshaller marshaller = ctx.createMarshaller();
     OvalNamespacePrefixMapper.configure(marshaller, OvalNamespacePrefixMapper.URI.RES);
     out = new FileOutputStream(f);
     marshaller.marshal(getOvalResults(), out);
   } catch (JAXBException e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, f.toString());
   } catch (FactoryConfigurationError e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, f.toString());
   } catch (FileNotFoundException e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, f.toString());
   } catch (OvalException e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, f.toString());
   } finally {
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
         logger.warn(JOVALMsg.ERROR_FILE_CLOSE, e.toString());
       }
     }
   }
 }
示例#2
0
  @Override
  protected void initScope() {
    for (WeldClass<?> clazz = getWeldAnnotated();
        clazz != null;
        clazz = clazz.getWeldSuperclass()) {
      Set<Annotation> scopes = new HashSet<Annotation>();
      scopes.addAll(clazz.getDeclaredMetaAnnotations(Scope.class));
      scopes.addAll(clazz.getDeclaredMetaAnnotations(NormalScope.class));
      if (scopes.size() == 1) {
        if (getWeldAnnotated().isAnnotationPresent(scopes.iterator().next().annotationType())) {
          this.scope = scopes.iterator().next().annotationType();
          log.trace(USING_SCOPE, scope, this);
        }
        break;
      } else if (scopes.size() > 1) {
        throw new DefinitionException(ONLY_ONE_SCOPE_ALLOWED, getWeldAnnotated());
      }
    }

    if (this.scope == null) {
      initScopeFromStereotype();
    }

    if (this.scope == null) {
      this.scope = Dependent.class;
      log.trace(USING_DEFAULT_SCOPE, this);
    }
  }
 @Override
 protected void removeAttribute(String key) {
   HttpSession session = getSession(false);
   if (session != null) {
     session.removeAttribute(key);
     log.trace("Removed " + key + " from session " + this.getSession(false).getId());
   } else {
     log.trace("Unable to remove " + key + " from non-existent session");
   }
 }
 @Override
 protected void setAttribute(String key, Object instance) {
   HttpSession session = getSession(true);
   if (session != null) {
     session.setAttribute(key, instance);
     log.trace("Added " + key + " to session " + this.getSession(false).getId());
   } else {
     log.trace("Unable to add " + key + " to session as no session could be obtained");
   }
 }
  public BeanDeployment(
      BeanDeploymentArchive beanDeploymentArchive,
      BeanManagerImpl deploymentManager,
      ServiceRegistry deploymentServices,
      Collection<ContextHolder<? extends Context>> contexts) {
    this.beanDeploymentArchive = beanDeploymentArchive;
    EjbDescriptors ejbDescriptors = new EjbDescriptors();
    beanDeploymentArchive.getServices().add(EjbDescriptors.class, ejbDescriptors);
    if (beanDeploymentArchive.getServices().get(ResourceLoader.class) == null) {
      beanDeploymentArchive.getServices().add(ResourceLoader.class, DefaultResourceLoader.INSTANCE);
    }
    ServiceRegistry services = new SimpleServiceRegistry();
    services.addAll(deploymentServices.entrySet());
    services.addAll(beanDeploymentArchive.getServices().entrySet());

    services.add(
        EJBApiAbstraction.class,
        new EJBApiAbstraction(beanDeploymentArchive.getServices().get(ResourceLoader.class)));
    services.add(
        JsfApiAbstraction.class,
        new JsfApiAbstraction(beanDeploymentArchive.getServices().get(ResourceLoader.class)));
    services.add(
        PersistenceApiAbstraction.class,
        new PersistenceApiAbstraction(
            beanDeploymentArchive.getServices().get(ResourceLoader.class)));
    services.add(
        WSApiAbstraction.class,
        new WSApiAbstraction(beanDeploymentArchive.getServices().get(ResourceLoader.class)));
    this.beanManager =
        BeanManagerImpl.newManager(
            deploymentManager,
            beanDeploymentArchive.getId(),
            services,
            Enabled.of(
                beanDeploymentArchive.getBeansXml(),
                beanDeploymentArchive.getServices().get(ResourceLoader.class)));
    log.debug(
        ENABLED_ALTERNATIVES,
        this.beanManager,
        beanManager.getEnabled().getAlternativeClasses(),
        beanManager.getEnabled().getAlternativeStereotypes());
    log.debug(ENABLED_DECORATORS, this.beanManager, beanManager.getEnabled().getDecorators());
    log.debug(ENABLED_INTERCEPTORS, this.beanManager, beanManager.getEnabled().getInterceptors());
    if (beanManager.getServices().contains(EjbServices.class)) {
      // Must populate EJB cache first, as we need it to detect whether a
      // bean is an EJB!
      ejbDescriptors.addAll(beanDeploymentArchive.getEjbs());
    }
    beanDeployer = new BeanDeployer(beanManager, ejbDescriptors);

    // Must at the Manager bean straight away, as it can be injected during startup!
    beanManager.addBean(new BeanManagerBean(beanManager));
    this.contexts = contexts;
  }
 @Override
 protected void initValid() {
   super.initValid();
   if (!getAnnotatedAnnotation().isAnnotationPresent(Target.class)) {
     this.valid = false;
     log.debug(MISSING_TARGET, getAnnotatedAnnotation());
   } else if (!Arrays2.unorderedEquals(
       getAnnotatedAnnotation().getAnnotation(Target.class).value(), METHOD, FIELD, TYPE)) {
     this.valid = false;
     log.debug(MISSING_TARGET_METHOD_FIELD_TYPE, getAnnotatedAnnotation());
   }
 }
  protected void activateConversationContext(HttpServletRequest request) {
    HttpConversationContext conversationContext = httpConversationContext();
    String cid = getConversationId(request, httpConversationContext());
    log.debug(RESUMING_CONVERSATION, cid);

    /*
     * Don't try to reactivate the ConversationContext if we have already activated it for this request WELD-877
     */
    if (!isContextActivatedInRequest(request)) {
      setContextActivatedInRequest(request);
      conversationContext.activate(cid);
      if (cid == null) { // transient conversation
        beanManager
            .getAccessibleLenientObserverNotifier()
            .fireEvent(request, InitializedLiteral.CONVERSATION);
      }
    } else {
      /*
       * We may have previously been associated with a ConversationContext, but the reference to that context may have
       * been lost during a Servlet forward WELD-877
       */
      conversationContext.dissociate(request);
      conversationContext.associate(request);
      conversationContext.activate(cid);
    }
  }
  @Override
  public void fileTransferRequest(FileTransferRequest request) {
    // Check to see if the request should be accepted
    if (shouldAccept(request)) {
      // Accept it
      IncomingFileTransfer transfer = request.accept();
      try {
        transfer.recieveFile(new File("shakespeare_complete_works.txt"));

        while (!transfer.isDone()) {
          if (transfer.getStatus().equals(Status.error)) {
            System.out.println("ERROR!!! " + transfer.getError());
          } else {
            System.out.println(transfer.getStatus());
            System.out.println(transfer.getProgress());
          }
          // sleep(1000);
        }

      } catch (XMPPException e) {
        log.error(e.getMessage());
      }
    } else {
      // Reject it
      request.reject();
    }
  }
 /**
  * Invokes the method on the correct version of the instance as obtained by a context lookup
  *
  * @param self the proxy instance.
  * @param proxiedMethod the overridden method declared in the super class or interface.
  * @param proceed the forwarder method for invoking the overridden method. It is null if the
  *     overridden mehtod is abstract or declared in the interface.
  * @param args an array of objects containing the values of the arguments passed in the method
  *     invocation on the proxy instance. If a parameter type is a primitive type, the type of the
  *     array element is a wrapper class.
  * @return the resulting value of the method invocation.
  * @throws Throwable if the method invocation fails.
  */
 public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[] args)
     throws Throwable {
   if (bean == null) {
     bean =
         Container.instance()
             .services()
             .get(ContextualStore.class)
             .<Bean<Object>, Object>getContextual(id);
   }
   Object proxiedInstance = getProxiedInstance(bean);
   if (proxiedInstance == null) {
     // TODO not sure if this right PLM
     return null;
   }
   if (proxiedMethod.getName().equals("equals")
       && proxiedMethod.getParameterTypes().length == 1
       && proxiedMethod.getParameterTypes()[0] == Object.class
       && args[0] == self) {
     return true;
   }
   try {
     Method method = SecureReflections.lookupMethod(proxiedInstance, proxiedMethod);
     Object returnValue = SecureReflections.invoke(proxiedInstance, method, args);
     log.trace(
         CALL_PROXIED_METHOD,
         proxiedMethod,
         proxiedInstance,
         args,
         returnValue == null ? null : returnValue);
     return returnValue;
   } catch (InvocationTargetException e) {
     throw e.getCause();
   }
 }
示例#10
0
 private void checkScopeAnnotations(InjectionPoint ij, MetaAnnotationStore metaAnnotationStore) {
   for (Annotation annotation : ij.getAnnotated().getAnnotations()) {
     if (hasScopeMetaAnnotation(annotation)) {
       log.warn(SCOPE_ANNOTATION_ON_INJECTION_POINT, annotation, ij);
     }
   }
 }
示例#11
0
 /** Transform using the specified template, and serialize to the specified file. */
 public void writeTransform(File transform, File output) {
   try {
     TransformerFactory xf = TransformerFactory.newInstance();
     Transformer transformer = xf.newTransformer(new StreamSource(new FileInputStream(transform)));
     transformer.transform(getSource(), new StreamResult(output));
   } catch (JAXBException e) {
     logger.warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e);
   } catch (OvalException e) {
     logger.warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e);
   } catch (FileNotFoundException e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, output);
   } catch (TransformerConfigurationException e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, output);
   } catch (TransformerException e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, output);
   }
 }
示例#12
0
 public void writeXML(File f) {
   OutputStream out = null;
   try {
     Marshaller marshaller = ctx.createMarshaller();
     marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
     out = new FileOutputStream(f);
     marshaller.marshal(getOvalVariables(), out);
   } catch (JAXBException e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, f.toString());
     logger.warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e);
   } catch (FactoryConfigurationError e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, f.toString());
     logger.warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e);
   } catch (FileNotFoundException e) {
     logger.warn(JOVALMsg.ERROR_FILE_GENERATE, f.toString());
     logger.warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e);
   } finally {
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
         logger.warn(JOVALMsg.ERROR_FILE_CLOSE, f.toString());
       }
     }
   }
 }
示例#13
0
 /** Create empty Variables. */
 Variables() {
   logger = JOVALMsg.getLogger();
   variables = new Hashtable<String, List<IType>>();
   comments = new Hashtable<String, String>();
   try {
     ctx = JAXBContext.newInstance(SchemaRegistry.lookup(SchemaRegistry.OVAL_VARIABLES));
   } catch (JAXBException e) {
     logger.error(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e);
   }
 }
 protected void deactivateConversationContext(HttpServletRequest request) {
   ConversationContext conversationContext = httpConversationContext();
   if (conversationContext.isActive()) {
     // Only deactivate the context if one is already active, otherwise we get Exceptions
     boolean isTransient = conversationContext.getCurrentConversation().isTransient();
     if (log.isTraceEnabled()) {
       if (isTransient) {
         log.trace(CLEANING_UP_TRANSIENT_CONVERSATION);
       } else {
         log.trace(CLEANING_UP_CONVERSATION, conversationContext.getCurrentConversation().getId());
       }
     }
     conversationContext.invalidate();
     conversationContext.deactivate();
     if (isTransient) {
       beanManager
           .getAccessibleLenientObserverNotifier()
           .fireEvent(request, DestroyedLiteral.CONVERSATION);
     }
   }
 }
示例#15
0
 /** Create a Results based on the specified Definitions and SystemCharacteristics. */
 public Results(IDefinitions definitions, ISystemCharacteristics sc) {
   this.definitions = definitions;
   this.sc = sc;
   logger = JOVALMsg.getLogger();
   definitionTable = new Hashtable<String, DefinitionType>();
   testTable = new Hashtable<String, TestType>();
   directives = new Directives();
   try {
     ctx = JAXBContext.newInstance(SchemaRegistry.lookup(SchemaRegistry.OVAL_RESULTS));
   } catch (JAXBException e) {
     logger.error(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e);
   }
 }
  /**
   * Gets the propagated conversation id parameter from the request
   *
   * @return The conversation id (or null if not found)
   */
  private static String getConversationId(
      HttpServletRequest request, ConversationContext conversationContext) {
    if (request.getParameter(NO_CID) != null) {
      return null; // ignore cid; WELD-919
    }

    if (CONVERSATION_PROPAGATION_NONE.equals(request.getParameter(CONVERSATION_PROPAGATION))) {
      return null; // conversationPropagation=none (CDI-135)
    }

    String cidName = conversationContext.getParameterName();
    String cid = request.getParameter(cidName);
    log.trace(FOUND_CONVERSATION_FROM_REQUEST, cid);
    return cid;
  }
示例#17
0
  public void close() throws IOException {
    if (closed) {
      return;
    }

    IOException ex = null;
    try {
      in.close();
    } catch (IOException e) {
      ex = e;
    }
    try {
      out.close();
    } catch (IOException e) {
      logger.warn(JOVALMsg.ERROR_STREAMLOGGER_CLOSE, e.getMessage());
    }
    closed = true;
    if (ex != null) {
      throw ex;
    }
  }
 /**
  * Constructor
  *
  * @param bean The bean to proxy
  * @param beanIndex The index to the bean in the manager bean list
  */
 public ClientProxyMethodHandler(Bean<?> bean, String id) {
   this.bean = bean;
   this.id = id;
   log.trace("Created method handler for bean " + bean + " identified as " + id);
 }