Add mediatype text/query-cql
diff --git a/src/main/java/de/mannheim/ids/sruws/SRU_WS.java b/src/main/java/de/mannheim/ids/sruws/SRU_WS.java
index 9748aeb..fa7d21d 100644
--- a/src/main/java/de/mannheim/ids/sruws/SRU_WS.java
+++ b/src/main/java/de/mannheim/ids/sruws/SRU_WS.java
@@ -26,6 +26,7 @@
import javax.xml.stream.events.XMLEvent;
import org.apache.http.HttpEntity;
+import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
@@ -108,7 +109,11 @@
String query = req.getParameter("query");
String max = req.getParameter("maximumRecords");
- if (endpoint == null || endpoint.isEmpty()){
+ if (!req.getHeader(HttpHeaders.ACCEPT).equals("text/query-cql")){
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "Only Accept request-header of mediatype 'text/query-cql' is accepted.");
+ }
+ else if (endpoint == null || endpoint.isEmpty()){
resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Endpoint parameter cannot be empty.");
}
@@ -118,7 +123,7 @@
}
else if (query == null || query.isEmpty()){
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Query cannot be empty.");
- }
+ }
else if (max == null || max.isEmpty() || max.equals("0")){
resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
"The maximumRecords must be specified greater than 0.");
diff --git a/src/test/java/TestClient.java b/src/test/java/TestClient.java
deleted file mode 100644
index 07624d9..0000000
--- a/src/test/java/TestClient.java
+++ /dev/null
@@ -1,42 +0,0 @@
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.ClientProtocolException;
-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.HttpClients;
-import org.apache.http.message.BasicNameValuePair;
-import org.junit.Test;
-
-
-public class TestClient {
-
- @Test
- public void testPost() throws IOException{
- String url = "http://localhost:8080/SRU-WS/";
- HttpClient client = HttpClients.createDefault();
- HttpPost post = new HttpPost(url);
-
- List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
- urlParameters.add(new BasicNameValuePair("query", "rot"));
- urlParameters.add(new BasicNameValuePair("maximumRecords", "5"));
- urlParameters.add(new BasicNameValuePair("endpoint", "korap"));
- post.setEntity(new UrlEncodedFormEntity(urlParameters));
-
- HttpResponse response = client.execute(post);
- //System.out.println("Sending 'POST' request to URL : " + url);
- //System.out.println("Post parameters : " + post.getEntity());
- //System.out.println("Response Code : " +
- // response.getStatusLine().getStatusCode());
- if (response.getStatusLine().getStatusCode() != 200){
- System.out.println("Response Code : " +
- response.getStatusLine().getReasonPhrase());
- }
-
- }
-}
diff --git a/src/test/java/de/mannheim/ids/sruws/test/TestClient.java b/src/test/java/de/mannheim/ids/sruws/test/TestClient.java
new file mode 100644
index 0000000..ee14d32
--- /dev/null
+++ b/src/test/java/de/mannheim/ids/sruws/test/TestClient.java
@@ -0,0 +1,53 @@
+package de.mannheim.ids.sruws.test;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+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.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+
+public class TestClient {
+
+ public static void main(String arg[]) throws IOException{
+ String url =
+ "http://localhost:8080/SRU-WS/";
+ //"http://clarin.ids-mannheim.de/sruws/";
+
+ HttpClient client = HttpClients.createDefault();
+ HttpPost post = new HttpPost(url);
+ post.setHeader(HttpHeaders.ACCEPT,"text/query-ddc");
+
+ List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
+ urlParameters.add(new BasicNameValuePair("query", "rot"));
+ urlParameters.add(new BasicNameValuePair("maximumRecords", "5"));
+ urlParameters.add(new BasicNameValuePair("endpoint", "korap"));
+ post.setEntity(new UrlEncodedFormEntity(urlParameters));
+
+ HttpResponse response = client.execute(post);
+ System.out.println("Sending 'POST' request to URL : " + url);
+ System.out.println("Post parameters : " + post.getEntity());
+ System.out.println("Response Code : " +
+ response.getStatusLine().getStatusCode());
+ if (response.getStatusLine().getStatusCode() != 200){
+ System.out.println("Response Code : " +
+ response.getStatusLine().getReasonPhrase());
+ }
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ response.getEntity().getContent()));
+ String line;
+ while ((line = reader.readLine()) != null){
+ System.out.println(line);
+ }
+
+ }
+}