本文整理汇总了Java中flex.messaging.io.SerializationContext.getSerializationContext方法的典型用法代码示例。如果您正苦于以下问题:Java SerializationContext.getSerializationContext方法的具体用法?Java SerializationContext.getSerializationContext怎么用?Java SerializationContext.getSerializationContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flex.messaging.io.SerializationContext
的用法示例。
在下文中一共展示了SerializationContext.getSerializationContext方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertXmlToAmf
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
/**
* Converts XML to an object then serializes it
*/
public static byte[] convertXmlToAmf(String xml) {
XStream xs = getXStream();
Amf3Output amf3out = new Amf3Output(SerializationContext.getSerializationContext());
try {
Object msg = xs.fromXML(xml);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
amf3out.setOutputStream(baos);
amf3out.writeObject(msg);
return baos.toByteArray();
} catch (Exception ex) {
}
return new byte[0];
}
示例2: setup
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
serverWrapper = new TestServerWrapper();
serverPort = serverWrapper.startServer("classpath:/WEB-INF/flex/services-config.xml");
if (serverPort == -1) {
Assert.fail("Couldn't start server process");
}
AMFConnection.registerAlias(
"remoting.amfclient.ServerCustomType" /* server type */,
"remoting.amfclient.ClientCustomType" /* client type */);
serializationContext = SerializationContext.getSerializationContext();
ClassDeserializationValidator deserializationValidator =
(ClassDeserializationValidator) serializationContext.getDeserializationValidator();
deserializationValidator.addAllowClassPattern("remoting.amfclient.*");
}
示例3: convert
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
/**
* 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;
}
示例4: decodeObject
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
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;
}
示例5: convertJavaObjToAmf3
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
/**
* 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());
}
示例6: convertXmlToAmfMessage
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
/**
* Converts XML to a complete AMF message
*/
public static byte[] convertXmlToAmfMessage(String xml) {
XStream xs = getXStream();
ActionMessage message = (ActionMessage) xs.fromXML(xml);
// if (checkAckMessage(message))
// return null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ActionContext actionContext = new ActionContext();
actionContext.setRequestMessage(message);
AmfMessageSerializer amfMessageSerializer = new AmfMessageSerializer();
SerializationContext serializationContext = SerializationContext.getSerializationContext();
amfMessageSerializer.initialize(serializationContext, baos, null);
try {
amfMessageSerializer.writeMessage(message);
return baos.toByteArray();
} catch (IOException ex) {
ex.printStackTrace();
return null;
} finally {
baos = null;
}
}
示例7: setup
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
standardValidationServerWrapper = new TestServerWrapper();
standardValidationServerPort = standardValidationServerWrapper.startServer("classpath:/WEB-INF/flex/services-config.xml");
if (standardValidationServerPort == -1) {
Assert.fail("Couldn't start server (standard validation) process");
}
customValidationServerWrapper = new TestServerWrapper();
customValidationServerPort = customValidationServerWrapper.startServer("classpath:/WEB-INF/flex/services-config-customized-validation.xml");
if(customValidationServerPort == -1) {
Assert.fail("Couldn't start server (custom validation) process");
}
AMFConnection.registerAlias(
"remoting.amfclient.ServerCustomType" /* server type */,
"remoting.amfclient.ClientCustomType" /* client type */);
serializationContext = SerializationContext.getSerializationContext();
ClassDeserializationValidator deserializationValidator =
(ClassDeserializationValidator) serializationContext.getDeserializationValidator();
deserializationValidator.addAllowClassPattern("remoting.amfclient.*");
serializationContext.createASObjectForMissingType = true;
// Make sure collections are written out as Arrays (vs. ArrayCollection),
// in case the server does not recognize ArrayCollections.
serializationContext.legacyCollection = true;
// When legacyMap is true, Java Maps are serialized as ECMA arrays
// instead of anonymous Object.
serializationContext.legacyMap = true;
// Disable serialization of xml documents.
serializationContext.allowXml = false;
}
示例8: canUseByReference
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
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;
}
示例9: isAMF
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
public static boolean isAMF(byte[] request, PrintWriter stdOut, PrintWriter stdErr) {
Object[] out;
byte[] requestBody;
SerializationContext serialContext = SerializationContext.getSerializationContext();
AmfMessageDeserializer localAmfMessageDeserializer = new AmfMessageDeserializer();
requestBody = GenericUtil.getBody(request);
try {
localAmfMessageDeserializer.initialize(serialContext, new ByteArrayInputStream(requestBody, 0, requestBody.length), null);
ActionMessage localActionMessage = new ActionMessage();
localAmfMessageDeserializer.readMessage(localActionMessage, new ActionContext());
//Expecting at least one "flex.messaging.messages.RemotingMessage". Note that messages can be encapsulated
for (int i = 0; i < localActionMessage.getBodyCount(); i++) {
out = (Object[]) localActionMessage.getBody(i).getData();
for (int j = 0; j < out.length; j++) {
if (out[j] instanceof RemotingMessage) {
return true;
}
}
}
} catch (flex.messaging.MessageException exM) {
if (exM.getCode().equalsIgnoreCase("Client.Message.Encoding")) {
//Something wrong while deserializating. Custom objects?
stdErr.println("[!] Blazer isAMF Exception: " + exM.toString().trim());
return true; //load Blazer anyway
} else {
return false;
}
} catch (Exception ex) {
stdErr.println("[!] Blazer isAMF Exception: " + ex.toString().trim());
stdErr.println("[!] Does the request contain a valid 'flex.messaging.messages.RemotingMessage' ?!?");
return false;
}
return false;
}
示例10: decodeArray
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
protected Object decodeArray(Object shellArray, Object array, Class arrayElementClass)
{
Object encodedValue = null;
Object decodedValue = null;
int n = 0;
int len = Array.getLength(array);
for (int i = 0; i < len; i++)
{
encodedValue = Array.get(array, i);
if (encodedValue == null)
{
Array.set(shellArray, n, null);
}
else
{
// We may need to honor our loose-typing rules for individual types as,
// unlike a Collection, an Array has a fixed element type. We'll use our handy
// decoder suite again to find us the right decoder...
ActionScriptDecoder decoder;
if (SerializationContext.getSerializationContext().restoreReferences)
decoder = DecoderFactory.getReferenceAwareDecoder(encodedValue, arrayElementClass);
else
decoder = DecoderFactory.getDecoder(encodedValue, arrayElementClass);
decodedValue = decoder.decodeObject(encodedValue, arrayElementClass);
try
{
Array.set(shellArray, n, decodedValue);
}
catch (IllegalArgumentException ex)
{
// FIXME: At least log this as a error...
// TODO: Should we report a failed Array element set?
// Perhaps the action here could be configurable on the translation context?
Array.set(shellArray, n, null);
}
}
n++;
}
return shellArray;
}
示例11: deserializateRequest
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
private void deserializateRequest(DeserializationValidator validator) {
try {
// Find sample AMF data, or read the default file.
String sample = System.getProperty("AMF_SAMPLE_FILE");
if (sample == null || sample.length() < 1)
sample = "amf_request.xml";
URL resource = ClassLoader.getSystemResource(sample);
URI uri = new URI(resource.toString());
File testData = new File(uri.getPath());
String testDataLocation = testData.getCanonicalPath();
// Generate sample AMF request from the data file.
PipedOutputStream pout = new PipedOutputStream();
DataOutputStream dout = new DataOutputStream(pout);
DataInputStream din = new DataInputStream(new PipedInputStream(pout));
AmfTrace trace = new AmfTrace();
trace.startResponse("Serializing AMF/HTTP response");
MessageGenerator gen = new MessageGenerator();
gen.setDebugTrace(trace);
gen.setOutputStream(dout);
gen.parse(testDataLocation);
trace.endMessage();
trace.newLine();
// Create a deserializer for sample AMF request.
ActionContext context = new ActionContext();
ActionMessage message = new ActionMessage();
context.setRequestMessage(message);
SerializationContext dsContext = SerializationContext.getSerializationContext();
if (validator != null)
dsContext.setDeserializationValidator(validator);
MessageDeserializer deserializer = new AmfMessageDeserializer();
deserializer.initialize(dsContext, din, trace);
deserializer.readMessage(message, context);
trace.endMessage();
trace.newLine();
//if (UnitTrace.debug) // Print trace output.
// System.out.print(trace.toString());
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
示例12: testDeserializeMessage
import flex.messaging.io.SerializationContext; //导入方法依赖的package包/类
@Test
public void testDeserializeMessage() {
try {
String sample = System.getProperty("AMF_SAMPLE_FILE");
if (sample == null || sample.length() < 1) {
sample = "amf_request.xml";
}
URL resource = ClassLoader.getSystemResource(sample);
URI uri = new URI(resource.toString());
File testData = new File(uri.getPath());
String testDataLocation = testData.getCanonicalPath();
PipedOutputStream pout = new PipedOutputStream();
DataOutputStream dout = new DataOutputStream(pout);
PipedInputStream pin = new PipedInputStream(pout);
DataInputStream din = new DataInputStream(pin);
AmfTrace trace = new AmfTrace();
trace.startResponse("Serializing AMF/HTTP response");
MessageGenerator gen = new MessageGenerator();
gen.setDebugTrace(trace);
gen.setOutputStream(dout);
gen.parse(testDataLocation);
trace.endMessage();
trace.newLine();
ActionContext context = new ActionContext();
ActionMessage message = new ActionMessage();
context.setRequestMessage(message);
trace.startRequest("Deserializing AMF/HTTP request");
SerializationContext dsContext = SerializationContext.getSerializationContext();
MessageDeserializer deserializer = new AmfMessageDeserializer();
deserializer.initialize(dsContext, din, trace);
long start = System.currentTimeMillis();
deserializer.readMessage(message, context);
long finish = System.currentTimeMillis();
trace.endMessage();
try {
if (metricsManager != null) {
long duration = finish - start;
Value v2 = metricsManager.createValue(duration);
metricsManager.saveValue(v2);
trace.newLine();
if (UnitTrace.debug) {
System.out.print("AMF Deserialization Time: " + duration + "ms");
}
}
} catch (Throwable t) {
if (UnitTrace.errors) {
t.printStackTrace();
}
}
if (UnitTrace.debug) {
System.out.print(trace.toString());
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}