summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Schwabe2014-04-30 11:49:53 +0200
committerNils Schwabe2014-04-30 11:49:53 +0200
commit4e410ed8de6b7bfaa26fc37a933de42a2f827dc9 (patch)
tree8589f509c072fcf77d973fb095a98ea59f30b232
parentAdd check file size of uploading files and process automatically (diff)
downloadmasterserver-4e410ed8de6b7bfaa26fc37a933de42a2f827dc9.tar.gz
masterserver-4e410ed8de6b7bfaa26fc37a933de42a2f827dc9.tar.xz
masterserver-4e410ed8de6b7bfaa26fc37a933de42a2f827dc9.zip
Add some new exceptions for problems with image's data
-rw-r--r--src/main/java/org/openslx/imagemaster/server/ApiServer.java18
-rw-r--r--src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java9
-rw-r--r--src/main/thrift/imagemaster.thrift18
3 files changed, 31 insertions, 14 deletions
diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
index 4080f75..8dd72f8 100644
--- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java
+++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
@@ -23,6 +23,8 @@ import org.openslx.imagemaster.thrift.iface.AuthorizationError;
import org.openslx.imagemaster.thrift.iface.AuthorizationException;
import org.openslx.imagemaster.thrift.iface.FtpCredentials;
import org.openslx.imagemaster.thrift.iface.ImageData;
+import org.openslx.imagemaster.thrift.iface.ImageDataError;
+import org.openslx.imagemaster.thrift.iface.ImageDataException;
import org.openslx.imagemaster.thrift.iface.InvalidTokenException;
import org.openslx.imagemaster.thrift.iface.ServerAuthenticationError;
import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException;
@@ -94,8 +96,7 @@ public class ApiServer
* @throws TException
*/
public static FtpCredentials submitImage( String serverSessionId,
- ImageData imageDescription ) throws AuthorizationException,
- TException
+ ImageData imageDescription ) throws AuthorizationException, ImageDataException
{
if ( ServerSessionManager.getSession( serverSessionId ) == null ) {
throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "No valid serverSessionData" );
@@ -111,7 +112,7 @@ public class ApiServer
if ( !ImageProcessor.addImageDataToProcess( imageDescription, ftpCredentials.username ) ) {
App.ftpServer.removeUser( serverSessionId );
- throw new TException( "ImageData is not valid." );
+ throw new ImageDataException( ImageDataError.INVALID_DATA, "ImageData is not valid." );
}
return ftpCredentials;
@@ -170,21 +171,26 @@ public class ApiServer
* @param ftpUser the user that was used to upload
* @param imageDescription the description of the uploaded image
* @return if nothing went wrong
+ * @throws ImageDataException if image was not submitted before
* @throws AuthorizationException if no valid session exists
*/
- public static boolean finishedUpload( String ftpUser, ImageData imageDescription )
+ public static boolean finishedUpload( String ftpUser, ImageData imageDescription ) throws ImageDataException
{
// check if user is valid
synchronized ( App.ftpServer.users ) {
- if (!App.ftpServer.users.containsKey( ftpUser )) return false;
+ if (!App.ftpServer.users.containsKey( ftpUser )) {
+ throw new ImageDataException( ImageDataError.UNKNOWN_IMAGE, "Image with this data was not submitted before." );
+ }
}
// process the image
File userDirectory = new File( Globals.getPropertyString( Globals.PropString.FTPBASEDIR ) + "/" + ftpUser );
File[] list = userDirectory.listFiles();
- if ( list.length != 1 )
+ if ( list.length != 1 ) {
+ // user uploaded too many files
return false;
+ }
log.info( ftpUser + " is done with upload" );
diff --git a/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java b/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
index d6bd59e..d3db11e 100644
--- a/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
+++ b/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
@@ -9,8 +9,10 @@ import org.openslx.imagemaster.thrift.iface.AuthenticationException;
import org.openslx.imagemaster.thrift.iface.AuthorizationException;
import org.openslx.imagemaster.thrift.iface.FtpCredentials;
import org.openslx.imagemaster.thrift.iface.ImageData;
+import org.openslx.imagemaster.thrift.iface.ImageDataException;
import org.openslx.imagemaster.thrift.iface.ImageServer;
import org.openslx.imagemaster.thrift.iface.InvalidTokenException;
+import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException;
import org.openslx.imagemaster.thrift.iface.ServerSessionData;
import org.openslx.imagemaster.thrift.iface.SessionData;
import org.openslx.imagemaster.thrift.iface.UserInfo;
@@ -44,7 +46,7 @@ public class ImageServerHandler implements ImageServer.Iface
@Override
public String startServerAuthentication( String organization )
- throws TException
+ throws ServerAuthenticationException
{
return ApiServer.startServerAuthentication( organization );
}
@@ -59,14 +61,13 @@ public class ImageServerHandler implements ImageServer.Iface
@Override
public FtpCredentials submitImage( String serverSessionId,
- ImageData imageDescription ) throws AuthorizationException,
- TException
+ ImageData imageDescription ) throws AuthorizationException, ImageDataException
{
return ApiServer.submitImage( serverSessionId, imageDescription );
}
@Override
- public boolean finshedUpload( String ftpUser, ImageData imageDescription )
+ public boolean finshedUpload( String ftpUser, ImageData imageDescription ) throws ImageDataException
{
return ApiServer.finishedUpload( ftpUser, imageDescription );
}
diff --git a/src/main/thrift/imagemaster.thrift b/src/main/thrift/imagemaster.thrift
index 3171416..97f4f27 100644
--- a/src/main/thrift/imagemaster.thrift
+++ b/src/main/thrift/imagemaster.thrift
@@ -26,7 +26,12 @@ enum AuthenticationError {
enum ServerAuthenticationError {
GENERIC_ERROR,
INVALID_ORGANIZATION,
- BANNED_NETWORK,
+ BANNED_NETWORK
+}
+
+enum ImageDataError {
+ INVALID_DATA,
+ UNKNOWN_IMAGE
}
exception AuthorizationException {
@@ -47,6 +52,11 @@ exception ServerAuthenticationException {
2: string message
}
+exception ImageDataException {
+ 1: ImageDataError number,
+ 2: string message
+}
+
struct UserInfo {
1: string userId,
2: string firstName,
@@ -92,13 +102,13 @@ service ImageServer {
UserInfo getUserFromToken(1:Token token) throws (1:InvalidTokenException failure),
- string startServerAuthentication(1:string organization),
+ string startServerAuthentication(1:string organization) throws (1: ServerAuthenticationException failure),
ServerSessionData serverAuthenticate(1:string organization, 2:binary challengeResponse) throws (1:ServerAuthenticationException failure),
- FtpCredentials submitImage(1:string serverSessionId, 2:ImageData imageDescription) throws (1:AuthorizationException failure),
+ FtpCredentials submitImage(1:string serverSessionId, 2:ImageData imageDescription) throws (1:AuthorizationException failure, 2: ImageDataException failure2),
- bool finshedUpload(1:string ftpUser, 2:ImageData imageDescription)
+ bool finshedUpload(1:string ftpUser, 2:ImageData imageDescription) throws (1: ImageDataException failure)
}