Skip to content

Commit

Permalink
Merge pull request #3 from dharmsheta/master
Browse files Browse the repository at this point in the history
JENKINS-17152 Large file upload fails using collabnet plugin
  • Loading branch information
jmcnally committed May 16, 2013
2 parents 27bddec + 8b70a7a commit 3b8b2a8
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/main/java/com/collabnet/ce/webservices/CollabNetApp.java
Expand Up @@ -10,6 +10,7 @@
import com.collabnet.ce.soap50.webservices.cemain.UserSoapRow;
import com.collabnet.ce.soap50.webservices.docman.IDocumentAppSoap;
import com.collabnet.ce.soap50.webservices.filestorage.IFileStorageAppSoap;
import com.collabnet.ce.soap50.webservices.filestorage.ISimpleFileStorageAppSoap;
import com.collabnet.ce.soap50.webservices.frs.IFrsAppSoap;
import com.collabnet.ce.soap50.webservices.rbac.IRbacAppSoap;
import com.collabnet.ce.soap50.webservices.scm.IScmAppSoap;
Expand All @@ -30,6 +31,8 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.rmi.RemoteException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -50,12 +53,15 @@
public class CollabNetApp {
private static Logger logger = Logger.getLogger(CollabNetApp.class);
public static String SOAP_SERVICE = "/ce-soap50/services/";
public static final int UPLOAD_FILE_CHUNK_SIZE = 780000;
public static final long MAX_FILE_STORAGE_APP_UPLOAD_SIZE = 130023424;
private String sessionId;
private String username;
private String url;
protected final ICollabNetSoap icns;
private volatile IFrsAppSoap ifrs;
private volatile IFileStorageAppSoap ifsa;
private volatile ISimpleFileStorageAppSoap isfsa;
private volatile ITrackerAppSoap itas;
private volatile IDocumentAppSoap idas;
private volatile IScmAppSoap isas;
Expand Down Expand Up @@ -151,6 +157,12 @@ protected IFileStorageAppSoap getFileStorageAppSoap() {
return ifsa;
}

protected ISimpleFileStorageAppSoap getSimpleFileStorageAppSoap() {
if (isfsa==null)
isfsa = createProxy(ISimpleFileStorageAppSoap.class, "SimpleFileStorageAppSoap");
return isfsa;
}

/**
* Returns the user name that this connection is set up with.
*/
Expand Down Expand Up @@ -229,12 +241,36 @@ public CTFFile upload(DataHandler src) throws RemoteException {
return new CTFFile(this,this.getFileStorageAppSoap().uploadFile(getSessionId(),src));
}

public CTFFile uploadLargeFile(File src) throws RemoteException {
String fieldId = this.getSimpleFileStorageAppSoap().startFileUpload(getSessionId());
byte[] buffer = new byte[UPLOAD_FILE_CHUNK_SIZE];
try {
InputStream fileInputStream = new FileDataSource(src).getInputStream();
while (true) {
int count = fileInputStream.read(buffer);
if (count==-1) {
break;
}
this.getSimpleFileStorageAppSoap().write(getSessionId(), fieldId, buffer);
}
this.getSimpleFileStorageAppSoap().endFileUpload(getSessionId(), fieldId);
fileInputStream.close();
} catch (IOException e) {
throw new Error(e);
}
return new CTFFile(this, fieldId);
}

/**
* Uploads a file. The returned file object can be then used as an input
* to methods like {@link CTFRelease#addFile(String, String, CTFFile)}.
*/
public CTFFile upload(File src) throws RemoteException {
return upload(new DataHandler(new FileDataSource(src)));
if (src.length() > MAX_FILE_STORAGE_APP_UPLOAD_SIZE) {
return uploadLargeFile(src);
} else {
return upload(new DataHandler(new FileDataSource(src)));
}
}

/**
Expand Down

0 comments on commit 3b8b2a8

Please sign in to comment.