Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 76264 invoked by uid 500); 26 Feb 2002 18:47:29 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 76252 invoked from network); 26 Feb 2002 18:47:29 -0000 Message-ID: From: "KUMAR,PANKAJ (HP-Cupertino,ex1)" To: "'cocoon-dev@xml.apache.org'" Subject: [C2.0.1]Problem with SOAP Logicsheet in accessing .Net Web Servic es Date: Tue, 26 Feb 2002 10:47:19 -0800 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C1BEF6.04AE7960" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------_=_NextPart_000_01C1BEF6.04AE7960 Content-Type: text/plain; charset="iso-8859-1" Hi, I observed some bizzare behaviour and thought might as well report it. I have written a simple web-application consisting of an XSP file ( zipcode-info.xsp ) and an XSL stylesheet ( zipcode-info.xsl ) that accesses two SOAP services at http://alethea.net:80/webservices/LocalTime.asmx and http://www.vbws.com:80/services/weatherretriever.asmx ( I found these at http://www.xmethods.org from .asmx, I guess they are .Net web services and the HTTP server is IIS ) using the SOAP logicsheet. This application worked fine from my office machine ( behind a firewall, so I had to specify http proxy host and port ), but failed to work ( first, it threw an exception "-1 port out of range" and then when I explicitly specified port 80, it just hung waiting for a response from the service ) from my home computer ( no firewall ). I should add that access to web services deployed under TomCat works fine ( as long as you explicitly specify port 80 for http ). I looked into the code and figured out that the use of httpclient code ( from org.apache.commons.httpclient.* ) in file SOAPHelper.java is the culprit. Replaced this file with another ( included in the mail ) that uses the JDK classes for HTTP transport and everything worked fine. Here are the files mentioned in this mail: <> <> <> To run this application, you need to place zipcode-info.xsl and zipcode-info.xsp at a suitable place within your cocoon deployment and have a suitable entry in the sitemap file. In my setup, I have the XSP and XSL files in docs\samples\xscript and following entry in the sitemap: Note: This application currently "streams-in" the SOAP documents returned from web-services to the main XML document and relies on the stylesheet to pickup appropriate fields. A better approach is perhaps to use XScript. I am still investigating/experimenting with this option. /Pankaj. ------_=_NextPart_000_01C1BEF6.04AE7960 Content-Type: application/octet-stream; name="zipcode-info.xsl" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="zipcode-info.xsl" =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= <= /b>=0A= =0A= =0A= =0A= <= /b>=0A= =0A= =0A= =0A= = =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= ------_=_NextPart_000_01C1BEF6.04AE7960 Content-Type: application/octet-stream; name="zipcode-info.xsp" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="zipcode-info.xsp" =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= Location Information from ZipCode=0A= =0A= =0A= =0A= =0A= String zipcode =3D request.getParameter("zipcode");=0A= =0A= if (zipcode =3D=3D null || zipcode.equals("")) {=0A= =0A= This example demonstrates the use of Cocoon to build a = simple=0A= application that invokes Web Services to get information about = a=0A= geographical location.=0A= =0A= Please enter a US zipcode: =0A=
=0A= =0A= =0A=
=0A= }=0A= else {=0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= =0A= Information for zipcode location = :=0A= =0A= Local Time : =0A= Weather Conditions ( updated at ): = =0A= Current Temperature: =0A= Current Humidity : =0A= Current Barometer : =0A= Barometer Direction: =0A= =0A=
=0A= =0A=
=0A= }=0A=
=0A= =0A=
=0A= =0A=
=0A= =0A= ------_=_NextPart_000_01C1BEF6.04AE7960 Content-Type: application/octet-stream; name="SOAPHelper.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="SOAPHelper.java" /***********************************************************************= ******=0A= * Copyright (C) The Apache Software Foundation. All rights reserved. = *=0A= * = ------------------------------------------------------------------------= - *=0A= * This software is published under the terms of the Apache Software = License *=0A= * version 1.1, a copy of which has been included with this = distribution in *=0A= * the LICENSE file. = *=0A= = ************************************************************************= *****/=0A= package org.apache.cocoon.components.language.markup.xsp;=0A= =0A= import java.io.BufferedReader;=0A= import java.io.IOException;=0A= import java.io.InputStream;=0A= import java.io.InputStreamReader;=0A= import java.io.OutputStream;=0A= import java.net.MalformedURLException;=0A= import java.net.URL;=0A= import java.util.HashMap;=0A= import org.apache.avalon.framework.component.ComponentException;=0A= import org.apache.avalon.framework.component.ComponentManager;=0A= import org.apache.cocoon.ProcessingException;=0A= import org.apache.cocoon.components.xscript.XScriptManager;=0A= import org.apache.cocoon.components.xscript.XScriptObject;=0A= import org.apache.cocoon.components.xscript.XScriptObjectInlineXML;=0A= =0A= import java.net.URLConnection;=0A= import java.io.*;=0A= =0A= import org.xml.sax.InputSource;=0A= =0A= /**=0A= * Helper for the SOAP logicsheet.=0A= *=0A= * @author Ovidiu Predescu=0A= * @since July 16, 2001=0A= */=0A= public class SOAPHelper=0A= {=0A= XScriptManager xscriptManager;=0A= URL url;=0A= String action =3D "";=0A= XScriptObject xscriptObject;=0A= char[] buf =3D new char[4096];=0A= =0A= public SOAPHelper(ComponentManager manager, String urlContext, String = url,=0A= String action, XScriptObject xscriptObject)=0A= throws MalformedURLException, ComponentException=0A= {=0A= this.xscriptManager =3D = (XScriptManager)manager.lookup(XScriptManager.ROLE);=0A= URL context =3D new URL(urlContext);=0A= this.url =3D new URL(context, url);=0A= this.action =3D action;=0A= this.xscriptObject =3D xscriptObject;=0A= }=0A= =0A= public XScriptObject invoke()=0A= throws ProcessingException=0A= {=0A= =0A= try {=0A= if (action =3D=3D null || action.equals(""))=0A= action =3D "\"\"";=0A= URLConnection con =3D url.openConnection();=0A= con.setDoInput(true);=0A= con.setDoOutput(true);=0A= con.setUseCaches(false);=0A= //con.setRequestProperty("CONTENT_LENGTH", "" + = postDataFile.length());=0A= con.setRequestProperty("Content-type", "text/xml; = charset=3D\"utf-8\"");=0A= con.setRequestProperty("SOAPAction", action);=0A= =0A= //BufferedReader br =3D new BufferedReader(new InputStreamReader(new = FileInputStream(postDataFile)));=0A= InputSource saxInputStream =3D xscriptObject.getInputSource();=0A= InputStream is =3D saxInputStream.getByteStream();=0A= InputStreamReader isr =3D new InputStreamReader(is);=0A= BufferedReader br =3D new BufferedReader(isr);=0A= =0A= BufferedWriter bw =3D new BufferedWriter(new = OutputStreamWriter(con.getOutputStream()));=0A= =0A= int nread =3D 0;=0A= int nwrote =3D 0;=0A= while ((nread =3D br.read(buf, 0, buf.length)) > 0){=0A= bw.write(buf, 0, nread);=0A= nwrote +=3D nread;=0A= }=0A= bw.flush();=0A= bw.close();=0A= br.close();=0A= System.out.println("Wrote " + nwrote + " bytes to " + url);=0A= =0A= br =3D new BufferedReader(new = InputStreamReader(con.getInputStream()));=0A= CharArrayWriter caw =3D new CharArrayWriter();=0A= =0A= nwrote =3D 0;=0A= while ((nread =3D br.read(buf, 0, buf.length)) > 0){=0A= caw.write(buf, 0, nread);=0A= nwrote +=3D nread;=0A= }=0A= System.out.println("Read " + nwrote + " bytes from " + url);=0A= =0A= return new XScriptObjectInlineXML(xscriptManager, = caw.toString());=0A= }=0A= catch (Exception ex) {=0A= throw new ProcessingException("Error invoking remote service: " + = ex,=0A= ex);=0A= }=0A= }=0A= }=0A= ------_=_NextPart_000_01C1BEF6.04AE7960 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org ------_=_NextPart_000_01C1BEF6.04AE7960--