Package org.jclouds.reflect

Examples of org.jclouds.reflect.Invocation


      }
   }));

   protected GeneratedHttpRequest requestForArgs(List<Object> args) {
      try {
         Invocation invocation = Invocation.create(method(String.class, "toString"), args);
         return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
               .invocation(invocation).build();
      } catch (SecurityException e) {
         throw Throwables.propagate(e);
      }
View Full Code Here


      assertEquals(getNameFor(request), "four");
   }

   GeneratedHttpRequest requestForEndpointAndArgs(String endpoint, List<Object> args) {
      try {
         Invocation invocation = Invocation.create(method(String.class, "toString"), args);
         return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create(endpoint)).invocation(invocation)
               .build();
      } catch (SecurityException e) {
         throw Throwables.propagate(e);
      }
View Full Code Here

   @Test
   public void testRequestFilterStripExpect() {
      // First, verify that by default, the StripExpectHeader filter is not applied
      Invokable<?, ?> method = method(TestRequestFilter.class, "post");
      Invocation invocation = Invocation.create(method,
         ImmutableList.<Object>of(HttpRequest.builder().method("POST").endpoint("http://localhost")
            .addHeader(HttpHeaders.EXPECT, "100-Continue").build()));
      GeneratedHttpRequest request = processor.apply(invocation);
      assertEquals(request.getFilters().size(), 1);
      assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter1.class);
View Full Code Here

      assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected);
   }

   protected GeneratedHttpRequest requestForArgs(List<Object> args) {
      try {
         Invocation invocation = Invocation.create(method(String.class, "toString"), args);
         return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
               .invocation(invocation).build();
      } catch (SecurityException e) {
         throw Throwables.propagate(e);
      }
View Full Code Here

   @Override
   public Object apply(Invocation in) {
      if (isFuture(in.getInvokable())) {
         return submit(in);
      }
      Invocation async = toAsync(in);
      Optional<Long> timeoutNanos = config.getTimeoutNanos(async);
      if (timeoutNanos.isPresent()) {
         return invokeWithTimeout(async, timeoutNanos.get());
      }
      return invoke(async);
View Full Code Here

    * looks up the corresponding {@code Invocation} that returns a
    * {@code Future}. Only Invokables that return {@code Futures} are annotated
    * in a way that can be parsed into an {@linkplain HttpRequest}.
    */
   private Invocation toAsync(Invocation in) {
      Invocation async = sync2async.apply(in);
      checkState(isFuture(async.getInvokable()), "not a future: %s", async);
      return async;
   }
View Full Code Here

      return invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(VirtualHost.class) || invocation
            .getInvokable().isAnnotationPresent(VirtualHost.class);
   }

   private GeneratedHttpRequest decorateRequest(GeneratedHttpRequest request) throws NegativeArraySizeException {
      Invocation invocation = request.getInvocation();
      List<Object> args = request.getInvocation().getArgs();
      Set<Parameter> binderOrWrapWith = ImmutableSet.copyOf(concat(
            parametersWithAnnotation(invocation.getInvokable(), BinderParam.class),
            parametersWithAnnotation(invocation.getInvokable(), WrapWith.class)));
      OUTER: for (Parameter entry : binderOrWrapWith) {
         int position = entry.hashCode();
         boolean shouldBreak = false;
         Binder binder;
         if (entry.isAnnotationPresent(BinderParam.class))
            binder = injector.getInstance(entry.getAnnotation(BinderParam.class).value());
         else
            binder = injector.getInstance(BindToJsonPayloadWrappedWith.Factory.class).create(
                  entry.getAnnotation(WrapWith.class).value());
         Object arg = args.size() >= position + 1 ? args.get(position) : null;
         if (args.size() >= position + 1 && arg != null) {
            Class<?> parameterType = entry.getType().getRawType();
            Class<? extends Object> argType = arg.getClass();
            if (!argType.isArray() && parameterType.isArray()) {// TODO: &&
                                                                // invocation.getInvokable().isVarArgs())
                                                                // {
               int arrayLength = args.size() - getInvokableParameters(invocation.getInvokable()).size() + 1;
               if (arrayLength == 0)
                  break OUTER;
               arg = (Object[]) Array.newInstance(arg.getClass(), arrayLength);
               System.arraycopy(args.toArray(), position, arg, 0, arrayLength);
               shouldBreak = true;
            } else if (argType.isArray() && parameterType.isArray()) {// TODO:
                                                                      // &&
                                                                      // invocation.getInvokable().isVarArgs())
                                                                      // {
            } else {
               if (arg.getClass().isArray()) {
                  Object[] payloadArray = (Object[]) arg;
                  arg = payloadArray.length > 0 ? payloadArray[0] : null;
               }
            }
            if (arg != null) {
               request = binder.bindToRequest(request, arg);
            }
            if (shouldBreak)
               break OUTER;
         } else {
            if (position + 1 == getInvokableParameters(invocation.getInvokable()).size() && entry.getType().isArray())// TODO:
                                                                                                              // &&
                                                                                                              // invocation.getInvokable().isVarArgs())
               continue OUTER;

            if (entry.isAnnotationPresent(Nullable.class)) {
               continue OUTER;
            }
            checkNotNull(arg, invocation.getInvokable().getName() + " parameter " + (position + 1));
         }
      }
      return request;
   }
View Full Code Here

public class BasePayloadTest {

   protected GeneratedHttpRequest requestForArgs(List<Object> args) {
      try {
         Invocation invocation = Invocation.create(method(String.class, "toString"), args);
         return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
               .invocation(invocation).build();
      } catch (SecurityException e) {
         throw Throwables.propagate(e);
      }
View Full Code Here

      void method(@PathParam("param1") Integer param1);
   }

   @Test(expectedExceptions = ClassCastException.class)
   public void testWrongPredicateTypeLiteral() throws Exception {
      Invocation invocation = Invocation.create(method(WrongValidator.class, "method", Integer.class),
            ImmutableList.<Object> of(55));
      new InputParamValidator(injector).validateMethodParametersOrThrow(invocation);
   }
View Full Code Here

      }
   }));

   protected GeneratedHttpRequest requestForArgs(List<Object> args) {
      try {
         Invocation invocation = Invocation.create(method(String.class, "toString"), args);
         return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
               .invocation(invocation).build();
      } catch (SecurityException e) {
         throw Throwables.propagate(e);
      }
View Full Code Here

TOP

Related Classes of org.jclouds.reflect.Invocation

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.