@SuppressWarnings("unchecked") private static Type getGenericReturnType(Class c, String methodName) throws SecurityException, NoSuchMethodException { Method m = c.getMethod(methodName, (Class[]) null); System.out.println(m.getGenericReturnType()); return m.getGenericReturnType(); }
ReadInvocationHandler( final Node node, final Method method, final String annotationValue, final XBProjector projector, final boolean absentIsEmpty) { super(node, method, annotationValue, projector); wrappedInOptional = ReflectionHelper.isOptional(method.getGenericReturnType()); returnType = wrappedInOptional ? ReflectionHelper.getParameterType(method.getGenericReturnType()) : method.getReturnType(); Class<?>[] exceptionTypes = method.getExceptionTypes(); exceptionType = exceptionTypes.length > 0 ? exceptionTypes[0] : null; this.isConvertable = projector.config().getTypeConverter().isConvertable(returnType); this.isReturnAsNode = Node.class.isAssignableFrom(returnType); this.isEvaluateAsList = List.class.equals(returnType) || ReflectionHelper.isStreamClass(returnType); this.isReturnAsStream = ReflectionHelper.isStreamClass(returnType); this.isEvaluateAsArray = returnType.isArray(); if (wrappedInOptional && (isEvaluateAsArray || isEvaluateAsList)) { throw new IllegalArgumentException( "Method " + method + " must not declare an optional return type of list or array. Lists and arrays may be empty but will never be null."); } this.isEvaluateAsSubProjection = returnType.isInterface(); this.isThrowIfAbsent = exceptionType != null; // Throwing exception overrides empty default value. this.absentIsEmpty = absentIsEmpty && (!isThrowIfAbsent); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Preference annotation = method.getAnnotation(Preference.class); String key = annotation.value(); String defaultString = annotation.defaultString(); boolean defaultBoolean = annotation.defaultBoolean(); int defaultInt = annotation.defaultInt(); long defaultLong = annotation.defaultLong(); float defaultFloat = annotation.defaultFloat(); if (method.getReturnType().equals(StringEntry.class)) { return new StringEntry(preferences, key, defaultString); } else if (method.getReturnType().equals(FloatEntry.class)) { return new FloatEntry(preferences, key, defaultFloat); } else if (method.getReturnType().equals(LongEntry.class)) { return new LongEntry(preferences, key, defaultLong); } else if (method.getReturnType().equals(IntEntry.class)) { return new IntEntry(preferences, key, defaultInt); } else if (method.getReturnType().equals(BooleanEntry.class)) { return new BooleanEntry(preferences, key, defaultBoolean); } else if (method.getReturnType().equals(ObjectEntry.class)) { if (method.getGenericReturnType() instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) method.getGenericReturnType(); Class<?> type = (Class) parameterizedType.getActualTypeArguments()[0]; return new ObjectEntry<>(preferences, key, gson, type); } throw new RuntimeException("ObjectEntries must have a parameter"); } else { return null; } }
public MethodPropertyContext(Method getter) { synchronized (cache) { Data previous = cache.get(getter); if (previous != null) { this.data = previous; return; } this.data = new Data(); data.genericType = getter.getGenericReturnType(); data.type = getter.getReturnType(); // Compute collection element type if (Collection.class.isAssignableFrom(getType())) { data.elementType = TypeUtils.ensureBaseType( TypeUtils.getSingleParameterization( Collection.class, getter.getGenericReturnType(), getter.getReturnType())); } else if (Map.class.isAssignableFrom(getType())) { Type[] types = TypeUtils.getParameterization(Map.class, getter.getGenericReturnType()); data.keyType = TypeUtils.ensureBaseType(types[0]); data.valueType = TypeUtils.ensureBaseType(types[1]); } cache.put(getter, data); } }
public Object extractEntity(ClientContext context, Object... args) { ClientResponse response = context.getClientResponse(); // only release connection if it is not an instance of an // InputStream boolean releaseConnectionAfter = response.getStatus() >= 200 && response.getStatus() < 300; try { // void methods should be handled before this method gets called, but it's worth being // defensive if (method.getReturnType() == null) { throw new RuntimeException( "No type information to extract entity with. You use other getEntity() methods"); } GenericType gt = null; if (method.getGenericReturnType() != null) { gt = new GenericType(method.getGenericReturnType()); } else { gt = new GenericType(method.getReturnType()); } Object obj = ClientInvocation.extractResult(gt, response, method.getAnnotations()); if (obj instanceof InputStream || obj instanceof Reader) releaseConnectionAfter = false; return obj; } finally { if (releaseConnectionAfter) response.close(); } }
/** * Resolve current method generic return type to a {@link GenericMetadataSupport}. * * @param method Method to resolve the return type. * @return {@link GenericMetadataSupport} representing this generic return type. */ public GenericMetadataSupport resolveGenericReturnType(Method method) { Type genericReturnType = method.getGenericReturnType(); // logger.log("Method '" + method.toGenericString() + "' has return type : " + // genericReturnType.getClass().getInterfaces()[0].getSimpleName() + " : " + genericReturnType); if (genericReturnType instanceof Class) { return new NotGenericReturnTypeSupport(genericReturnType); } if (genericReturnType instanceof ParameterizedType) { return new ParameterizedReturnType( this, method.getTypeParameters(), (ParameterizedType) method.getGenericReturnType()); } if (genericReturnType instanceof TypeVariable) { return new TypeVariableReturnType( this, method.getTypeParameters(), (TypeVariable) genericReturnType); } throw new MockitoException( "Ouch, it shouldn't happen, type '" + genericReturnType.getClass().getCanonicalName() + "' on method : '" + method.toGenericString() + "' is not supported : " + genericReturnType); }
private void handleMethod( String prefix, Collection<DetailedLink> results, Method m, Class<?> resource, Map<String, Type> parametersMap) throws ClassNotFoundException { if (isRequiresDescription(m)) { Type genericReturnType = m.getGenericReturnType(); Class<?> concreteReturnType = findConcreteType(genericReturnType, resource, parametersMap); if (concreteReturnType == null) { concreteReturnType = m.getReturnType(); } Type[] genericParameterTypes = m.getGenericParameterTypes(); Class<?>[] concreteParameterTypes = m.getParameterTypes(); for (int i = 0; i < concreteParameterTypes.length; i++) { Class<?> concreteParameterType = findConcreteType(genericParameterTypes[i], resource, parametersMap); if (concreteParameterType != null) { concreteParameterTypes[i] = concreteParameterType; } } if (m.isAnnotationPresent(javax.ws.rs.GET.class)) { handleGet(prefix, results, concreteReturnType); } else if (m.isAnnotationPresent(PUT.class)) { handlePut(prefix, results, concreteReturnType); } else if (m.isAnnotationPresent(javax.ws.rs.DELETE.class)) { handleDelete(prefix, results, m); } else if (m.isAnnotationPresent(Path.class)) { String path = m.getAnnotation(Path.class).value(); if (isAction(m)) { handleAction(prefix, results, path, m); } else { if (isSingleEntityResource(m)) { path = "{" + getSingleForm(prefix) + ":id}"; } if (m.getGenericReturnType() instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) m.getGenericReturnType(); addToGenericParamsMap( resource, parameterizedType.getActualTypeArguments(), m.getReturnType().getTypeParameters(), parametersMap); } results.addAll( describe( concreteReturnType, prefix + "/" + path, new HashMap<String, Type>(parametersMap))); } } else { if (m.getName().equals(ADD)) { handleAdd(prefix, results, concreteParameterTypes); } } } }
public static void main(String[]argv) throws Exception { Method m = Goo.class.getDeclaredMethod("getStrings"); Type t = m.getGenericReturnType(); if (!t.toString().equals("java.util.List<java.lang.String>")) throw new RuntimeException("Incorrect signature. Signature is "+t); m = IFace.class.getDeclaredMethod("getStrings"); t = m.getGenericReturnType(); if (!t.toString().equals("java.util.List<java.lang.String>")) throw new RuntimeException("Incorrect signature. Signature is "+t); }
/** * Get the DBus member output signature. * * @param method the method */ public static String getOutSig(Method method) throws AnnotationBusException { BusMethod busMethod = method.getAnnotation(BusMethod.class); if (busMethod != null && busMethod.replySignature().length() > 0) { return Signature.typeSig(method.getGenericReturnType(), busMethod.replySignature()); } BusSignal busSignal = method.getAnnotation(BusSignal.class); if (busSignal != null && busSignal.replySignature().length() > 0) { return Signature.typeSig(method.getGenericReturnType(), busSignal.replySignature()); } return Signature.typeSig(method.getGenericReturnType(), null); }
@Test public void testURIDeclarations() throws NoSuchMethodException, SecurityException { Assert.assertNotNull(A.class.getMethod("addA", Object.class)); Assert.assertNotNull(B.class.getMethod("addA", Object.class)); Method uriMethod = B.class.getMethod("getA"); Assert.assertTrue(uriMethod.getGenericReturnType() instanceof ParameterizedType); ParameterizedType returnType = (ParameterizedType) uriMethod.getGenericReturnType(); Assert.assertEquals(returnType.getActualTypeArguments().length, 1); Assert.assertTrue(returnType.getActualTypeArguments()[0] instanceof WildcardType); Assert.assertEquals( ((WildcardType) returnType.getActualTypeArguments()[0]).getUpperBounds()[0], URI.class); }
private List<Method> GetMethods(java.lang.reflect.Method[] methods) { List<Method> list = new ArrayList<>(); for (java.lang.reflect.Method mthd : methods) { String visibility = this.GetVisibility(mthd.getModifiers()); boolean isStatic = this.GetIsStatic(mthd.getModifiers()); boolean isfinal = this.GetIsFinal(mthd.getModifiers()); String outputType = mthd.getGenericReturnType().toString(); List<InputParameter> inputParameters = this.GetInputParameters(mthd.getParameters()); List<String> annotations = this.GetAnnotations(mthd.getAnnotations()); String name = mthd.getName(); if (name.contains("_")) continue; boolean isThrowExceptions = false; if (mthd.getExceptionTypes().length > 0) { isThrowExceptions = true; } Method method = ModelFactory.GetMethodWithValue( outputType, name, visibility, isfinal, isStatic, isThrowExceptions, inputParameters, annotations, new ArrayList<>()); list.add(method); } return list; }
private void BuildSignature() { Var[] vars = new Var[samMethod.getParameterTypes().length]; lambdaApplyParameters = new Class<?>[samMethod.getParameterTypes().length]; for (int i = 0; i < vars.length; i++) { //noinspection unchecked Type paramType = samMethod.getGenericParameterTypes()[i]; if (paramType instanceof Class) vars[i] = new Var((Class<?>) paramType); else if (paramType instanceof TypeVariable) vars[i] = new Var(findMaterializedType(((TypeVariable) paramType).getName())); else throw new LambdaException( "unexpected param generic type [%s] for SAM [%s]", paramType, samType.getName()); lambdaApplyParameters[i] = Object.class; } Class<?> materializedRetType; Type genericRetType = samMethod.getGenericReturnType(); if (genericRetType instanceof Class<?>) materializedRetType = samMethod.getReturnType(); else if (genericRetType instanceof TypeVariable) materializedRetType = findMaterializedType(((TypeVariable) genericRetType).getName()); else throw new LambdaException( "unexpected generic return type [%s] for SAM [%s]", samMethod.getReturnType(), samType.getName()); this.lambdaSignature = new LambdaSignature<Object>(materializedRetType, vars); }
static Class<?> resultType(Method finderMethod) { checkArgument(finderMethod.getReturnType() == Iterator.class); Type t = finderMethod.getGenericReturnType(); ParameterizedType pt = (ParameterizedType) t; Type r = pt.getActualTypeArguments()[0]; return (Class<?>) r; }
public void populateExchangeFromCxfRsRequest( org.apache.cxf.message.Exchange cxfExchange, Exchange camelExchange, Method method, Object[] paramArray) { Message camelMessage = camelExchange.getIn(); // Copy the CXF message header into the Camel inMessage org.apache.cxf.message.Message cxfMessage = cxfExchange.getInMessage(); // TODO use header filter strategy and cxfToCamelHeaderMap CxfUtils.copyHttpHeadersFromCxfToCamel(cxfMessage, camelMessage); // copy the protocol header copyProtocolHeader(cxfMessage, camelMessage, camelMessage.getExchange()); camelMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, method.getReturnType()); camelMessage.setHeader( CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE, method.getGenericReturnType()); copyOperationResourceInfoStack(cxfMessage, camelMessage); camelMessage.setHeader(CxfConstants.OPERATION_NAME, method.getName()); camelMessage.setHeader(CxfConstants.CAMEL_CXF_MESSAGE, cxfMessage); camelMessage.setBody(new MessageContentsList(paramArray)); }
protected Object handleResponse(Message outMessage, Class<?> serviceCls) throws Throwable { try { Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build(); ((ResponseImpl) r).setOutMessage(outMessage); getState().setResponse(r); Method method = outMessage.getExchange().get(Method.class); checkResponse(method, r, outMessage); if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE) { return null; } if (method.getReturnType() == Response.class && (r.getEntity() == null || InputStream.class.isAssignableFrom(r.getEntity().getClass()) && ((InputStream) r.getEntity()).available() == 0)) { return r; } if (PropertyUtils.isTrue( super.getConfiguration().getResponseContext().get(BUFFER_PROXY_RESPONSE))) { r.bufferEntity(); } Class<?> returnType = method.getReturnType(); Type genericType = InjectionUtils.processGenericTypeIfNeeded( serviceCls, returnType, method.getGenericReturnType()); returnType = InjectionUtils.updateParamClassToTypeIfNeeded(returnType, genericType); return readBody(r, outMessage, returnType, genericType, method.getDeclaredAnnotations()); } finally { ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies(); } }
public Object invoke(Object target, Method method, Object[] params) throws Throwable { if (EQUALS_METHOD.equals(method)) { Object param = params[0]; if (param == null || !Proxy.isProxyClass(param.getClass())) { return false; } InvocationHandler other = Proxy.getInvocationHandler(param); return equals(other); } else if (HASHCODE_METHOD.equals(method)) { return hashCode(); } MethodInvocation invocation = new MethodInvocation( method.getName(), method.getReturnType(), method.getGenericReturnType(), method.getParameterTypes(), delegate, params); invoker.invoke(invocation); if (!invocation.found()) { String methodName = method.getDeclaringClass().getSimpleName() + "." + method.getName() + "()"; throw Exceptions.unsupportedMethod(methodName); } return invocation.getResult(); }
/** * When reading collections, determine the collection component type. * * @param method * @return */ private static Class<?> findTargetComponentType(final Method method) { if (method.getReturnType().isArray()) { return method.getReturnType().getComponentType(); } if (!(ReflectionHelper.isStreamClass(method.getReturnType()) || List.class.equals(method.getReturnType()))) { return null; } final Type type = method.getGenericReturnType(); if (!(type instanceof ParameterizedType) || (((ParameterizedType) type).getActualTypeArguments() == null) || (((ParameterizedType) type).getActualTypeArguments().length < 1)) { throw new IllegalArgumentException( "When using List as return type for method " + method + ", please specify a generic type for the List. Otherwise I do not know which type I should fill the List with."); } assert ((ParameterizedType) type).getActualTypeArguments().length == 1 : ""; Type componentType = ((ParameterizedType) type).getActualTypeArguments()[0]; if (!(componentType instanceof Class)) { throw new IllegalArgumentException( "I don't know how to instantiate the generic type for the return type of method " + method); } return (Class<?>) componentType; }
private static ParameterizedType getReturnType(Method paramMethod) { paramMethod = paramMethod.getGenericReturnType(); if ((paramMethod instanceof ParameterizedType)) { return (ParameterizedType) paramMethod; } return null; }
/** * メソッドの戻り値型を表現する{@link ParameterizedClassDesc}を作成して返します。 * * @param method メソッド。{@literal null}であってはいけません * @param map パラメータ化された型が持つ型変数をキー、型引数を値とする{@link Map}。{@literal null} であってはいけません * @return メソッドの戻り値型を表現する{@link ParameterizedClassDesc} */ public static ParameterizedClassDesc createParameterizedClassDesc( final Method method, final Map<TypeVariable<?>, Type> map) { assertArgumentNotNull("method", method); assertArgumentNotNull("map", map); return createParameterizedClassDesc(method.getGenericReturnType(), map); }
private Status getProperties(Class<?> busInterface) throws AnnotationBusException { for (Method method : busInterface.getMethods()) { if (method.getAnnotation(BusProperty.class) != null) { String name = getName(method); Property property = properties.get(name); BusAnnotations propertyAnnotations = method.getAnnotation(BusAnnotations.class); TreeMap<String, String> annotations = new TreeMap<String, String>(); if (propertyAnnotations != null) { for (BusAnnotation propertyAnnotation : propertyAnnotations.value()) { annotations.put(propertyAnnotation.name(), propertyAnnotation.value()); } } if (property == null) { property = new Property(name, getPropertySig(method), annotations); } else if (!property.signature.equals(getPropertySig(method))) { return Status.BAD_ANNOTATION; } if (method.getName().startsWith("get")) { property.get = method; } else if (method.getName().startsWith("set") && (method.getGenericReturnType().equals(void.class))) { property.set = method; } else { return Status.BAD_ANNOTATION; } properties.put(name, property); } } return Status.OK; }
/** * Checks if the two types of methods are the same. * * @param jDiffMethod the jDiffMethod to compare * @param method the reflected method to compare * @return true, if both methods are the same */ private boolean matches(JDiffMethod jDiffMethod, Method method) { // If the method names aren't equal, the methods can't match. if (jDiffMethod.mName.equals(method.getName())) { String jdiffReturnType = jDiffMethod.mReturnType; String reflectionReturnType = typeToString(method.getGenericReturnType()); List<String> jdiffParamList = jDiffMethod.mParamList; // Next, compare the return types of the two methods. If // they aren't equal, the methods can't match. if (jdiffReturnType.equals(reflectionReturnType)) { Type[] params = method.getGenericParameterTypes(); // Next, check the method parameters. If they have // different number of parameters, the two methods // can't match. if (jdiffParamList.size() == params.length) { // If any of the parameters don't match, the // methods can't match. for (int i = 0; i < jdiffParamList.size(); i++) { if (!compareParam(jdiffParamList.get(i), params[i])) { return false; } } // We've passed all the tests, the methods do // match. return true; } } } return false; }
/** * Test case for TEATROVE-55. * * <p>https://github.com/teatrove/teatrove/issues/55 */ @Test public void testGetConstructorWithGenerics() throws Exception { ClassInjector injector = ClassInjector.getInstance(this.getClass().getClassLoader()); // build first constructor that purely merges general play context Constructor<?> ctor1 = MergedClass.getConstructor2( injector, new Class[] {PlayContext.class, GameContext.class, StringContext.class}, new String[] {"PlayContext$", "GameContext$", "StringContext$"}); // ensure two get play methods and both return hockey game int found1 = 0, bridge1 = 0; Method[] methods1 = ctor1.getDeclaringClass().getMethods(); for (Method method1 : methods1) { if (method1.getName().equals("getPlay")) { found1++; if (method1.isBridge()) { bridge1++; } } } assertEquals("expected two getPlay methods", 2, found1); assertEquals("expected one getPlay bridge method", 1, bridge1); // now build another constructor that merges that merge plus another // to ensure generics flow through from one merge to another Constructor<?> ctor2 = MergedClass.getConstructor2( ClassInjector.getInstance(this.getClass().getClassLoader()), new Class[] {ctor1.getDeclaringClass(), Dog.class}); // ensure two get play methods and both return hockey game int found2 = 0, bridge2 = 0; Method[] methods2 = ctor2.getDeclaringClass().getMethods(); for (Method method2 : methods2) { if (method2.getName().equals("getPlay")) { found2++; if (method2.isBridge()) { bridge2++; } } } assertEquals("expected two getPlay methods", 2, found1); assertEquals("expected one getPlay bridge method", 1, bridge1); // ensure get plays method has generic signature for list Method playsMethod = ctor2.getDeclaringClass().getMethod("getPlays"); Type returnType = playsMethod.getGenericReturnType(); assertTrue("expected param type", returnType instanceof ParameterizedType); assertEquals( "expected plays type for type param", HockeyGamePlayLog.class, ((ParameterizedType) returnType).getActualTypeArguments()[0]); }
/** * Populate model from given reflect getter method * * @param method the method to analyze * @param methodModel the model to update */ protected void analyzeDtoGetterMethod(Method method, MethodModel methodModel) { methodModel.setGetter(true); Type fieldType = method.getGenericReturnType(); String fieldName = getGetterFieldName(method); fieldAttributes.put(fieldName, fieldType); methodModel.setFieldName(fieldName); methodModel.setFieldType(convertType(fieldType)); }
/** * Returns the resolved generic return type of {@code method}. * * @param method a method defined by this or any supertype. * @since 2.0 */ public TypeLiteral<?> getReturnType(Method method) { Assert.checkArgument( method.getDeclaringClass().isAssignableFrom(rawType), "%s is not defined by a supertype of %s", method, type); return resolve(method.getGenericReturnType()); }
/** java.lang.reflect.Method#getGenericReturnType() */ public void test_getGenericReturnType() throws Exception { Method method = GenericReturnType.class.getDeclaredMethod("returnGeneric"); Type returnType = method.getGenericReturnType(); assertNotNull("getGenericReturnType returned null", returnType); assertTrue(returnType instanceof TypeVariable<?>); @SuppressWarnings("unchecked") TypeVariable<Class<ExceptionTest<?>>> tv = (TypeVariable<Class<ExceptionTest<?>>>) returnType; assertEquals("T", tv.getName()); }
@Test public void test_two_elem_string_list() throws Throwable { data = new MethodData(method, method.getGenericReturnType(), "['x', ' y']"); Object o = new CollectionConstructor().construct(data); Assert.assertTrue(o.getClass().equals(StringList.class)); Assert.assertTrue(((Collection<?>) o).size() == 2); Assert.assertTrue(((List<String>) o).get(0).equals("x")); Assert.assertTrue(((List<String>) o).get(1).equals(" y")); }
/** * Called by {@link #createChangeMetaData()} to create metadata for a given parameter. It finds * the method that corresponds to the parameter and calls the corresponding create*MetaData * methods such as {@link #createRequiredDatabasesMetaData(String, DatabaseChangeProperty)} to * determine the correct values for the ChangeParameterMetaData fields. * * @throws UnexpectedLiquibaseException if the passed parameter does not exist */ protected ChangeParameterMetaData createChangeParameterMetadata(String parameterName) { try { String displayName = parameterName.replaceAll("([A-Z])", " $1"); displayName = displayName.substring(0, 1).toUpperCase() + displayName.substring(1); PropertyDescriptor property = null; for (PropertyDescriptor prop : Introspector.getBeanInfo(this.getClass()).getPropertyDescriptors()) { if (prop.getDisplayName().equals(parameterName)) { property = prop; break; } } if (property == null) { throw new UnexpectedLiquibaseException("Could not find property " + parameterName); } Method readMethod = property.getReadMethod(); if (readMethod == null) { readMethod = getClass().getMethod("is" + StringUtils.upperCaseFirst(property.getName())); } Type type = readMethod.getGenericReturnType(); DatabaseChangeProperty changePropertyAnnotation = readMethod.getAnnotation(DatabaseChangeProperty.class); String mustEqualExisting = createMustEqualExistingMetaData(parameterName, changePropertyAnnotation); String description = createDescriptionMetaData(parameterName, changePropertyAnnotation); Map<String, Object> examples = createExampleValueMetaData(parameterName, changePropertyAnnotation); String since = createSinceMetaData(parameterName, changePropertyAnnotation); SerializationType serializationType = createSerializationTypeMetaData(parameterName, changePropertyAnnotation); String[] requiredForDatabase = createRequiredDatabasesMetaData(parameterName, changePropertyAnnotation); String[] supportsDatabase = createSupportedDatabasesMetaData(parameterName, changePropertyAnnotation); return new ChangeParameterMetaData( this, parameterName, displayName, description, examples, since, type, requiredForDatabase, supportsDatabase, mustEqualExisting, serializationType); } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } }
/** * Invokes this method with the provided arguments * * @param args @return @throws WiseException If an unknown exception is received * @throws WiseWebServiceException There are 4 known failure conditions - The wsdl (url) could not * be found - The wsdl is password protected - The endpoint (url) could not be found - The * endpoint is password protected * @throws InvocationException * @throws IllegalArgumentException */ InvocationResultImpl invoke(Map<String, Object> args) throws WiseWebServiceException, InvocationException, IllegalArgumentException { InvocationResultImpl result = null; Map<String, Object> emptyHolder = Collections.emptyMap(); try { EndpointMethodCaller caller = new EndpointMethodCaller( this.getEndpoint(), this.getMethod(), this.getParametersInRightPositionArray(args)); Future<Object> invocation = ((WSEndpointImpl) this.getEndpoint()).getService().submit(caller); if (isOneWay()) { invocation.get(); result = new InvocationResultImpl(null, null, null, emptyHolder); } else { result = new InvocationResultImpl( RESULT, method.getGenericReturnType(), invocation.get(), getHoldersResult(args)); } } catch (java.util.concurrent.ExecutionException wse) { Throwable ite = wse.getCause(); if (ite != null && ite != wse && ite instanceof InvocationTargetException) { Throwable t = ite.getCause(); // unchecked exception ? if (t != null && t != ite && t != wse && t instanceof WebServiceException) { // authentication exception ? if (isAuthenticationException(t, new HashSet<Throwable>())) { throw new WiseWebServiceException( "Authentication exception", null); // TODO improve this } throw new WiseWebServiceException(t.getMessage(), t); } // checked exception ? if (t != null && t != ite && t != wse && t instanceof Exception) { Method methodPointer = this.getMethod(); if (methodPointer != null && methodPointer.getExceptionTypes() != null) { for (int i = 0; i < methodPointer.getExceptionTypes().length; i++) { Class<?> excType = methodPointer.getExceptionTypes()[i]; if (t.getClass().isAssignableFrom(excType)) { // checked exception result = new InvocationResultImpl("exception", excType, t, emptyHolder); return result; } } } } throw new InvocationException("Unknown exception received: " + ite.getMessage(), ite); } throw new WiseWebServiceException(wse.getMessage(), wse); } catch (Throwable e) { throw new InvocationException("Generic Error during method invocation!", e); } return result; }
public static Type[] getPropertyGenericTypes(Object obj, String name) { Method getter = getterMethod(obj, name); if (getter == null) return null; Type type = getter.getGenericReturnType(); if (type instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) type; return paramType.getActualTypeArguments(); } return null; }
public static <T> Class<T> tellMeTheTypeOfThisThing() throws NoSuchMethodException { Method method = InferGenericTypeForAStaticMethodTest.class.getDeclaredMethod( "tellMeTheTypeOfThisThing", null); ParameterizedType type = (ParameterizedType) method.getGenericReturnType(); TypeVariableImpl typeImpl = (TypeVariableImpl) type.getActualTypeArguments()[0]; System.out.println(typeImpl); return null; }