Index: FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/connector/ConnectorServlet.java
===================================================================
--- FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/connector/ConnectorServlet.java	(revision 2784)
+++ FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/connector/ConnectorServlet.java	(revision 2785)
@@ -22,4 +22,5 @@
 
 import java.io.IOException;
+import java.io.PrintWriter;
 
 import javax.servlet.ServletException;
@@ -32,4 +33,6 @@
 
 import net.fckeditor.requestcycle.ThreadLocalData;
+import net.fckeditor.response.GetResponse;
+import net.fckeditor.response.UploadResponse;
 
 /**
@@ -92,17 +95,24 @@
 			final HttpServletResponse response) throws ServletException,
 			IOException {
+		
+		request.setCharacterEncoding("UTF-8");
+		response.setCharacterEncoding("UTF-8");
+		response.setContentType("application/xml; charset=UTF-8");
+		response.setHeader("Cache-Control", "no-cache");
+		PrintWriter out = response.getWriter();
+		GetResponse getResponse = null;
+		
 		try {
 			ThreadLocalData.beginRequest(request);
-			dispatcher.doGet(request, response);
+			getResponse = dispatcher.doGet(request);
 		} catch (Exception e) {
-			// if an exception wasn't catched by the Dispatcher, it is a fatal
-			// one and has to re-thrown.
-			if (e instanceof IOException)
-				throw (IOException) e;
-			else
 				throw new ServletException(e);
 		} finally {
 			ThreadLocalData.endRequest();
 		}
+		
+		out.print(getResponse);
+		out.flush();
+		out.close();
 	}
 
@@ -118,17 +128,24 @@
 			final HttpServletResponse response) throws ServletException,
 			IOException {
+		
+		request.setCharacterEncoding("UTF-8");
+		response.setCharacterEncoding("UTF-8");
+		response.setContentType("text/html; charset=UTF-8");
+		response.setHeader("Cache-Control", "no-cache");
+		PrintWriter out = response.getWriter();
+		UploadResponse uploadResponse = null;
+		
 		try {
 			ThreadLocalData.beginRequest(request);
-			dispatcher.doPost(request, response);
+			uploadResponse = dispatcher.doPost(request);
 		} catch (Exception e) {
-			// if an exception wasn't catched by the Dispatcher, it is a fatal
-			// one and has to re-thrown.
-			if (e instanceof IOException)
-				throw (IOException) e;
-			else
 				throw new ServletException(e);
 		} finally {
 			ThreadLocalData.endRequest();
 		}
+		
+		out.print(uploadResponse);
+		out.flush();
+		out.close();
 	}
 
Index: FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/connector/Dispatcher.java
===================================================================
--- FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/connector/Dispatcher.java	(revision 2784)
+++ FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/connector/Dispatcher.java	(revision 2785)
@@ -22,10 +22,8 @@
 
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.List;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import net.fckeditor.connector.exception.FolderAlreadyExistsException;
@@ -93,15 +91,8 @@
 	 * </p>
 	 */
-	public void doGet(final HttpServletRequest request,
-			final HttpServletResponse response) throws IOException {
+	public GetResponse doGet(final HttpServletRequest request) {
 		logger.debug("Entering Dispatcher#doGet");
+		
 		Context context = ThreadLocalData.getContext();
-
-		request.setCharacterEncoding("UTF-8");
-		response.setCharacterEncoding("UTF-8");
-		response.setContentType("application/xml; charset=UTF-8");
-		response.setHeader("Cache-Control", "no-cache");
-		PrintWriter out = response.getWriter();
-
 		context.logBaseParameters();
 		
@@ -174,8 +165,6 @@
 		}
 		
-		out.print(getResponse);
-		out.flush();
-		out.close();
 		logger.debug("Exiting Dispatcher#doGet");
+		return getResponse;
 	}
 	
@@ -219,18 +208,11 @@
 	 *             if some unpredictable write error happens
 	 */
-	public void doPost(final HttpServletRequest request,
-			final HttpServletResponse response) throws IOException {
+	public UploadResponse doPost(final HttpServletRequest request) {
 		logger.debug("Entering Dispatcher#doPost");
+		
 		Context context = ThreadLocalData.getContext();
-		
-		request.setCharacterEncoding("UTF-8");
-		response.setCharacterEncoding("UTF-8");
-		response.setContentType("text/html; charset=UTF-8");
-		response.setHeader("Cache-Control", "no-cache");
-		PrintWriter out = response.getWriter();
-
 		context.logBaseParameters();
 		
-		UploadResponse uploadResponse;
+		UploadResponse uploadResponse = null;
 		// check permissions for user actions
 		if (!RequestCycleHandler.isEnabledForFileUpload(request))
@@ -298,8 +280,7 @@
 			}
 		}
-		out.print(uploadResponse);
-		out.flush();
-		out.close();
+		
 		logger.debug("Exiting Dispatcher#doPost");
+		return uploadResponse;
 	}
 	
