use of org.springframework.beans.factory.BeanClassLoaderAware in project spring-framework by spring-projects.
the class HttpInvokerTests method doTestHttpInvokerProxyFactoryBeanAndServiceExporter.
private void doTestHttpInvokerProxyFactoryBeanAndServiceExporter(boolean explicitClassLoader) throws Throwable {
TestBean target = new TestBean("myname", 99);
final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setServiceInterface(ITestBean.class);
exporter.setService(target);
exporter.afterPropertiesSet();
HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
pfb.setServiceInterface(ITestBean.class);
pfb.setServiceUrl("http://myurl");
pfb.setHttpInvokerRequestExecutor(new AbstractHttpInvokerRequestExecutor() {
@Override
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws Exception {
assertEquals("http://myurl", config.getServiceUrl());
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setContent(baos.toByteArray());
exporter.handleRequest(request, response);
return readRemoteInvocationResult(new ByteArrayInputStream(response.getContentAsByteArray()), config.getCodebaseUrl());
}
});
if (explicitClassLoader) {
((BeanClassLoaderAware) pfb.getHttpInvokerRequestExecutor()).setBeanClassLoader(getClass().getClassLoader());
}
pfb.afterPropertiesSet();
ITestBean proxy = (ITestBean) pfb.getObject();
assertEquals("myname", proxy.getName());
assertEquals(99, proxy.getAge());
proxy.setAge(50);
assertEquals(50, proxy.getAge());
proxy.setStringArray(new String[] { "str1", "str2" });
assertTrue(Arrays.equals(new String[] { "str1", "str2" }, proxy.getStringArray()));
proxy.setSomeIntegerArray(new Integer[] { 1, 2, 3 });
assertTrue(Arrays.equals(new Integer[] { 1, 2, 3 }, proxy.getSomeIntegerArray()));
proxy.setNestedIntegerArray(new Integer[][] { { 1, 2, 3 }, { 4, 5, 6 } });
Integer[][] integerArray = proxy.getNestedIntegerArray();
assertTrue(Arrays.equals(new Integer[] { 1, 2, 3 }, integerArray[0]));
assertTrue(Arrays.equals(new Integer[] { 4, 5, 6 }, integerArray[1]));
proxy.setSomeIntArray(new int[] { 1, 2, 3 });
assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, proxy.getSomeIntArray()));
proxy.setNestedIntArray(new int[][] { { 1, 2, 3 }, { 4, 5, 6 } });
int[][] intArray = proxy.getNestedIntArray();
assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, intArray[0]));
assertTrue(Arrays.equals(new int[] { 4, 5, 6 }, intArray[1]));
try {
proxy.exceptional(new IllegalStateException());
fail("Should have thrown IllegalStateException");
} catch (IllegalStateException ex) {
// expected
}
try {
proxy.exceptional(new IllegalAccessException());
fail("Should have thrown IllegalAccessException");
} catch (IllegalAccessException ex) {
// expected
}
}
Aggregations