Package com.linkedin.restli.internal.server

Examples of com.linkedin.restli.internal.server.RestLiInternalException


  {
    BeanDependencies deps = _fieldDependencyBindings.get(beanClass);

    if (deps == null)
    {
      throw new RestLiInternalException("Could not find bean of class '" + beanClass.getName() + "'");
    }

    try
    {
      Constructor<?> constructor = _constructorParameterDependencies.get(beanClass).getConstructor();
      Object[] arguments = _constructorParameterBindings.get(beanClass);
      @SuppressWarnings("unchecked")
      T bean = (T)constructor.newInstance(arguments);

      for (Entry<Field, Object> fieldDep : deps.iterator())
      {
        Field f = fieldDep.getKey();
        f.setAccessible(true);
        f.set(bean, fieldDep.getValue());
      }

      return bean;
    }
    catch (Exception e)
    {
      throw new RestLiInternalException(String.format("Error initializing bean %s", beanClass.getName()), e);
    }
  }
View Full Code Here


      if (injectAnnotation != null)
      {
        ++annotatedConstructors;
        if (annotatedConstructors > 1)
        {
          throw new RestLiInternalException("Found multiple constructors annotated with @Inject in "
                                                    + "class '" + beanClazz.getCanonicalName() +
                                                    "'.  At most one constructor can be annotated "
                                                    +"with @Inject.");
        }

        Class<?>[] parameters = constructor.getParameterTypes();
        Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();

        List<DependencyDecl> parameterDecls = new ArrayList<DependencyDecl>(parameters.length);

        for (int i = 0; i < parameters.length; ++i)
        {
          Class<?> parameter = parameters[i];
          AnnotationSet annotations = new AnnotationSet(parameterAnnotations[i]);
          Named namedAnno = annotations.get(Named.class);

          parameterDecls.add(new DependencyDecl(parameter,
                                                namedAnno != null ? namedAnno.value() : null));
        }

        constructor.setAccessible(true);
        _constructorParameterDependencies.put(beanClazz,
                                new InjectableConstructor(constructor, parameterDecls));
      }
    }
    if (annotatedConstructors == 0)
    {
      try
      {
        Constructor<?> defaultConstructor = beanClazz.getConstructor();
        defaultConstructor.setAccessible(true);
        _constructorParameterDependencies.put(beanClazz,
                                              new InjectableConstructor(defaultConstructor,
                                                                     Collections.<DependencyDecl>emptyList()));
      }
      catch (NoSuchMethodException e)
      {
        throw new RestLiInternalException(
                String.format("No injectable constructor defined for class %s.  Classes must define"
                                      +" either a default constructor or a constructor annotated "
                                      + "with @Inject.", beanClazz.getName()), e);
      }
View Full Code Here

    if (decl.hasBeanName())
    {
      resolvedBean = _beanProvider.getBean(decl.getBeanName());
      if (resolvedBean == null)
      {
        throw new RestLiInternalException("Expected to find bean with name '" + decl.getBeanName() + "', but did not find such bean." +
            " This bean needs to be injected into class '" + beanClazz + "', " + dependencyTarget + ".");
      }
    }
    else
    {
      Map<String, ?> matchingBeans = _beanProvider.getBeansOfType(decl.getBeanType());
      if (matchingBeans.size() != 1)
      {
        throw new RestLiInternalException("Expected to find exactly 1 bean of type '" + decl.getBeanType() +
                                          "', but found " + matchingBeans.size() + ". You can use the @Named " +
                                          "annotation to further qualify ambiguous dependencies");
      }

      resolvedBean = matchingBeans.values().iterator().next();
View Full Code Here

TOP

Related Classes of com.linkedin.restli.internal.server.RestLiInternalException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.