use of java.io.IOException in project camel by apache.
the class CamelSSLIRCConnection method connect.
@Override
public void connect() throws IOException {
if (sslContextParameters == null) {
super.connect();
} else {
if (level != 0) {
throw new SocketException("Socket closed or already open (" + level + ")");
}
IOException exception = null;
final SSLContext sslContext;
try {
sslContext = sslContextParameters.createSSLContext(camelContext);
} catch (GeneralSecurityException e) {
throw new RuntimeCamelException("Error in SSLContextParameters configuration or instantiation.", e);
}
final SSLSocketFactory sf = sslContext.getSocketFactory();
SSLSocket s = null;
for (int i = 0; i < ports.length && s == null; i++) {
try {
s = (SSLSocket) sf.createSocket(host, ports[i]);
s.startHandshake();
exception = null;
} catch (SSLNotSupportedException exc) {
if (s != null) {
s.close();
}
s = null;
throw exc;
} catch (IOException exc) {
if (s != null) {
s.close();
}
s = null;
exception = exc;
}
}
if (exception != null) {
// connection wasn't successful at any port
throw exception;
}
prepare(s);
}
}
use of java.io.IOException in project camel by apache.
the class CodehausIrcChat method main.
public static void main(String[] args) throws InterruptedException {
List<IrcChannel> channels = new ArrayList<IrcChannel>();
channels.add(new IrcChannel("camel-test", null));
final IrcConfiguration config = new IrcConfiguration("irc.codehaus.org", "camel-rc", "Camel IRC Component", channels);
final IRCConnection conn = new IRCConnection(config.getHostname(), config.getPorts(), config.getPassword(), config.getNickname(), config.getUsername(), config.getRealname());
conn.addIRCEventListener(new CodehausIRCEventAdapter());
conn.setEncoding("UTF-8");
// conn.setDaemon(true);
conn.setColors(false);
conn.setPong(true);
try {
conn.connect();
} catch (IOException e) {
e.printStackTrace();
}
// while (!conn.isConnected()) {
// Thread.sleep(1000);
// LOG.info("Sleeping");
// }
LOG.info("Connected");
for (IrcChannel channel : config.getChannels()) {
conn.doJoin(channel.getName());
}
conn.doPrivmsg("#camel-test", "hi!");
Thread.sleep(Integer.MAX_VALUE);
}
use of java.io.IOException in project camel by apache.
the class Utility method setSecurityPolicy.
public static synchronized void setSecurityPolicy(String policyResourceName, String tmpFileName) throws IOException {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(policyResourceName);
if (in == null) {
throw new IOException("Unable to find the resource policy.all on classpath");
}
File outfile = new File(tmpFileName);
OutputStream out = new FileOutputStream(outfile);
byte[] tmp = new byte[8192];
int len = 0;
while (true) {
len = in.read(tmp);
if (len <= 0) {
break;
}
out.write(tmp, 0, len);
}
out.close();
in.close();
System.setProperty("java.security.policy", outfile.getAbsolutePath());
}
use of java.io.IOException in project camel by apache.
the class JaxbDataFormat method unmarshal.
public Object unmarshal(Exchange exchange, InputStream stream) throws IOException, SAXException {
try {
Object answer;
XMLStreamReader xmlReader;
if (needFiltering(exchange)) {
xmlReader = typeConverter.convertTo(XMLStreamReader.class, createNonXmlFilterReader(exchange, stream));
} else {
xmlReader = typeConverter.convertTo(XMLStreamReader.class, stream);
}
if (partialClass != null) {
// partial unmarshalling
answer = createUnmarshaller().unmarshal(xmlReader, partialClass);
} else {
answer = createUnmarshaller().unmarshal(xmlReader);
}
if (answer instanceof JAXBElement && isIgnoreJAXBElement()) {
answer = ((JAXBElement<?>) answer).getValue();
}
return answer;
} catch (JAXBException e) {
throw new IOException(e);
}
}
use of java.io.IOException in project camel by apache.
the class JaxbDataFormat method marshal.
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws IOException, SAXException {
try {
// must create a new instance of marshaller as its not thread safe
Marshaller marshaller = createMarshaller();
if (isPrettyPrint()) {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
}
// exchange take precedence over encoding option
String charset = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
if (charset == null) {
charset = encoding;
}
if (charset != null) {
marshaller.setProperty(Marshaller.JAXB_ENCODING, charset);
}
if (isFragment()) {
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
}
if (ObjectHelper.isNotEmpty(schemaLocation)) {
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation);
}
if (ObjectHelper.isNotEmpty(noNamespaceSchemaLocation)) {
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, noNamespaceSchemaLocation);
}
if (namespacePrefixMapper != null) {
marshaller.setProperty(namespacePrefixMapper.getRegistrationKey(), namespacePrefixMapper);
}
// Inject any JAX-RI custom properties from the exchange or from the instance into the marshaller
Map<String, Object> customProperties = exchange.getProperty(JaxbConstants.JAXB_PROVIDER_PROPERTIES, Map.class);
if (customProperties == null) {
customProperties = getJaxbProviderProperties();
}
if (customProperties != null) {
for (Entry<String, Object> property : customProperties.entrySet()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Using JAXB Provider Property {}={}", property.getKey(), property.getValue());
}
marshaller.setProperty(property.getKey(), property.getValue());
}
}
marshal(exchange, graph, stream, marshaller);
if (contentTypeHeader) {
if (exchange.hasOut()) {
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml");
} else {
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml");
}
}
} catch (Exception e) {
throw new IOException(e);
}
}
Aggregations