private static MemberValue[] toMemberValue(Object[] value, Class<?> valueType, ConstPool constpool, ClassPool classPool) throws NotFoundException { final MemberValue[] memberValues = new MemberValue[value.length]; for (int i = 0; i < value.length; i++) { memberValues[i] = toMemberValue(value[i], valueType, constpool, classPool); } return memberValues; }
protected Map<String, String> getHeaders(Class<?> clazz, Method method) { final Map<String, String> headers = getHeaders(clazz); headers.putAll(getHeaders(method)); return headers; }
@Override protected Object enrichByType(Class<?> clazz, Method method, ArquillianResteasyResource annotation, Consumes consumes, Produces produces) { Object result = null; if (ClientBuilder.class.isAssignableFrom(clazz)) { result = ClientBuilder.newBuilder(); } else if (Client.class.isAssignableFrom(clazz)) { result = ClientBuilder.newClient(); } else if (WebTarget.class.isAssignableFrom(clazz)) { WebTarget webTarget = ClientBuilder.newClient().target(getBaseURL() + annotation.value()); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { webTarget.register(new HeaderFilter(headers)); } result = webTarget; } return result; } }
protected Map<String, String> getHeaders(AnnotatedElement annotatedElement) { final Map<String, String> headersMap = new HashMap<String, String>(); final Headers headersAnnotation = annotatedElement.getAnnotation(Headers.class); if (null != headersAnnotation && null != headersAnnotation.value()) { for (Header header : headersAnnotation.value()) { addHeaders(headersMap, header); } } addHeaders(headersMap, annotatedElement.getAnnotation(Header.class)); return headersMap; }
@Override public Object[] resolve(Method method) { Object[] values = new Object[method.getParameterTypes().length]; Class<?>[] parameterTypes = method.getParameterTypes(); final Consumes consumes = method.getDeclaringClass().getAnnotation(Consumes.class); final Produces produces = method.getDeclaringClass().getAnnotation(Produces.class); if (responseInst.get() != null) { for (int i = 0; i < parameterTypes.length; i++) { if (Response.class.isAssignableFrom(parameterTypes[i])) { values[i] = responseInst.get(); } } } else { for (int i = 0; i < parameterTypes.length; i++) { final Annotation[] parameterAnnotations = method.getParameterAnnotations()[i]; for (Annotation annotation : parameterAnnotations) { if (annotation instanceof ArquillianResteasyResource) { ArquillianResteasyResource arr = (ArquillianResteasyResource) annotation; Class<?> clazz = parameterTypes[i]; if (isSupportedParameter(clazz)) { values[i] = enrichByType(clazz, method, arr, consumes, produces); } else { throw new RuntimeException("Not able to provide a client injection for type " + clazz); } } } } } return values; }
@SuppressWarnings("unchecked") public static <T> Class<T> getModifiedClass(Class<T> clazz, Annotation[] add) throws javassist.NotFoundException, CannotCompileException, InvocationTargetException, IllegalAccessException { ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.get(clazz.getCanonicalName()); for (CtMethod method : cc.getDeclaredMethods()) { ClassFile ccFile = cc.getClassFile(); ConstPool constpool = ccFile.getConstPool(); AnnotationsAttribute attr; attr = filterExistingAnnotations(add, method); addNewAnnotations(add, method, constpool, pool, attr); } cc.setName(cc.getName() + "$ClassModifier$" + COUNTER.increment()); cc.setSuperclass(pool.get(clazz.getCanonicalName())); return cc.toClass(); }
private static MemberValue toMemberValue(Object value, Class<?> componentType, ConstPool constpool, ClassPool classPool) throws NotFoundException { final CtClass type = getType(value, componentType, classPool); final MemberValue memberValue = javassist.bytecode.annotation.Annotation.createMemberValue(constpool, type); if (memberValue instanceof BooleanMemberValue) { } else if (type.isArray()) { ((ArrayMemberValue) memberValue).setValue( toMemberValue((Object[]) value, componentType, constpool, classPool)); } else if (type.isInterface()) { final javassist.bytecode.annotation.Annotation annotation = try { annotation.addMemberValue(method.getName(), toMemberValue(method.invoke(value), null, constpool, classPool)); } catch (Exception e) { throw new RuntimeException(e);
private static void addNewAnnotations(Annotation[] add, CtMethod method, ConstPool constpool, ClassPool classPool, AnnotationsAttribute attr) throws IllegalAccessException, NotFoundException, InvocationTargetException { if (null == attr) { attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); method.getMethodInfo().addAttribute(attr); } for (Annotation toAdd : add) { attr.addAnnotation(toJavassist(toAdd, constpool, classPool)); } }
protected URI getBaseURL() { HTTPContext context = metaDataInst.get().getContext(HTTPContext.class); if (allInSameContext(context.getServlets())) { return context.getServlets().get(0).getBaseURI(); } throw new IllegalStateException("No baseURL found in HTTPContext"); }
@RunAsClient @Parameters({ "gluuConfigurationPath", "webTarget" }) @Consumes(MediaType.APPLICATION_JSON) @Test public void getConfigurationTest(String gluuConfigurationPath, @Optional @ArquillianResteasyResource("") final WebTarget webTarget) throws Exception { Response response = webTarget.path(gluuConfigurationPath).request().get(); String entity = response.readEntity(String.class); BaseTest.showResponse("UMA : TConfiguration.configuration", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); try { GluuConfiguration appConfiguration = ServerUtil.createJsonMapper().readValue(entity, GluuConfiguration.class); System.err.println(appConfiguration.getIdGenerationEndpoint()); assertNotNull(appConfiguration, "Meta data configuration is null"); assertNotNull(appConfiguration.getIdGenerationEndpoint()); assertNotNull(appConfiguration.getIntrospectionEndpoint()); assertNotNull(appConfiguration.getAuthLevelMapping()); assertNotNull(appConfiguration.getScopeToClaimsMapping()); } catch (IOException e) { e.printStackTrace(); fail(); } } }
@Override protected Object enrichByType(Class<?> clazz, Method method, ArquillianResteasyResource annotation, Consumes consumes, Produces produces) { Object value; Client client = JerseyClientBuilder.newClient(); WebTarget webTarget = client.target(getBaseURL() + annotation.value()); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { webTarget.register(new HeaderFilter(headers)); } JerseyWebTarget jerseyWebTarget = (JerseyWebTarget) webTarget; if (WebTarget.class.isAssignableFrom(clazz)) { value = jerseyWebTarget; } else { final Class<?> parameterType; try { final Annotation[] methodDeclaredAnnotations = method.getDeclaredAnnotations(); // This is test method so if it only contains @Test annotation then we don't need to hassel with substitutions parameterType = methodDeclaredAnnotations.length <= 1 ? clazz : ClassModifier.getModifiedClass(clazz, methodDeclaredAnnotations); } catch (Exception e) { throw new RuntimeException("Cannot substitute annotations for method " + method.getName(), e); } value = WebResourceFactory.newResource(parameterType, jerseyWebTarget); } return value; }
private static javassist.bytecode.annotation.Annotation toJavassist(Annotation annotation, ConstPool constpool, ClassPool classPool) throws NotFoundException, InvocationTargetException, IllegalAccessException { final javassist.bytecode.annotation.Annotation newAnnotation = new javassist.bytecode.annotation.Annotation( annotation.annotationType().getCanonicalName(), constpool); for (Method method : annotation.annotationType().getDeclaredMethods()) { final Object value = method.invoke(annotation); Class<?> componentType = null; if (method.getReturnType().isArray()) { componentType = method.getReturnType().getComponentType(); } newAnnotation.addMemberValue(method.getName(), toMemberValue(value, componentType, constpool, classPool)); } return newAnnotation; }
@Override protected Object enrichByType(Class<?> clazz, Method method, ArquillianResteasyResource annotation, Consumes consumes, Produces produces) { Object value; Client client = JerseyClientBuilder.newClient(); WebTarget webTarget = client.target(getBaseURL() + annotation.value()); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { webTarget.register(new HeaderFilter(headers)); } JerseyWebTarget jerseyWebTarget = (JerseyWebTarget) webTarget; if (WebTarget.class.isAssignableFrom(clazz)) { value = jerseyWebTarget; } else { final Class<?> parameterType; try { final Annotation[] methodDeclaredAnnotations = method.getDeclaredAnnotations(); // This is test method so if it only contains @Test annotation then we don't need to hassel with substitutions parameterType = methodDeclaredAnnotations.length <= 1 ? clazz : ClassModifier.getModifiedClass(clazz, methodDeclaredAnnotations); } catch (Exception e) { throw new RuntimeException("Cannot substitute annotations for method " + method.getName(), e); } value = WebResourceFactory.newResource(parameterType, jerseyWebTarget); } return value; }
WebTarget webTarget = client.target(getBaseURL() + annotation.value()); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { webTarget.register(new HeaderFilter(headers)); final Annotation[] methodDeclaredAnnotations = method.getDeclaredAnnotations(); parameterType = methodDeclaredAnnotations.length <= 1 ? clazz : ClassModifier.getModifiedClass(clazz, methodDeclaredAnnotations); } catch (Exception e) { throw new RuntimeException("Cannot substitute annotations for method " + method.getName(), e);
Object value; Client client = ResteasyClientBuilder.newClient(); WebTarget webTarget = client.target(getBaseURL() + annotation.value()); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { webTarget.register(new HeaderFilter(headers)); : ClassModifier.getModifiedClass(clazz, methodDeclaredAnnotations); } catch (Exception e) { throw new RuntimeException("Cannot substitute annotations for method " + method.getName(), e);
Produces produces) { Object value; final String resourcePath = annotation.value(); if (ClientRequest.class.isAssignableFrom(clazz)) { final ClientRequest clientRequest = new ClientRequestFactory(getBaseURL()).createRelativeRequest(resourcePath); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { clientRequest.registerInterceptor(new HeaderFilter(headers)); : ClassModifier.getModifiedClass(clazz, methodDeclaredAnnotations); } catch (Exception e) { throw new RuntimeException("Cannot substitute annotations for method " + method.getName(), e); final ProxyBuilder<?> proxyBuilder = ProxyBuilder.build(parameterType, getBaseURL() + resourcePath); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { proxyBuilder.executor(new ApacheHttpClient4Executor() {
final String resourcePath = annotation.value(); if (ClientRequest.class.isAssignableFrom(clazz)) { final ClientRequest clientRequest = new ClientRequestFactory(getBaseURL()).createRelativeRequest(resourcePath); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { clientRequest.registerInterceptor(new HeaderFilter(headers)); final Annotation[] methodDeclaredAnnotations = method.getDeclaredAnnotations(); parameterType = methodDeclaredAnnotations.length <= 1 ? clazz : ClassModifier.getModifiedClass(clazz, methodDeclaredAnnotations); } catch (Exception e) { throw new RuntimeException("Cannot substitute annotations for method " + method.getName(), e); final ProxyBuilder<?> proxyBuilder = ProxyBuilder.build(parameterType, getBaseURL() + resourcePath); final Map<String, String> headers = getHeaders(clazz, method); if (!headers.isEmpty()) { proxyBuilder.executor(new ApacheHttpClient4Executor() {