Skip to content

Commit

Permalink
upgraded Spring and Camel dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
einspanier committed Nov 20, 2018
1 parent d9cce79 commit 8fa6409
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 43 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<artifactId>oai-pmh-geo-harvest</artifactId>
<packaging>war</packaging>
<name>EU ODP Geo-Harvesting via OAI-PMH</name>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<description>This is the web application of the harvest service</description>
<!-- core developers ======================================================= -->
<developers>
Expand Down Expand Up @@ -160,8 +160,8 @@
</pluginManagement>
</build>
<properties>
<camel.version>2.13.0</camel.version>
<spring.version>3.2.8.RELEASE</spring.version>
<camel.version>2.22.2</camel.version>
<spring.version>5.0.10.RELEASE</spring.version>
<!--
<oai-pmh.base.url.external>http://localhost:8080/omdf</oai-pmh.base.url.external>
<db.item.csw.TYPE>inspire</db.item.csw.TYPE>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,30 @@

import org.apache.camel.CamelContext;
import org.apache.camel.builder.xml.XsltUriResolver;
import org.apache.camel.spi.ClassResolver;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ResourceHelper;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.log4j.Logger;

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
* Resolves a document reference for protcols "http" or "https" in an XSL document with HTTP client.
* For all other URIs uses the default rsolver base don classpath.
* Resolves a document reference for protocols "http" or "https" in an XSL document with HTTP client.
* For all other URIs uses the default resolver base don classpath.
*/
public class HttpAwareUriResolver implements URIResolver {
public class HttpAwareUriResolver extends XsltUriResolver {

private final static Logger LOG = Logger.getLogger(HttpAwareUriResolver.class);

private static HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

@Override
public Source resolve(String href, String base) throws TransformerException {
if (ObjectHelper.isEmpty(href)) {
throw new TransformerException("include href is empty");
} else {
LOG.debug("Resolving URI with href: " + href);
if (href.startsWith("http:") || href.startsWith("https:")) {
try {
return resolveHttp(href);
} catch (Exception e) {
throw new TransformerException(e);
}
} else {
String scheme = ResourceHelper.getScheme(href);
href = href.startsWith("/") ? href : "/" + href;
return new StreamSource(getClass().getResourceAsStream(href));
}
}
public HttpAwareUriResolver(CamelContext context, String location) {
super(context, location);
}
/*

public Source resolve(String href, String base) throws TransformerException {
if (href.startsWith("http:") || href.startsWith("https:")) {
try {
Expand All @@ -63,15 +40,13 @@ public Source resolve(String href, String base) throws TransformerException {
return super.resolve(href, base);
}
}
*/

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));
// return new StreamSource(method.getResponseBodyAsStream());
}
finally {
method.releaseConnection();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package eu.odp.harvest.geo.oai.xslt;

import org.apache.camel.CamelContext;
//import org.apache.camel.builder.xml.XsltUriResolver;
//import org.apache.camel.component.xslt.DefaultXsltUriResolverFactory;
import org.apache.camel.component.xslt.XsltUriResolverFactory;

import javax.xml.transform.URIResolver;

public class HttpAwareUriResolverFactory {
public class HttpAwareUriResolverFactory implements XsltUriResolverFactory {
public URIResolver createUriResolver(CamelContext camelContext, String resourceUri) {
// return new HttpAwareUriResolver(camelContext, resourceUri);
return null;
return new HttpAwareUriResolver(camelContext, resourceUri);
}
}
6 changes: 2 additions & 4 deletions src/main/resources/camel-oai-pmh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
certificates. Remove this bean from the configuration if you require trusted HTTPS connections! -->
<bean id="httpClientConfigurer" class="eu.odp.harvest.geo.oai.http.AllowAllHttpClientConfig"/>

<!-- <bean id="uriResolverFactory" class="eu.odp.harvest.geo.oai.xslt.HttpAwareUriResolverFactory"/> -->
<bean id="uriResolver" class="eu.odp.harvest.geo.oai.xslt.HttpAwareUriResolver"/>

<bean id="uriResolverFactory" class="eu.odp.harvest.geo.oai.xslt.HttpAwareUriResolverFactory"/>

<!-- Camel context for this application -->
<camelContext xmlns="http://camel.apache.org/schema/spring" xmlns:oai="http://www.openarchives.org/OAI/2.0/">
Expand Down Expand Up @@ -262,7 +260,7 @@
<choice>
<when>
<simple>${header.out} == null || ${header.out} != 'dcat'</simple>
<to uri="xslt:jsonPackageResponse.xsl?uriResolver=uriResolver"/>
<to uri="xslt:jsonPackageResponse.xsl?uriResolverFactory=uriResolverFactory"/>
</when>
</choice>
</when>
Expand Down

0 comments on commit 8fa6409

Please sign in to comment.