Change-Id: I0c52536ebeeb8e71d95c6420f6db7055ff082dfa Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>tags/v4.10.0.201712302008-r
@@ -55,6 +55,8 @@ import org.eclipse.jgit.lfs.lib.AnyLongObjectId; | |||
public interface LargeFileRepository { | |||
/** | |||
* Get download action | |||
* | |||
* @param id | |||
* id of the object to download | |||
* @return Action for downloading the object | |||
@@ -62,6 +64,8 @@ public interface LargeFileRepository { | |||
public Response.Action getDownloadAction(AnyLongObjectId id); | |||
/** | |||
* Get upload action | |||
* | |||
* @param id | |||
* id of the object to upload | |||
* @param size | |||
@@ -71,6 +75,8 @@ public interface LargeFileRepository { | |||
public Response.Action getUploadAction(AnyLongObjectId id, long size); | |||
/** | |||
* Get verify action | |||
* | |||
* @param id | |||
* id of the object to be verified | |||
* @return Action for verifying the object, or {@code null} if the server | |||
@@ -79,11 +85,13 @@ public interface LargeFileRepository { | |||
public @Nullable Response.Action getVerifyAction(AnyLongObjectId id); | |||
/** | |||
* Get size of an object | |||
* | |||
* @param id | |||
* id of the object | |||
* @return length of the object content in bytes, -1 if the object doesn't | |||
* exist | |||
* @throws IOException | |||
* @throws java.io.IOException | |||
*/ | |||
public long getSize(AnyLongObjectId id) throws IOException; | |||
} |
@@ -52,6 +52,8 @@ public class LfsObject { | |||
long size; | |||
/** | |||
* Get the <code>oid</code> of this object. | |||
* | |||
* @return the object ID. | |||
*/ | |||
public String getOid() { | |||
@@ -59,6 +61,8 @@ public class LfsObject { | |||
} | |||
/** | |||
* Get the <code>size</code> of this object. | |||
* | |||
* @return the object size. | |||
*/ | |||
public long getSize() { |
@@ -112,30 +112,29 @@ public abstract class LfsProtocolServlet extends HttpServlet { | |||
* the request | |||
* @param path | |||
* the path | |||
* | |||
* @return the large file repository storing large files. | |||
* @throws LfsException | |||
* @throws org.eclipse.jgit.lfs.errors.LfsException | |||
* implementations should throw more specific exceptions to | |||
* signal which type of error occurred: | |||
* <dl> | |||
* <dt>{@link LfsValidationError}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsValidationError}</dt> | |||
* <dd>when there is a validation error with one or more of the | |||
* objects in the request</dd> | |||
* <dt>{@link LfsRepositoryNotFound}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsRepositoryNotFound}</dt> | |||
* <dd>when the repository does not exist for the user</dd> | |||
* <dt>{@link LfsRepositoryReadOnly}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsRepositoryReadOnly}</dt> | |||
* <dd>when the user has read, but not write access. Only | |||
* applicable when the operation in the request is "upload"</dd> | |||
* <dt>{@link LfsRateLimitExceeded}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsRateLimitExceeded}</dt> | |||
* <dd>when the user has hit a rate limit with the server</dd> | |||
* <dt>{@link LfsBandwidthLimitExceeded}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsBandwidthLimitExceeded}</dt> | |||
* <dd>when the bandwidth limit for the user or repository has | |||
* been exceeded</dd> | |||
* <dt>{@link LfsInsufficientStorage}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsInsufficientStorage}</dt> | |||
* <dd>when there is insufficient storage on the server</dd> | |||
* <dt>{@link LfsUnavailable}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsUnavailable}</dt> | |||
* <dd>when LFS is not available</dd> | |||
* <dt>{@link LfsException}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsException}</dt> | |||
* <dd>when an unexpected internal server error occurred</dd> | |||
* </dl> | |||
* @since 4.5 | |||
@@ -157,30 +156,29 @@ public abstract class LfsProtocolServlet extends HttpServlet { | |||
* the path | |||
* @param auth | |||
* the Authorization HTTP header | |||
* | |||
* @return the large file repository storing large files. | |||
* @throws LfsException | |||
* @throws org.eclipse.jgit.lfs.errors.LfsException | |||
* implementations should throw more specific exceptions to | |||
* signal which type of error occurred: | |||
* <dl> | |||
* <dt>{@link LfsValidationError}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsValidationError}</dt> | |||
* <dd>when there is a validation error with one or more of the | |||
* objects in the request</dd> | |||
* <dt>{@link LfsRepositoryNotFound}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsRepositoryNotFound}</dt> | |||
* <dd>when the repository does not exist for the user</dd> | |||
* <dt>{@link LfsRepositoryReadOnly}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsRepositoryReadOnly}</dt> | |||
* <dd>when the user has read, but not write access. Only | |||
* applicable when the operation in the request is "upload"</dd> | |||
* <dt>{@link LfsRateLimitExceeded}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsRateLimitExceeded}</dt> | |||
* <dd>when the user has hit a rate limit with the server</dd> | |||
* <dt>{@link LfsBandwidthLimitExceeded}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsBandwidthLimitExceeded}</dt> | |||
* <dd>when the bandwidth limit for the user or repository has | |||
* been exceeded</dd> | |||
* <dt>{@link LfsInsufficientStorage}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsInsufficientStorage}</dt> | |||
* <dd>when there is insufficient storage on the server</dd> | |||
* <dt>{@link LfsUnavailable}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsUnavailable}</dt> | |||
* <dd>when LFS is not available</dd> | |||
* <dt>{@link LfsException}</dt> | |||
* <dt>{@link org.eclipse.jgit.lfs.errors.LfsException}</dt> | |||
* <dd>when an unexpected internal server error occurred</dd> | |||
* </dl> | |||
* @since 4.7 | |||
@@ -241,6 +239,7 @@ public abstract class LfsProtocolServlet extends HttpServlet { | |||
} | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
protected void doPost(HttpServletRequest req, HttpServletResponse res) | |||
throws ServletException, IOException { |
@@ -71,11 +71,13 @@ public class FileLfsRepository implements LargeFileRepository { | |||
private final Path dir; | |||
/** | |||
* <p>Constructor for FileLfsRepository.</p> | |||
* | |||
* @param url | |||
* external URL of this repository | |||
* @param dir | |||
* storage directory | |||
* @throws IOException | |||
* @throws java.io.IOException | |||
*/ | |||
public FileLfsRepository(String url, Path dir) throws IOException { | |||
this.url = url; | |||
@@ -83,21 +85,25 @@ public class FileLfsRepository implements LargeFileRepository { | |||
Files.createDirectories(dir); | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public Response.Action getDownloadAction(AnyLongObjectId id) { | |||
return getAction(id); | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public Action getUploadAction(AnyLongObjectId id, long size) { | |||
return getAction(id); | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public @Nullable Action getVerifyAction(AnyLongObjectId id) { | |||
return null; | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public long getSize(AnyLongObjectId id) throws IOException { | |||
Path p = getPath(id); |
@@ -79,6 +79,8 @@ public class FileLfsServlet extends HttpServlet { | |||
private final long timeout; | |||
/** | |||
* <p>Constructor for FileLfsServlet.</p> | |||
* | |||
* @param repository | |||
* the repository storing the large objects | |||
* @param timeout | |||
@@ -90,16 +92,9 @@ public class FileLfsServlet extends HttpServlet { | |||
} | |||
/** | |||
* Handles object downloads | |||
* {@inheritDoc} | |||
* | |||
* @param req | |||
* servlet request | |||
* @param rsp | |||
* servlet response | |||
* @throws ServletException | |||
* if a servlet-specific error occurs | |||
* @throws IOException | |||
* if an I/O error occurs | |||
* Handle object downloads | |||
*/ | |||
@Override | |||
protected void doGet(HttpServletRequest req, | |||
@@ -129,9 +124,9 @@ public class FileLfsServlet extends HttpServlet { | |||
* servlet response | |||
* @return object id, or <code>null</code> if the object id could not be | |||
* retrieved | |||
* @throws IOException | |||
* @throws java.io.IOException | |||
* if an I/O error occurs | |||
* @since 4.6 | |||
* @since 4.6 | |||
*/ | |||
protected AnyLongObjectId getObjectToTransfer(HttpServletRequest req, | |||
HttpServletResponse rsp) throws IOException { | |||
@@ -151,16 +146,9 @@ public class FileLfsServlet extends HttpServlet { | |||
} | |||
/** | |||
* Handle object uploads | |||
* {@inheritDoc} | |||
* | |||
* @param req | |||
* servlet request | |||
* @param rsp | |||
* servlet response | |||
* @throws ServletException | |||
* if a servlet-specific error occurs | |||
* @throws IOException | |||
* if an I/O error occurs | |||
* Handle object uploads | |||
*/ | |||
@Override | |||
protected void doPut(HttpServletRequest req, | |||
@@ -183,7 +171,7 @@ public class FileLfsServlet extends HttpServlet { | |||
* HTTP status code | |||
* @param message | |||
* error message | |||
* @throws IOException | |||
* @throws java.io.IOException | |||
* on failure to send the response | |||
* @since 4.6 | |||
*/ |
@@ -83,6 +83,8 @@ public class ObjectDownloadListener implements WriteListener { | |||
private final ByteBuffer buffer = ByteBuffer.allocateDirect(8192); | |||
/** | |||
* <p>Constructor for ObjectDownloadListener.</p> | |||
* | |||
* @param repository | |||
* the repository storing large objects | |||
* @param context | |||
@@ -91,7 +93,7 @@ public class ObjectDownloadListener implements WriteListener { | |||
* the servlet response | |||
* @param id | |||
* id of the object to be downloaded | |||
* @throws IOException | |||
* @throws java.io.IOException | |||
*/ | |||
public ObjectDownloadListener(FileLfsRepository repository, | |||
AsyncContext context, HttpServletResponse response, | |||
@@ -108,9 +110,9 @@ public class ObjectDownloadListener implements WriteListener { | |||
} | |||
/** | |||
* Write file content | |||
* {@inheritDoc} | |||
* | |||
* @throws IOException | |||
* Write file content | |||
*/ | |||
@Override | |||
public void onWritePossible() throws IOException { | |||
@@ -134,10 +136,9 @@ public class ObjectDownloadListener implements WriteListener { | |||
} | |||
/** | |||
* Handle errors | |||
* {@inheritDoc} | |||
* | |||
* @param e | |||
* the cause | |||
* Handle errors | |||
*/ | |||
@Override | |||
public void onError(Throwable e) { |
@@ -88,14 +88,20 @@ public class ObjectUploadListener implements ReadListener { | |||
private final ByteBuffer buffer = ByteBuffer.allocateDirect(8192); | |||
/** | |||
* Constructor for ObjectUploadListener. | |||
* | |||
* @param repository | |||
* the repository storing large objects | |||
* @param context | |||
* a {@link javax.servlet.AsyncContext} object. | |||
* @param request | |||
* a {@link javax.servlet.http.HttpServletRequest} object. | |||
* @param response | |||
* a {@link javax.servlet.http.HttpServletResponse} object. | |||
* @param id | |||
* @throws FileNotFoundException | |||
* @throws IOException | |||
* a {@link org.eclipse.jgit.lfs.lib.AnyLongObjectId} object. | |||
* @throws java.io.FileNotFoundException | |||
* @throws java.io.IOException | |||
*/ | |||
public ObjectUploadListener(FileLfsRepository repository, | |||
AsyncContext context, HttpServletRequest request, | |||
@@ -111,9 +117,9 @@ public class ObjectUploadListener implements ReadListener { | |||
} | |||
/** | |||
* Writes all the received data to the output channel | |||
* {@inheritDoc} | |||
* | |||
* @throws IOException | |||
* Writes all the received data to the output channel | |||
*/ | |||
@Override | |||
public void onDataAvailable() throws IOException { | |||
@@ -133,16 +139,16 @@ public class ObjectUploadListener implements ReadListener { | |||
} | |||
} | |||
/** | |||
* @throws IOException | |||
*/ | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void onAllDataRead() throws IOException { | |||
close(); | |||
} | |||
/** | |||
* @throws IOException | |||
* Close resources held by this listener | |||
* | |||
* @throws java.io.IOException | |||
*/ | |||
protected void close() throws IOException { | |||
try { | |||
@@ -156,10 +162,7 @@ public class ObjectUploadListener implements ReadListener { | |||
} | |||
} | |||
/** | |||
* @param e | |||
* the exception that caused the problem | |||
*/ | |||
/** {@inheritDoc} */ | |||
@Override | |||
public void onError(Throwable e) { | |||
try { |
@@ -52,8 +52,9 @@ import com.google.gson.JsonIOException; | |||
import com.google.gson.JsonSyntaxException; | |||
/** | |||
* Wrapper for {@link Gson} used by LFS servlets. | |||
* Wrapper for {@link com.google.gson.Gson} used by LFS servlets. | |||
* | |||
* @since 4.10.0 | |||
*/ | |||
public class LfsGson { | |||
private static final Gson gson = new GsonBuilder() | |||
@@ -78,10 +79,10 @@ public class LfsGson { | |||
* @param src | |||
* the object for which Json representation is to be created. If | |||
* this is a String, it is wrapped in an instance of | |||
* {@link Error}. | |||
* {@link org.eclipse.jgit.lfs.server.internal.LfsGson.Error}. | |||
* @param writer | |||
* Writer to which the Json representation needs to be written | |||
* @throws JsonIOException | |||
* @throws com.google.gson.JsonIOException | |||
* if there was a problem writing to the writer | |||
* @see Gson#toJson(Object, Appendable) | |||
*/ | |||
@@ -104,11 +105,13 @@ public class LfsGson { | |||
* @param classOfT | |||
* specified type to deserialize | |||
* @return an Object of type T | |||
* @throws JsonIOException | |||
* @throws com.google.gson.JsonIOException | |||
* if there was a problem reading from the Reader | |||
* @throws JsonSyntaxException | |||
* @throws com.google.gson.JsonSyntaxException | |||
* if json is not a valid representation for an object of type | |||
* @see Gson#fromJson(Reader, java.lang.reflect.Type) | |||
* @param <T> | |||
* a T object. | |||
*/ | |||
public static <T> T fromJson(Reader json, Class<T> classOfT) | |||
throws JsonSyntaxException, JsonIOException { |
@@ -51,6 +51,8 @@ import org.eclipse.jgit.nls.TranslationBundle; | |||
public class LfsServerText extends TranslationBundle { | |||
/** | |||
* Get an instance of this translation bundle | |||
* | |||
* @return an instance of this translation bundle | |||
*/ | |||
public static LfsServerText get() { |
@@ -58,6 +58,8 @@ public class S3Config { | |||
private final boolean disableSslVerify; | |||
/** | |||
* <p>Constructor for S3Config.</p> | |||
* | |||
* @param region | |||
* AWS region | |||
* @param bucket | |||
@@ -88,6 +90,8 @@ public class S3Config { | |||
} | |||
/** | |||
* Get the <code>region</code>. | |||
* | |||
* @return Get name of AWS region this bucket resides in | |||
*/ | |||
public String getRegion() { | |||
@@ -95,6 +99,8 @@ public class S3Config { | |||
} | |||
/** | |||
* Get the <code>bucket</code>. | |||
* | |||
* @return Get S3 storage bucket name | |||
*/ | |||
public String getBucket() { | |||
@@ -102,6 +108,8 @@ public class S3Config { | |||
} | |||
/** | |||
* Get the <code>storageClass</code>. | |||
* | |||
* @return S3 storage class to use for objects stored in this bucket | |||
*/ | |||
public String getStorageClass() { | |||
@@ -109,6 +117,8 @@ public class S3Config { | |||
} | |||
/** | |||
* Get the <code>accessKey</code>. | |||
* | |||
* @return access key for authenticating to AWS | |||
*/ | |||
public String getAccessKey() { | |||
@@ -116,6 +126,8 @@ public class S3Config { | |||
} | |||
/** | |||
* Get the <code>secretKey</code>. | |||
* | |||
* @return secret key for authenticating to AWS | |||
*/ | |||
public String getSecretKey() { | |||
@@ -123,6 +135,8 @@ public class S3Config { | |||
} | |||
/** | |||
* Get the <code>expirationSeconds</code>. | |||
* | |||
* @return period in seconds after which requests signed for this bucket | |||
* will expire | |||
*/ |
@@ -91,6 +91,7 @@ public class S3Repository implements LargeFileRepository { | |||
this.s3Config = config; | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public Response.Action getDownloadAction(AnyLongObjectId oid) { | |||
URL endpointUrl = getObjectUrl(oid); | |||
@@ -107,6 +108,7 @@ public class S3Repository implements LargeFileRepository { | |||
return a; | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public Response.Action getUploadAction(AnyLongObjectId oid, long size) { | |||
cacheObjectMetaData(oid, size); | |||
@@ -126,11 +128,13 @@ public class S3Repository implements LargeFileRepository { | |||
return a; | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public Action getVerifyAction(AnyLongObjectId id) { | |||
return null; // TODO(ms) implement this | |||
} | |||
/** {@inheritDoc} */ | |||
@Override | |||
public long getSize(AnyLongObjectId oid) throws IOException { | |||
URL endpointUrl = getObjectUrl(oid); |