List of usage examples for java.lang Class getClassLoader
@CallerSensitive
@ForceInline
public ClassLoader getClassLoader()
From source file:org.codice.ddf.cxf.client.impl.SecureCxfClientFactoryImpl.java
/** * Constructs a factory that will return security-aware cxf clients. Once constructed, use the * getClient* methods to retrieve a fresh client with the same configuration. Providing {@link * WebClient} to interfaceClass will create a generic web client. * * <p>This factory can and should be cached. The clients it constructs should not be. * * @param endpointUrl the remote url to connect to * @param interfaceClass an interface representing the resource at the remote url * @param providers optional list of providers to further configure the client * @param interceptor optional message interceptor for the client * @param disableCnCheck disable ssl check for common name / host name match * @param allowRedirects allow this client to follow redirects *//*from ww w .j ava2 s. co m*/ public SecureCxfClientFactoryImpl(String endpointUrl, Class<T> interfaceClass, List<?> providers, Interceptor<? extends Message> interceptor, boolean disableCnCheck, boolean allowRedirects, PropertyResolver propertyResolver) { if (StringUtils.isEmpty(endpointUrl) || interfaceClass == null) { throw new IllegalArgumentException("Called without a valid URL, will not be able to connect."); } if (propertyResolver != null) { endpointUrl = propertyResolver.getResolvedString(); } else { LOGGER.warn("Called without a valid propertyResolver, system properties in URI may not resolve."); } this.interfaceClass = interfaceClass; this.disableCnCheck = disableCnCheck; this.allowRedirects = allowRedirects; JAXRSClientFactoryBean jaxrsClientFactoryBean = new JAXRSClientFactoryBean(); jaxrsClientFactoryBean.setServiceClass(interfaceClass); jaxrsClientFactoryBean.setAddress(endpointUrl); jaxrsClientFactoryBean.setClassLoader(interfaceClass.getClassLoader()); jaxrsClientFactoryBean.getInInterceptors().add(new LoggingInInterceptor()); jaxrsClientFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor()); if (!basicAuth && StringUtils.startsWithIgnoreCase(endpointUrl, HTTPS)) { jaxrsClientFactoryBean.getInInterceptors().add(new PaosInInterceptor(Phase.RECEIVE)); jaxrsClientFactoryBean.getOutInterceptors().add(new PaosOutInterceptor(Phase.POST_LOGICAL)); } if (CollectionUtils.isNotEmpty(providers)) { jaxrsClientFactoryBean.setProviders(providers); } if (interceptor != null) { jaxrsClientFactoryBean.getInInterceptors().add(interceptor); } this.clientFactory = jaxrsClientFactoryBean; }
From source file:com.asakusafw.testdriver.JobFlowTester.java
private void runTestInternal(Class<? extends FlowDescription> jobFlowDescriptionClass) throws IOException { LOG.info("?????: {}", driverContext.getCallerClass().getName()); if (driverContext.isSkipValidateCondition() == false) { LOG.info("??????: {}", driverContext.getCallerClass().getName()); validateTestCondition();/* w w w .ja va2 s . c om*/ } // ? LOG.info("?????: {}", jobFlowDescriptionClass.getName()); JobFlowDriver jobFlowDriver = JobFlowDriver.analyze(jobFlowDescriptionClass); assertFalse(jobFlowDriver.getDiagnostics().toString(), jobFlowDriver.hasError()); // ? driverContext.validateCompileEnvironment(); JobFlowClass jobFlowClass = jobFlowDriver.getJobFlowClass(); File compileWorkDir = driverContext.getCompilerWorkingDirectory(); if (compileWorkDir.exists()) { FileUtils.forceDelete(compileWorkDir); } FlowGraph flowGraph = jobFlowClass.getGraph(); String batchId = "testing"; //$NON-NLS-1$ String flowId = jobFlowClass.getConfig().name(); JobflowInfo jobflowInfo = DirectFlowCompiler.compile(flowGraph, batchId, flowId, "test.jobflow", //$NON-NLS-1$ Location.fromPath(driverContext.getClusterWorkDir(), '/'), compileWorkDir, Arrays.asList(new File[] { DirectFlowCompiler.toLibraryPath(jobFlowDescriptionClass) }), jobFlowDescriptionClass.getClassLoader(), driverContext.getOptions()); // ? driverContext.validateExecutionEnvironment(); JobflowExecutor executor = new JobflowExecutor(driverContext); driverContext.prepareCurrentJobflow(jobflowInfo); LOG.info("??????: {}", driverContext.getCallerClass().getName()); executor.cleanWorkingDirectory(); executor.cleanInputOutput(jobflowInfo); executor.cleanExtraResources(getExternalResources()); LOG.info("??????: {}", driverContext.getCallerClass().getName()); executor.prepareExternalResources(getExternalResources()); executor.prepareInput(jobflowInfo, inputs); executor.prepareOutput(jobflowInfo, outputs); LOG.info("?????: {}", jobFlowDescriptionClass.getName()); VerifyContext verifyContext = new VerifyContext(driverContext); executor.runJobflow(jobflowInfo); verifyContext.testFinished(); LOG.info("??????: {}", driverContext.getCallerClass().getName()); executor.verify(jobflowInfo, verifyContext, outputs); }
From source file:com.asakusafw.testdriver.BatchTester.java
private void runTestInternal(Class<? extends BatchDescription> batchDescriptionClass) throws IOException { LOG.info("?????: {}", driverContext.getCallerClass().getName()); if (driverContext.isSkipValidateCondition() == false) { LOG.info("??????: {}", driverContext.getCallerClass().getName()); validateTestCondition();/* w w w . j a va 2s. c o m*/ } // ? LOG.info("???????: {}", batchDescriptionClass.getName()); // ??? BatchDriver batchDriver = BatchDriver.analyze(batchDescriptionClass); assertFalse(batchDriver.getDiagnostics().toString(), batchDriver.hasError()); // ? driverContext.validateCompileEnvironment(); File compileWorkDir = driverContext.getCompilerWorkingDirectory(); if (compileWorkDir.exists()) { FileUtils.forceDelete(compileWorkDir); } File compilerOutputDir = new File(compileWorkDir, "output"); //$NON-NLS-1$ File compilerLocalWorkingDir = new File(compileWorkDir, "build"); //$NON-NLS-1$ BatchInfo batchInfo = DirectBatchCompiler.compile(batchDescriptionClass, "test.batch", //$NON-NLS-1$ Location.fromPath(driverContext.getClusterWorkDir(), '/'), compilerOutputDir, compilerLocalWorkingDir, Arrays.asList(new File[] { DirectFlowCompiler.toLibraryPath(batchDescriptionClass) }), batchDescriptionClass.getClassLoader(), driverContext.getOptions()); // ??? for (String flowId : jobFlowMap.keySet()) { if (batchInfo.findJobflow(flowId) == null) { throw new IllegalStateException( MessageFormat.format("{1}???{0}??????", driverContext.getCallerClass().getName(), flowId)); } } // ? driverContext.validateExecutionEnvironment(); LOG.info("??????: {}", driverContext.getCallerClass().getName()); JobflowExecutor executor = new JobflowExecutor(driverContext); executor.cleanWorkingDirectory(); for (JobflowInfo jobflowInfo : batchInfo.getJobflows()) { driverContext.prepareCurrentJobflow(jobflowInfo); executor.cleanInputOutput(jobflowInfo); } executor.cleanExtraResources(getExternalResources()); if (getExternalResources().isEmpty() == false) { LOG.debug("initializing external resources: {}", //$NON-NLS-1$ batchDescriptionClass.getName()); executor.prepareExternalResources(getExternalResources()); } for (JobflowInfo jobflowInfo : batchInfo.getJobflows()) { driverContext.prepareCurrentJobflow(jobflowInfo); String flowId = jobflowInfo.getJobflow().getFlowId(); JobFlowTester tester = jobFlowMap.get(flowId); if (tester != null) { LOG.debug("initializing jobflow input/output: {}#{}", //$NON-NLS-1$ batchDescriptionClass.getName(), flowId); executor.prepareInput(jobflowInfo, tester.inputs); executor.prepareOutput(jobflowInfo, tester.outputs); LOG.info("?????: {}#{}", batchDescriptionClass.getName(), flowId); VerifyContext verifyContext = new VerifyContext(driverContext); executor.runJobflow(jobflowInfo); verifyContext.testFinished(); LOG.info("???????: {}#{}", batchDescriptionClass.getName(), flowId); executor.verify(jobflowInfo, verifyContext, tester.outputs); } } }
From source file:com.jskaleel.xml.JSONObject.java
private void populateMap(Object bean) { Class klass = bean.getClass(); // If klass is a System class then set includeSuperClass to false. boolean includeSuperClass = klass.getClassLoader() != null; Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods(); for (int i = 0; i < methods.length; i += 1) { try {//from w w w . j a v a 2s.c o m Method method = methods[i]; if (Modifier.isPublic(method.getModifiers())) { String name = method.getName(); String key = ""; if (name.startsWith("get")) { if ("getClass".equals(name) || "getDeclaringClass".equals(name)) { key = ""; } else { key = name.substring(3); } } else if (name.startsWith("is")) { key = name.substring(2); } if (key.length() > 0 && Character.isUpperCase(key.charAt(0)) && method.getParameterTypes().length == 0) { if (key.length() == 1) { key = key.toLowerCase(); } else if (!Character.isUpperCase(key.charAt(1))) { key = key.substring(0, 1).toLowerCase() + key.substring(1); } Object result = method.invoke(bean, (Object[]) null); if (result != null) { this.map.put(key, wrap(result)); } } } } catch (Exception ignore) { } } }
From source file:io.apiman.manager.test.junit.ManagerRestTester.java
/** * Loads the test plans./* w ww. j a va 2s.c o m*/ * @param testClass * @throws InitializationError */ private void loadTestPlans(Class<?> testClass) throws InitializationError { try { ManagerRestTestPlan annotation = testClass.getAnnotation(ManagerRestTestPlan.class); if (annotation == null) { Method[] methods = testClass.getMethods(); TreeSet<ManagerRestTestPlan> annotations = new TreeSet<>(new Comparator<ManagerRestTestPlan>() { @Override public int compare(ManagerRestTestPlan o1, ManagerRestTestPlan o2) { Integer i1 = o1.order(); Integer i2 = o2.order(); return i1.compareTo(i2); } }); for (Method method : methods) { annotation = method.getAnnotation(ManagerRestTestPlan.class); if (annotation != null) { annotations.add(annotation); } } for (ManagerRestTestPlan anno : annotations) { TestPlanInfo planInfo = new TestPlanInfo(); planInfo.planPath = anno.value(); planInfo.name = new File(planInfo.planPath).getName(); planInfo.endpoint = TestUtil.doPropertyReplacement(anno.endpoint()); planInfo.plan = TestUtil.loadTestPlan(planInfo.planPath, testClass.getClassLoader()); testPlans.add(planInfo); } } else { TestPlanInfo planInfo = new TestPlanInfo(); planInfo.planPath = annotation.value(); planInfo.name = new File(planInfo.planPath).getName(); planInfo.plan = TestUtil.loadTestPlan(planInfo.planPath, testClass.getClassLoader()); planInfo.endpoint = TestUtil.doPropertyReplacement(annotation.endpoint()); testPlans.add(planInfo); } } catch (Throwable e) { throw new InitializationError(e); } if (testPlans.isEmpty()) { throw new InitializationError("No @ManagerRestTestPlan annotations found on test class: " + testClass); } }
From source file:com.ng.mats.psa.mt.paga.data.JSONObject.java
private void populateMap(Object bean) { Class<?> klass = bean.getClass(); // If klass is a System class then set includeSuperClass to false. boolean includeSuperClass = klass.getClassLoader() != null; Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods(); for (int i = 0; i < methods.length; i += 1) { try {/*w ww .ja v a 2 s . co m*/ Method method = methods[i]; if (Modifier.isPublic(method.getModifiers())) { String name = method.getName(); String key = ""; if (name.startsWith("get")) { if ("getClass".equals(name) || "getDeclaringClass".equals(name)) { key = ""; } else { key = name.substring(3); } } else if (name.startsWith("is")) { key = name.substring(2); } if (key.length() > 0 && Character.isUpperCase(key.charAt(0)) && method.getParameterTypes().length == 0) { if (key.length() == 1) { key = key.toLowerCase(); } else if (!Character.isUpperCase(key.charAt(1))) { key = key.substring(0, 1).toLowerCase() + key.substring(1); } Object result = method.invoke(bean, (Object[]) null); if (result != null) { this.map.put(key, wrap(result)); } } } } catch (Exception ignore) { } } }
From source file:org.eclipse.wb.tests.designer.core.util.reflect.ReflectionUtilsTest.java
/** * Test for {@link ReflectionUtils#getClassLoader(Class)}. *//*from w w w. ja v a 2 s . com*/ public void test_getClassLoader() throws Exception { // "normal" class { Class<?> clazz = getClass(); assertSame(clazz.getClassLoader(), ReflectionUtils.getClassLoader(clazz)); } // "system" class { Class<?> clazz = String.class; assertNull(clazz.getClassLoader()); assertSame(ClassLoader.getSystemClassLoader(), ReflectionUtils.getClassLoader(clazz)); } }
From source file:org.eclipse.wb.tests.designer.core.util.reflect.ReflectionUtilsTest.java
public void test_hasClass() throws Exception { Class<?> thisClass = getClass(); ClassLoader classLoader = thisClass.getClassLoader(); // has this Class assertTrue(ReflectionUtils.hasClass(classLoader, thisClass.getName())); // no invalid class assertFalse(ReflectionUtils.hasClass(classLoader, "no.such.Class")); }
From source file:com.futureplatforms.kirin.internal.attic.ProxyGenerator.java
public <T> T javascriptProxyForRequest(final JSONObject obj, Class<T> baseInterface, Class<?>... otherClasses) { Class<?>[] allClasses;//from w w w. jav a 2s . co m if (otherClasses.length == 0) { allClasses = new Class[] { baseInterface }; } else { allClasses = new Class[otherClasses.length + 1]; allClasses[0] = baseInterface; System.arraycopy(otherClasses, 0, allClasses, 1, otherClasses.length); } InvocationHandler h = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); Class<?> returnType = method.getReturnType(); if (obj.has(methodName)) { String id = obj.optString("__id"); if (id != null) { // so assume it's a callback if (void.class.equals(returnType)) { mKirinHelper.jsCallbackObjectMethod(id, methodName, (Object[]) args); } else { return mKirinHelper.jsSyncCallbackObjectMethod(id, returnType, methodName, (Object[]) args); } } return null; } String propertyName = findGetter(methodName); if (propertyName != null) { return handleGetter(obj, returnType, propertyName); } if ("toString".equals(methodName) && String.class.equals(returnType)) { return obj.toString(); } return null; } }; Object proxy = Proxy.newProxyInstance(baseInterface.getClassLoader(), allClasses, h); return baseInterface.cast(proxy); }
From source file:org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.java
private static ClassLoader getClassLoader(final Class cls) { ClassLoader cl = null;/* w w w . ja v a2 s. c om*/ try { cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws ClassNotFoundException { return cls.getClassLoader(); } }); } catch (PrivilegedActionException e) { if (log.isDebugEnabled()) { log.debug("Exception thrown from AccessController: " + e); } throw ExceptionFactory.makeWebServiceException(e.getException()); } return cl; }