Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #50 from fcrepo4/missing-baseURI-error
Parsing baseURI and returning 400 Bad Request if blank/invalid/etc.
  • Loading branch information
Andrew Woods committed Aug 13, 2014
2 parents 1ae653d + 71993fb commit bea6e80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Expand Up @@ -19,6 +19,8 @@
import org.slf4j.Logger;

import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand All @@ -28,7 +30,6 @@
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


import org.fcrepo.indexer.IndexerGroup;

/**
Expand Down Expand Up @@ -59,12 +60,21 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
final String recurParam = request.getParameter("recursive");
final boolean recursive = (recurParam == null || recurParam.equals("true"));
final String baseURI = request.getParameter("baseURI");
indexer.reindex( baseURI, recursive );

String message;
try {
final URL url = new URL( baseURI );
indexer.reindex( url.toString(), recursive );
message = "Reindexing started";
} catch ( MalformedURLException ex ) {
message = "Error: the baseURI parameter must be specified";
response.setStatus(response.SC_BAD_REQUEST);
}

try {
response.setContentType("text/plain");
final PrintWriter out = response.getWriter();
out.println("Reindexing started");
out.println(message);
} catch ( Exception ex ) {
LOGGER.warn("Error sending output");
}
Expand Down
Expand Up @@ -26,14 +26,15 @@
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

/**
* @author Esmé Cowles
* Date: April 08, 2014
* @since 2014-04-08
*/
public class FedoraIndexerIT {

Expand All @@ -58,7 +59,8 @@ public class FedoraIndexerIT {
private static final String repoAddress = "http://" + HOSTNAME + ":" +
SERVER_PORT + "/f4/rest/";

private static HttpClient client = new DefaultHttpClient();
private static HttpClient client = HttpClients.custom()
.setConnectionManager(new PoolingHttpClientConnectionManager()).build();

@Test
public void testReindex() throws IOException {
Expand All @@ -71,4 +73,11 @@ public void testReindex() throws IOException {
//substring required for OS specific differences
assertEquals("Reindexing started".substring(0,18), EntityUtils.toString(response.getEntity()).substring(0,18));
}

@Test
public void testReindexWithoutBaseURI() throws IOException {
final HttpPost reindex = new HttpPost(serverAddress + "/reindex/");
final HttpResponse response = client.execute(reindex);
assertEquals(400, response.getStatusLine().getStatusCode());
}
}

0 comments on commit bea6e80

Please sign in to comment.