diff --git a/pom.xml b/pom.xml index c2fb416..17b0000 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,10 @@ org.apache.camel camel-spring + + org.apache.camel + camel-spring-xml + org.apache.camel camel-core @@ -96,20 +100,6 @@ Saxon-HE 9.8.0-14 - - - - javax.xml.bind - jaxb-api - ${jaxb.version} - - - javax.activation - activation - 1.1.1 - @@ -126,10 +116,9 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.8.0 - 1.8 - 1.8 + 11 @@ -137,7 +126,7 @@ maven-javadoc-plugin 2.10.1 - 1.8 + 1.11 256m 512m @@ -187,7 +176,7 @@ maven-war-plugin true - 2.2 + 3.2.3 package @@ -223,11 +212,10 @@ - 2.24.3 - 2.3.0 - 5.1.19.RELEASE - 2.1.18.RELEASE - ${spring.version} + 3.14.0 + 2.6.1 + + UTF-8 http://localhost:8080/omdf inspire diff --git a/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllHttpClientConfig.java b/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllHttpClientConfig.java deleted file mode 100644 index c9553c3..0000000 --- a/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllHttpClientConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package eu.odp.harvest.geo.oai.http; - -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; - -/** - * Configures HttpClient that is used for Camel outgoing HTTP connections. Registers an SSL ProtocolSocketFactory that - * trusts all server certificates. - * WARNING: Use of this class is insecure, as it basically nullifies the purpose of HTTPS. - * Do not use it if you need connections to trusted providers. - */ -public class AllowAllHttpClientConfig { - /** - * Constructor. Registers the custom ProtocolSocketFactory. - */ - public AllowAllHttpClientConfig() { - Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new AllowAllSslProtocolSocketFactory(), 443); - Protocol.registerProtocol("https", easyhttps); - } -} diff --git a/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllSslProtocolSocketFactory.java b/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllSslProtocolSocketFactory.java deleted file mode 100644 index a27f199..0000000 --- a/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllSslProtocolSocketFactory.java +++ /dev/null @@ -1,146 +0,0 @@ -package eu.odp.harvest.geo.oai.http; - -import org.apache.commons.httpclient.ConnectTimeoutException; -import org.apache.commons.httpclient.HttpClientError; -import org.apache.commons.httpclient.params.HttpConnectionParams; -import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; - -import javax.net.SocketFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import java.io.IOException; -import java.net.*; - -/** - * Based on EasySSLProtocolSocketFactory from Apache httpclient-ssl-contrib, but trusts all server certificates, not just - * self-signed. - * WARNING: Use of this class is insecure, as it basically nullifies the purpose of HTTPS. - * Do not use it if you need connections to trusted providers. - */ -public class AllowAllSslProtocolSocketFactory implements SecureProtocolSocketFactory { - private SSLContext sslcontext = null; - - /** - * Constructor for AllowAllSslProtocolSocketFactory. - */ - public AllowAllSslProtocolSocketFactory() { - super(); - } - - private static SSLContext createCustomSSLContext() { - try { - SSLContext context = SSLContext.getInstance("SSL"); - context.init( - null, - new TrustManager[] {new AllowAllX509TrustManager(null)}, - null); - return context; - } catch (Exception e) { - throw new HttpClientError(e.toString()); - } - } - - private SSLContext getSSLContext() { - if (this.sslcontext == null) { - this.sslcontext = createCustomSSLContext(); - } - return this.sslcontext; - } - - /** - * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int) - */ - public Socket createSocket( - String host, - int port, - InetAddress clientHost, - int clientPort) - throws IOException, UnknownHostException { - - return getSSLContext().getSocketFactory().createSocket( - host, - port, - clientHost, - clientPort - ); - } - - /** - * Attempts to get a new socket connection to the given host within the given time limit. - *

- * To circumvent the limitations of older JREs that do not support connect timeout a - * controller thread is executed. The controller thread attempts to create a new socket - * within the given limit of time. If socket constructor does not return until the - * timeout expires, the controller terminates and throws an {@link ConnectTimeoutException} - *

- * - * @param host the host name/IP - * @param port the port on the host - * @param params {@link HttpConnectionParams Http connection parameters} - * - * @return Socket a new socket - * - * @throws IOException if an I/O error occurs while creating the socket - * @throws UnknownHostException if the IP address of the host cannot be - * determined - */ - public Socket createSocket( - final String host, - final int port, - final InetAddress localAddress, - final int localPort, - final HttpConnectionParams params - ) throws IOException, UnknownHostException, ConnectTimeoutException { - if (params == null) { - throw new IllegalArgumentException("Parameters may not be null"); - } - int timeout = params.getConnectionTimeout(); - SocketFactory socketfactory = getSSLContext().getSocketFactory(); - if (timeout == 0) { - return socketfactory.createSocket(host, port, localAddress, localPort); - } else { - Socket socket = socketfactory.createSocket(); - SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); - SocketAddress remoteaddr = new InetSocketAddress(host, port); - socket.bind(localaddr); - socket.connect(remoteaddr, timeout); - return socket; - } - } - - /** - * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int) - */ - public Socket createSocket(String host, int port) - throws IOException, UnknownHostException { - return getSSLContext().getSocketFactory().createSocket( - host, - port - ); - } - - /** - * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean) - */ - public Socket createSocket( - Socket socket, - String host, - int port, - boolean autoClose) - throws IOException, UnknownHostException { - return getSSLContext().getSocketFactory().createSocket( - socket, - host, - port, - autoClose - ); - } - - public boolean equals(Object obj) { - return ((obj != null) && obj.getClass().equals(AllowAllSslProtocolSocketFactory.class)); - } - - public int hashCode() { - return AllowAllSslProtocolSocketFactory.class.hashCode(); - } -} diff --git a/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllX509TrustManager.java b/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllX509TrustManager.java deleted file mode 100644 index 8191325..0000000 --- a/src/main/java/eu/odp/harvest/geo/oai/http/AllowAllX509TrustManager.java +++ /dev/null @@ -1,61 +0,0 @@ -package eu.odp.harvest.geo.oai.http; - -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; -import javax.net.ssl.X509TrustManager; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - -/** - * Based on AllowAllX509TrustManager from Apache httpclient-ssl-contrib, but trusts all server certificates, not just - * self-signed. - * WARNING: Use of this class is insecure, as it basically nullifies the purpose of HTTPS. - * Do not use it if you need connections to trusted providers. - */ -public class AllowAllX509TrustManager implements X509TrustManager { - private X509TrustManager standardTrustManager = null; - - /** - * Constructor for AllowAllX509TrustManager. - */ - public AllowAllX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException { - super(); - TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - factory.init(keystore); - TrustManager[] trustmanagers = factory.getTrustManagers(); - if (trustmanagers.length == 0) { - throw new NoSuchAlgorithmException("no trust manager found"); - } - this.standardTrustManager = (X509TrustManager)trustmanagers[0]; - } - - /** - * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType) - */ - public void checkClientTrusted(X509Certificate[] certificates,String authType) throws CertificateException { - standardTrustManager.checkClientTrusted(certificates,authType); - } - - /** - * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType) - */ - public void checkServerTrusted(X509Certificate[] certificates,String authType) throws CertificateException { -/* - if ((certificates != null) && (certificates.length == 1)) { - certificates[0].checkValidity(); - } else { - standardTrustManager.checkServerTrusted(certificates,authType); - } -*/ - } - - /** - * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers() - */ - public X509Certificate[] getAcceptedIssuers() { - return this.standardTrustManager.getAcceptedIssuers(); - } -} diff --git a/src/main/java/eu/odp/harvest/geo/oai/xslt/HttpAwareUriResolver.java b/src/main/java/eu/odp/harvest/geo/oai/xslt/HttpAwareUriResolver.java index d4640af..9e70765 100644 --- a/src/main/java/eu/odp/harvest/geo/oai/xslt/HttpAwareUriResolver.java +++ b/src/main/java/eu/odp/harvest/geo/oai/xslt/HttpAwareUriResolver.java @@ -4,17 +4,18 @@ import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; import org.apache.camel.ProducerTemplate; -import org.apache.camel.builder.xml.XsltUriResolver; -import org.apache.camel.impl.DefaultExchange; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; -import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.camel.component.xslt.XsltUriResolver; +import org.apache.camel.support.DefaultExchange; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.log4j.Logger; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; import javax.xml.transform.stream.StreamSource; -import java.io.ByteArrayInputStream; /** * Resolves a document reference for protocols "http" or "https" in an XSL document with HTTP client. @@ -25,7 +26,8 @@ public class HttpAwareUriResolver extends XsltUriResolver { private final static Logger LOG = Logger.getLogger(HttpAwareUriResolver.class); - private static HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); + private static HttpClient httpClient = HttpClients.custom() + .setConnectionManager(new PoolingHttpClientConnectionManager()).build(); private ProducerTemplate template; private CamelContext context; @@ -71,18 +73,11 @@ private Source resolveRoute(String href) { String[] parts = href.split("\\?"); exchange.getIn().setHeader("resourceIdentifiers", parts[1]); template.send(parts[0], exchange); - return new StreamSource(exchange.getOut().getBody(java.io.InputStream.class)); + return new StreamSource(exchange.getMessage().getBody(java.io.InputStream.class)); } private Source resolveHttp(String href) throws Exception { - GetMethod method = new GetMethod(href); - try { - httpClient.executeMethod(method); - byte[] bytes = method.getResponseBody(); - return new StreamSource(new ByteArrayInputStream(bytes)); - } - finally { - method.releaseConnection(); - } + HttpResponse response = httpClient.execute(new HttpGet(href)); + return new StreamSource(response.getEntity().getContent()); } } diff --git a/src/main/resources/camel-oai-pmh.xml b/src/main/resources/camel-oai-pmh.xml index 83a71a5..ba97401 100644 --- a/src/main/resources/camel-oai-pmh.xml +++ b/src/main/resources/camel-oai-pmh.xml @@ -1,11 +1,7 @@ @@ -20,21 +16,12 @@ - - - - - - - -