use of java.io.IOException in project camel by apache.
the class CxfCustomizedExceptionTest method testInvokingServiceFromHTTPURL.
@Test
public void testInvokingServiceFromHTTPURL() throws Exception {
URL url = new URL(routerAddress);
URLConnection urlConnection = url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/xml");
// Send POST data
OutputStream out = urlConnection.getOutputStream();
// copy the message out
InputStream is = this.getClass().getResourceAsStream("SimpleSoapRequest.xml");
IOHelper.copy(is, out);
out.flush();
is.close();
// check the response code
try {
urlConnection.getInputStream();
fail("We except an IOException here");
} catch (IOException exception) {
assertTrue(exception.getMessage().contains("500"));
}
}
use of java.io.IOException in project camel by apache.
the class CxfRsConsumerTest method testGetWrongCustomer.
@Test
public void testGetWrongCustomer() throws Exception {
URL url = new URL("http://localhost:" + CXT + "/rest/customerservice/customers/456");
try {
url.openStream();
fail("Expect to get exception here");
} catch (FileNotFoundException exception) {
// do nothing here
}
url = new URL("http://localhost:" + CXT + "/rest/customerservice/customers/234");
try {
url.openStream();
fail("Expect to get exception here");
} catch (FileNotFoundException exception) {
// do nothing here
}
url = new URL("http://localhost:" + CXT + "/rest/customerservice/customers/256");
try {
url.openStream();
fail("Expect to get exception here");
} catch (IOException exception) {
// expect the Internal error exception
}
}
use of java.io.IOException in project camel by apache.
the class UTPasswordCallback method handle.
/**
* Here, we attempt to get the password from the private
* alias/passwords map.
*/
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
try {
String id = (String) callback.getClass().getMethod("getIdentifier").invoke(callback);
String pass = passwords.get(id);
if (pass != null) {
callback.getClass().getMethod("setPassword", String.class).invoke(callback, pass);
return;
}
} catch (Exception ex) {
UnsupportedCallbackException e = new UnsupportedCallbackException(callback);
e.initCause(ex);
throw e;
}
}
}
use of java.io.IOException in project camel by apache.
the class UTPasswordCallback method handle.
/**
* Here, we attempt to get the password from the private
* alias/passwords map.
*/
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
try {
String id = (String) callback.getClass().getMethod("getIdentifier").invoke(callback);
String pass = passwords.get(id);
if (pass != null) {
callback.getClass().getMethod("setPassword", String.class).invoke(callback, pass);
return;
}
} catch (Exception ex) {
UnsupportedCallbackException e = new UnsupportedCallbackException(callback);
e.initCause(ex);
throw e;
}
}
}
use of java.io.IOException in project camel by apache.
the class MessageLossSimulator method handleMessage.
public void handleMessage(Message message) throws Fault {
Object maps = RMContextUtils.retrieveMAPs(message, false, true);
// RMContextUtils.ensureExposedVersion(maps);
String action = getAction(maps);
if (RMContextUtils.isRMProtocolMessage(action)) {
return;
}
appMessageCount++;
// do not discard odd-numbered messages
if (0 != (appMessageCount % 2)) {
return;
}
// discard even-numbered message
InterceptorChain chain = message.getInterceptorChain();
ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
while (it.hasNext()) {
PhaseInterceptor<?> pi = (PhaseInterceptor<?>) it.next();
if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
chain.remove(pi);
LOG.debug("Removed MessageSenderInterceptor from interceptor chain.");
break;
}
}
message.setContent(OutputStream.class, new WrappedOutputStream(message));
message.getInterceptorChain().add(new AbstractPhaseInterceptor<Message>(Phase.PREPARE_SEND_ENDING) {
public void handleMessage(Message message) throws Fault {
try {
message.getContent(OutputStream.class).close();
} catch (IOException e) {
throw new Fault(e);
}
}
});
}
Aggregations