migrate to jersey for an easy wadl generator, 
add sentences and keywords positions
diff --git a/src/main/java/de/mannheim/ids/sruws/Corpus.java b/src/main/java/de/mannheim/ids/sruws/Corpus.java
index b980e15..3d80def 100644
--- a/src/main/java/de/mannheim/ids/sruws/Corpus.java
+++ b/src/main/java/de/mannheim/ids/sruws/Corpus.java
@@ -3,19 +3,27 @@
 import java.util.ArrayList;
 import java.util.List;
 
-public class Corpus {
+public class Corpus {	
 	String name;
 	String pid;
-	List<String[]> tokenizedSentences;
+	List<Sentence> sentences;
 	
 	public Corpus(String pid, String name) {
 		this.pid = pid;
 		this.name = name;
-		tokenizedSentences =new ArrayList<String[]>();
+		this.sentences = new ArrayList<Sentence>();		
 	}
 	
-	public void addSentence(String sentence){
-		tokenizedSentences.add(sentence.split("\\s+"));
+	public List<Sentence> getSentences() {
+		return sentences;
+	}
+
+	public void setSentences(List<Sentence> sentences) {
+		this.sentences = sentences;
+	}
+
+	public void addSentence(Sentence s){
+		sentences.add(s);
 	}
 	
 	public String getName() {
@@ -30,13 +38,4 @@
 	public void setPid(String pid) {
 		this.pid = pid;
 	}
-	public List<String[]> getTokenizedSentences() {
-		return tokenizedSentences;
-	}
-	public void setTokenizedSentences(List<String[]> tokenizedSentences) {
-		this.tokenizedSentences = tokenizedSentences;
-	}
-
-	
-	
 }
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 fa7d21d..a58e14c 100644
--- a/src/main/java/de/mannheim/ids/sruws/SRU_WS.java
+++ b/src/main/java/de/mannheim/ids/sruws/SRU_WS.java
@@ -9,14 +9,24 @@
 import java.net.URISyntaxException;
 import java.net.URLDecoder;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
@@ -25,8 +35,8 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.events.XMLEvent;
 
+import org.apache.commons.lang3.ArrayUtils;
 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;
@@ -37,7 +47,6 @@
 import org.xml.sax.SAXException;
 
 import eu.clarin.weblicht.wlfxb.io.WLDObjector;
-import eu.clarin.weblicht.wlfxb.io.WLFormatException;
 import eu.clarin.weblicht.wlfxb.tc.api.MatchedCorpus;
 import eu.clarin.weblicht.wlfxb.tc.api.MatchesLayer;
 import eu.clarin.weblicht.wlfxb.tc.api.SentencesLayer;
@@ -50,12 +59,14 @@
  * @author margaretha
  * */
 
-public class SRU_WS extends HttpServlet{
+@Path("/")
+public class SRU_WS{
 	
 	private String endpointUri;
 	private String endpointBase = "de.mannheim.ids.sruws.endpoint.";
-	private String DUMMY_PID = "Wikipedia";
+	private Corpus defaultCorpus;
 	
+	private static final int DEFAULT_MAX_RECORDS = 10;
 	private static final String HITS_NS = "http://clarin.eu/fcs/dataview/hits";
     private static final String HITS_PREFIX = "hits";    
     private static final String FCS_NS = "http://clarin.eu/fcs/1.0";
@@ -65,11 +76,85 @@
         
     private static String CORPUS_LANG = "de";
     private static String QUERY_LANG = "CQL";   
-	private Map<String,Corpus> corpusList = new HashMap<String,Corpus>();
-    
-	private Logger logger = (Logger) LoggerFactory.getLogger(SRU_WS.class);
-	private SAXParserFactory factory = SAXParserFactory.newInstance();
-			
+	private Map<String,Corpus> corpusList;
+	private SAXParserFactory factory;
+	private Logger logger;
+	
+	@Context
+	ServletConfig config;	
+	
+	public SRU_WS() {
+		logger = (Logger) LoggerFactory.getLogger(SRU_WS.class);
+		factory = SAXParserFactory.newInstance();
+		corpusList = new HashMap<String,Corpus>();
+	}
+	
+	@GET
+	@Produces(MediaType.TEXT_XML)
+	public StreamingOutput doGet(@QueryParam("query") String query, 
+			@QueryParam("endpoint") String endpoint, 
+			@QueryParam("maximumRecords") int maximumRecords) throws IOException, ServletException{
+		return process(endpoint, query,  maximumRecords);
+	};
+	
+	@POST
+	@Produces(MediaType.TEXT_XML)
+	@Consumes("text/query-cql")
+	public StreamingOutput doPost(@QueryParam("query") String query, 
+			@QueryParam("endpoint") String endpoint, 
+			@QueryParam("maximumRecords") int maximumRecords) throws IOException, ServletException{
+		
+		return process(endpoint, query,  maximumRecords);				
+	}
+	
+	private StreamingOutput process(String endpoint, String query, int max) 
+			throws IOException, ServletException {		
+		
+		if (endpoint == null || endpoint.isEmpty()){
+			throw new WebApplicationException(
+					Response.status(Response.Status.BAD_REQUEST)
+							.entity("Endpoint parameter cannot be empty.")
+							.type(MediaType.TEXT_PLAIN).build());
+		}
+		else if (config.getInitParameter(endpointBase+endpoint) == null){
+			throw new WebApplicationException(
+					Response.status(Response.Status.BAD_REQUEST)
+							.entity("Endpoint URL for the endpoint parameter cannot be found.")
+							.type(MediaType.TEXT_PLAIN).build());
+		}
+		else if (query == null || query.isEmpty()){
+			throw new WebApplicationException(
+					Response.status(Response.Status.BAD_REQUEST)
+							.entity("Query cannot be empty.")
+							.type(MediaType.TEXT_PLAIN).build());
+		}
+					
+		if (max==0) max = DEFAULT_MAX_RECORDS;
+		
+		endpointUri = config.getInitParameter(endpointBase+endpoint);
+		logger.info("Endpoint URL {} ",endpointUri);
+		
+		generateCorpusList();
+		logger.info(query.toString());
+		
+		HttpGet getReq = createSearchRetrieveRequest(query, max);			
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse httpResponse = httpClient.execute(getReq);
+		HttpEntity httpEntity = httpResponse.getEntity();
+		BufferedInputStream bis = new BufferedInputStream(httpEntity.getContent());
+		
+		String text;
+		try {
+			text = readKwicInput(bis);
+			//logger.info(text);
+		} catch (XMLStreamException e) {				
+			throw new ServletException("XML streaming error");
+		}			
+		
+		return writeTCL(text, query);
+		
+	}
+	
 	private void generateCorpusList() throws IOException{
 		corpusList = new HashMap<String, Corpus>();
 		
@@ -94,106 +179,20 @@
 			SAXParser saxParser = factory.newSAXParser();
 			SRUScanResonseHandler handler = new SRUScanResonseHandler();
 			saxParser.parse(bis, handler);
-			corpusList = handler.getCorpora();
+			corpusList = handler.getCorpora();					
 			
 		} catch (ParserConfigurationException | SAXException e) {
 			e.printStackTrace();
 		}
-	}
 		
-	@Override
-	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
-			throws ServletException, IOException {
-						
-		String endpoint = req.getParameter("endpoint");
-		String query = req.getParameter("query");
-		String max = req.getParameter("maximumRecords");
-		
-		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.");
-		}
-		else if (getServletConfig().getInitParameter(endpointBase+endpoint) == null){
-			resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
-					"Endpoint parameter is incorrect.");
-		}
-		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.");
-		}
-		else{			
-			
-			endpointUri = getServletConfig().getInitParameter(endpointBase+endpoint);
-			logger.info("Endpoint URL {} ",endpointUri);		
-			
-			generateCorpusList();
-			
-			HttpGet getReq = createSearchRetrieveRequest(query, req.getParameter("maximumRecords"));			
-			CloseableHttpClient httpClient = HttpClients.createDefault();
-			CloseableHttpResponse httpResponse = httpClient.execute(getReq);
-			HttpEntity httpEntity = httpResponse.getEntity();
-			BufferedInputStream bis = new BufferedInputStream(httpEntity.getContent());
-			
-			//List<String[]> tokenizedSentences = new ArrayList<String[]>();
-			String text;
-			try {
-				//text = readInput(bis, tokenizedSentences);
-				text = readKwicInput(bis);
-				//logger.info(text);
-			} catch (XMLStreamException e) {				
-				throw new ServletException("XML streaming error");
-			}
-			
-			writeTCL(resp.getOutputStream(), text, query);
-			//writeTCL(resp.getOutputStream(), text, tokenizedSentences, query);
-		}
+		defaultCorpus = new Corpus(endpointUri, endpointUri);
+		corpusList.put(endpointUri, defaultCorpus);
 	}
-	
-	public void writeTCL(OutputStream out, String text, List<String[]> tokenizedSentences, String query){
-		TextCorpusStored textCorpus = new TextCorpusStored(CORPUS_LANG);
+			
+	private StreamingOutput writeTCL(String text, String query){
+		final TextCorpusStored textCorpus = new TextCorpusStored(CORPUS_LANG);
 		textCorpus.createTextLayer().addText(text);
-
-		TokensLayer tokensLayer = textCorpus.createTokensLayer();
-		SentencesLayer sentencesLayer = textCorpus.createSentencesLayer();	
-		MatchesLayer matchesLayer = textCorpus.createMatchesLayer(QUERY_LANG, query);
-		MatchedCorpus matchedCorpus = matchesLayer.addCorpus("Wikipedia", "WikiPID");
 		
-		List<Token> itemToken = new ArrayList<Token>();
-		for (int i=0; i<tokenizedSentences.size();i++){			
-			List<Token> sentenceTokens = new ArrayList<Token>();				
-			for (String tokenString : tokenizedSentences.get(i)) {
-				
-				Token token = tokensLayer.addToken(tokenString);
-				sentenceTokens.add(token);
-				
-				if (tokenString.equalsIgnoreCase(query)){
-					itemToken.add(token);
-				}
-			}
-			sentencesLayer.addSentence(sentenceTokens);
-			matchesLayer.addItem(matchedCorpus, itemToken);
-			itemToken.clear();
-		}
-		
-		WLData wlData = new WLData(textCorpus);
-		try {
-			WLDObjector.write(wlData, out);
-		} catch (WLFormatException e) {			
-			e.printStackTrace();
-		}
-	}
-	
-	public void writeTCL(OutputStream out, String text, String query){
-		TextCorpusStored textCorpus = new TextCorpusStored(CORPUS_LANG);
-		textCorpus.createTextLayer().addText(text);
-
 		TokensLayer tokensLayer = textCorpus.createTokensLayer();
 		SentencesLayer sentencesLayer = textCorpus.createSentencesLayer();	
 		MatchesLayer matchesLayer = textCorpus.createMatchesLayer(QUERY_LANG, query);
@@ -201,38 +200,49 @@
 		Corpus c;
 		MatchedCorpus matchedCorpus; 
 		for (String pid : corpusList.keySet()){
-			c = corpusList.get(pid);
-			if (c.getTokenizedSentences().size() == 0) continue;
+			c = corpusList.get(pid);			
+			//logger.info(pid);
+			List<Sentence> sentences = c.getSentences();
+			if (sentences.size() == 0) continue;
 			
-			matchedCorpus = matchesLayer.addCorpus(c.getName(), c.getPid());
-			
-			List<String[]> tokenizedSentences = c.getTokenizedSentences();
+			matchedCorpus = matchesLayer.addCorpus(c.getName(), c.getPid());			
 			List<Token> itemToken = new ArrayList<Token>();			
 			
-			for (int i=0; i<tokenizedSentences.size();i++){
+			for (Sentence sentence : sentences){								
+				List<Token> sentenceTokens = new ArrayList<Token>();
 				
-				List<Token> sentenceTokens = new ArrayList<Token>();				
-				for (String tokenString : tokenizedSentences.get(i)) {
+				String[] tokenStrings = sentence.getTokens();				
+				int[] keyIndexes = sentence.getKeyIndexes();				
+				
+				int j=0; // counter for keyIndexes				
+				for (int k = 0; k < tokenStrings.length; k++) {
 					
+					String tokenString = tokenStrings[k];
 					Token token = tokensLayer.addToken(tokenString);
-					sentenceTokens.add(token);
-					
-					if (tokenString.equalsIgnoreCase(query)){
-						itemToken.add(token);
+					sentenceTokens.add(token);	
+										
+					if (j < keyIndexes.length && keyIndexes[j] == k){
+						itemToken.add(j,token);
+						j++;
 					}
-				}
-				sentencesLayer.addSentence(sentenceTokens);
+				}		
+				
+				sentencesLayer.addSentence(sentenceTokens);		
 				matchesLayer.addItem(matchedCorpus, itemToken);
 				itemToken.clear();
 			}
 		}
 		
-		WLData wlData = new WLData(textCorpus);
-		try {
-			WLDObjector.write(wlData, out);
-		} catch (WLFormatException e) {			
-			e.printStackTrace();
-		}
+		return new StreamingOutput() {			
+			@Override
+			public void write(OutputStream output) throws IOException,
+					WebApplicationException {				
+				WLData wlData = new WLData(textCorpus);
+				WLDObjector.write(wlData, output);
+				output.flush();
+			}
+		};
+		
 	}
 	
 	private String readKwicInput(InputStream is) throws XMLStreamException, UnsupportedEncodingException{
@@ -259,12 +269,10 @@
 						String pid = reader.getAttributeValue(i);						
 						logger.info("Corpus: " + URLDecoder.decode(pid,"UTF-8"));						
 						c = corpusList.get(URLDecoder.decode(pid,"UTF-8"));
-						if (c == null) c = corpusList.get(DUMMY_PID);
-						//logger.info(c.getPid());
+						if (c == null) c = defaultCorpus;
 					}					
 				}
 			}
-				
 							
 			else if (e == XMLEvent.START_ELEMENT &&
 					reader.getLocalName().equals("kwic") ){
@@ -273,35 +281,38 @@
 			
 			else if (e == XMLEvent.START_ELEMENT &&
 					reader.getLocalName().equals("c") ){					
-				reader.next();
-				sb.append(reader.getText());
+				e = reader.next();
+				while (e == XMLEvent.CHARACTERS){
+					//logger.info("context: "+reader.getText());
+					sb.append(reader.getText());
+					e = reader.next();
+				}
 				sb.append(" ");
 			}				
 
 			else if (e == XMLEvent.START_ELEMENT &&
 					reader.getLocalName().equals("kw")){				
-				reader.next();
-				sb.append(reader.getText());
-				sb.append(" ");
-			}
-			
-			else if (e == XMLEvent.START_ELEMENT &&
-					reader.getLocalName().equals("c")){					
-				reader.next();
-				sb.append(reader.getText());
-				sb.append(" ");
+				e = reader.next();
+				if (e == XMLEvent.CHARACTERS){
+					String keyword = reader.getText();
+					sb.append("#");
+					sb.append(keyword);
+					sb.append("# ");	
+				}
 			}
 			
 			else if (e == XMLEvent.END_ELEMENT && 
 					reader.getLocalName().equals("kwic")){
+				
 				kwic = normalizeString(sb.toString());
-				//logger.info("sentence {}", kwic);
-				c.addSentence(kwic);					
-				kwicCollector.append(kwic);
+				Sentence s = createSentence(kwic);
+				c.addSentence(s);
+				//logger.info(kwic);
+				kwicCollector.append(s.getSentenceString());				
 			}				
 		}
 		return kwicCollector.toString();
-	}
+	}	
 	
 	private String readInput(InputStream is, List<String[]> tokenizedSentences) 
 			throws XMLStreamException{
@@ -346,20 +357,55 @@
 		return kwicCollector.toString();
 	}
 	
-	private String normalizeString(String text){
+	private Sentence createSentence(String kwic){
+		String[] tokens = kwic.split("\\s+");				
+		int open = ArrayUtils.indexOf(tokens,"#");
+		tokens = ArrayUtils.remove(tokens, open);
+		int close = ArrayUtils.lastIndexOf(tokens,"#");				
+		tokens= ArrayUtils.remove(tokens, close);
+		
+		int[] keyIndexes = new int[close-open];
+		int j=0;
+		for (int i=open; i<close; i++){
+			//logger.info(i+" "+tokens[i]);
+			keyIndexes[j] = i;
+			j++;
+		}
+		
 		StringBuilder sb = new StringBuilder();
+		for (String t: tokens){
+			sb.append(t);
+			sb.append(" ");
+		}
+		String sentenceString = sb.toString();
+		
+		return new Sentence(sentenceString, tokens, keyIndexes);		
+	}
+	
+	private String normalizeString(String text){
+		boolean isPrevPunctuation = false;
+		
+		StringBuilder sb = new StringBuilder();		
 		for (int j = 0; j < text.length(); j++){
 			char temp = text.charAt(j);					
 			if (!Character.isDigit(temp) && !Character.isLetter(temp)){						
 				if (temp == '\''){ sb.append(temp);	}
-				else { sb.append(" "+temp);	}							
+				else { 
+					sb.append(" ");
+					isPrevPunctuation = true;
+				}							
 			}
-			else{ sb.append(temp); }
+			sb.append(temp);
+			
+			if (isPrevPunctuation) {
+				sb.append(" ");
+				isPrevPunctuation = false;
+			}
 		}
-		return sb.toString();			
+		return sb.toString().replaceAll("\\s+", " ");			
 	}	
 	
-	private HttpGet createSearchRetrieveRequest(String query, String maximumRecords) 
+	private HttpGet createSearchRetrieveRequest(String query, int maximumRecords) 
 			throws ServletException{
 		try {
 			URIBuilder builder = new URIBuilder(endpointUri);	
@@ -367,7 +413,7 @@
 			builder.setParameter("version", "1.2");
 			builder.setParameter("query", query);
 			builder.setParameter("startRecord", "1");
-			builder.setParameter("maximumRecords", maximumRecords);
+			builder.setParameter("maximumRecords", String.valueOf(maximumRecords));
 			URI requestURI = builder.build();
 			return new HttpGet(requestURI);
 		}
diff --git a/src/main/java/de/mannheim/ids/sruws/Sentence.java b/src/main/java/de/mannheim/ids/sruws/Sentence.java
new file mode 100644
index 0000000..705f720
--- /dev/null
+++ b/src/main/java/de/mannheim/ids/sruws/Sentence.java
@@ -0,0 +1,34 @@
+package de.mannheim.ids.sruws;
+
+public class Sentence{
+	
+	String sentenceString;
+	String[] tokens;
+	int[] keyIndexes;		
+	
+	public Sentence(String str, String[] tokens, int[] keyIndexes) {
+		this.sentenceString = str;		
+		this.tokens = tokens;
+		this.keyIndexes = keyIndexes;
+	}
+	
+	public String getSentenceString() {
+		return sentenceString;
+	}
+	public void setSentenceString(String sentenceString) {
+		this.sentenceString = sentenceString;
+	}
+	
+	public String[] getTokens() {
+		return tokens;
+	}
+	public void setTokens(String[] tokens) {
+		this.tokens = tokens;
+	}
+	public int[] getKeyIndexes() {
+		return keyIndexes;
+	}
+	public void setKeyIndexes(int[] keyIndexes) {
+		this.keyIndexes = keyIndexes;
+	}		
+}
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index 022a9df..ffee5c4 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -1,6 +1,6 @@
 
-log4j.rootLogger=DEBUG, STDOUT
-log4j.de.mannheim.ids.sruws.SRU_WS = INFO, STDOUT
+log4j.rootLogger=INFO, STDOUT
+log4j.de.mannheim.ids.sruws.SRU_WS = DEBUG, STDOUT
 
 log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
 log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 27ff16c..d2235e6 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -1,9 +1,18 @@
-<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="SRU_WEB_SERVICE">
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app id="SRU_WEB_SERVICE">
   <display-name>SRU Web-service</display-name>
   
   <servlet>    
     <servlet-name>SRU_WS</servlet-name>        
-    <servlet-class>de.mannheim.ids.sruws.SRU_WS</servlet-class>
+    <!-- <servlet-class>de.mannheim.ids.sruws.SRU_WS</servlet-class> -->
+    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+    <init-param>
+      <param-name>com.sun.jersey.config.property.packages</param-name>
+      <param-value>de.mannheim.ids.sruws</param-value>
+    </init-param>
     <init-param>
         <param-name>de.mannheim.ids.sruws.endpoint.korap</param-name>
         <param-value>http://clarin.ids-mannheim.de/korapsru</param-value>
@@ -24,34 +33,45 @@
         <param-name>de.mannheim.ids.sruws.endpoint.stuttgart</param-name>
         <param-value>http://clarin01.ims.uni-stuttgart.de/SRUCQIBridge</param-value>
     </init-param>
-    <!-- same case like goethe, pid is sub-resource -->
-    <init-param> 
-        <param-name>de.mannheim.ids.sruws.endpoint.muenchen</param-name>
-        <param-value>https://clarin.phonetik.uni-muenchen.de/BASSRU/</param-value>
-    </init-param>
-    <!-- weird pid -->
-    <init-param>
-        <param-name>de.mannheim.ids.sruws.endpoint.mpi</param-name>
-        <param-value>http://cqlservlet.mpi.nl/</param-value>
-    </init-param>   
-    <!-- doesnt provide scan -->		
-    <init-param>
-        <param-name>de.mannheim.ids.sruws.endpoint.saarland</param-name>
-        <param-value>http://fedora.clarin-d.uni-saarland.de/sru2</param-value>
-    </init-param>
-    <!-- empty pid -->
+
+    <!-- empty pid -->    
     <init-param>
         <param-name>de.mannheim.ids.sruws.endpoint.berlin</param-name>
         <param-value>http://dspin.dwds.de:8088/DDC-Endpoint/sru</param-value>
-    </init-param>
+    </init-param>    			 
+
+    
+    <!-- broken sentences -->
+    
+    <!-- same case like goethe, pid is sub-resource  -->    
+    <!-- <init-param> 
+        <param-name>de.mannheim.ids.sruws.endpoint.muenchen</param-name>
+        <param-value>https://clarin.phonetik.uni-muenchen.de/BASSRU/</param-value>
+    </init-param> -->
+    
+    <!-- weird pid -->
+    <!-- <init-param>
+        <param-name>de.mannheim.ids.sruws.endpoint.mpi</param-name>
+        <param-value>http://cqlservlet.mpi.nl/</param-value>
+    </init-param> -->  
+    
     <!-- pid doesn't match -->
-    <init-param>
+    <!-- <init-param>
         <param-name>de.mannheim.ids.sruws.endpoint.hamburg</param-name>
         <param-value>http://virt-fedora.multilingua.uni-hamburg.de:8080/HZSKsru/</param-value>
-    </init-param>			 
+    </init-param> -->
+     
+    <!-- doesnt provide scan -->		
+   <!--  <init-param>
+        <param-name>de.mannheim.ids.sruws.endpoint.saarland</param-name>
+        <param-value>http://fedora.clarin-d.uni-saarland.de/sru2/</param-value>
+    </init-param> -->
+    
+    <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
     <servlet-name>SRU_WS</servlet-name>
     <url-pattern>/*</url-pattern>
-  </servlet-mapping>
+  </servlet-mapping>  
+ 
 </web-app>
\ No newline at end of file
diff --git a/src/test/java/de/mannheim/ids/sruws/test/TestClient.java b/src/test/java/de/mannheim/ids/sruws/test/TestClient.java
index ee14d32..45de13d 100644
--- a/src/test/java/de/mannheim/ids/sruws/test/TestClient.java
+++ b/src/test/java/de/mannheim/ids/sruws/test/TestClient.java
@@ -1,11 +1,14 @@
 package de.mannheim.ids.sruws.test;
 import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
 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;
@@ -19,15 +22,15 @@
 		
 	public static void main(String arg[]) throws IOException{
 		String url =
-				"http://localhost:8080/SRU-WS/";
-				//"http://clarin.ids-mannheim.de/sruws/";
+				//"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");		
+		post.setHeader(HttpHeaders.ACCEPT,"text/query-cql");		
 		
 		List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
-		urlParameters.add(new BasicNameValuePair("query", "rot"));
+		urlParameters.add(new BasicNameValuePair("query", "Baden-Württemberg"));
 		urlParameters.add(new BasicNameValuePair("maximumRecords", "5"));
 		urlParameters.add(new BasicNameValuePair("endpoint", "korap")); 
 		post.setEntity(new UrlEncodedFormEntity(urlParameters));
@@ -41,13 +44,16 @@
 			System.out.println("Response Code : " + 
 					response.getStatusLine().getReasonPhrase());
 		}
+				
+		FileWriter fw = new FileWriter(new File("test.xml"));
 		
 		BufferedReader reader = new BufferedReader(new InputStreamReader(
 				response.getEntity().getContent()));
 		String line;
 		while ((line = reader.readLine()) != null){
-			System.out.println(line);
+			//System.out.println(line);
+			fw.append(line+"\n");
 		}
-		
+		fw.close();
 	}	
 }