use of java.io.InputStreamReader in project camel by apache.
the class OSGiCacheManager method getClassLoader.
private ClassLoader getClassLoader(String providerName) throws Exception {
if (providerName == null || !getConfiguration().isLookupProviders()) {
return null;
}
final BundleContext bc = FrameworkUtil.getBundle(JCacheHelper.class).getBundleContext();
final ClassLoader bcl = bc.getBundle().adapt(BundleWiring.class).getClassLoader();
final ClassLoader acl = getConfiguration().getApplicationContextClassLoader();
for (final Bundle bundle : bc.getBundles()) {
URL spi = bundle.getResource("META-INF/services/javax.cache.spi.CachingProvider");
if (spi != null) {
try (BufferedReader in = new BufferedReader(new InputStreamReader(spi.openStream()))) {
if (ObjectHelper.equal(providerName, in.readLine())) {
return new ClassLoader(bcl) {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
try {
return acl.loadClass(name);
} catch (ClassNotFoundException e) {
return bundle.loadClass(name);
}
}
@Override
protected URL findResource(String name) {
URL resource = acl.getResource(name);
if (resource == null) {
resource = bundle.getResource(name);
}
return resource;
}
@Override
protected Enumeration findResources(String name) throws IOException {
try {
return acl.getResources(name);
} catch (IOException e) {
return bundle.getResources(name);
}
}
};
}
}
}
}
return null;
}
use of java.io.InputStreamReader in project camel by apache.
the class HandlerTest method testWithTwoHandlersTwoEndpointsOnSamePort.
@Test
public void testWithTwoHandlersTwoEndpointsOnSamePort() throws Exception {
// First test the situation where one should invoke the handler once
assertEquals(0, statisticsHandler1.getRequests());
assertEquals(0, statisticsHandler2.getRequests());
assertEquals(0, statisticsHandler3.getRequests());
InputStream html1 = (InputStream) template.requestBody("http://localhost:" + port2, "");
BufferedReader br1 = IOHelper.buffered(new InputStreamReader(html1));
assertEquals(htmlResponse, br1.readLine());
InputStream html2 = (InputStream) template.requestBody("http://localhost:" + port2 + "/endpoint2", "");
BufferedReader br2 = IOHelper.buffered(new InputStreamReader(html2));
assertEquals(htmlResponse, br2.readLine());
assertEquals(0, statisticsHandler1.getRequests());
assertEquals(2, statisticsHandler2.getRequests());
assertEquals(2, statisticsHandler3.getRequests());
}
use of java.io.InputStreamReader in project camel by apache.
the class HandlerTest method testWithTwoHandlers.
@Test
public void testWithTwoHandlers() throws Exception {
// First test the situation where one should invoke the handler once
assertEquals(0, statisticsHandler1.getRequests());
assertEquals(0, statisticsHandler2.getRequests());
assertEquals(0, statisticsHandler3.getRequests());
InputStream html = (InputStream) template.requestBody("http://localhost:" + port2, "");
BufferedReader br = IOHelper.buffered(new InputStreamReader(html));
assertEquals(htmlResponse, br.readLine());
assertEquals(0, statisticsHandler1.getRequests());
assertEquals(1, statisticsHandler2.getRequests());
assertEquals(1, statisticsHandler3.getRequests());
}
use of java.io.InputStreamReader in project camel by apache.
the class RestJettyBindingModeJsonWithContractTest method testBindingModeJsonWithContract.
@Test
public void testBindingModeJsonWithContract() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(UserPojoEx.class);
String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
Object answer = template.requestBody("http://localhost:" + getPort() + "/users/new", body);
assertNotNull(answer);
BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) answer));
String line;
String answerString = "";
while ((line = reader.readLine()) != null) {
answerString += line;
}
assertTrue("Unexpected response: " + answerString, answerString.contains("\"active\":true"));
assertMockEndpointsSatisfied();
Object obj = mock.getReceivedExchanges().get(0).getIn().getBody();
assertEquals(UserPojoEx.class, obj.getClass());
UserPojoEx user = (UserPojoEx) obj;
assertNotNull(user);
assertEquals(123, user.getId());
assertEquals("Donald Duck", user.getName());
assertEquals(true, user.isActive());
}
use of java.io.InputStreamReader in project camel by apache.
the class RestJettyBindingModeOffWithContractTest method testBindingModeOffWithContract.
@Test
public void testBindingModeOffWithContract() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:input");
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(UserPojoEx.class);
String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
Object answer = template.requestBodyAndHeader("http://localhost:" + getPort() + "/users/new", body, Exchange.CONTENT_TYPE, "application/json");
assertNotNull(answer);
BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) answer));
String line;
String answerString = "";
while ((line = reader.readLine()) != null) {
answerString += line;
}
assertTrue("Unexpected response: " + answerString, answerString.contains("\"active\":true"));
assertMockEndpointsSatisfied();
Object obj = mock.getReceivedExchanges().get(0).getIn().getBody();
assertEquals(UserPojoEx.class, obj.getClass());
UserPojoEx user = (UserPojoEx) obj;
assertNotNull(user);
assertEquals(123, user.getId());
assertEquals("Donald Duck", user.getName());
assertEquals(true, user.isActive());
}
Aggregations