cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Boisvert, Éric" <ebois...@nrcan.gc.ca>
Subject SAX parser problem
Date Thu, 01 Dec 2005 20:24:46 GMT
I try to create a transformer that send a POST request to a server, grab the
result and send it down the pipe.  I cannot use CInclude for a variety of
reason it's not necessary to expose here. 

For sanity check I create a small console application that send a POST query
and write it back.

public class ConsoleTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// try to get a darn response for MapServer
		try
		{
		URL imsUrl = new
URL("http://my.wfsserver.gc.ca/WebScripts/mapserv.exe?map=c:\\ngwd\\map\\bed
rock\\bedrock.map&service=WFS&version=1.0.0");
		HttpURLConnection connection =
(HttpURLConnection)imsUrl.openConnection();
		connection.setRequestMethod("POST");
	
connection.setRequestProperty("Content-Type","application/xml");
		connection.setDoOutput(true);
		connection.setDoInput(true);
		
		// get the incoming xml document
		PrintStream ps = new PrintStream(
connection.getOutputStream() );
		// send it to connection
		ps.print("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
		ps.print("<wfs:GetFeature
xmlns:wfs=\"http://www.opengis.net/wfs\"
xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"www.opengis.net/ogc\"
xmlns:lcnp=\"http://www.cgcq.rncan.gc.ca/lcnp\" version=\"1.0.0\"
service=\"WFS\" maxFeatures=\"100\" outputFormat=\"GML2\">");
		ps.print("<wfs:Query typeName=\"bedrock\">");
		ps.print("</wfs:Query>");
		ps.print("</wfs:GetFeature>");
		ps.flush();
		ps.close();
		System.out.print("Send query");
		// get the response
		InputStream response = connection.getInputStream();
		//		 debug info 
		System.out.print("Response
message:"+((HttpURLConnection)connection).getResponseMessage()+"\n");
		System.out.print("Response
method:"+((HttpURLConnection)connection).getRequestMethod()+"\n");
		System.out.print("Response
code:"+String.valueOf(((HttpURLConnection)connection).getResponseCode())+"\n
");
		System.out.print("content
length:"+String.valueOf(connection.getContentLength())+"\n");
		System.out.print("Content type" +
connection.getContentType()+"\n");
	
System.out.print("-----------------------------------------\n");
		 int c = 0;
         StringBuffer sb = new StringBuffer();
         while ( (c = response.read()) >= 0 ) {
             sb.append( (char)c );
         }
         System.out.print("my God, it works');
         System.out.print(sb.toString());
         response.close();
         
		// debug info
		}
		catch (Exception e)
		{
		System.out.print(e.getMessage());
		}
		

	}

}

This works fine.  Now I want to implement the same thing in a transformer
and stream the result to the next component.

but when I try to use this in the context of a component, the sax events
stops before getting to the end
The HttpUrlConnection portion is identical to the console app. it works, for
the rest, this is my code

 		WfsXMLPipe n = new WfsXMLPipe(contentHandler);
			   // this is where I catch the inputstream..
WfsResponse is 
			   // the InputStream : 
			   // WfsResponse = connection.getInputStream();
			   InputSource i = new InputSource(new
InputStreamReader(WfsResponse));
			   getLogger().debug("got the input source");
			   SAXParser respParser =
(SAXParser)manager.lookup(SAXParser.ROLE);
			   try
			   {
				   respParser.parse(i,n);
			   }
			   finally
			   {
	
				   manager.release((Component)respParser);
				   WfsResponse.close();
			   }
			   
  I loggued the event going through WfsXMLPipe and the complete file is
indeed received and sent and processed by the SAXParser.
  the problem is not all the document makes it to the next component (in my
test case, a serializer), the end of the document is missing, and for small
documents, I get absolutly nothing.  

So, the whole document is received, and seems to be processed by the
SAXParser (by monitoring the WfsXMLPipe, which is an EmbeddedXMLPipe), but
it does not reappear at the end of the pipe.
  
  Any idea ?
  
  oh. Cocoon 2.1.6, on a WinXP box.

Cheers and thanks

================================================================
Eric Boisvert
Spécialiste TI-GI / IT-IM specialist
Eric.Boisvert@rncan.gc.ca, 418-654-3705, facsimile/télécopieur 
418-654-2615
490, rue de la Couronne, Québec (Québec), G1K 9A9
490, rue de la Couronne, Quebec, Quebec, G1K 9A9

Laboratoire de cartographie numérique et de photogrammétrie (LCNP)
Digital Cartography and Photogrammetry Laboratory (DCPL)
Commission géologique du Canada (Québec) / Geological Survey of Canada
(Quebec)
Ressources naturelles Canada / Natural Resources Canada
Gouvernement du Canada / Government of Canada
http://www.cgcq.rncan.gc.ca/lcnp
http://www.nrcan.gc.ca/gsc



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message