示例#1
0
  /**
   * Override to run the test and assert its state.
   *
   * @exception Throwable if any exception is thrown
   */
  protected void runTest() throws Throwable {
    assertNotNull(fName); // Some VMs crash when calling getMethod(null,null);
    Method runMethod = null;
    try {
      // use getMethod to get all public inherited
      // methods. getDeclaredMethods returns all
      // methods of this class but excludes the
      // inherited ones.
      runMethod = getClass().getMethod(fName, (Class[]) null);
    } catch (NoSuchMethodException e) {
      fail("Method \"" + fName + "\" not found");
    }
    if (!Modifier.isPublic(runMethod.getModifiers())) {
      fail("Method \"" + fName + "\" should be public");
    }

    try {
      runMethod.invoke(this, (Object[]) new Class[0]);
    } catch (InvocationTargetException e) {
      e.fillInStackTrace();
      throw e.getTargetException();
    } catch (IllegalAccessException e) {
      e.fillInStackTrace();
      throw e;
    }
  }
示例#2
0
 /** invoke the test method */
 protected void invokeTest() throws Throwable {
   Method method = this.methodNamed(this.getZName());
   try {
     method.invoke(this, new Object[0]);
   } catch (IllegalAccessException iae) {
     throw new RuntimeException("The method '" + method + "' (and its class) must be public.");
   } catch (InvocationTargetException ite) {
     ite.fillInStackTrace();
     throw ite.getTargetException();
   }
 }
示例#3
0
  /**
   * Call the setSuite method of the test. The parameter type can be a variant of FuncTestSuite,
   * meaning that it in the type of the actually FuncTestSuite implementation, or its super class.
   *
   * @param test the specified test in which its setSuite method is called
   * @param suite the parameter of the method
   */
  protected final void setVariantSuite(Test test, FuncTestSuite suite) {

    try {
      Method suiteMethod = null;
      String methodName = "setSuite";
      Class[] paramTypes = new Class[1];
      Class suiteClass = suite.getClass();

      // obtain the setSuite method, try setSuite(suite.getClass()).
      // if not found, try the super class...
      while (suiteMethod == null) {
        try {
          paramTypes[0] = suiteClass;
          suiteMethod = test.getClass().getMethod(methodName, paramTypes);
        } catch (NoSuchMethodException e) {
          suiteClass = suiteClass.getSuperclass();
          if (!FuncTestSuite.class.isAssignableFrom(suiteClass)) {
            // addTest(warning("Method \""+methodName+"\" not found"));
            return;
          }
        }
      }

      if (!Modifier.isPublic(suiteMethod.getModifiers())) {
        addTest(warning("Method \"" + getName() + "\" should be public"));
        return;
      }

      try {
        suiteMethod.invoke(test, new Object[] {suite});
      } catch (InvocationTargetException e) {
        e.fillInStackTrace();
        addTest(error("Error seting the suite", e));
      } catch (IllegalAccessException e) {
        e.fillInStackTrace();
        addTest(error("Error setting the suite", e));
      }
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
示例#4
0
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

    Endpoint endpoint = getClient().getEndpoint();
    String address = endpoint.getEndpointInfo().getAddress();
    MethodDispatcher dispatcher =
        (MethodDispatcher) endpoint.getService().get(MethodDispatcher.class.getName());
    Object[] params = args;
    if (null == params) {
      params = new Object[0];
    }

    BindingOperationInfo oi = dispatcher.getBindingOperation(method, endpoint);
    if (oi == null) {
      // check for method on BindingProvider and Object
      if (method.getDeclaringClass().equals(BindingProvider.class)
          || method.getDeclaringClass().equals(Object.class)) {
        try {
          return method.invoke(this, params);
        } catch (InvocationTargetException e) {
          throw e.fillInStackTrace().getCause();
        }
      }

      Message msg = new Message("NO_BINDING_OPERATION_INFO", LOG, method.getName());
      throw new WebServiceException(msg.toString());
    }

    client.getRequestContext().put(Method.class.getName(), method);
    boolean isAsync = isAsync(method);

    Object result = null;
    try {
      if (isAsync) {
        result = invokeAsync(method, oi, params);
      } else {
        result = invokeSync(method, oi, params);
      }
    } catch (WebServiceException wex) {
      throw wex.fillInStackTrace();
    } catch (Exception ex) {
      for (Class<?> excls : method.getExceptionTypes()) {
        if (excls.isInstance(ex)) {
          throw ex.fillInStackTrace();
        }
      }

      if (getBinding() instanceof HTTPBinding) {
        HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
        exception.initCause(ex);
        throw exception;
      } else if (getBinding() instanceof SOAPBinding) {
        SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
        if (soapFault == null) {
          throw new WebServiceException(ex);
        }
        SOAPFaultException exception = new SOAPFaultException(soapFault);
        if (ex instanceof Fault && ex.getCause() != null) {
          exception.initCause(ex.getCause());
        } else {
          exception.initCause(ex);
        }
        throw exception;
      } else {
        throw new WebServiceException(ex);
      }
    } finally {
      if (addressChanged(address)) {
        setupEndpointAddressContext(getClient().getEndpoint());
      }
    }

    Map<String, Object> respContext = client.getResponseContext();
    Map<String, Scope> scopes =
        CastUtils.cast((Map<?, ?>) respContext.get(WrappedMessageContext.SCOPES));
    if (scopes != null) {
      for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
        if (scope.getValue() == Scope.HANDLER) {
          respContext.remove(scope.getKey());
        }
      }
    }
    return result;
  }