You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gk...@apache.org on 2007/05/07 19:13:37 UTC
svn commit: r535930 - in
/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main:
java/org/apache/cocoon/servletservice/postable/components/
resources/META-INF/cocoon/spring/
Author: gkossakowski
Date: Mon May 7 10:13:36 2007
New Revision: 535930
URL: http://svn.apache.org/viewvc?view=rev&rev=535930
Log:
COCOON-2050: Implementation of ServletServiceSerializer.
Added:
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/ServletServiceSerializer.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml (with props)
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/ServletServiceSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/ServletServiceSerializer.java?view=auto&rev=535930
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/ServletServiceSerializer.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/ServletServiceSerializer.java Mon May 7 10:13:36 2007
@@ -0,0 +1,97 @@
+/*
+ * 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.servletservice.postable.components;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.source.util.SourceUtil;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.serialization.AbstractSerializer;
+import org.apache.cocoon.servletservice.postable.PostableSource;
+import org.apache.cocoon.sitemap.SitemapModelComponent;
+import org.apache.cocoon.util.avalon.CLLoggerWrapper;
+import org.apache.cocoon.xml.SaxBuffer;
+import org.apache.cocoon.xml.XMLUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.excalibur.source.SourceException;
+import org.xml.sax.SAXException;
+
+public class ServletServiceSerializer extends AbstractSerializer implements SitemapModelComponent {
+
+ private Log logger = LogFactory.getLog(getClass());
+
+ private PostableSource servletSource;
+
+ private SaxBuffer saxBuffer;
+
+ public void init() {
+ this.enableLogging(new CLLoggerWrapper(this.logger));
+ }
+
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
+ String service;
+ try {
+ service = par.getParameter("service");
+ } catch (ParameterException e) {
+ throw new ProcessingException(e);
+ }
+
+ try {
+ servletSource = (PostableSource) resolver.resolveURI(service);
+ } catch (ClassCastException e) {
+ throw new ProcessingException("Resolved '" + service + "' to source that is not postable. Use servlet: protocol for service calls.");
+ } catch (SourceException se) {
+ throw SourceUtil.handle("Error during resolving of '" + service + "'.", se);
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Source " + service + " resolved to " + servletSource.getURI());
+ }
+
+ saxBuffer = new SaxBuffer();
+ setConsumer(saxBuffer);
+ }
+
+ public void endDocument() throws SAXException {
+ super.endDocument();
+
+ String serializedXML;
+ try {
+ serializedXML = XMLUtils.serialize(saxBuffer, XMLUtils.createPropertiesForXML(false));
+ } catch (ProcessingException e) {
+ throw new SAXException("Exception occured while serializing content of sax buffer", e);
+ }
+ try {
+ IOUtils.copy(new StringReader(serializedXML), servletSource.getOutputStream());
+ } catch (IOException e) {
+ throw new SAXException("Exception occured while writing to the output stream of source '" + servletSource.getURI() + "'", e);
+ }
+ try {
+ IOUtils.copy(servletSource.getInputStream(), super.output);
+ } catch (Exception e) {
+ throw new SAXException("Exception occured while copying response from the service to the output stream", e);
+ }
+ }
+
+}
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/ServletServiceSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml?view=auto&rev=535930
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml Mon May 7 10:13:36 2007
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <bean name="org.apache.cocoon.serialization.Serializer/servletService"
+ class="org.apache.cocoon.servletservice.postable.components.ServletServiceSerializer" init-method="init" scope="prototype"/>
+</beans>
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-serializer.xml
------------------------------------------------------------------------------
svn:eol-style = native