public SerializationContext get() { // Threadlocal SerializationContent SerializationContext serializationContext = SerializationContext .getSerializationContext(); serializationContext.enableSmallMessages = true; serializationContext.instantiateTypes = true; // use _remoteClass field serializationContext.supportRemoteClass = true; // false Legacy Flex 1.5 behavior was to return a java.util.Collection // for Array, New Flex 2+ behavior is to return Object[] for AS3 Array serializationContext.legacyCollection = false; // false Legacy flash.xml.XMLDocument Type serializationContext.legacyMap = false; // true New E4X XML Type serializationContext.legacyXMLDocument = false; // determines whether the constructed Document is name-space aware serializationContext.legacyXMLNamespaces = false; serializationContext.legacyThrowable = false; serializationContext.legacyBigNumbers = false; serializationContext.restoreReferences = false; serializationContext.logPropertyErrors = false; serializationContext.ignorePropertyErrors = true; return serializationContext; } }
protected Object deSerializeObjectFromStream(ByteArrayInputStream bis) throws Exception { AMFDeSerializer serializer = new AMFDeSerializer(SerializationContext .getSerializationContext()); Object o = null; try { // do the deserialization. o = serializer.fromAmf(bis); LOG.trace("Serialized object: {}",o); bis.close(); } catch (IOException e) { LOG.error("IO error in AMF3ToJavaObjectDecoder: {}",e); throw e; } catch (ClassNotFoundException e) { LOG.error("Error in AMF3ToJavaObjectDecoder: {}.\n " + "Check if flash class has corresponding java class",e); throw e; } return o; } }
/** {@inheritDoc} */ public SerializationContext getSerializationContext() { if (context == null) { return SerializationContext.getSerializationContext(); } return context; }
/** {@inheritDoc} */ public SerializationContext getSerializationContext() { return context == null? SerializationContext.getSerializationContext() : context; }
/** {@inheritDoc} */ public SerializationContext getSerializationContext() { return context == null? SerializationContext.getSerializationContext() : context; }
protected boolean canUseByReference(Object o) { if (o == null) return false; else if (o instanceof String) return false; else if (o instanceof Number) return false; else if (o instanceof Boolean) return false; else if (o instanceof Date) { return SerializationContext.getSerializationContext().supportDatesByReference; } else if (o instanceof Calendar) return false; else if (o instanceof Character) return false; return true; }
protected boolean canUseByReference(Object o) { if (o == null) return false; else if (o instanceof String) return false; else if (o instanceof Number) return false; else if (o instanceof Boolean) return false; else if (o instanceof Date) { return SerializationContext.getSerializationContext().supportDatesByReference; } else if (o instanceof Calendar) return false; else if (o instanceof Character) return false; return true; }
protected boolean canUseByReference(Object o) { if (o == null) return false; else if (o instanceof String) return false; else if (o instanceof Number) return false; else if (o instanceof Boolean) return false; else if (o instanceof Date) { if (SerializationContext.getSerializationContext().supportDatesByReference) return true; else return false; } else if (o instanceof Calendar) return false; else if (o instanceof Character) return false; return true; }
public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) { Object result = super.decodeObject(shell, encodedObject, desiredClass); // Only AMF 3 Dates can be sent by reference so we only // need to remember this translation to re-establish pointers // to the encodedObject if the incoming type was a Date object. if (result != null && SerializationContext.getSerializationContext().supportDatesByReference && encodedObject instanceof java.util.Date) { TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); context.getKnownObjects().put(encodedObject, result); } return result; } }
public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) { Object result = super.decodeObject(shell, encodedObject, desiredClass); // Only AMF 3 Dates can be sent by reference so we only // need to remember this translation to re-establish pointers // to the encodedObject if the incoming type was a Date object. if (result != null && SerializationContext.getSerializationContext().supportDatesByReference && encodedObject instanceof java.util.Date) { TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); context.getKnownObjects().put(encodedObject, result); } return result; } }
public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) { Object result = super.decodeObject(shell, encodedObject, desiredClass); // Only AMF 3 Dates can be sent by reference so we only // need to remember this translation to re-establish pointers // to the encodedObject if the incoming type was a Date object. if (result != null && SerializationContext.getSerializationContext().supportDatesByReference && encodedObject instanceof java.util.Date) { TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); context.getKnownObjects().put(encodedObject, result); } return result; } }
public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) { Object result = super.decodeObject(shell, encodedObject, desiredClass); // Only AMF 3 Dates can be sent by reference so we only // need to remember this translation to re-establish pointers // to the encodedObject if the incoming type was a Date object. if (result != null && SerializationContext.getSerializationContext().supportDatesByReference && encodedObject instanceof java.util.Date) { TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); context.getKnownObjects().put(encodedObject, result); } return result; } }
public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) { Object result = super.decodeObject(shell, encodedObject, desiredClass); // Only AMF 3 Dates can be sent by reference so we only // need to remember this translation to re-establish pointers // to the encodedObject if the incoming type was a Date object. if (result != null && SerializationContext.getSerializationContext().supportDatesByReference && encodedObject instanceof java.util.Date) { TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); context.getKnownObjects().put(encodedObject, result); } return result; } }
public Object decodeObject(Object shell, Object encodedObject, Class desiredClass) { Object result = super.decodeObject(shell, encodedObject, desiredClass); // Only AMF 3 Dates can be sent by reference so we only // need to remember this translation to re-establish pointers // to the encodedObject if the incoming type was a Date object. if (result != null && SerializationContext.getSerializationContext().supportDatesByReference && encodedObject instanceof java.util.Date) { TypeMarshallingContext context = TypeMarshallingContext.getTypeMarshallingContext(); context.getKnownObjects().put(encodedObject, result); } return result; } }
/** * Translate an object to another object of type class. * obj types should be ASObject, Boolean, String, Double, Date, ArrayList */ public Object convert(Object source, Class desiredClass) { if (source == null && !desiredClass.isPrimitive()) { return null; } SerializationContext serializationContext = SerializationContext.getSerializationContext(); ActionScriptDecoder decoder; if (serializationContext.restoreReferences) decoder = DecoderFactory.getReferenceAwareDecoder(source, desiredClass); else decoder = DecoderFactory.getDecoder(source, desiredClass); if (Trace.remote) { Trace.trace("Decoder for " + (source == null ? "null" : source.getClass().toString()) + " with desired " + desiredClass + " is " + decoder.getClass()); } Object result = decoder.decodeObject(source, desiredClass); return result; } }
/** * Translate an object to another object of type class. * obj types should be ASObject, Boolean, String, Double, Date, ArrayList */ public Object convert(Object source, Class desiredClass) { if (source == null && !desiredClass.isPrimitive()) { return null; } SerializationContext serializationContext = SerializationContext.getSerializationContext(); ActionScriptDecoder decoder; if (serializationContext.restoreReferences) decoder = DecoderFactory.getReferenceAwareDecoder(source, desiredClass); else decoder = DecoderFactory.getDecoder(source, desiredClass); if (Trace.remote) { Trace.trace("Decoder for " + (source == null ? "null" : source.getClass().toString()) + " with desired " + desiredClass + " is " + decoder.getClass()); } Object result = decoder.decodeObject(source, desiredClass); return result; } }
/** * Convert Java Object to AMF3 protocol's byte[] * * @param msg Java object * @return return byte array see: {@link ByteBuf}. * @throws IOException amf3 output exception. * @throws NullPointerException where the msg is Null, throw the NullPointerException. */ public static ByteBuf convertJavaObjToAmf3(Object msg) throws IOException { if (msg == null) { throw new NullPointerException("msg"); } final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final Amf3Output op = new Amf3Output(SerializationContext.getSerializationContext()); op.setOutputStream(bout); op.writeObject(msg); op.flush(); op.close(); return Unpooled.wrappedBuffer(bout.toByteArray()); }
/** * Translate an object to another object of type class. * obj types should be ASObject, Boolean, String, Double, Date, ArrayList */ public Object convert(Object source, Class desiredClass) { if (source == null && !desiredClass.isPrimitive()) { return null; } SerializationContext serializationContext = SerializationContext.getSerializationContext(); ActionScriptDecoder decoder; if (serializationContext.restoreReferences) decoder = DecoderFactory.getReferenceAwareDecoder(source, desiredClass); else decoder = DecoderFactory.getDecoder(source, desiredClass); if (Trace.remote) { Trace.trace("Decoder for " + (source == null ? "null" : source.getClass().toString()) + " with desired " + desiredClass + " is " + decoder.getClass()); } Object result = decoder.decodeObject(source, desiredClass); return result; } }
public static ActionMessage extractAM(byte[] reqresp, PrintWriter stdOut, PrintWriter stdErr) { ActionMessage localActionMessage = null; SerializationContext serialContext = SerializationContext.getSerializationContext(); AmfMessageDeserializer localAmfMessageDeserializer = new AmfMessageDeserializer(); byte[] body = GenericUtil.getBody(reqresp); try { localAmfMessageDeserializer.initialize(serialContext, new ByteArrayInputStream(body, 0, body.length), null); localActionMessage = new ActionMessage(); localAmfMessageDeserializer.readMessage(localActionMessage, new ActionContext()); } catch (Exception ex) { stdErr.println("[!] Blazer extractAM Exception: " + ex.toString().trim()); } return localActionMessage; } }
/** * Convert stream of AMF3 protocol's byte[] to Java Object. * * @throws Exception amf3 output exception. */ public static Object convertAmf3ToObj(ByteArrayInputStream bis) throws Exception { Object obj; final Amf3Input amf3Input = new Amf3Input(SerializationContext.getSerializationContext()); try { amf3Input.setInputStream(bis); obj = amf3Input.readObject(); amf3Input.close(); } catch (ClassNotFoundException e) { LOG.error("Error in AMF3Utils: {}.\n " + "Check if flash class has corresponding java class.", e); throw e; } catch (IOException e) { LOG.error("IO error in AMF3Utils: {}.", e); throw e; } return obj; } }