- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Mon, 19 Oct 2009 10:09:05 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/request In directory hutz:/tmp/cvs-serv29765/src/org/w3c/unicorn/request Modified Files: UploadRequest.java DirectRequestGET.java Request.java URIRequest.java DirectRequestPOST.java Log Message: new response parsing process + implementations for the new observer schema Index: DirectRequestPOST.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/DirectRequestPOST.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- DirectRequestPOST.java 23 Sep 2009 13:55:19 -0000 1.7 +++ DirectRequestPOST.java 19 Oct 2009 10:09:03 -0000 1.8 @@ -5,13 +5,13 @@ package org.w3c.unicorn.request; import java.io.IOException; -import java.io.InputStream; import java.util.Hashtable; import java.util.Map; import org.w3c.unicorn.contract.EnumInputMethod; import org.w3c.unicorn.input.DirectInputModule; import org.w3c.unicorn.response.Response; +import org.w3c.unicorn.response.ResponseFactory; import org.w3c.unicorn.util.ClientHttpRequest; import org.w3c.unicorn.util.Message; import org.w3c.unicorn.exceptions.UnicornException; @@ -77,9 +77,10 @@ ClientHttpRequest request = new ClientHttpRequest(sURL); request.setLang(sLang); request.setParameters(mapOfParameter); - - InputStream is = request.post(); - return streamToResponse(is); + + // TODO How to find the response content encoding here ? + return ResponseFactory.getResponse(request.post(), responseType, sURL.toString(), null); + } catch (IOException e) { throw new UnicornException(new Message(e)); } Index: DirectRequestGET.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/DirectRequestGET.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- DirectRequestGET.java 23 Sep 2009 13:55:19 -0000 1.8 +++ DirectRequestGET.java 19 Oct 2009 10:09:03 -0000 1.9 @@ -5,7 +5,6 @@ package org.w3c.unicorn.request; import java.io.IOException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLConnection; @@ -14,6 +13,7 @@ import org.w3c.unicorn.contract.EnumInputMethod; import org.w3c.unicorn.input.DirectInputModule; import org.w3c.unicorn.response.Response; +import org.w3c.unicorn.response.ResponseFactory; import org.w3c.unicorn.util.Message; import org.w3c.unicorn.exceptions.UnicornException; @@ -84,19 +84,18 @@ public Response doRequest() throws UnicornException { try { logger.trace("doRequest"); - final URL aURL; + URL aURL; if (null == this.sParameter) { aURL = new URL(this.sURL); } else { logger.debug(this.sParameter); aURL = new URL(this.sURL + "?" + this.sParameter); } - final URLConnection aURLConnection = aURL.openConnection(); + URLConnection aURLConnection = aURL.openConnection(); aURLConnection.setRequestProperty("Accept-Language", this.sLang); - - InputStream is = aURLConnection.getInputStream(); - - return streamToResponse(is); + + return ResponseFactory.getResponse(aURLConnection.getInputStream(), responseType, sURL.toString(), aURLConnection.getContentEncoding()); + } catch (IOException e) { throw new UnicornException(new Message(e)); } Index: UploadRequest.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/UploadRequest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- UploadRequest.java 23 Sep 2009 13:55:19 -0000 1.7 +++ UploadRequest.java 19 Oct 2009 10:09:03 -0000 1.8 @@ -5,7 +5,6 @@ package org.w3c.unicorn.request; import java.io.IOException; -import java.io.InputStream; import java.net.MalformedURLException; import java.util.Hashtable; import java.util.Map; @@ -16,6 +15,7 @@ import org.w3c.unicorn.util.ClientHttpRequest; import org.w3c.unicorn.util.Message; import org.w3c.unicorn.exceptions.UnicornException; +import org.w3c.unicorn.response.ResponseFactory; /** * Class to deal with the upload request @@ -107,9 +107,10 @@ logger.debug("Value :" + sValue + "."); aClientHttpRequest.setParameter(sName, sValue); } - InputStream is = this.aClientHttpRequest.post(); + + // TODO How to find the response content encoding here ? + return ResponseFactory.getResponse(aClientHttpRequest.post(), responseType, sURL.toString(), null); - return streamToResponse(is); } catch (MalformedURLException e) { throw new UnicornException(new Message(e)); } catch (IOException e) { Index: Request.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/Request.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Request.java 23 Sep 2009 13:55:19 -0000 1.10 +++ Request.java 19 Oct 2009 10:09:03 -0000 1.11 @@ -4,10 +4,7 @@ // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.request; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -16,8 +13,6 @@ import org.w3c.unicorn.input.InputModule; import org.w3c.unicorn.input.URIInputModule; import org.w3c.unicorn.input.UploadInputModule; -import org.w3c.unicorn.response.Response; -import org.w3c.unicorn.response.parser.ResponseParserFactory; import org.w3c.unicorn.exceptions.UnicornException; /** @@ -132,25 +127,6 @@ this.responseType = responseType; } - protected Response streamToResponse(InputStream is) throws IOException { - - InputStreamReader isr = new InputStreamReader(is, "UTF-8"); - BufferedReader buf = new BufferedReader(isr); - StringBuilder build = new StringBuilder(); - - String s = buf.readLine(); - while (s != null) { - build.append(s + "\n"); - s = buf.readLine(); - } - - Response res = ResponseParserFactory.parse(build.toString(), this.getResponseType()); - if(res != null) - res.setXml(build); - - return res; - } - public String getObserverId() { return observerId; } Index: URIRequest.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/request/URIRequest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- URIRequest.java 6 Oct 2009 14:48:16 -0000 1.14 +++ URIRequest.java 19 Oct 2009 10:09:03 -0000 1.15 @@ -5,7 +5,6 @@ package org.w3c.unicorn.request; import java.io.IOException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.ConnectException; import java.net.HttpURLConnection; @@ -21,6 +20,7 @@ import org.w3c.unicorn.response.Response; import org.w3c.unicorn.util.Message; import org.w3c.unicorn.util.Property; +import org.w3c.unicorn.response.ResponseFactory; /** * Use to handle a request to a observer. @@ -137,10 +137,8 @@ throw new UnicornException(Message.ERROR, "$message_observer_internal_error", null, observerName); } - InputStream is = aURLConnection.getInputStream(); - Response response = streamToResponse(is); - response.setRequestUri(aURL.toString()); - return response; + return ResponseFactory.getResponse(aURLConnection.getInputStream(), responseType, aURL.toString(), aURLConnection.getContentEncoding()); + } catch (MalformedURLException e) { throw new UnicornException(new Message(e)); } catch (ConnectException e) {
Received on Monday, 19 October 2009 10:09:07 UTC