diff --git a/common/build.gradle b/common/build.gradle
index 78a265e21a..1c6139c8f5 100644
--- a/common/build.gradle
+++ b/common/build.gradle
@@ -73,6 +73,10 @@ dependencies {
compile "com.sun.jersey.contribs:jersey-apache-client:${jerseyversion}"
compile "com.sun.jersey.contribs:jersey-guice:${jerseyversion}"
+
+ // for audio support
+ compile 'net.sf.ehcache:ehcache:2.6.0'
+ compile 'org.apache.httpcomponents:httpclient:4.3.2'
// dependencies in maven profile
diff --git a/search/src/java/cz/incad/Kramerius/Initializable.java b/common/src/main/java/cz/incad/kramerius/Initializable.java
similarity index 96%
rename from search/src/java/cz/incad/Kramerius/Initializable.java
rename to common/src/main/java/cz/incad/kramerius/Initializable.java
index d5b1b3b577..758f21fdd9 100644
--- a/search/src/java/cz/incad/Kramerius/Initializable.java
+++ b/common/src/main/java/cz/incad/kramerius/Initializable.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius;
+package cz.incad.kramerius;
/**
* Implementation of this interface can be initialized after injection
diff --git a/common/src/main/java/cz/incad/kramerius/audio/AbstractAudioHttpRequestForwarder.java b/common/src/main/java/cz/incad/kramerius/audio/AbstractAudioHttpRequestForwarder.java
new file mode 100644
index 0000000000..b45c23a956
--- /dev/null
+++ b/common/src/main/java/cz/incad/kramerius/audio/AbstractAudioHttpRequestForwarder.java
@@ -0,0 +1,25 @@
+package cz.incad.kramerius.audio;
+
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+
+public abstract class AbstractAudioHttpRequestForwarder implements AudioHttpRequestForwarder {
+
+ protected static final String CONNECTION_RESET = "Connection reset";
+ protected static final String BROKEN_PIPE = "Broken pipe";
+ protected static int BUFFER_SIZE = 10240;
+
+ protected static final DefaultHttpClient httpClient = initClient();
+
+ static DefaultHttpClient initClient() {
+ ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager();
+ return new DefaultHttpClient(manager);
+ }
+
+ public static void destroy() {
+ if (httpClient != null) {
+ httpClient.getConnectionManager().shutdown();
+ }
+ }
+
+}
diff --git a/search/src/java/cz/incad/Kramerius/audio/AudioFormat.java b/common/src/main/java/cz/incad/kramerius/audio/AudioFormat.java
similarity index 96%
rename from search/src/java/cz/incad/Kramerius/audio/AudioFormat.java
rename to common/src/main/java/cz/incad/kramerius/audio/AudioFormat.java
index 01c6211b32..3e527b7d5a 100644
--- a/search/src/java/cz/incad/Kramerius/audio/AudioFormat.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/AudioFormat.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio;
+package cz.incad.kramerius.audio;
/**
* Format or version of audio. Matches datastream identifiers in Fedora.
diff --git a/common/src/main/java/cz/incad/kramerius/audio/AudioHttpRequestForwarder.java b/common/src/main/java/cz/incad/kramerius/audio/AudioHttpRequestForwarder.java
new file mode 100644
index 0000000000..5ce77d6a79
--- /dev/null
+++ b/common/src/main/java/cz/incad/kramerius/audio/AudioHttpRequestForwarder.java
@@ -0,0 +1,37 @@
+package cz.incad.kramerius.audio;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.logging.Level;
+
+import org.apache.http.impl.client.DefaultHttpClient;
+
+/**
+ * Iplementations is able to forward request
+ * @author pavels
+ *
+ * @param
+ */
+public interface AudioHttpRequestForwarder {
+
+
+ /**
+ * Forward GET HTTP method
+ * @param url
+ * @return
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public abstract T forwardGetRequest(URL url) throws IOException, URISyntaxException;
+
+ /**
+ * Forward HEAD HTTP method
+ * @param url
+ * @return
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public abstract T forwardHeadRequest(URL url) throws IOException, URISyntaxException;
+
+}
diff --git a/search/src/java/cz/incad/Kramerius/audio/AudioLifeCycleHook.java b/common/src/main/java/cz/incad/kramerius/audio/AudioLifeCycleHook.java
similarity index 84%
rename from search/src/java/cz/incad/Kramerius/audio/AudioLifeCycleHook.java
rename to common/src/main/java/cz/incad/kramerius/audio/AudioLifeCycleHook.java
index e123a9baf6..db00738932 100644
--- a/search/src/java/cz/incad/Kramerius/audio/AudioLifeCycleHook.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/AudioLifeCycleHook.java
@@ -1,10 +1,10 @@
-package cz.incad.Kramerius.audio;
+package cz.incad.kramerius.audio;
import java.util.logging.Logger;
import com.google.inject.Inject;
-import cz.incad.Kramerius.audio.urlMapping.RepositoryUrlManager;
+import cz.incad.kramerius.audio.urlMapping.RepositoryUrlManager;
import cz.incad.kramerius.service.LifeCycleHook;
public class AudioLifeCycleHook implements LifeCycleHook {
diff --git a/common/src/main/java/cz/incad/kramerius/audio/AudioStreamForwardUtils.java b/common/src/main/java/cz/incad/kramerius/audio/AudioStreamForwardUtils.java
new file mode 100644
index 0000000000..8e8e32e80e
--- /dev/null
+++ b/common/src/main/java/cz/incad/kramerius/audio/AudioStreamForwardUtils.java
@@ -0,0 +1,144 @@
+package cz.incad.kramerius.audio;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import cz.incad.kramerius.ObjectPidsPath;
+import cz.incad.kramerius.SolrAccess;
+import cz.incad.kramerius.audio.jersey.JerseyAudioHttpRequestForwarder;
+import cz.incad.kramerius.audio.servlets.ServletAudioHttpRequestForwarder;
+import cz.incad.kramerius.audio.urlMapping.RepositoryUrlManager;
+import cz.incad.kramerius.security.IsActionAllowed;
+import cz.incad.kramerius.security.SecuredActions;
+import cz.incad.kramerius.security.SecurityException;
+import cz.incad.kramerius.security.User;
+
+/**
+ * Utility class for sharing funcionality between servlet and API point
+ * @author pavels
+ *
+ */
+public class AudioStreamForwardUtils {
+
+ public static Logger LOGGER = Logger.getLogger(AudioStreamForwardUtils.class.getName());
+
+ public static boolean canBeRead(String pid, SolrAccess sa, User user, IsActionAllowed actionAllowed) throws IOException {
+ ObjectPidsPath[] paths = sa.getPath(pid);
+ for (ObjectPidsPath pth : paths) {
+ if (actionAllowed.isActionAllowed(user, SecuredActions.READ.getFormalName(), pid, null, pth)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+
+ public static ResponseBuilder GET(HttpServletRequest request,
+ ResponseBuilder builder, SolrAccess solrAccess, User user, IsActionAllowed actionAllowed, RepositoryUrlManager urlManager) throws IOException {
+ AudioStreamId id = AudioStreamId.fromPathInfo(request.getPathInfo());
+ LOGGER.info(id.toString());
+ if (canBeRead(id.getPid(), solrAccess, user, actionAllowed)) {
+ try {
+ URL url = urlManager.getAudiostreamRepositoryUrl(id);
+ if (url == null) {
+ throw new IllegalArgumentException("url for id " + id.toString() + " is null");
+ }
+ LOGGER.info(url.toString());
+ //appendTestHeaders(response, id, url); //testovaci hlavicky
+ JerseyAudioHttpRequestForwarder forwarder = new JerseyAudioHttpRequestForwarder(request, builder);
+ ResponseBuilder respBuilder = forwarder.forwardGetRequest(url);
+ return respBuilder;
+ } catch (URISyntaxException ex) {
+ Logger.getLogger(AudioStreamForwardUtils.class.getName()).log(Level.SEVERE, null, ex);
+ throw new IllegalArgumentException(ex);
+ }
+ } else {
+ throw new SecurityException("not allowed");
+ }
+
+ }
+
+ public static void GET(HttpServletRequest request,
+ HttpServletResponse response, SolrAccess solrAccess, User user, IsActionAllowed actionAllowed, RepositoryUrlManager urlManager) throws IOException, ServletException {
+ //TODO: tune logging levels (staci vetsinou FINE)
+ LOGGER.log(Level.INFO, "GET {0}", request.getPathInfo());
+ AudioStreamId id = AudioStreamId.fromPathInfo(request.getPathInfo());
+ LOGGER.info(id.toString());
+ if (canBeRead(id.getPid(), solrAccess, user, actionAllowed)) {
+ try {
+ URL url = urlManager.getAudiostreamRepositoryUrl(id);
+ if (url == null) {
+ throw new ServletException("url for id " + id.toString() + " is null");
+ }
+ LOGGER.info(url.toString());
+ //appendTestHeaders(response, id, url); //testovaci hlavicky
+ ServletAudioHttpRequestForwarder forwarder = new ServletAudioHttpRequestForwarder(request, response);
+ forwarder.forwardGetRequest(url);
+ } catch (URISyntaxException ex) {
+ Logger.getLogger(AudioStreamForwardUtils.class.getName()).log(Level.SEVERE, null, ex);
+ throw new ServletException(ex);
+ }
+ } else {
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
+ }
+ }
+
+ public static void HEAD(HttpServletRequest request,
+ HttpServletResponse response, SolrAccess solrAccess, User user, IsActionAllowed actionAllowed, RepositoryUrlManager urlManager) throws IOException, ServletException {
+ LOGGER.log(Level.INFO, "HEAD {0}", request.getPathInfo());
+ AudioStreamId id = AudioStreamId.fromPathInfo(request.getPathInfo());
+ LOGGER.info(id.toString());
+ if (canBeRead(id.getPid(),solrAccess, user, actionAllowed)) {
+ try {
+ URL url = urlManager.getAudiostreamRepositoryUrl(id);
+ if (url == null) {
+ throw new ServletException("url for id " + id.toString() + " is null");
+ }
+ LOGGER.info(url.toString());
+ //appendTestHeaders(response, id, url); //testovaci hlavicky
+ ServletAudioHttpRequestForwarder forwarder = new ServletAudioHttpRequestForwarder(request, response);
+ forwarder.forwardHeadRequest(url);
+ } catch (URISyntaxException ex) {
+ Logger.getLogger(AudioStreamForwardUtils.class.getName()).log(Level.SEVERE, null, ex);
+ throw new ServletException(ex);
+ }
+ } else {
+ response.sendError(HttpServletResponse.SC_FORBIDDEN);
+ }
+ }
+
+ public static ResponseBuilder HEAD(HttpServletRequest request,
+ ResponseBuilder builder, SolrAccess solrAccess, User user, IsActionAllowed actionAllowed, RepositoryUrlManager urlManager) throws IOException {
+ LOGGER.log(Level.INFO, "HEAD {0}", request.getPathInfo());
+ AudioStreamId id = AudioStreamId.fromPathInfo(request.getPathInfo());
+ LOGGER.info(id.toString());
+ if (canBeRead(id.getPid(),solrAccess, user, actionAllowed)) {
+ try {
+ URL url = urlManager.getAudiostreamRepositoryUrl(id);
+ if (url == null) {
+ throw new IllegalArgumentException("url for id " + id.toString() + " is null");
+ }
+ //LOGGER.info(url.toString());
+ //appendTestHeaders(response, id, url); //testovaci hlavicky
+ JerseyAudioHttpRequestForwarder forwarder = new JerseyAudioHttpRequestForwarder(request, builder);
+ return forwarder.forwardHeadRequest(url);
+ } catch (URISyntaxException ex) {
+ Logger.getLogger(AudioStreamForwardUtils.class.getName()).log(Level.SEVERE, null, ex);
+ throw new IllegalArgumentException(ex);
+ }
+ } else {
+ throw new SecurityException("not allowed");
+ }
+ }
+
+}
diff --git a/search/src/java/cz/incad/Kramerius/audio/AudioStreamId.java b/common/src/main/java/cz/incad/kramerius/audio/AudioStreamId.java
similarity index 98%
rename from search/src/java/cz/incad/Kramerius/audio/AudioStreamId.java
rename to common/src/main/java/cz/incad/kramerius/audio/AudioStreamId.java
index 032b39e5e7..35746bb928 100644
--- a/search/src/java/cz/incad/Kramerius/audio/AudioStreamId.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/AudioStreamId.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio;
+package cz.incad.kramerius.audio;
import java.io.Serializable;
import java.util.regex.Pattern;
diff --git a/search/src/java/cz/incad/Kramerius/audio/GetRequestHeaderForwarder.java b/common/src/main/java/cz/incad/kramerius/audio/GetRequestHeaderForwarder.java
similarity index 98%
rename from search/src/java/cz/incad/Kramerius/audio/GetRequestHeaderForwarder.java
rename to common/src/main/java/cz/incad/kramerius/audio/GetRequestHeaderForwarder.java
index 4f7aca40be..a4a9eb79a0 100644
--- a/search/src/java/cz/incad/Kramerius/audio/GetRequestHeaderForwarder.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/GetRequestHeaderForwarder.java
@@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio;
+package cz.incad.kramerius.audio;
import javax.servlet.http.HttpServletRequest;
+
import org.apache.http.client.methods.HttpRequestBase;
/**
diff --git a/common/src/main/java/cz/incad/kramerius/audio/ResponseHeaderForwarder.java b/common/src/main/java/cz/incad/kramerius/audio/ResponseHeaderForwarder.java
new file mode 100644
index 0000000000..816ca9ff59
--- /dev/null
+++ b/common/src/main/java/cz/incad/kramerius/audio/ResponseHeaderForwarder.java
@@ -0,0 +1,7 @@
+package cz.incad.kramerius.audio;
+
+public interface ResponseHeaderForwarder {
+
+ public String forwardHeaderIfPresent(String headerName);
+
+}
diff --git a/search/src/java/cz/incad/Kramerius/audio/XpathEvaluator.java b/common/src/main/java/cz/incad/kramerius/audio/XpathEvaluator.java
similarity index 98%
rename from search/src/java/cz/incad/Kramerius/audio/XpathEvaluator.java
rename to common/src/main/java/cz/incad/kramerius/audio/XpathEvaluator.java
index 5e41a9117c..c0d47650a4 100644
--- a/search/src/java/cz/incad/Kramerius/audio/XpathEvaluator.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/XpathEvaluator.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio;
+package cz.incad.kramerius.audio;
import java.util.Iterator;
import javax.xml.namespace.NamespaceContext;
diff --git a/common/src/main/java/cz/incad/kramerius/audio/jersey/JerseyAudioHttpRequestForwarder.java b/common/src/main/java/cz/incad/kramerius/audio/jersey/JerseyAudioHttpRequestForwarder.java
new file mode 100644
index 0000000000..a53b7ed213
--- /dev/null
+++ b/common/src/main/java/cz/incad/kramerius/audio/jersey/JerseyAudioHttpRequestForwarder.java
@@ -0,0 +1,148 @@
+package cz.incad.kramerius.audio.jersey;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.SocketException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.StreamingOutput;
+
+import org.apache.http.Header;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpRequestBase;
+
+import cz.incad.kramerius.audio.AbstractAudioHttpRequestForwarder;
+import cz.incad.kramerius.audio.AudioHttpRequestForwarder;
+import cz.incad.kramerius.audio.GetRequestHeaderForwarder;
+import cz.incad.kramerius.utils.IOUtils;
+
+public class JerseyAudioHttpRequestForwarder extends AbstractAudioHttpRequestForwarder implements AudioHttpRequestForwarder {
+
+ public static final Logger LOGGER = Logger.getLogger(JerseyResponseHeaderForwarder.class.getName());
+
+ final HttpServletRequest clientToProxyRequest;
+ final ResponseBuilder responseBuilder;
+
+ public JerseyAudioHttpRequestForwarder(HttpServletRequest clientToProxyRequest, ResponseBuilder respBuilder) {
+ this.clientToProxyRequest = clientToProxyRequest;
+ this.responseBuilder = respBuilder;
+ }
+
+ public ResponseBuilder forwardGetRequest(URL url) throws IOException, URISyntaxException {
+ //LOGGER.log(Level.INFO, "forwarding {0}", url);
+
+
+ HttpGet proxyToRepositoryRequest = new HttpGet(url.toURI());
+ forwardSelectedRequestHeaders(clientToProxyRequest, proxyToRepositoryRequest);
+ //printRepositoryRequestHeaders(repositoryRequest);
+ HttpResponse repositoryToProxyResponse = httpClient.execute(proxyToRepositoryRequest);
+ //printRepositoryResponseHeaders(repositoryResponse);
+ forwardSelectedResponseHeaders(repositoryToProxyResponse, responseBuilder);
+ forwardResponseCode(repositoryToProxyResponse, responseBuilder);
+ forwardData(repositoryToProxyResponse.getEntity().getContent(), this.responseBuilder);
+
+ return responseBuilder;
+ }
+
+
+ public ResponseBuilder forwardHeadRequest(URL url) throws IOException, URISyntaxException {
+ LOGGER.log(Level.INFO, "forwarding {0}", url);
+ HttpHead repositoryRequest = new HttpHead(url.toURI());
+ forwardSelectedRequestHeaders(clientToProxyRequest, repositoryRequest);
+ //printRepositoryRequestHeaders(repositoryRequest);
+ HttpResponse repositoryResponse = httpClient.execute(repositoryRequest);
+ //printRepositoryResponseHeaders(repositoryResponse);
+ forwardSelectedResponseHeaders(repositoryResponse, this.responseBuilder);
+ forwardResponseCode(repositoryResponse, this.responseBuilder);
+
+ return this.responseBuilder;
+ }
+
+ private void forwardSelectedResponseHeaders(HttpResponse repositoryResponse, ResponseBuilder builder) {
+ JerseyResponseHeaderForwarder forwarder = new JerseyResponseHeaderForwarder(repositoryResponse, builder);
+ forwarder.forwardHeaderIfPresent("Content-Range");
+ forwarder.forwardHeaderIfPresent("Content-Type");
+ forwarder.forwardHeaderIfPresent("Content-Length");
+ forwarder.forwardHeaderIfPresent("Etag");
+ forwarder.forwardHeaderIfPresent("Accept-Ranges");
+ //forwarder.forwardHeaderIfPresent("Transfer-Encoding");
+ forwarder.forwardHeaderIfPresent("Date");
+ forwarder.forwardHeaderIfPresent("Last-Modified");
+ //co s content encoding?
+ }
+
+ private void forwardSelectedRequestHeaders(HttpServletRequest clientRequest, HttpRequestBase repositoryRequest) {
+ GetRequestHeaderForwarder forwarder = new GetRequestHeaderForwarder(clientRequest, repositoryRequest);
+ //Pragma a Cache-control must be allways forwarded
+ forwarder.forwardHeaderIfPresent("Pragma");
+ forwarder.forwardHeaderIfPresent("Cache-Control");
+ forwarder.forwardHeaderIfPresent("Range");
+ forwarder.forwardHeaderIfPresent("If-Range");
+ //tady si nejsem jisty
+ forwarder.forwardHeaderIfPresent("Accept");
+ }
+
+
+ private void forwardData(final InputStream input, ResponseBuilder respBuilder) {
+ StreamingOutput stream = new StreamingOutput() {
+ public void write(OutputStream output)
+ throws IOException, WebApplicationException {
+ try {
+ IOUtils.copyStreams(input, output);
+ } catch (IOException e) {
+ if (e.getCause() != null && e.getCause() instanceof SocketException
+ && (e.getCause().getMessage().equals(CONNECTION_RESET) || e.getCause().getMessage().equals(BROKEN_PIPE))) {
+ LOGGER.warning("Connection reset probably by client (or by repository)");
+ } else {
+ LOGGER.log(Level.SEVERE, null, e);
+ }
+ throw new WebApplicationException(e);
+ } finally {
+ LOGGER.fine("closing connection to repository");
+ IOUtils.tryClose(input);
+ }
+ }
+ };
+ respBuilder.entity(stream);
+ }
+
+ private void forwardResponseCode(HttpResponse repositoryResponse, ResponseBuilder builder) {
+ int repositoryResponseCode = repositoryResponse.getStatusLine().getStatusCode();
+ builder.status(repositoryResponseCode);
+ }
+
+ private void printRepositoryRequestHeaders(HttpGet repositoryRequest) {
+ System.err.println("================================");
+ System.err.println("downloader request headers(" + repositoryRequest.getAllHeaders().length + "):");
+ System.err.println("================================");
+ printHeaders(repositoryRequest.getAllHeaders());
+ System.err.println("================================");
+ System.err.println("\n");
+ }
+
+ private void printRepositoryResponseHeaders(HttpResponse repositoryResponse) {
+ System.err.println("================================");
+ System.err.println("downloader response headers(" + repositoryResponse.getAllHeaders().length + "):");
+ System.err.println("================================");
+ printHeaders(repositoryResponse.getAllHeaders());
+ System.err.println("================================");
+ System.err.println("\n");
+ }
+
+ private static void printHeaders(Header[] headers) {
+ for (int i = 0; i < headers.length; i++) {
+ Header header = headers[i];
+ System.err.println(header.getName() + ": " + header.getValue());
+ }
+ }
+
+}
diff --git a/common/src/main/java/cz/incad/kramerius/audio/jersey/JerseyResponseHeaderForwarder.java b/common/src/main/java/cz/incad/kramerius/audio/jersey/JerseyResponseHeaderForwarder.java
new file mode 100644
index 0000000000..09ac805f5a
--- /dev/null
+++ b/common/src/main/java/cz/incad/kramerius/audio/jersey/JerseyResponseHeaderForwarder.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2012 Martin Řehánek
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package cz.incad.kramerius.audio.jersey;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.apache.http.Header;
+import org.apache.http.HttpResponse;
+
+import cz.incad.kramerius.audio.ResponseHeaderForwarder;
+
+/**
+ * Forwarder forwards (copies) headers from repository's response to audio proxy
+ * to audio proxy's response to client.
+ *
+ * @author Martin Řehánek
+ */
+public class JerseyResponseHeaderForwarder implements ResponseHeaderForwarder{
+
+ private final HttpResponse repositoryResponse;
+ private final ResponseBuilder proxyResponse;
+
+ /**
+ * Initializes Forwarder.
+ *
+ * @param repositoryResponse response from repository to proxy
+ * @param proxyResponse response from proxy to client
+ *
+ */
+ public JerseyResponseHeaderForwarder(HttpResponse repositoryResponse, ResponseBuilder proxyResponse) {
+ this.repositoryResponse = repositoryResponse;
+ this.proxyResponse = proxyResponse;
+ }
+
+ /**
+ * Forwards value of header if header is found. Uses only first appearance
+ * of the header therefore doesn't work correctly for multiple headers with
+ * same name.
+ *
+ * @param headerName name of header
+ * @return value of header if header is found or null
+ */
+ public String forwardHeaderIfPresent(String headerName) {
+ Header header = repositoryResponse.getFirstHeader(headerName);
+ if (header != null) {
+ //System.err.println("found response header " + header.getName() + ": " + header.getValue());
+ proxyResponse.header(header.getName(), header.getValue());
+ return header.getValue();
+ }
+ return null;
+ }
+}
diff --git a/search/src/java/cz/incad/Kramerius/audio/AudioHttpRequestForwarder.java b/common/src/main/java/cz/incad/kramerius/audio/servlets/ServletAudioHttpRequestForwarder.java
similarity index 83%
rename from search/src/java/cz/incad/Kramerius/audio/AudioHttpRequestForwarder.java
rename to common/src/main/java/cz/incad/kramerius/audio/servlets/ServletAudioHttpRequestForwarder.java
index 45b4dc3ca1..a91c21e37a 100644
--- a/search/src/java/cz/incad/Kramerius/audio/AudioHttpRequestForwarder.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/servlets/ServletAudioHttpRequestForwarder.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio;
+package cz.incad.kramerius.audio.servlets;
import java.io.IOException;
import java.io.InputStream;
@@ -23,48 +23,39 @@
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
+
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.StreamingOutput;
+
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+
+import cz.incad.kramerius.audio.AbstractAudioHttpRequestForwarder;
+import cz.incad.kramerius.audio.AudioHttpRequestForwarder;
+import cz.incad.kramerius.audio.GetRequestHeaderForwarder;
/**
*
* @author Martin Řehánek
*/
-public class AudioHttpRequestForwarder {
-
- private static final Logger LOGGER = Logger.getLogger(AudioHttpRequestForwarder.class.getName());
- private static final String CONNECTION_RESET = "Connection reset";
- private static final String BROKEN_PIPE = "Broken pipe";
- private static DefaultHttpClient httpClient = initClient();
- private static int BUFFER_SIZE = 10240;
- private final HttpServletResponse proxyToClientResponse;
- private final HttpServletRequest clientToProxyRequest;
-
- private static DefaultHttpClient initClient() {
- ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager();
- return new DefaultHttpClient(manager);
- }
+public class ServletAudioHttpRequestForwarder extends AbstractAudioHttpRequestForwarder implements AudioHttpRequestForwarder {
- public static void destroy() {
- if (httpClient != null) {
- httpClient.getConnectionManager().shutdown();
- }
- }
+ private static final Logger LOGGER = Logger.getLogger(ServletAudioHttpRequestForwarder.class.getName());
+
+ final HttpServletResponse proxyToClientResponse;
+ final HttpServletRequest clientToProxyRequest;
- public AudioHttpRequestForwarder(HttpServletRequest clientToProxyRequest, HttpServletResponse proxyToClientResponse) {
+ public ServletAudioHttpRequestForwarder(HttpServletRequest clientToProxyRequest, HttpServletResponse proxyToClientResponse) {
this.clientToProxyRequest = clientToProxyRequest;
this.proxyToClientResponse = proxyToClientResponse;
}
- public void forwardGetRequest(URL url) throws IOException, URISyntaxException {
+ public Void forwardGetRequest(URL url) throws IOException, URISyntaxException {
LOGGER.log(Level.INFO, "forwarding {0}", url);
HttpGet proxyToRepositoryRequest = new HttpGet(url.toURI());
forwardSelectedRequestHeaders(clientToProxyRequest, proxyToRepositoryRequest);
@@ -74,9 +65,13 @@ public void forwardGetRequest(URL url) throws IOException, URISyntaxException {
forwardSelectedResponseHeaders(repositoryToProxyResponse, proxyToClientResponse);
forwardResponseCode(repositoryToProxyResponse, proxyToClientResponse);
forwardData(repositoryToProxyResponse.getEntity().getContent(), proxyToClientResponse.getOutputStream());
+ return null;
}
+
+
+
- public void forwardHeadRequest(URL url) throws IOException, URISyntaxException {
+ public Void forwardHeadRequest(URL url) throws IOException, URISyntaxException {
LOGGER.log(Level.INFO, "forwarding {0}", url);
HttpHead repositoryRequest = new HttpHead(url.toURI());
forwardSelectedRequestHeaders(clientToProxyRequest, repositoryRequest);
@@ -85,10 +80,11 @@ public void forwardHeadRequest(URL url) throws IOException, URISyntaxException {
//printRepositoryResponseHeaders(repositoryResponse);
forwardSelectedResponseHeaders(repositoryResponse, proxyToClientResponse);
forwardResponseCode(repositoryResponse, proxyToClientResponse);
+ return null;
}
private void forwardSelectedResponseHeaders(HttpResponse repositoryResponse, HttpServletResponse clientResponse) {
- ResponseHeaderForwarder forwarder = new ResponseHeaderForwarder(repositoryResponse, clientResponse);
+ ServletResponseHeaderForwarder forwarder = new ServletResponseHeaderForwarder(repositoryResponse, clientResponse);
forwarder.forwardHeaderIfPresent("Content-Range");
forwarder.forwardHeaderIfPresent("Content-Type");
forwarder.forwardHeaderIfPresent("Content-Length");
@@ -111,6 +107,7 @@ private void forwardSelectedRequestHeaders(HttpServletRequest clientRequest, Htt
forwarder.forwardHeaderIfPresent("Accept");
}
+
private void forwardData(InputStream input, ServletOutputStream output) {
try {
byte[] buffer = new byte[BUFFER_SIZE];
diff --git a/search/src/java/cz/incad/Kramerius/audio/ResponseHeaderForwarder.java b/common/src/main/java/cz/incad/kramerius/audio/servlets/ServletResponseHeaderForwarder.java
similarity index 87%
rename from search/src/java/cz/incad/Kramerius/audio/ResponseHeaderForwarder.java
rename to common/src/main/java/cz/incad/kramerius/audio/servlets/ServletResponseHeaderForwarder.java
index b76ea42ea3..fb0299c8fe 100644
--- a/search/src/java/cz/incad/Kramerius/audio/ResponseHeaderForwarder.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/servlets/ServletResponseHeaderForwarder.java
@@ -14,19 +14,22 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio;
+package cz.incad.kramerius.audio.servlets;
import javax.servlet.http.HttpServletResponse;
+
import org.apache.http.Header;
import org.apache.http.HttpResponse;
+import cz.incad.kramerius.audio.ResponseHeaderForwarder;
+
/**
* Forwarder forwards (copies) headers from repository's response to audio proxy
* to audio proxy's response to client.
*
* @author Martin Řehánek
*/
-public class ResponseHeaderForwarder {
+public class ServletResponseHeaderForwarder implements ResponseHeaderForwarder{
private final HttpResponse repositoryResponse;
private final HttpServletResponse proxyResponse;
@@ -38,7 +41,7 @@ public class ResponseHeaderForwarder {
* @param proxyResponse response from proxy to client
*
*/
- public ResponseHeaderForwarder(HttpResponse repositoryResponse, HttpServletResponse proxyResponse) {
+ public ServletResponseHeaderForwarder(HttpResponse repositoryResponse, HttpServletResponse proxyResponse) {
this.repositoryResponse = repositoryResponse;
this.proxyResponse = proxyResponse;
}
diff --git a/search/src/java/cz/incad/Kramerius/audio/urlMapping/CachingFedoraUrlManager.java b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/CachingFedoraUrlManager.java
similarity index 95%
rename from search/src/java/cz/incad/Kramerius/audio/urlMapping/CachingFedoraUrlManager.java
rename to common/src/main/java/cz/incad/kramerius/audio/urlMapping/CachingFedoraUrlManager.java
index 395cf2ac85..57354e38a9 100644
--- a/search/src/java/cz/incad/Kramerius/audio/urlMapping/CachingFedoraUrlManager.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/CachingFedoraUrlManager.java
@@ -14,19 +14,22 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio.urlMapping;
+package cz.incad.kramerius.audio.urlMapping;
import com.google.inject.Inject;
import com.google.inject.name.Named;
-import cz.incad.Kramerius.Initializable;
-import cz.incad.Kramerius.audio.AudioStreamId;
-import cz.incad.Kramerius.audio.XpathEvaluator;
+
import cz.incad.kramerius.FedoraAccess;
+import cz.incad.kramerius.Initializable;
+import cz.incad.kramerius.audio.AudioStreamId;
+import cz.incad.kramerius.audio.XpathEvaluator;
+
import org.w3c.dom.Document;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
+
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
diff --git a/search/src/java/cz/incad/Kramerius/audio/urlMapping/EhcacheUrlCache.java b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/EhcacheUrlCache.java
similarity index 95%
rename from search/src/java/cz/incad/Kramerius/audio/urlMapping/EhcacheUrlCache.java
rename to common/src/main/java/cz/incad/kramerius/audio/urlMapping/EhcacheUrlCache.java
index 7518b2a370..ca60a792b6 100644
--- a/search/src/java/cz/incad/Kramerius/audio/urlMapping/EhcacheUrlCache.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/EhcacheUrlCache.java
@@ -14,11 +14,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio.urlMapping;
+package cz.incad.kramerius.audio.urlMapping;
+
+import cz.incad.kramerius.audio.AudioStreamId;
-import cz.incad.Kramerius.audio.AudioStreamId;
import java.net.URL;
import java.util.logging.Logger;
+
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
diff --git a/search/src/java/cz/incad/Kramerius/audio/urlMapping/MockUrlManager.java b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/MockUrlManager.java
similarity index 78%
rename from search/src/java/cz/incad/Kramerius/audio/urlMapping/MockUrlManager.java
rename to common/src/main/java/cz/incad/kramerius/audio/urlMapping/MockUrlManager.java
index a9a69c582c..4b0593ed0e 100644
--- a/search/src/java/cz/incad/Kramerius/audio/urlMapping/MockUrlManager.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/MockUrlManager.java
@@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio.urlMapping;
+package cz.incad.kramerius.audio.urlMapping;
+
+import cz.incad.kramerius.audio.AudioStreamId;
-import cz.incad.Kramerius.audio.AudioStreamId;
import java.io.IOException;
import java.net.URL;
@@ -28,7 +29,8 @@ public class MockUrlManager implements RepositoryUrlManager {
@Override
public URL getAudiostreamRepositoryUrl(AudioStreamId id) throws IOException {
- return new URL("http://iris.mzk.cz/cache/audio/files/124.mp3");
+ return new URL("http://kramerius.mzk.cz/search/audioProxy/uuid:df6c2a49-d9f6-40fe-9533-8c96f67fa229/OGG");
+ //return new URL("http://iris.mzk.cz/cache/audio/files/124.mp3");
}
@Override
diff --git a/search/src/java/cz/incad/Kramerius/audio/urlMapping/RepositoryUrlCache.java b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/RepositoryUrlCache.java
similarity index 93%
rename from search/src/java/cz/incad/Kramerius/audio/urlMapping/RepositoryUrlCache.java
rename to common/src/main/java/cz/incad/kramerius/audio/urlMapping/RepositoryUrlCache.java
index 03ff8085f2..f80c5da887 100644
--- a/search/src/java/cz/incad/Kramerius/audio/urlMapping/RepositoryUrlCache.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/RepositoryUrlCache.java
@@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio.urlMapping;
+package cz.incad.kramerius.audio.urlMapping;
+
+import cz.incad.kramerius.audio.AudioStreamId;
-import cz.incad.Kramerius.audio.AudioStreamId;
import java.net.URL;
/**
diff --git a/search/src/java/cz/incad/Kramerius/audio/urlMapping/RepositoryUrlManager.java b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/RepositoryUrlManager.java
similarity index 93%
rename from search/src/java/cz/incad/Kramerius/audio/urlMapping/RepositoryUrlManager.java
rename to common/src/main/java/cz/incad/kramerius/audio/urlMapping/RepositoryUrlManager.java
index 15d8b46c48..e886d5882c 100644
--- a/search/src/java/cz/incad/Kramerius/audio/urlMapping/RepositoryUrlManager.java
+++ b/common/src/main/java/cz/incad/kramerius/audio/urlMapping/RepositoryUrlManager.java
@@ -14,9 +14,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package cz.incad.Kramerius.audio.urlMapping;
+package cz.incad.kramerius.audio.urlMapping;
+
+import cz.incad.kramerius.audio.AudioStreamId;
-import cz.incad.Kramerius.audio.AudioStreamId;
import java.io.IOException;
import java.net.URL;
diff --git a/common/src/main/java/cz/incad/kramerius/utils/FedoraUtils.java b/common/src/main/java/cz/incad/kramerius/utils/FedoraUtils.java
index 189b79bcb4..5683d82400 100644
--- a/common/src/main/java/cz/incad/kramerius/utils/FedoraUtils.java
+++ b/common/src/main/java/cz/incad/kramerius/utils/FedoraUtils.java
@@ -64,6 +64,12 @@ public class FedoraUtils {
add(BIBLIO_MODS_STREAM);
}};
+ public static List AUDIO_STREAMS = new ArrayList(){{
+ add(OGG_STREAM);
+ add(MP3_STREAM);
+ add(WAV_STREAM);
+ }};
+
/** Stream for fedora internal use */
public static List FEDORA_INTERNAL_STREAMS = new ArrayList(){{
add(RELS_EXT_STREAM);
diff --git a/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/item/ItemResource.java b/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/item/ItemResource.java
index 657cafcea8..cb6045450e 100644
--- a/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/item/ItemResource.java
+++ b/rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/item/ItemResource.java
@@ -2,7 +2,10 @@
import com.google.inject.*;
import com.google.inject.name.*;
+
import cz.incad.kramerius.*;
+import cz.incad.kramerius.audio.AudioStreamForwardUtils;
+import cz.incad.kramerius.audio.urlMapping.RepositoryUrlManager;
import cz.incad.kramerius.rest.api.exceptions.*;
import cz.incad.kramerius.rest.api.k5.client.*;
import cz.incad.kramerius.rest.api.k5.client.item.exceptions.*;
@@ -13,14 +16,17 @@
import cz.incad.kramerius.service.*;
import cz.incad.kramerius.service.replication.*;
import cz.incad.kramerius.utils.*;
-import cz.incad.kramerius.utils.XMLUtils;
import cz.incad.kramerius.utils.pid.*;
import net.sf.json.*;
+
import org.w3c.dom.*;
+import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
import java.io.*;
import java.net.*;
import java.util.*;
@@ -47,7 +53,10 @@ public class ItemResource {
@Inject
Provider requestProvider;
-
+
+ @Inject
+ Provider responseProvider;
+
@Inject
JSONDecoratorsAggregate decoratorsAggregate;
@@ -60,6 +69,14 @@ public class ItemResource {
@Inject
ReplicationService replicationService;
+
+ @Inject
+ Provider userProvider;
+
+ // only for audio streams
+ @Inject
+ RepositoryUrlManager urlManager;
+
@GET
@Path("{pid}/foxml")
@@ -96,6 +113,65 @@ public void write(OutputStream output)
throw new PIDNotFound("cannot foxml for " + pid);
}
}
+
+
+ @HEAD
+ @Path("{pid}/streams/{dsid}")
+ public Response streamHead(@PathParam("pid") String pid,
+ @PathParam("dsid") String dsid) {
+ checkPid(pid);
+ try {
+ checkPid(pid);
+ if (!FedoraUtils.FEDORA_INTERNAL_STREAMS.contains(dsid)) {
+ if (!PIDSupport.isComposedPID(pid)) {
+
+ // audio streams - bacause of support rage in headers
+ if (FedoraUtils.AUDIO_STREAMS.contains(dsid)) {
+ String mimeTypeForStream = this.fedoraAccess
+ .getMimeTypeForStream(pid, dsid);
+
+ ResponseBuilder responseBuilder = Response.ok();
+ responseBuilder = responseBuilder.type(mimeTypeForStream);
+
+ HttpServletRequest request = this.requestProvider.get();
+ User user = this.userProvider.get();
+
+ ResponseBuilder builder = AudioStreamForwardUtils.HEAD(request, responseBuilder, solrAccess, user, this.isActionAllowed, urlManager);
+ return builder.build();
+
+ } else {
+ // TODO: change it !
+ final InputStream is = this.fedoraAccess.getDataStream(pid,
+ dsid);
+ String mimeTypeForStream = this.fedoraAccess
+ .getMimeTypeForStream(pid, dsid);
+ /*
+ StreamingOutput stream = new StreamingOutput() {
+ public void write(OutputStream output)
+ throws IOException, WebApplicationException {
+ try {
+ IOUtils.copyStreams(is, output);
+ } catch (Exception e) {
+ throw new WebApplicationException(e);
+ }
+ }
+ }'*/
+ return Response.ok().type(mimeTypeForStream)
+ .build();
+ }
+ } else
+ throw new PIDNotFound("cannot find stream " + dsid);
+ } else {
+ throw new PIDNotFound("cannot find stream " + dsid);
+ }
+ } catch (IOException e) {
+ throw new PIDNotFound(e.getMessage());
+ } catch (SecurityException e) {
+ throw new ActionNotAllowed(e.getMessage());
+ }
+
+
+ }
@GET
@Path("{pid}/streams/{dsid}")
@@ -105,22 +181,39 @@ public Response stream(@PathParam("pid") String pid,
checkPid(pid);
if (!FedoraUtils.FEDORA_INTERNAL_STREAMS.contains(dsid)) {
if (!PIDSupport.isComposedPID(pid)) {
- final InputStream is = this.fedoraAccess.getDataStream(pid,
- dsid);
- String mimeTypeForStream = this.fedoraAccess
- .getMimeTypeForStream(pid, dsid);
- StreamingOutput stream = new StreamingOutput() {
- public void write(OutputStream output)
- throws IOException, WebApplicationException {
- try {
- IOUtils.copyStreams(is, output);
- } catch (Exception e) {
- throw new WebApplicationException(e);
+
+ // audio streams - bacause of support rage in headers
+ if (FedoraUtils.AUDIO_STREAMS.contains(dsid)) {
+ String mimeTypeForStream = this.fedoraAccess
+ .getMimeTypeForStream(pid, dsid);
+
+ ResponseBuilder responseBuilder = Response.ok();
+ responseBuilder = responseBuilder.type(mimeTypeForStream);
+
+ HttpServletRequest request = this.requestProvider.get();
+ User user = this.userProvider.get();
+
+ ResponseBuilder builder = AudioStreamForwardUtils.GET(request, responseBuilder, solrAccess, user, this.isActionAllowed, urlManager);
+ return builder.build();
+
+ } else {
+ final InputStream is = this.fedoraAccess.getDataStream(pid,
+ dsid);
+ String mimeTypeForStream = this.fedoraAccess
+ .getMimeTypeForStream(pid, dsid);
+ StreamingOutput stream = new StreamingOutput() {
+ public void write(OutputStream output)
+ throws IOException, WebApplicationException {
+ try {
+ IOUtils.copyStreams(is, output);
+ } catch (Exception e) {
+ throw new WebApplicationException(e);
+ }
}
- }
- };
- return Response.ok().entity(stream).type(mimeTypeForStream)
- .build();
+ };
+ return Response.ok().entity(stream).type(mimeTypeForStream)
+ .build();
+ }
} else
throw new PIDNotFound("cannot find stream " + dsid);
} else {
diff --git a/search/build.gradle b/search/build.gradle
index cf3adc930e..51f17f91c7 100644
--- a/search/build.gradle
+++ b/search/build.gradle
@@ -60,8 +60,6 @@ dependencies {
compile "org.slf4j:log4j-over-slf4j:${slf4jversion}"
compile "org.slf4j:slf4j-jdk14:${slf4jversion}"
- compile 'net.sf.ehcache:ehcache:2.6.0'
- compile 'org.apache.httpcomponents:httpclient:4.3.2'
compile 'net.sf.json-lib:json-lib:2.4:jdk15'
}
diff --git a/search/src/java/cz/incad/Kramerius/audio/servlet/AudioProxyServlet.java b/search/src/java/cz/incad/Kramerius/audio/servlet/AudioProxyServlet.java
index 1a16249609..714cb4caf7 100644
--- a/search/src/java/cz/incad/Kramerius/audio/servlet/AudioProxyServlet.java
+++ b/search/src/java/cz/incad/Kramerius/audio/servlet/AudioProxyServlet.java
@@ -18,20 +18,21 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
-import cz.incad.Kramerius.audio.AudioHttpRequestForwarder;
-import cz.incad.Kramerius.audio.AudioStreamId;
-import cz.incad.Kramerius.audio.urlMapping.RepositoryUrlManager;
+
import cz.incad.Kramerius.backend.guice.GuiceServlet;
-import cz.incad.kramerius.ObjectPidsPath;
import cz.incad.kramerius.SolrAccess;
+import cz.incad.kramerius.audio.AudioStreamForwardUtils;
+import cz.incad.kramerius.audio.AudioStreamId;
+import cz.incad.kramerius.audio.servlets.ServletAudioHttpRequestForwarder;
+import cz.incad.kramerius.audio.urlMapping.RepositoryUrlManager;
import cz.incad.kramerius.security.IsActionAllowed;
-import cz.incad.kramerius.security.SecuredActions;
import cz.incad.kramerius.security.User;
+
import java.io.IOException;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
+
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -52,13 +53,16 @@
*/
public class AudioProxyServlet extends GuiceServlet {
+ private static final Logger LOGGER = Logger.getLogger(AudioProxyServlet.class.getName());
+
@Inject
IsActionAllowed actionAllowed;
@Inject
SolrAccess solrAccess;
@Inject
Provider userProvider;
- private static final Logger LOGGER = Logger.getLogger(AudioProxyServlet.class.getName());
+
+
@Inject
RepositoryUrlManager urlManager;
@@ -72,7 +76,7 @@ public void init() throws ServletException {
public void destroy() {
LOGGER.log(Level.INFO, "shutting down {0}", AudioProxyServlet.class.getName());
urlManager.close();
- AudioHttpRequestForwarder.destroy();
+ ServletAudioHttpRequestForwarder.destroy();
}
/**
@@ -87,37 +91,7 @@ public void destroy() {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- //TODO: tune logging levels (staci vetsinou FINE)
- LOGGER.log(Level.INFO, "GET {0}", request.getPathInfo());
- AudioStreamId id = AudioStreamId.fromPathInfo(request.getPathInfo());
- LOGGER.info(id.toString());
- if (canBeRead(id.getPid())) {
- try {
- URL url = urlManager.getAudiostreamRepositoryUrl(id);
- if (url == null) {
- throw new ServletException("url for id " + id.toString() + " is null");
- }
- LOGGER.info(url.toString());
- //appendTestHeaders(response, id, url); //testovaci hlavicky
- AudioHttpRequestForwarder forwarder = new AudioHttpRequestForwarder(request, response);
- forwarder.forwardGetRequest(url);
- } catch (URISyntaxException ex) {
- Logger.getLogger(AudioProxyServlet.class.getName()).log(Level.SEVERE, null, ex);
- throw new ServletException(ex);
- }
- } else {
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- }
- }
-
- private boolean canBeRead(String pid) throws IOException {
- ObjectPidsPath[] paths = solrAccess.getPath(pid);
- for (ObjectPidsPath pth : paths) {
- if (this.actionAllowed.isActionAllowed(userProvider.get(), SecuredActions.READ.getFormalName(), pid, null, pth)) {
- return true;
- }
- }
- return false;
+ AudioStreamForwardUtils.GET(request, response, this.solrAccess, this.userProvider.get(),this.actionAllowed, this.urlManager);
}
/**
@@ -131,27 +105,7 @@ private boolean canBeRead(String pid) throws IOException {
*/
@Override
protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
- LOGGER.log(Level.INFO, "HEAD {0}", request.getPathInfo());
- AudioStreamId id = AudioStreamId.fromPathInfo(request.getPathInfo());
- LOGGER.info(id.toString());
- if (canBeRead(id.getPid())) {
- try {
- URL url = urlManager.getAudiostreamRepositoryUrl(id);
- if (url == null) {
- throw new ServletException("url for id " + id.toString() + " is null");
- }
- LOGGER.info(url.toString());
- //appendTestHeaders(response, id, url); //testovaci hlavicky
- AudioHttpRequestForwarder forwarder = new AudioHttpRequestForwarder(request, response);
- forwarder.forwardHeadRequest(url);
- } catch (URISyntaxException ex) {
- Logger.getLogger(AudioProxyServlet.class.getName()).log(Level.SEVERE, null, ex);
- throw new ServletException(ex);
- }
- } else {
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- }
+ AudioStreamForwardUtils.HEAD(request, response,this.solrAccess, this.userProvider.get(),this.actionAllowed, this.urlManager);
}
/**
diff --git a/search/src/java/cz/incad/Kramerius/audio/servlet/AudioTracksServlet.java b/search/src/java/cz/incad/Kramerius/audio/servlet/AudioTracksServlet.java
index 3585f3dbeb..c357a726b9 100644
--- a/search/src/java/cz/incad/Kramerius/audio/servlet/AudioTracksServlet.java
+++ b/search/src/java/cz/incad/Kramerius/audio/servlet/AudioTracksServlet.java
@@ -19,12 +19,14 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;
-import cz.incad.Kramerius.audio.XpathEvaluator;
+
import cz.incad.Kramerius.backend.guice.GuiceServlet;
import cz.incad.kramerius.FedoraAccess;
+import cz.incad.kramerius.audio.XpathEvaluator;
import cz.incad.kramerius.service.ResourceBundleService;
import cz.incad.kramerius.service.TextsService;
import net.sf.json.JSONObject;
+
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
@@ -34,6 +36,7 @@
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
+
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
diff --git a/search/src/java/cz/incad/Kramerius/backend/guice/BaseModule.java b/search/src/java/cz/incad/Kramerius/backend/guice/BaseModule.java
index 7bf66d1412..1128b50ec3 100644
--- a/search/src/java/cz/incad/Kramerius/backend/guice/BaseModule.java
+++ b/search/src/java/cz/incad/Kramerius/backend/guice/BaseModule.java
@@ -7,13 +7,14 @@
import com.google.inject.name.Named;
import com.google.inject.name.Names;
-import cz.incad.Kramerius.audio.AudioLifeCycleHook;
-import cz.incad.Kramerius.audio.urlMapping.CachingFedoraUrlManager;
-import cz.incad.Kramerius.audio.urlMapping.RepositoryUrlManager;
import cz.incad.kramerius.Constants;
import cz.incad.kramerius.FedoraAccess;
import cz.incad.kramerius.MostDesirable;
import cz.incad.kramerius.SolrAccess;
+import cz.incad.kramerius.audio.AudioLifeCycleHook;
+import cz.incad.kramerius.audio.urlMapping.CachingFedoraUrlManager;
+import cz.incad.kramerius.audio.urlMapping.MockUrlManager;
+import cz.incad.kramerius.audio.urlMapping.RepositoryUrlManager;
import cz.incad.kramerius.impl.FedoraAccessImpl;
import cz.incad.kramerius.impl.MostDesirableImpl;
import cz.incad.kramerius.impl.SolrAccessImpl;
diff --git a/search/src/java/cz/incad/Kramerius/exts/menu/main/impl/adm/items/MovingWallProcess.java b/search/src/java/cz/incad/Kramerius/exts/menu/main/impl/adm/items/MovingWallProcess.java
new file mode 100644
index 0000000000..33bc084817
--- /dev/null
+++ b/search/src/java/cz/incad/Kramerius/exts/menu/main/impl/adm/items/MovingWallProcess.java
@@ -0,0 +1,23 @@
+package cz.incad.Kramerius.exts.menu.main.impl.adm.items;
+
+import java.io.IOException;
+
+import cz.incad.Kramerius.exts.menu.main.impl.AbstractMainMenuItem;
+import cz.incad.Kramerius.exts.menu.main.impl.adm.AdminMenuItem;
+import cz.incad.kramerius.security.SecuredActions;
+
+public class MovingWallProcess extends AbstractMainMenuItem implements AdminMenuItem {
+
+ @Override
+ public boolean isRenderable() {
+ return (hasUserAllowedAction(SecuredActions.ADMINISTRATE.getFormalName()));
+ }
+
+ @Override
+ public String getRenderedItem() throws IOException {
+ return renderMainMenuItem(
+ "javascript:movingwallOverRepo(); javascript:hideAdminMenu();",
+ "administrator.menu.dialogs.mw.title", false);
+ }
+
+}
diff --git a/search/src/java/cz/incad/Kramerius/tags/ViewObjectsTag.java b/search/src/java/cz/incad/Kramerius/tags/ViewObjectsTag.java
index 469ab79dc9..3646a3be79 100644
--- a/search/src/java/cz/incad/Kramerius/tags/ViewObjectsTag.java
+++ b/search/src/java/cz/incad/Kramerius/tags/ViewObjectsTag.java
@@ -21,7 +21,7 @@
import com.google.inject.Injector;
-import cz.incad.Kramerius.Initializable;
+import cz.incad.kramerius.Initializable;
public class ViewObjectsTag extends TagSupport {
diff --git a/search/src/java/cz/incad/Kramerius/views/AbstractPrintViewObject.java b/search/src/java/cz/incad/Kramerius/views/AbstractPrintViewObject.java
index 76ff98e4cb..b021514948 100644
--- a/search/src/java/cz/incad/Kramerius/views/AbstractPrintViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/AbstractPrintViewObject.java
@@ -38,8 +38,8 @@
import com.google.inject.Inject;
import com.google.inject.name.Named;
-import cz.incad.Kramerius.Initializable;
import cz.incad.kramerius.FedoraAccess;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.ObjectPidsPath;
import cz.incad.kramerius.SolrAccess;
import cz.incad.kramerius.document.model.DCConent;
diff --git a/search/src/java/cz/incad/Kramerius/views/FavoritesViewObject.java b/search/src/java/cz/incad/Kramerius/views/FavoritesViewObject.java
index 7751f95947..018eef0c2e 100644
--- a/search/src/java/cz/incad/Kramerius/views/FavoritesViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/FavoritesViewObject.java
@@ -34,8 +34,8 @@
import com.google.inject.Provider;
import com.google.inject.name.Named;
-import cz.incad.Kramerius.Initializable;
import cz.incad.kramerius.FedoraAccess;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.SolrAccess;
import cz.incad.kramerius.document.model.DCConent;
import cz.incad.kramerius.document.model.utils.DCContentUtils;
diff --git a/search/src/java/cz/incad/Kramerius/views/PrintViewObject.java b/search/src/java/cz/incad/Kramerius/views/PrintViewObject.java
index 15f05a5b83..becee89873 100644
--- a/search/src/java/cz/incad/Kramerius/views/PrintViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/PrintViewObject.java
@@ -16,7 +16,7 @@
*/
package cz.incad.Kramerius.views;
-import cz.incad.Kramerius.Initializable;
+import cz.incad.kramerius.Initializable;
public class PrintViewObject extends AbstractPrintViewObject {
diff --git a/search/src/java/cz/incad/Kramerius/views/ProcessesViewObject.java b/search/src/java/cz/incad/Kramerius/views/ProcessesViewObject.java
index ea5838f057..79e4e9824b 100644
--- a/search/src/java/cz/incad/Kramerius/views/ProcessesViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/ProcessesViewObject.java
@@ -14,7 +14,7 @@
import antlr.RecognitionException;
import antlr.TokenStreamException;
-import cz.incad.Kramerius.Initializable;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.processes.BatchStates;
import cz.incad.kramerius.processes.DefinitionManager;
import cz.incad.kramerius.processes.LRProcess;
diff --git a/search/src/java/cz/incad/Kramerius/views/inc/FooterViewObject.java b/search/src/java/cz/incad/Kramerius/views/inc/FooterViewObject.java
index 21c3b87b06..79089af489 100644
--- a/search/src/java/cz/incad/Kramerius/views/inc/FooterViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/inc/FooterViewObject.java
@@ -23,7 +23,7 @@
import java.util.Properties;
import java.util.logging.Level;
-import cz.incad.Kramerius.Initializable;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.utils.IOUtils;
/**
diff --git a/search/src/java/cz/incad/Kramerius/views/inc/SearchParamsHTMLView.java b/search/src/java/cz/incad/Kramerius/views/inc/SearchParamsHTMLView.java
index 80de4faa8c..f97331d5c2 100644
--- a/search/src/java/cz/incad/Kramerius/views/inc/SearchParamsHTMLView.java
+++ b/search/src/java/cz/incad/Kramerius/views/inc/SearchParamsHTMLView.java
@@ -37,12 +37,11 @@
+
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
-
-
-import cz.incad.Kramerius.Initializable;
import cz.incad.Kramerius.users.ProfilePrepareUtils;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.users.UserProfile;
import cz.incad.kramerius.utils.conf.KConfiguration;
import cz.incad.kramerius.utils.json.JSONUtils;
diff --git a/search/src/java/cz/incad/Kramerius/views/inc/details/tabs/AltoSupportViewObject.java b/search/src/java/cz/incad/Kramerius/views/inc/details/tabs/AltoSupportViewObject.java
index aaedb5b948..b25c9b82d9 100644
--- a/search/src/java/cz/incad/Kramerius/views/inc/details/tabs/AltoSupportViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/inc/details/tabs/AltoSupportViewObject.java
@@ -36,8 +36,8 @@
import com.google.inject.Provider;
import com.google.inject.name.Named;
-import cz.incad.Kramerius.Initializable;
import cz.incad.kramerius.FedoraAccess;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.utils.ALTOUtils;
import cz.incad.kramerius.utils.ALTOUtils.AltoDisected;
import cz.incad.kramerius.utils.XMLUtils;
diff --git a/search/src/java/cz/incad/Kramerius/views/inc/details/tabs/LoadCustomViewObject.java b/search/src/java/cz/incad/Kramerius/views/inc/details/tabs/LoadCustomViewObject.java
index 4f14fb9223..2fceaf6978 100644
--- a/search/src/java/cz/incad/Kramerius/views/inc/details/tabs/LoadCustomViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/inc/details/tabs/LoadCustomViewObject.java
@@ -19,19 +19,22 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;
+
import cz.incad.Kramerius.I18NServlet;
-import cz.incad.Kramerius.Initializable;
import cz.incad.kramerius.FedoraAccess;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.service.ResourceBundleService;
import cz.incad.kramerius.service.XSLService;
import cz.incad.kramerius.utils.IOUtils;
import cz.incad.kramerius.utils.UnicodeUtil;
import cz.incad.kramerius.utils.XMLUtils;
+
import org.apache.commons.lang3.StringEscapeUtils;
import org.xml.sax.SAXException;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.ParserConfigurationException;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
diff --git a/search/src/java/cz/incad/Kramerius/views/localprint/DisectionPrepareViewObject.java b/search/src/java/cz/incad/Kramerius/views/localprint/DisectionPrepareViewObject.java
index b81a5052b7..f1e985cb86 100644
--- a/search/src/java/cz/incad/Kramerius/views/localprint/DisectionPrepareViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/localprint/DisectionPrepareViewObject.java
@@ -15,8 +15,8 @@
import com.google.inject.Provider;
import com.google.inject.name.Named;
-import cz.incad.Kramerius.Initializable;
import cz.incad.kramerius.FedoraAccess;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.utils.conf.KConfiguration;
import cz.incad.kramerius.utils.imgs.KrameriusImageSupport;
diff --git a/search/src/java/cz/incad/Kramerius/views/localprint/PicturePrepareViewObject.java b/search/src/java/cz/incad/Kramerius/views/localprint/PicturePrepareViewObject.java
index d655901ae9..51b4334948 100644
--- a/search/src/java/cz/incad/Kramerius/views/localprint/PicturePrepareViewObject.java
+++ b/search/src/java/cz/incad/Kramerius/views/localprint/PicturePrepareViewObject.java
@@ -16,8 +16,8 @@
import com.google.inject.Provider;
import com.google.inject.name.Named;
-import cz.incad.Kramerius.Initializable;
import cz.incad.kramerius.FedoraAccess;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.ObjectPidsPath;
import cz.incad.kramerius.SolrAccess;
import cz.incad.kramerius.rest.api.k5.client.SolrMemoization;
diff --git a/search/src/java/cz/incad/Kramerius/views/rights/RolesView.java b/search/src/java/cz/incad/Kramerius/views/rights/RolesView.java
index b71e507c29..f661d5cc29 100644
--- a/search/src/java/cz/incad/Kramerius/views/rights/RolesView.java
+++ b/search/src/java/cz/incad/Kramerius/views/rights/RolesView.java
@@ -25,8 +25,8 @@
import com.google.inject.Provider;
import com.lizardtech.djvu.anno.Mapper;
-import cz.incad.Kramerius.Initializable;
import cz.incad.Kramerius.security.strenderers.RoleWrapper;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.security.DefaultRoles;
import cz.incad.kramerius.security.RightsManager;
import cz.incad.kramerius.security.Role;
diff --git a/search/src/java/cz/incad/Kramerius/views/rights/UsersView.java b/search/src/java/cz/incad/Kramerius/views/rights/UsersView.java
index b17d7bf9ba..dc32968acc 100644
--- a/search/src/java/cz/incad/Kramerius/views/rights/UsersView.java
+++ b/search/src/java/cz/incad/Kramerius/views/rights/UsersView.java
@@ -27,8 +27,8 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
-import cz.incad.Kramerius.Initializable;
import cz.incad.Kramerius.security.strenderers.RoleWrapper;
+import cz.incad.kramerius.Initializable;
import cz.incad.kramerius.security.DefaultRoles;
import cz.incad.kramerius.security.RightsManager;
import cz.incad.kramerius.security.Role;