Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK - I've found the answer on my own. This involved writing my own AMF endpoint class + related serializing classes. I've gotta say that the guys over at <a href="http://flexblog.faratasystems.com">http://flexblog.faratasystems.com</a> have been a great source of inspiration on hacking BlazeDS.</p> <p>This code should really be incorporated into BlazeDS itself or some Open Source extension project - it's so basic.</p> <h1>Channel Definition</h1> <pre><code> &lt;channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"&gt; &lt;endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="ch.hedgesphere.core.blazeds.endpoint.AMFEndpoint"/&gt; &lt;properties&gt; &lt;serialization&gt; &lt;type-marshaller&gt;ch.hedgesphere.core.blazeds.translator.HedgesphereASTranslator&lt;/type-marshaller&gt; &lt;/serialization&gt; &lt;/properties&gt; &lt;/channel-definition&gt; </code></pre> <h1>Custom AMF Endpoint</h1> <pre><code>package ch.hedgesphere.core.blazeds.endpoint; import ch.hedgesphere.core.blazeds.serialization.Serializer; public class AMFEndpoint extends flex.messaging.endpoints.AMFEndpoint { @Override protected String getSerializerClassName() { return Serializer.class.getName(); } } </code></pre> <h1>Custom Serializer</h1> <pre><code>package ch.hedgesphere.core.blazeds.serialization; import java.io.OutputStream; import flex.messaging.io.MessageIOConstants; import flex.messaging.io.SerializationContext; import flex.messaging.io.amf.AmfMessageSerializer; import flex.messaging.io.amf.AmfTrace; public class Serializer extends AmfMessageSerializer { @Override public void initialize(SerializationContext context, OutputStream out, AmfTrace trace) { amfOut = new AMF0Output(context); amfOut.setOutputStream(out); amfOut.setAvmPlus(version &gt;= MessageIOConstants.AMF3); debugTrace = trace; isDebug = trace != null; amfOut.setDebugTrace(debugTrace); } } </code></pre> <h1>Custom AMF 0 Handling</h1> <pre><code>package ch.hedgesphere.core.blazeds.serialization; import flex.messaging.io.SerializationContext; public class AMF0Output extends flex.messaging.io.amf.Amf0Output { public AMF0Output(SerializationContext context) { super(context); } @Override protected void createAMF3Output() { avmPlusOutput = new AMF3Output(context); avmPlusOutput.setOutputStream(out); avmPlusOutput.setDebugTrace(trace); } } </code></pre> <h1>Custom AMF 3 Handling</h1> <pre><code>package ch.hedgesphere.core.blazeds.serialization; import java.io.IOException; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.LocalTime; import flex.messaging.io.SerializationContext; public class AMF3Output extends flex.messaging.io.amf.Amf3Output { public AMF3Output(SerializationContext context) { super(context); } @Override public void writeObject(Object value) throws IOException { if(value instanceof DateTime) { value = convertToDate((DateTime)value); } if(value instanceof LocalDate) { value = convertToDate((LocalDate)value); } if(value instanceof LocalTime) { value = convertToDate((LocalTime)value); } super.writeObject(value); } private Object convertToDate(LocalTime time) { return time.toDateTimeToday().toDate(); } private Object convertToDate(LocalDate date) { return date.toDateMidnight().toDate(); } private Object convertToDate(DateTime dateTime) { return dateTime.toDate(); } } </code></pre> <h1>Custom Marshaller for Flex->Java Calling</h1> <pre><code>package ch.hedgesphere.core.blazeds.translator; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.LocalTime; import flex.messaging.io.amf.translator.ASTranslator; public class HedgesphereASTranslator extends ASTranslator { @SuppressWarnings({"rawtypes"}) @Override public Object convert(Object originalValue, Class type) { if( type.equals(DateTime.class)) { return convertToDateTime(originalValue); } if( type.equals(LocalDate.class)) { return convertToLocalDate(originalValue); } if( type.equals(LocalTime.class)) { return convertToLocalTime(originalValue); } return super.convert(originalValue, type); } private Object convertToLocalTime(Object originalValue) { return originalValue == null ? null : new LocalTime(originalValue); } private Object convertToLocalDate(Object originalValue) { return originalValue == null ? null : new LocalDate(originalValue); } private Object convertToDateTime(Object originalValue) { return originalValue == null ? null : new DateTime(originalValue); } @SuppressWarnings({"rawtypes"}) @Override public Object createInstance(Object source, Class type) { return super.createInstance(source, type); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload