Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commons-fileupload and null checks #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.hp.hpl.jena</groupId>
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/swordapp/server/AtomStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void writeTo(Writer out)
entry.setSummary("Original Deposit");
entry.setUpdated(new Date());

entry.setContent(new IRI(deposit.getUri()), deposit.getMediaType());
if (deposit.getMediaType() != null)
entry.setContent(new IRI(deposit.getUri()), deposit.getMediaType());
entry.addCategory(UriRegistry.SWORD_TERMS_NAMESPACE, UriRegistry.SWORD_ORIGINAL_DEPOSIT, "Original Deposit");
if (deposit.getDepositedOn() != null)
{
Expand All @@ -102,9 +103,11 @@ public void writeTo(Writer out)
entry.addSimpleExtension(new QName(UriRegistry.SWORD_DEPOSITED_BY), deposit.getDepositedBy());
}

for (String packaging : deposit.getPackaging())
{
entry.addSimpleExtension(UriRegistry.SWORD_PACKAGING, packaging);
if (deposit.getPackaging() != null) {
for (String packaging : deposit.getPackaging())
{
entry.addSimpleExtension(UriRegistry.SWORD_PACKAGING, packaging);
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/swordapp/server/MediaResourceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ public void get(HttpServletRequest req, HttpServletResponse resp, boolean sendBo
{
OutputStream out = resp.getOutputStream();
InputStream in = resource.getInputStream();
this.copyInputToOutput(in, out);
out.flush();
in.close();
try {
this.copyInputToOutput(in, out);
out.flush();
} finally {
if (in != null)
in.close();
}
}
}
catch (SwordError se)
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/swordapp/server/SwordAPIEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import org.apache.abdera.model.Entry;
import org.apache.abdera.parser.Parser;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.ParameterParser;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -254,8 +254,8 @@ protected void addDepositPropertiesFromMultipart(Deposit deposit, HttpServletReq
throws ServletException, IOException, SwordError
{
// Parse the request for files (using the fileupload commons library)
List<DiskFileItem> items = this.getPartsFromRequest(req);
for (DiskFileItem item : items)
List<FileItem> items = this.getPartsFromRequest(req);
for (FileItem item : items)
{
// find out which part we are looking at
String contentDisposition = item.getHeaders().getHeader("Content-Disposition");
Expand Down Expand Up @@ -453,7 +453,7 @@ protected String getContentDispositionValue(String contentDisposition, String ke
return parameters.get(key);
}

protected List<DiskFileItem> getPartsFromRequest(HttpServletRequest request)
protected List<FileItem> getPartsFromRequest(HttpServletRequest request)
throws ServletException
{
try
Expand All @@ -465,7 +465,7 @@ protected List<DiskFileItem> getPartsFromRequest(HttpServletRequest request)
ServletFileUpload upload = new ServletFileUpload(factory);

// Parse the request
List<DiskFileItem> items = upload.parseRequest(request);
List<FileItem> items = upload.parseRequest(request);

return items;
}
Expand Down