Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add external content fetcher
- Loading branch information
Showing
10 changed files
with
197 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
fcrepo-http-commons/src/main/java/org/fcrepo/http/commons/domain/ContentInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.fcrepo.http.commons.domain; | ||
|
||
import java.io.InputStream; | ||
|
||
public class ContentInputStream { | ||
private final InputStream entityStream; | ||
|
||
public ContentInputStream(final InputStream entityStream) { | ||
this.entityStream = entityStream; | ||
} | ||
|
||
public InputStream getEntityStream() { | ||
return entityStream; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...-http-commons/src/main/java/org/fcrepo/http/commons/domain/ExternalMessageBodyReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.fcrepo.http.commons.domain; | ||
|
||
import org.fcrepo.kernel.services.ExternalContentService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.ext.MessageBodyReader; | ||
import javax.ws.rs.ext.Provider; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ||
|
||
/** | ||
* @author cabeer | ||
*/ | ||
@Provider | ||
@Component | ||
public class ExternalMessageBodyReader implements MessageBodyReader<ContentInputStream> { | ||
|
||
/** | ||
* The fcrepo node service | ||
*/ | ||
@Autowired | ||
private ExternalContentService contentService; | ||
|
||
@Override | ||
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | ||
return type == ContentInputStream.class; | ||
} | ||
|
||
@Override | ||
public ContentInputStream readFrom(Class<ContentInputStream> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { | ||
final InputStream realEntityStream; | ||
|
||
if (httpHeaders.containsKey("Content-Location")) { | ||
final String location = httpHeaders.getFirst("Content-Location"); | ||
final URI sourceUri; | ||
try { | ||
sourceUri = new URI(location); | ||
} catch (URISyntaxException e) { | ||
throw new WebApplicationException(e, BAD_REQUEST); | ||
} | ||
realEntityStream = contentService.retrieveExternalContent(sourceUri); | ||
} else { | ||
realEntityStream = entityStream; | ||
} | ||
|
||
return new ContentInputStream(realEntityStream); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
fcrepo-kernel-api/src/main/java/org/fcrepo/kernel/services/ExternalContentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.fcrepo.kernel.services; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
|
||
/** | ||
* @author cabeer | ||
*/ | ||
public interface ExternalContentService { | ||
/** | ||
* Fetch a | ||
* @param sourceUri | ||
* @return | ||
* @throws IOException | ||
*/ | ||
InputStream retrieveExternalContent(URI sourceUri) throws IOException; | ||
} |
Oops, something went wrong.