Skip to content

Commit

Permalink
update camel to 3.14 + stop trusting all ssl connections
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanzadelhoff committed Jan 10, 2022
1 parent f2ad0bb commit 431e2b8
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 383 deletions.
36 changes: 12 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
Expand Down Expand Up @@ -96,20 +100,6 @@
<artifactId>Saxon-HE</artifactId>
<version>9.8.0-14</version>
</dependency>
<!-- Explicitly add JAXB dependencies. Needed for newer Java versions.
See also https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j
-->
<!-- JAXB version corresponding to version used in Apache Camel -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<resources>
Expand All @@ -126,18 +116,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<source>1.8</source>
<source>1.11</source>
<minmemory>256m</minmemory>
<maxmemory>512m</maxmemory>
</configuration>
Expand Down Expand Up @@ -187,7 +176,7 @@
<plugin>
<artifactId>maven-war-plugin</artifactId>
<inherited>true</inherited>
<version>2.2</version>
<version>3.2.3</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -223,11 +212,10 @@
</pluginManagement>
</build>
<properties>
<camel.version>2.24.3</camel.version>
<jaxb.version>2.3.0</jaxb.version>
<spring.version>5.1.19.RELEASE</spring.version>
<spring-boot.version>2.1.18.RELEASE</spring-boot.version>
<spring-framework.version>${spring.version}</spring-framework.version>
<camel.version>3.14.0</camel.version>
<spring-boot.version>2.6.1</spring-boot.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<oai-pmh.base.url.external>http:https://localhost:8080/omdf</oai-pmh.base.url.external>
<oai-pmh.db.item.csw.TYPE>inspire</oai-pmh.db.item.csw.TYPE>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

29 changes: 12 additions & 17 deletions src/main/java/eu/odp/harvest/geo/oai/xslt/HttpAwareUriResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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());
}
}
Loading

0 comments on commit 431e2b8

Please sign in to comment.