Details
-
New Feature
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
None
-
None
-
None
-
Patch
Description
I've created content handler for adobe specific amf and amfx extensions. Here is the patch for the same.
Index: plugins/rest/pom.xml
===================================================================
— plugins/rest/pom.xml (revision 832711)
+++ plugins/rest/pom.xml (working copy)
@@ -34,6 +34,26 @@
<name>Struts 2 REST Plugin</name>
<dependencies>
+ <dependency>
+ <groupId>org.apache.pluto</groupId>
+ <artifactId>pluto</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.adobe.blazeds</groupId>
+ <artifactId>blazeds-core</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.adobe.blazeds</groupId>
+ <artifactId>blazeds-common</artifactId>
+ <version>3.0</version>
+ </dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
Index: plugins/rest/src/main/java/org/apache/struts2/rest/handler/AmfHandler.java
===================================================================
— plugins/rest/src/main/java/org/apache/struts2/rest/handler/AmfHandler.java (revision 0)
+++ plugins/rest/src/main/java/org/apache/struts2/rest/handler/AmfHandler.java (revision 0)
@@ -0,0 +1,95 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.rest.handler;
+
+import flex.messaging.io.SerializationContext;
+import flex.messaging.io.amf.Amf3Input;
+import flex.messaging.io.amf.Amf3Output;
+
+import org.apache.struts2.rest.handler.ContentTypeHandler;
+import org.apache.pluto.util.WriterOutputStream;
+import org.apache.tools.ant.util.ReaderInputStream;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+
+/**
+ * Handles Amf content using flex api
+ */
+public class AmfHandler implements ContentTypeHandler {
+
+ public void toObject(Reader in, Object target) throws IOException {
+ SerializationContext context = getSerializationContext();
+ ReaderInputStream input = new ReaderInputStream(in);
+ Amf3Input amf3Input = new Amf3Input(context);
+ amf3Input.setInputStream(input);
+
+ try
catch (ClassNotFoundException e)
{ + e.printStackTrace(); + }+ }
+
+ public String fromObject(Object obj, String resultCode, Writer stream)
+ throws IOException {
+ if (obj != null) { + Amf3Output amf3Output = new Amf3Output(getSerializationContext()); + WriterOutputStream out = new WriterOutputStream(stream,"UTF-8"); + amf3Output.setOutputStream(out); + amf3Output.writeObject(obj); + amf3Output.flush(); + amf3Output.close(); + }
+
+ return null;
+ }
+
+ public String getContentType() { + return "application/x-amf"; + }
+
+ public String getExtension() { + return "amf"; + }
+
+ SerializationContext getSerializationContext() { + SerializationContext serializationContext = SerializationContext.getSerializationContext(); + serializationContext.enableSmallMessages = true; + serializationContext.instantiateTypes = true; + serializationContext.supportRemoteClass = true; + serializationContext.legacyCollection = true; + serializationContext.legacyMap = true; + serializationContext.legacyXMLDocument = true; + serializationContext.legacyXMLNamespaces = true; + serializationContext.legacyThrowable = false; + serializationContext.legacyBigNumbers = true; + serializationContext.restoreReferences = false; + serializationContext.logPropertyErrors = false; + serializationContext.ignorePropertyErrors = true; + + return serializationContext; + }
+
+}
Index: plugins/rest/src/main/java/org/apache/struts2/rest/handler/AmfxHandler.java
===================================================================
— plugins/rest/src/main/java/org/apache/struts2/rest/handler/AmfxHandler.java (revision 0)
+++ plugins/rest/src/main/java/org/apache/struts2/rest/handler/AmfxHandler.java (revision 0)
@@ -0,0 +1,97 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.rest.handler;
+
+import flex.messaging.io.SerializationContext;
+import flex.messaging.io.amf.AmfTrace;
+import flex.messaging.io.amfx.AmfxMessageDeserializer;
+import flex.messaging.io.amfx.AmfxOutput;
+
+import org.apache.struts2.rest.handler.ContentTypeHandler;
+import org.apache.pluto.util.WriterOutputStream;
+import org.apache.tools.ant.util.ReaderInputStream;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+
+/**
+ * Handles Amfx content using flex api
+ */
+public class AmfxHandler implements ContentTypeHandler {
+
+ public void toObject(Reader in, Object target) throws IOException {
+ SerializationContext context = getSerializationContext();
+ ReaderInputStream input = new ReaderInputStream(in);
+ AmfxMessageDeserializer s = new AmfxMessageDeserializer();
+ AmfTrace trace = new AmfTrace();
+ s.initialize(context, input, trace);
+
+ try { + target = s.readObject(); + } catch (ClassNotFoundException e) {+ e.printStackTrace();+ }
+ }
+
+ public String fromObject(Object obj, String resultCode, Writer stream)
+ throws IOException {
+ if (obj != null)
+
+ return null;
+ }
+
+ public String getContentType()
+
+ public String getExtension()
+
+ SerializationContext getSerializationContext()
+
+}
\ No newline at end of file
Index: plugins/rest/src/main/resources/struts-plugin.xml
===================================================================
— plugins/rest/src/main/resources/struts-plugin.xml (revision 832711)
+++ plugins/rest/src/main/resources/struts-plugin.xml (working copy)
@@ -37,12 +37,14 @@
<bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="html" class="org.apache.struts2.rest.handler.HtmlHandler" />
<bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="x-www-form-urlencoded" class="org.apache.struts2.rest.handler.FormUrlEncodedHandler" />
<bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="multipart/form-data" class="org.apache.struts2.rest.handler.MultipartFormDataHandler" />
+ <bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="amf" class="org.apache.struts2.rest.handler.AmfHandler" />
+ <bean type="org.apache.struts2.rest.handler.ContentTypeHandler" name="amfx" class="org.apache.struts2.rest.handler.AmfxHandler" />
<constant name="struts.actionProxyFactory" value="rest" />
<constant name="struts.rest.defaultExtension" value="xhtml" />
<constant name="struts.mapper.class" value="rest" />
<constant name="struts.mapper.idParameterName" value="id" />
- <constant name="struts.action.extension" value="xhtml,,xml,json" />
+ <constant name="struts.action.extension" value="xhtml,,xml,json,amf,amfx" />
<package name="rest-default" extends="struts-default">
<result-types>