[EMAIL PROTECTED] wrote: >I've been hunting a solution for this for 2 days -- >I found several similar questions on google, but no answers. > >In order to use Flash's XML.sendAndLoad function, >(which sends and receives XML data), >I need to get access to the raw POST string in my XSP page, >but I can't find any information on how to go about doing that. > >the xsp-request logicsheet gives me access to headers, name/val pairs, >etc...but nowhere can I find the actual POST content. > >Ordinarily, I'd change my architecture...but Flash is a more >limiting factor than cocoon, so I don't have a choice. > >Given the number of people I've seen asking similar questions, >(Flash isn't the only client that doesn't send name/value data) >someone's got to have found a solution. > >TIA >-j > This is a well know bugs of POST method of Flash's XML Api, post method is not interpreted by some Servlet contatiners, for example Orion/Oracle OC4J. You has to process directly the input stream of http request. I attached an example of XSP which process the XML input stream, this example could help you as jump start to solve your problem. If it doesn't work I'll sent to you other JSP tomorrow. Best regards, Marcelo.
-- Marcelo F. Ochoa - [EMAIL PROTECTED] Do you Know DB Prism? Look @ http://www.plenix.com/dbprism/ More info? Chapter 21 of the book "Professional XML Databases" (Wrox Press http://www.wrox.com/) Chapter 8 of the book "Oracle & Open Source" (O'Reilly http://www.oreilly.com/catalog/oracleopen/) ----------------------------------------------- Lab. de Sistemas - Fac. de Cs. Exactas - UNICEN Paraje Arroyo Seco - Campus Universitario (7000) Tandil - Bs. AS. - Argentina Te: +54-2293-444430 Fax: +54-2293-444431
<?xml version="1.0" encoding="ISO-8859-1"?> <xsp:page language="java" xmlns:xsp="http://apache.org/xsp" > <xsp:structure> <xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include> <xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include> <xsp:include>org.apache.avalon.framework.parameters.Parameters</xsp:include> <xsp:include>org.apache.avalon.framework.parameters.ParameterException</xsp:include> <xsp:include>org.apache.cocoon.xml.XMLConsumer</xsp:include> <xsp:include>com.prism.components.cache.Server</xsp:include> <xsp:include>java.io.BufferedReader</xsp:include> <xsp:include>java.io.InputStreamReader</xsp:include> <xsp:include>java.util.Enumeration</xsp:include> <xsp:include>java.util.Hashtable</xsp:include> <xsp:include>java.util.HashMap</xsp:include> <xsp:include>java.util.Locale</xsp:include> <xsp:include>java.util.Vector</xsp:include> <xsp:include>java.security.Principal</xsp:include> <xsp:include>javax.servlet.http.HttpServletRequest</xsp:include> <xsp:include>javax.servlet.http.Cookie</xsp:include> <xsp:include>javax.servlet.http.HttpSession</xsp:include> <xsp:include>javax.servlet.ServletInputStream</xsp:include> <xsp:include>javax.servlet.RequestDispatcher</xsp:include> <xsp:include>org.apache.cocoon.environment.http.HttpEnvironment</xsp:include> <xsp:include>org.w3c.dom.Document</xsp:include> <xsp:include>org.xml.sax.Attributes</xsp:include> <xsp:include>org.apache.cocoon.xml.AbstractXMLPipe</xsp:include> <xsp:include>sun.misc.BASE64Decoder</xsp:include> </xsp:structure> <xsp:logic><![CDATA[ // Class attributes private static String EXTRACT_URI="http://www.plenix.com/dbprism/invalidation"; private static String EXTRACT_ELEMENT_INVALIDATION="invalidation"; private static String EXTRACT_ELEMENT_URI="url"; private static String EXTRACT_ELEMENT_VALIDITY="validity"; private static String EXTRACT_ELEMENT_COOKIE="cookie"; private static String EXTRACT_ELEMENT_HTTP="http-argument"; private static String EXTRACT_ELEMENT_ARGUMENT="sitemap-argument"; Server cacheServer = null; String name = ""; String passwd = ""; ]]></xsp:logic> <xsp:logic><![CDATA[ // Inher class, private request // Note that it only implement getter/setter class for parameters and cookies // other methots returns null, be carefull with this. public class MyHtppRequest implements HttpServletRequest { HttpServletRequest request; Hashtable parameters; Vector cookies; MyHtppRequest(HttpServletRequest request) { this.cookies = null; this.request = request; this.parameters = new Hashtable(); } public String getAuthType(){ return request.getAuthType(); } public Cookie[] getCookies() { if (cookies.isEmpty()) return null; else return (Cookie[])cookies.toArray(); } public void setCookies(Cookie cookie) { cookies.add(cookie); } public long getDateHeader(String s){ return request.getDateHeader(s); } public String getHeader(String s){ return request.getHeader(s); } public Enumeration getHeaders(String s){ return request.getHeaders(s); } public Enumeration getHeaderNames(){ return request.getHeaderNames(); } public int getIntHeader(String s){ return request.getIntHeader(s); } public String getMethod(){ return request.getMethod(); } public String getPathInfo(){ return request.getPathInfo(); } public String getPathTranslated(){ return request.getPathTranslated(); } public String getContextPath(){ return request.getContextPath(); } public String getQueryString(){ return request.getQueryString(); } public String getRemoteUser(){ return request.getRemoteUser(); } public boolean isUserInRole(String s){ return request.isUserInRole(s); } public Principal getUserPrincipal(){ return request.getUserPrincipal(); } public String getRequestedSessionId(){ return request.getRequestedSessionId(); } public String getRequestURI(){ return request.getRequestURI(); } public String getServletPath(){ return this.getServletPath(); } public HttpSession getSession(boolean flag){ return request.getSession(flag); } public HttpSession getSession(){ return request.getSession(); } public boolean isRequestedSessionIdValid(){ return request.isRequestedSessionIdValid(); } public boolean isRequestedSessionIdFromCookie(){ return request.isRequestedSessionIdFromCookie(); } public boolean isRequestedSessionIdFromURL(){ return request.isRequestedSessionIdFromURL(); } public boolean isRequestedSessionIdFromUrl(){ return request.isRequestedSessionIdFromUrl(); } public Object getAttribute(String s){ return request.getAttribute(s); } public Enumeration getAttributeNames(){ return request.getAttributeNames(); } public String getCharacterEncoding(){ return request.getCharacterEncoding(); } public int getContentLength(){ return request.getContentLength(); } public String getContentType(){ return request.getContentType(); } public ServletInputStream getInputStream() throws IOException{ return request.getInputStream(); } public String getParameter(String s) { return (String)this.parameters.get(s); } public Enumeration getParameterNames() { return this.parameters.keys(); } public String[] getParameterValues(String s) { String [] val = new String[1]; val[0] = (String)parameters.get(s); return val; } public void setParameter(String name, String value) { this.parameters.put(name,value); } public String getProtocol(){ return request.getProtocol(); } public String getScheme(){ return request.getScheme(); } public String getServerName(){ return request.getServerName(); } public int getServerPort(){ return request.getServerPort(); } public BufferedReader getReader() throws IOException{ return request.getReader(); } public String getRemoteAddr(){ return request.getRemoteAddr(); } public String getRemoteHost(){ return request.getRemoteHost(); } public void setAttribute(String s, Object obj){ request.setAttribute(s,obj); } public void removeAttribute(String s){ request.removeAttribute(s); } public Locale getLocale(){ return request.getLocale(); } public Enumeration getLocales(){ return request.getLocales(); } public boolean isSecure(){ return request.isSecure(); } public RequestDispatcher getRequestDispatcher(String s){ return request.getRequestDispatcher(s); } public String getRealPath(String s){ return request.getRealPath(s); } public java.lang.StringBuffer getRequestURL() { return null; } public java.util.Map getParameterMap() { return null; } public void setCharacterEncoding(java.lang.String $1) { } } // end inher class ]]></xsp:logic> <xsp:logic><![CDATA[ // Inher class public class InvalidateExtractor extends AbstractXMLPipe { HttpServletRequest request; private int state = 0; int count = 0; private String url; private boolean prefix; private int validity; Parameters par; Cookie cookie; MyHtppRequest httpParameter; AttributesImpl xspAttr; InvalidateExtractor(XMLConsumer consumer, HttpServletRequest request) { this.xspAttr = new AttributesImpl(); this.setConsumer(consumer); this.url = ""; this.prefix = false; this.validity = 0; this.par = new Parameters(); this.request = request; this.httpParameter = new MyHtppRequest(this.request); this.cookie = null; this.xspAttr.clear(); } /** * Receive notification of the beginning of an element. * * @param uri The Namespace URI, or the empty string if the element has no * Namespace URI or if Namespace * processing is not being performed. * @param loc The local name (without prefix), or the empty string if * Namespace processing is not being performed. * @param raw The raw XML 1.0 name (with prefix), or the empty string if * raw names are not available. * @param a The attributes attached to the element. If there are no * attributes, it shall be an empty Attributes object. */ public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException { //System.out.println(" Start uri="+uri+" loc="+loc+" raw="+raw+" state="+state); if (state == 0 && EXTRACT_ELEMENT_INVALIDATION.equals(loc)) state = 1; else if (state == 1 && EXTRACT_ELEMENT_URI.equals(loc)) { url = a.getValue("exp"); prefix = "yes".equalsIgnoreCase(a.getValue("prefix")); state = 2; //System.out.println("url="+url + " prefix="+prefix); } else if (state == 2 && EXTRACT_ELEMENT_ARGUMENT.equals(loc)) { String name = a.getValue("name"); String value = a.getValue("value"); par.setParameter(name,value); //System.out.println("sitemap argument name="+name+" value="+value); } else if (state == 2 && EXTRACT_ELEMENT_HTTP.equals(loc)) { String name = a.getValue("name"); String value = a.getValue("value"); httpParameter.setParameter(name,value); //System.out.println("http argument name="+name+" value="+value); } else if (state == 2 && EXTRACT_ELEMENT_VALIDITY.equals(loc)) { validity = Integer.parseInt(a.getValue("level")); //System.out.println("url="+url + " prefix="+prefix + " validity="+validity); } else if (state == 2 && EXTRACT_ELEMENT_COOKIE.equals(loc)) { String name = a.getValue("name"); String value = a.getValue("value"); cookie = new Cookie(name,value); httpParameter.setCookies(cookie); //System.out.println("cookie name="+name+" value="+value); } } /** * Receive notification of the end of an element. * * @param uri The Namespace URI, or the empty string if the element has no * Namespace URI or if Namespace * processing is not being performed. * @param loc The local name (without prefix), or the empty string if * Namespace processing is not being performed. * @param raw The raw XML 1.0 name (with prefix), or the empty string if * raw names are not available. */ public void endElement(String uri, String loc, String raw) throws SAXException { //System.out.println("End uri="+uri+" loc="+loc+" raw="+raw+" state="+state); if (state==2 && EXTRACT_ELEMENT_URI.equals(loc)) { state=1; try { String key = cacheServer.encodeURL(url,par,httpParameter); count++; //System.out.println("remove key ="+key); cacheServer.removeCacheablePage(name,passwd,key,validity); xspAttr.addAttribute("", "expr", "expr", "CDATA", url); xspAttr.addAttribute("", "id", "id", "CDATA", ""+count); xspAttr.addAttribute("", "status", "status", "CDATA", "ok"); xspAttr.addAttribute("", "numinv", "numinv", "CDATA", "0"); } catch (Exception e) { xspAttr.addAttribute("", "expr", "expr", "CDATA", url); xspAttr.addAttribute("", "id", "id", "CDATA", ""+count); xspAttr.addAttribute("", "status", "status", "CDATA", "not found"); xspAttr.addAttribute("", "numinv", "numinv", "CDATA", "0"); System.out.println("Error in remove ="+e.getMessage()); } finally { this.contentHandler.startElement("", "url", "url", xspAttr); this.url = ""; this.prefix = false; this.validity = 0; this.par = new Parameters(); this.httpParameter = new MyHtppRequest(this.request); this.cookie = null; this.xspAttr.clear(); this.contentHandler.endElement("", "url", "url"); } } else if (state==1 && EXTRACT_ELEMENT_INVALIDATION.equals(loc)) state=0; } } ]]></xsp:logic> <invalidationresult><xsp:logic><![CDATA[ try { this.cacheServer = (Server) this.manager.lookup(Server.ROLE); } catch (ComponentException ce) { System.out.println("invalidate.xsp: Can't get External Invalidator Server instance"); } HttpServletRequest httpRequest = (HttpServletRequest)objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT); if (httpRequest == null) { throw new ProcessingException("HttpServletRequest object not available"); } Parser parser = null; BASE64Decoder B64 = new BASE64Decoder(); int i; String str; try { str = httpRequest.getHeader("Authorization").substring(6); str = new String(B64.decodeBuffer(str),"iso-8859-1"); } catch (Exception e) { str = ":"; } i = str.indexOf(':'); name = str.substring(0,i); passwd = str.substring(i+1); BufferedReader ir = new BufferedReader(new InputStreamReader(httpRequest.getInputStream())); String line; StringBuffer msg = new StringBuffer(); while((line=ir.readLine())!=null) msg.append(line+"\n"); //System.out.println("User=>"+name); //System.out.println("Password=>"+passwd); //System.out.println("POST Message=>"); //System.out.println(msg.toString()); InvalidateExtractor extractor = new InvalidateExtractor((XMLConsumer)this.contentHandler,httpRequest); try { parser = (Parser)this.manager.lookup(Parser.ROLE); if (parser==null) System.out.println("Parser is null"); else { parser.setConsumer(extractor); parser.parse(new InputSource(new StringReader(msg.toString()))); } } catch (ComponentException e) { if (getLogger().isDebugEnabled()) { getLogger().debug("ComponentException in invalidate.generate()", e); getLogger().debug("Embedded ComponentException in invalidate.generate()", e); } //System.out.println("ComponentException="+e.getMessage()); } catch (SAXException e) { if (getLogger().isDebugEnabled()) { getLogger().debug("SAXException in invalidate.generate()", e); getLogger().debug("Embedded SAXException in invalidate.generate()", e); } //System.out.println("SAXException="+e.getMessage()); } catch (IOException e) { if (getLogger().isDebugEnabled()) { getLogger().debug("IOException in invalidate.generate()", e); getLogger().debug("Embedded IOException in invalidate.generate()", e); } //System.out.println("IOException="+e.getMessage()); } finally { // Cleanup local resources if (parser != null) this.manager.release(parser); } ]]></xsp:logic></invalidationresult> </xsp:page>
--------------------------------------------------------------------- Please check that your question has not already been answered in the FAQ before posting. <http://xml.apache.org/cocoon/faqs.html> To unsubscribe, e-mail: <[EMAIL PROTECTED]> For additional commands, e-mail: <[EMAIL PROTECTED]>