You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/06/24 09:17:11 UTC

svn commit: r671047 - in /cocoon/whiteboard/corona/trunk/corona-servlet/src/main: java/org/apache/cocoon/corona/servlet/ssf/ resources/META-INF/cocoon/spring/

Author: reinhard
Date: Tue Jun 24 00:17:10 2008
New Revision: 671047

URL: http://svn.apache.org/viewvc?rev=671047&view=rev
Log:
. sitemap components for the usage of servlet services (however, no saxbuffering between pipelines yet)

Added:
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java   (with props)
Modified:
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml

Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java?rev=671047&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java Tue Jun 24 00:17:10 2008
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.corona.servlet.ssf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cocoon.corona.pipeline.ProcessingException;
+import org.apache.cocoon.corona.pipeline.component.AbstractXMLProducer;
+import org.apache.cocoon.corona.pipeline.component.Starter;
+import org.apache.cocoon.corona.pipeline.util.XMLUtils;
+import org.apache.cocoon.corona.servlet.util.HttpContextHelper;
+
+public class ServiceConsumerGenerator extends AbstractXMLProducer implements Starter {
+
+    private Map<String, ? extends Object> parameters;
+
+    public void execute() {
+        HttpServletRequest request = HttpContextHelper.getRequest(this.parameters);
+        if (!"POST".equals(request.getMethod())) {
+            throw new ProcessingException("Cannot create consumer source for request that is not POST.");
+        }
+
+        InputStream inputStream = null;
+        try {
+            inputStream = request.getInputStream();
+        } catch (IOException e) {
+            throw new RuntimeException("Can't open inputStream on request.");
+        }
+
+        XMLUtils.toSax(inputStream, this.getXMLConsumer());
+    }
+
+    @Override
+    public void setInputParameters(Map<String, Object> parameters) {
+        this.parameters = parameters;
+    }
+}
\ No newline at end of file

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java?rev=671047&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java Tue Jun 24 00:17:10 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.corona.servlet.ssf;
+
+import java.net.URL;
+import java.util.Map;
+
+import org.apache.cocoon.corona.pipeline.component.AbstractXMLProducer;
+import org.apache.cocoon.corona.pipeline.component.Starter;
+import org.apache.cocoon.corona.pipeline.util.URLConnectionUtils;
+
+public class ServletServiceGenerator extends AbstractXMLProducer implements Starter {
+
+    private URL service;
+
+    public void execute() {
+        if (this.service == null) {
+            throw new IllegalArgumentException("ServletServiceGenerator has no service set.");
+        }
+
+        try {
+            URLConnectionUtils.toSax(this.service.openConnection(), this.getXMLConsumer());
+        } catch (Exception e) {
+            throw new RuntimeException("Can't parse " + this.service, e);
+        }
+    }
+
+    @Override
+    public void setConfiguration(Map<String, ? extends Object> parameters) {
+        this.service = (URL) parameters.get("service");
+    }
+}
\ No newline at end of file

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java?rev=671047&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java Tue Jun 24 00:17:10 2008
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.corona.servlet.ssf;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Map;
+
+import org.apache.cocoon.corona.pipeline.ProcessingException;
+import org.apache.cocoon.corona.pipeline.component.AbstractSerializer;
+import org.apache.cocoon.corona.pipeline.util.SaxBuffer;
+import org.apache.cocoon.corona.pipeline.util.XMLUtils;
+import org.apache.commons.io.IOUtils;
+import org.xml.sax.SAXException;
+
+public class ServletServiceSerializer extends AbstractSerializer {
+
+    private URL service;
+    private SaxBuffer saxBuffer = new SaxBuffer();
+    private URLConnection servletConnection;
+
+    public void init() {
+        this.setConsumer(this.saxBuffer);
+    }
+
+    @Override
+    public void endDocument() throws SAXException {
+        if (this.service == null) {
+            throw new IllegalArgumentException("ServletServiceSerialzer has no service set.");
+        }
+
+        this.saxBuffer.endDocument();
+
+        try {
+            XMLUtils.toOutputStream(this.getUrlConnection().getOutputStream(), this.saxBuffer);
+            IOUtils.copy(this.getUrlConnection().getInputStream(), this.outputStream);
+        } catch (IOException e) {
+            throw new SAXException("Can't copy result of servlet service to the output stream", e);
+        }
+    }
+
+    private URLConnection getUrlConnection() {
+        if (this.servletConnection == null) {
+            try {
+                this.servletConnection = this.service.openConnection();
+            } catch (IOException e) {
+                throw new ProcessingException("Can't use connected servlet service: " + this.service, e);
+            }
+        }
+
+        return this.servletConnection;
+    }
+
+    @Override
+    public String getContentType() {
+        return this.getUrlConnection().getContentType();
+    }
+
+    @Override
+    public void setConfiguration(Map<String, ? extends Object> parameters) {
+        try {
+            this.service = new URL((String) parameters.get("service"));
+        } catch (MalformedURLException e) {
+            throw new ProcessingException(("Can't create an URL for " + parameters.get("service") + "."), e);
+        }
+    }
+}
\ No newline at end of file

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java?rev=671047&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java Tue Jun 24 00:17:10 2008
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.corona.servlet.ssf;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Map;
+
+import org.apache.cocoon.corona.pipeline.ProcessingException;
+import org.apache.cocoon.corona.pipeline.component.AbstractTransformer;
+import org.apache.cocoon.corona.pipeline.util.SaxBuffer;
+import org.apache.cocoon.corona.pipeline.util.URLConnectionUtils;
+import org.apache.cocoon.corona.pipeline.util.XMLUtils;
+import org.xml.sax.SAXException;
+
+public class ServletServiceTransformer extends AbstractTransformer {
+
+    private URL service;
+    private URLConnection servletConnection;
+
+    @Override
+    public void startDocument() throws SAXException {
+        this.startSAXRecording();
+        this.getXMLConsumer().startDocument();
+    }
+
+    @Override
+    public void endDocument() throws SAXException {
+        if (this.service == null) {
+            throw new IllegalArgumentException("ServletServiceTransformer has no service set.");
+        }
+
+        this.getXMLConsumer().endDocument();
+        SaxBuffer saxBuffer = this.endSAXRecording();
+
+        try {
+            XMLUtils.toOutputStream(this.getUrlConnection().getOutputStream(), saxBuffer);
+        } catch (IOException e) {
+            throw new ProcessingException("Can't stream SaxBuffer into the output stream of the URL "
+                    + this.getUrlConnection().getURL());
+        }
+
+        URLConnectionUtils.toSax(this.getUrlConnection(), this.getXMLConsumer());
+    }
+
+    private URLConnection getUrlConnection() {
+        if (this.servletConnection == null) {
+            try {
+                this.servletConnection = this.service.openConnection();
+            } catch (IOException e) {
+                throw new ProcessingException("Can't use connected servlet service: " + this.service, e);
+            }
+        }
+
+        return this.servletConnection;
+    }
+
+    @Override
+    public void setConfiguration(Map<String, ? extends Object> parameters) {
+        try {
+            this.service = new URL((String) parameters.get("service"));
+        } catch (MalformedURLException e) {
+            throw new ProcessingException(("Can't create an URL for " + parameters.get("service") + "."), e);
+        }
+    }
+}
\ No newline at end of file

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml?rev=671047&r1=671046&r2=671047&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml (original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/resources/META-INF/cocoon/spring/corona-servlet-component.xml Tue Jun 24 00:17:10 2008
@@ -25,5 +25,11 @@
   <bean name="redirector" class="org.apache.cocoon.corona.servlet.component.RedirectorComponent" scope="prototype" />
 
   <bean name="generator:request-parameters" class="org.apache.cocoon.corona.servlet.component.RequestParametersGenerator" scope="prototype" />
+  
+  <bean name="generator:service-consumer" class="org.apache.cocoon.corona.servlet.ssf.ServiceConsumerGenerator" scope="prototype" />
+  
+  <bean name="transformer:servlet-service" class="org.apache.cocoon.corona.servlet.ssf.ServletServiceTransformer" scope="prototype" />
+  
+  <bean name="serializer:servlet-service" class="org.apache.cocoon.corona.servlet.ssf.ServletServiceSerializer" scope="prototype" init-method="init" />
 
 </beans>