Search in sources :

Example 11 with IOException

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"));
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) Test(org.junit.Test)

Example 12 with IOException

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
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) URL(java.net.URL) Test(org.junit.Test)

Example 13 with IOException

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;
        }
    }
}
Also used : Callback(javax.security.auth.callback.Callback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException)

Example 14 with IOException

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;
        }
    }
}
Also used : Callback(javax.security.auth.callback.Callback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException)

Example 15 with IOException

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);
            }
        }
    });
}
Also used : Message(org.apache.cxf.message.Message) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) MessageSenderInterceptor(org.apache.cxf.interceptor.MessageSenderInterceptor) AbstractWrappedOutputStream(org.apache.cxf.io.AbstractWrappedOutputStream) Interceptor(org.apache.cxf.interceptor.Interceptor) MessageSenderInterceptor(org.apache.cxf.interceptor.MessageSenderInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor)

Aggregations

IOException (java.io.IOException)41104 File (java.io.File)7663 InputStream (java.io.InputStream)4105 Test (org.junit.Test)3557 ArrayList (java.util.ArrayList)3023 FileInputStream (java.io.FileInputStream)2674 FileOutputStream (java.io.FileOutputStream)2358 FileNotFoundException (java.io.FileNotFoundException)2146 BufferedReader (java.io.BufferedReader)2028 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1761 InputStreamReader (java.io.InputStreamReader)1677 URL (java.net.URL)1608 HashMap (java.util.HashMap)1552 ByteArrayInputStream (java.io.ByteArrayInputStream)1534 OutputStream (java.io.OutputStream)1349 Path (org.apache.hadoop.fs.Path)1316 Map (java.util.Map)1212 List (java.util.List)1042 Properties (java.util.Properties)994 ServletException (javax.servlet.ServletException)916