parent
18d9a1542a
commit
ba19f0891f
6
pom.xml
6
pom.xml
|
@ -4,7 +4,7 @@
|
||||||
<groupId>se.kb</groupId>
|
<groupId>se.kb</groupId>
|
||||||
<artifactId>oai4j</artifactId>
|
<artifactId>oai4j</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.6-SNAPSHOT</version>
|
<version>0.7-SNAPSHOT</version>
|
||||||
<name>oai4j</name>
|
<name>oai4j</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.0</version>
|
<version>2.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.5</source>
|
<source>1.6</source>
|
||||||
<target>1.5</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
@ -16,11 +16,16 @@
|
||||||
|
|
||||||
package se.kb.oai.ore;
|
package se.kb.oai.ore;
|
||||||
|
|
||||||
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import javax.net.ssl.SSLSession;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An aggregated resource is a resource, that together with other resources,
|
* An aggregated resource is a resource, that together with other resources,
|
||||||
|
@ -78,8 +83,43 @@ public class AggregatedResource extends AggregateBase {
|
||||||
* @return a stream to the content
|
* @return a stream to the content
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public InputStream getContent() throws IOException {
|
public InputStream getContent() throws IOException, URISyntaxException {
|
||||||
return id.toURL().openStream();
|
URL url;
|
||||||
|
String uri_schema;
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
boolean redirect = true;
|
||||||
|
|
||||||
|
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
|
||||||
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
while (redirect) {
|
||||||
|
redirect = false;
|
||||||
|
uri_schema = id.getScheme();
|
||||||
|
url = id.toURL();
|
||||||
|
if (uri_schema.equals("https")) {
|
||||||
|
HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
|
||||||
|
https.setHostnameVerifier(hostnameVerifier);
|
||||||
|
con = https;
|
||||||
|
} else if (uri_schema.equals("http")) {
|
||||||
|
con = (HttpURLConnection) url.openConnection();
|
||||||
|
}
|
||||||
|
int status = con.getResponseCode();
|
||||||
|
if (status != HttpURLConnection.HTTP_OK) {
|
||||||
|
if (status == HttpURLConnection.HTTP_MOVED_TEMP
|
||||||
|
|| status == HttpURLConnection.HTTP_MOVED_PERM
|
||||||
|
|| status == HttpURLConnection.HTTP_SEE_OTHER) {
|
||||||
|
redirect = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (redirect) {
|
||||||
|
new URI(con.getHeaderField("Location"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return con.getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,7 +129,7 @@ public class AggregatedResource extends AggregateBase {
|
||||||
* @return a stream to the content
|
* @return a stream to the content
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public String getContentAsString() throws IOException {
|
public String getContentAsString() throws IOException, URISyntaxException {
|
||||||
InputStream in = getContent();
|
InputStream in = getContent();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
byte[] bytes = new byte[4 * 1024];
|
byte[] bytes = new byte[4 * 1024];
|
||||||
|
|
Loading…
Reference in New Issue