http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/AmfMessageDeserializer.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/AmfMessageDeserializer.java b/core/src/flex/messaging/io/amf/AmfMessageDeserializer.java deleted file mode 100644 index 2cc5287..0000000 --- a/core/src/flex/messaging/io/amf/AmfMessageDeserializer.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * 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 flex.messaging.io.amf; - -import flex.messaging.MessageException; -import flex.messaging.io.MessageDeserializer; -import flex.messaging.io.MessageIOConstants; -import flex.messaging.io.RecoverableSerializationException; -import flex.messaging.io.SerializationContext; - -import java.io.IOException; -import java.io.InputStream; - -public class AmfMessageDeserializer implements MessageDeserializer -{ - public static final String CODE_VERSION_MISMATCH = "VersionMismatch"; - private static final int UNSUPPORTED_AMF_VERSION = 10310; - - protected ActionMessageInput amfIn; - - protected AmfTrace debugTrace; - protected boolean isDebug; - - public AmfMessageDeserializer() - { - } - - public void initialize(SerializationContext context, InputStream in, AmfTrace trace) - { - amfIn = new Amf0Input(context); - amfIn.setInputStream(in); - - debugTrace = trace; - isDebug = debugTrace != null; - amfIn.setDebugTrace(debugTrace); - } - - public void readMessage(ActionMessage m, ActionContext context) throws ClassNotFoundException, IOException - { - if (isDebug) - debugTrace.startRequest("Deserializing AMF/HTTP request"); - - int version = amfIn.readUnsignedShort(); - - // Treat FMS's AMF1 as AMF0. - if (version == MessageIOConstants.AMF1) - version = MessageIOConstants.AMF0; - - if (version != MessageIOConstants.AMF0 && version != MessageIOConstants.AMF3) - { - //Unsupported AMF version {version}. - MessageException ex = new MessageException(); - ex.setMessage(UNSUPPORTED_AMF_VERSION, new Object[] {new Integer(version)}); - ex.setCode(CODE_VERSION_MISMATCH); - throw ex; - } - - m.setVersion(version); - context.setVersion(version); - - if (isDebug) - debugTrace.version(version); - - // Read headers - int headerCount = amfIn.readUnsignedShort(); - for (int i = 0; i < headerCount; ++i) - { - MessageHeader header = new MessageHeader(); - m.addHeader(header); - readHeader(header, i); - } - - // Read bodies - int bodyCount = amfIn.readUnsignedShort(); - for (int i = 0; i < bodyCount; ++i) - { - MessageBody body = new MessageBody(); - m.addBody(body); - readBody(body, i); - } - } - - - /** - * Deserialize a message header from the input stream. - * A message header is structured as: - * NAME kString - * MUST UNDERSTAND kBoolean - * LENGTH kInt - * DATA kObject - * - * @param header - will hold the deserialized message header - * @param index header index for debugging - * @throws IOException thrown by the underlying stream - * @throws ClassNotFoundException if we don't find the class for the header data. - */ - public void readHeader(MessageHeader header, int index) throws ClassNotFoundException, IOException - { - String name = amfIn.readUTF(); - header.setName(name); - boolean mustUnderstand = amfIn.readBoolean(); - header.setMustUnderstand(mustUnderstand); - - amfIn.readInt(); // Length - - amfIn.reset(); - Object data; - - if (isDebug) - debugTrace.startHeader(name, mustUnderstand, index); - - try - { - data = readObject(); - } - catch (RecoverableSerializationException ex) - { - ex.setCode("Client.Header.Encoding"); - data = ex; - } - catch (MessageException ex) - { - ex.setCode("Client.Header.Encoding"); - throw ex; - } - - header.setData(data); - - if (isDebug) - debugTrace.endHeader(); - } - - - /** - * Deserialize a message body from the input stream. - * - * @param body - will hold the deserialized message body - * @param index message index for debugging - * @throws IOException thrown by the underlying stream - * @throws ClassNotFoundException if we don't find the class for the body data. - */ - public void readBody(MessageBody body, int index) throws ClassNotFoundException, IOException - { - String targetURI = amfIn.readUTF(); - body.setTargetURI(targetURI); - String responseURI = amfIn.readUTF(); - body.setResponseURI(responseURI); - - amfIn.readInt(); // Length - - amfIn.reset(); - Object data; - - if (isDebug) - debugTrace.startMessage(targetURI, responseURI, index); - - try - { - data = readObject(); - } - catch (RecoverableSerializationException ex) - { - ex.setCode("Client.Message.Encoding"); - data = ex; - } - catch (MessageException ex) - { - ex.setCode("Client.Message.Encoding"); - throw ex; - } - - body.setData(data); - - if (isDebug) - debugTrace.endMessage(); - } - - /** - * Read Object. - * @return Object the object read from AmfInput - * @throws ClassNotFoundException, IOException when exceptions occurs in reading the object - */ - public Object readObject() throws ClassNotFoundException, IOException - { - return amfIn.readObject(); - } -} -
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/AmfMessageSerializer.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/AmfMessageSerializer.java b/core/src/flex/messaging/io/amf/AmfMessageSerializer.java deleted file mode 100644 index 118d542..0000000 --- a/core/src/flex/messaging/io/amf/AmfMessageSerializer.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 flex.messaging.io.amf; - -import flex.messaging.io.MessageIOConstants; -import flex.messaging.io.MessageSerializer; -import flex.messaging.io.SerializationContext; - -import java.io.IOException; -import java.io.OutputStream; - -public class AmfMessageSerializer implements MessageSerializer -{ - public static final int UNKNOWN_CONTENT_LENGTH = 1; //-1; - - protected Amf0Output amfOut; - - protected boolean isDebug; - protected AmfTrace debugTrace; - protected int version; - - public AmfMessageSerializer() - { - } - - public void setVersion(int value) - { - version = value; - } - - public void initialize(SerializationContext context, OutputStream out, AmfTrace trace) - { - amfOut = new Amf0Output(context); - amfOut.setOutputStream(out); - amfOut.setAvmPlus(version >= MessageIOConstants.AMF3); - - debugTrace = trace; - isDebug = trace != null; - amfOut.setDebugTrace(debugTrace); - } - - /** - * Serializes a message to the output stream. - * - * @param m message to serialize - * @throws IOException - */ - public void writeMessage(ActionMessage m) throws IOException - { - if (isDebug) - debugTrace.startResponse("Serializing AMF/HTTP response"); - - int version = m.getVersion(); - - amfOut.setAvmPlus(version >= MessageIOConstants.AMF3); - - // Write packet header - amfOut.writeShort(version); - - if (isDebug) - debugTrace.version(version); - - // Write out headers - int headerCount = m.getHeaderCount(); - amfOut.writeShort(headerCount); - for (int i = 0; i < headerCount; ++i) - { - MessageHeader header = m.getHeader(i); - - if (isDebug) - debugTrace.startHeader(header.getName(), header.getMustUnderstand(), i); - - writeHeader(header); - - if (isDebug) - debugTrace.endHeader(); - } - - // Write out the bodies - int bodyCount = m.getBodyCount(); - amfOut.writeShort(bodyCount); - for (int i = 0; i < bodyCount; ++i) - { - MessageBody body = m.getBody(i); - - if (isDebug) - debugTrace.startMessage(body.getTargetURI(), body.getResponseURI(), i); - - writeBody(body); - - if (isDebug) - debugTrace.endMessage(); - } - } - - /** - * Serializes a message header to the output stream. - * - * @param h header to serialize - * @throws IOException if write fails. - */ - public void writeHeader(MessageHeader h) throws IOException - { - amfOut.writeUTF(h.getName()); - amfOut.writeBoolean(h.getMustUnderstand()); - amfOut.writeInt(UNKNOWN_CONTENT_LENGTH); - amfOut.reset(); - writeObject(h.getData()); - } - - /** - * Serializes a message body to the output stream. - * - * @param b body to serialize - * @throws IOException if write fails. - */ - public void writeBody(MessageBody b) throws IOException - { - if (b.getTargetURI() == null) - amfOut.writeUTF("null"); - else - amfOut.writeUTF(b.getTargetURI()); - - if (b.getResponseURI() == null) - amfOut.writeUTF("null"); - else - amfOut.writeUTF(b.getResponseURI()); - - amfOut.writeInt(UNKNOWN_CONTENT_LENGTH); - amfOut.reset(); - - Object data = b.getData(); - writeObject(data); - } - - /** - * Serializes an Object directly to the output stream. - * - * @param value - the Object to write to the AMF stream. - */ - public void writeObject(Object value) throws IOException - { - amfOut.writeObject(value); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/AmfTrace.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/AmfTrace.java b/core/src/flex/messaging/io/amf/AmfTrace.java deleted file mode 100644 index a8cb406..0000000 --- a/core/src/flex/messaging/io/amf/AmfTrace.java +++ /dev/null @@ -1,577 +0,0 @@ -/* - * 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 flex.messaging.io.amf; - -import flex.messaging.util.ObjectTrace; -import flex.messaging.log.Log; - -/** - * The AMFTrace class is an AMF extension to the ObjectTrace utility to format - * AMF input/output in a similar manner to the client-side - * NetConnection Debugger. - * - * Note that in this version new lines are added after the - * individual values in complex type properties automatically. - */ -public class AmfTrace extends ObjectTrace -{ - /** - * Default constructor. - */ - public AmfTrace() - { - buffer = new StringBuffer(4096); - } - - /** - * Starts a request with the message. - * - * @param message start message string - */ - public void startRequest(String message) - { - m_indent = 0; - buffer.append(message); - m_indent++; - } - - /** - * Starts a response with the message. - * - * @param message start response string - */ - public void startResponse(String message) - { - m_indent = 0; - buffer.append(message); - m_indent++; - } - - /** - * Adds the version to the buffer. - * - * @param version the current version - */ - public void version(int version) - { - newLine(); - buffer.append("Version: ").append(version); - } - - /** - * Starts a header. - * - * @param name header name - * @param mustUnderstand mustUnderstand value - * @param index header number - */ - public void startHeader(String name, boolean mustUnderstand, int index) - { - newLine(); - buffer.append(indentString()); - buffer.append("(Header #").append(index).append(" name=").append(name); - buffer.append(", mustUnderstand=").append(mustUnderstand).append(")"); - newLine(); - m_indent++; - } - - /** - * Ends the header. - */ - public void endHeader() - { - m_indent--; - } - - /** - * Starts a command. - * - * @param cmd command object - * @param iCmd command index - * @param trxId transaction id - */ - public void startCommand(Object cmd, int iCmd, Object trxId) - { - newLine(); - buffer.append(indentString()); - buffer.append("(Command method=").append(cmd).append(" (").append(iCmd).append(")"); - buffer.append(" trxId=").append(trxId).append(")"); - newLine(); - m_indent++; - } - - /** - * Ends the command. - */ - public void endCommand() - { - m_indent--; - } - - /** - * Starts a message. - * - * @param targetURI the target URI - * @param responseURI the response URI - * @param index the message number - */ - public void startMessage(String targetURI, String responseURI, int index) - { - newLine(); - buffer.append(indentString()); - buffer.append("(Message #").append(index).append(" targetURI=").append(targetURI); - buffer.append(", responseURI=").append(responseURI).append(")"); - newLine(); - m_indent++; - } - - /** - * Ends the message. - */ - public void endMessage() - { - m_indent--; - } - - /** - * Checks to make sure that this property is allowed to be written. - * @return true if caller should not print value - */ - private boolean isExcluded() - { - if (nextElementExclude) - { - nextElementExclude = false; - buffer.append(Log.VALUE_SUPRESSED); - newLine(); - return true; - } - return false; - } - - /** - * Writes an Object type. - */ - @Override public void write(Object o) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append(String.valueOf(o)); - newLine(); - } - - /** - * Writes a boolean type. - * @param b value to write - */ - public void write(boolean b) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append(b); - newLine(); - } - - /** - * Writes a double type. - * @param d value to write - */ - public void write(double d) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append(d); - newLine(); - } - - /** - * Writes a float type. - * @param f value to write - */ - public void write(float f) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append(f); - newLine(); - } - - /** - * Writes an integer type. - * @param i value to write - */ - public void write(int i) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append(i); - newLine(); - } - - /** - * Writes a long type. - * @param l value to write - */ - public void write(long l) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append(l); - newLine(); - } - - /** - * Writes a short type. - * @param s value to write - */ - public void write(short s) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append(s); - newLine(); - } - - /** - * Writes a byte type. - * @param b value to write. - */ - public void write(byte b) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append(b); - newLine(); - } - - /** - * Writes a null type. - */ - @Override public void writeNull() - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("null"); - newLine(); - } - - /** - * Writes a ref type. - */ - @Override public void writeRef(int ref) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("(Ref #").append(ref).append(")"); - newLine(); - } - - /** - * Writes a String type. - */ - @Override public void writeString(String s) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("\"").append(s).append("\""); - - newLine(); - } - - /** - * Writes a String ref type. - * @param ref string reference number - */ - public void writeStringRef(int ref) - { - if (isExcluded()) - return; - - buffer.append(" (String Ref #").append(ref).append(")"); - } - - /** - * Writes a traits info type. - * @param ref trait reference number - */ - public void writeTraitsInfoRef(int ref) - { - if (isExcluded()) - return; - - buffer.append(" (Traits Ref #").append(ref).append(")"); - } - - /** - * Writes an undefined type. - */ - public void writeUndefined() - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("undefined"); - newLine(); - } - - /** - * Starts an AMF array. - * - * @param ref the array reference number - */ - public void startAMFArray(int ref) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("(Array #").append(ref).append(")").append(newLine); - m_indent++; - m_nested++; - } - - /** - * Starts an ECMA array. - * - * @param ref the array reference number - */ - public void startECMAArray(int ref) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("(ECMA Array #").append(ref).append(")").append(newLine); - m_indent++; - m_nested++; - } - - /** - * Starts a ByteArrray. - * - * @param ref array reference number - * @param length length of the array - */ - public void startByteArray(int ref, int length) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("(Byte Array #").append(ref).append(", Length ").append(length).append(")").append(newLine); - } - - /** - * Ends a ByteArray. - */ - public void endAMFArray() - { - m_indent--; - m_nested--; - } - - /** - * Starts an ExternalizableObject. - * - * @param type the type of the object - * @param ref the object number - */ - public void startExternalizableObject(String type, int ref) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("(Externalizable Object #").append(ref).append(" \'").append(type).append("\')").append(newLine); - - m_indent++; - m_nested++; - - buffer.append(indentString()); - } - - /** - * Starts an AMFObject. - * - * @param type the type of the object - * @param ref the reference number - */ - public void startAMFObject(String type, int ref) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - if (type != null && type.length() > 0) - buffer.append("(Typed Object #").append(ref).append(" \'").append(type).append("\')").append(newLine); - else - buffer.append("(Object #").append(ref).append(")").append(newLine); - - m_indent++; - m_nested++; - } - - /** - * Ends an AMFObject. - */ - public void endAMFObject() - { - m_indent--; - m_nested--; - } - - /** - * Starts an AMF Dictionary - * - * @param ref the reference number - */ - public void startAMFDictionary(int ref) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("(Dictionary #").append(ref).append(")").append(newLine); - - m_indent++; - m_nested++; - } - - /** - * Starts an AMF Dictionary element. - */ - public void startDictionaryElement() - { - buffer.append(indentString()); - } - - /** - * Adds an equals sign after a dictionary key. - */ - public void addDictionaryEquals() - { - buffer.append(indentString()).append(" ").append(" = "); - } - - /** - * Ends an AMF Dictionary. - */ - public void endAMFDictionary() - { - m_indent--; - m_nested--; - } - - /** - * Enum for different Vector types. - */ - public enum VectorType - { - INT, UINT, DOUBLE, OBJECT; - - @Override public String toString() - { - return super.toString().toLowerCase(); - } - }; - - /** - * Starts an AMF Vector. - * - * @param ref The reference number. - */ - public void startAMFVector(int ref, VectorType vectorType) - { - if (isExcluded()) - return; - - if (m_nested <= 0) - buffer.append(indentString()); - - buffer.append("(Vector-" + vectorType + " #").append(ref).append(")").append(newLine); - m_indent++; - m_nested++; - } - - /** - * Ends an AMF Dictionary. - */ - public void endAMFVector() - { - m_indent--; - m_nested--; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/AmfTypes.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/AmfTypes.java b/core/src/flex/messaging/io/amf/AmfTypes.java deleted file mode 100644 index 01ea6b9..0000000 --- a/core/src/flex/messaging/io/amf/AmfTypes.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 flex.messaging.io.amf; - -/** - * The amf/rtmp data encoding format constants. - */ -public interface AmfTypes -{ - // AMF marker constants - int kNumberType = 0; - int kBooleanType = 1; - int kStringType = 2; - int kObjectType = 3; - int kMovieClipType = 4; - int kNullType = 5; - int kUndefinedType = 6; - int kReferenceType = 7; - int kECMAArrayType = 8; - int kObjectEndType = 9; - int kStrictArrayType = 10; - int kDateType = 11; - int kLongStringType = 12; - int kUnsupportedType = 13; - int kRecordsetType = 14; - int kXMLObjectType = 15; - int kTypedObjectType = 16; - int kAvmPlusObjectType = 17; -} - - http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/MessageBody.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/MessageBody.java b/core/src/flex/messaging/io/amf/MessageBody.java deleted file mode 100644 index b3b3efb..0000000 --- a/core/src/flex/messaging/io/amf/MessageBody.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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 flex.messaging.io.amf; - -import flex.messaging.MessageException; -import flex.messaging.io.MessageIOConstants; -import flex.messaging.messages.Message; - -import java.io.Serializable; -import java.lang.reflect.Array; -import java.util.List; - -public class MessageBody implements Serializable -{ - private static final int ERR_MSG_INVALID_REQUEST_TYPE = 10037; - - static final long serialVersionUID = 3874002169129668459L; - - private String targetURI = ""; - - private String responseURI = ""; - - protected Object data; - - public MessageBody() - { - } - - public MessageBody(String targetURI, String responseURI, Object data) - { - setTargetURI(targetURI); - setResponseURI(responseURI); - this.data = data; - } - - - public String getTargetURI() - { - return targetURI; - } - - public void setTargetURI(String uri) - { - if (uri == null) - uri = ""; - - targetURI = uri; - } - - public void setReplyMethod(String methodName) - { - if (targetURI.endsWith(MessageIOConstants.STATUS_METHOD) || targetURI.endsWith(MessageIOConstants.RESULT_METHOD)) - targetURI = targetURI.substring(0, targetURI.lastIndexOf('/')); - - targetURI = targetURI + methodName; - } - - public String getReplyMethod() - { - return targetURI.substring((targetURI.lastIndexOf('/') + 1), targetURI.length()); - } - - - public String getResponseURI() - { - return responseURI; - } - - public void setResponseURI(String uri) - { - if (uri == null) - uri = ""; - - responseURI = uri; - } - - public Object getData() - { - return data; - } - - public Message getDataAsMessage() - { - if (data instanceof List) - data = ((List)data).get(0); - else if (data.getClass().isArray()) - data = Array.get(data, 0); - - if (data instanceof Message) - return (Message)data; - - MessageException me = new MessageException(); - me.setMessage(ERR_MSG_INVALID_REQUEST_TYPE, new Object[] {data.getClass().getName()}); - throw me; - } - - public void setData(Object data) - { - this.data = data; - } -} - http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/MessageHeader.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/MessageHeader.java b/core/src/flex/messaging/io/amf/MessageHeader.java deleted file mode 100644 index 0b6417f..0000000 --- a/core/src/flex/messaging/io/amf/MessageHeader.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 flex.messaging.io.amf; - -import java.io.Serializable; - -public class MessageHeader implements Serializable -{ - static final long serialVersionUID = -4535655145953153945L; - - private String name; - private boolean mustUnderstand; - private Object data; - - public MessageHeader() - { - } - - public MessageHeader(String name, boolean mustUnderstand, Object data) - { - this.name = name; - this.mustUnderstand = mustUnderstand; - this.data = data; - } - - - public String getName() - { - return name; - } - - - public void setName(String name) - { - this.name = name; - } - - - public boolean getMustUnderstand() - { - return mustUnderstand; - } - - - public void setMustUnderstand(boolean mustUnderstand) - { - this.mustUnderstand = mustUnderstand; - } - - - public Object getData() - { - return data; - } - - public void setData(Object data) - { - this.data = data; - } - -} - http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/SerializedObject.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/SerializedObject.java b/core/src/flex/messaging/io/amf/SerializedObject.java deleted file mode 100644 index 30b9aef..0000000 --- a/core/src/flex/messaging/io/amf/SerializedObject.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 flex.messaging.io.amf; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; - -/** - * This class represents an already serialized "pass thru" value, whose bytes - * need to be passed "as is" to the output stream. - * - * <p>The scenario that drove this need is to process message return values - * from non-Java method implementations (e.g .Net), that have already been - * serialized on the non-Java side.</p> - */ -public class SerializedObject implements Externalizable -{ - protected byte[] objectBytes; - protected int offset; - - /** - * Constructor. - * Construct a SerializedObject with specified object bytes - - * @param objectBytes the actual bytes to write to the output stream. - */ - public SerializedObject(byte[] objectBytes) - { - this(objectBytes, 0); - } - - /** - * Constructor. - * Construct a SerializedObject with specified object bytes and offset - * @param objectBytes the actual bytes to write to the output stream. - * @param offset the offset into the byte array from which to start writing. - */ - public SerializedObject(byte[] objectBytes, int offset) - { - this.objectBytes = objectBytes; - this.offset = offset; - } - - /** - * Get the object bytes. - * @return the object bytes being held. - */ - public byte[] getObjectBytes() - { - return objectBytes; - } - - /** - * Not supported. Serialized objects are intended to be "write only" values. - * @param in the ObjectInput object - * @throws IOException, ClassNotFoundException if the read failed - */ - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException - { - throw new UnsupportedOperationException("serialized values can only be written, not read."); - } - - /** - * Writes the object bytes directly to the output stream. - * @param out the ObjectOutput object - * @throws IOException when the write failed - */ - public void writeExternal(ObjectOutput out) throws IOException - { - /** - * So far that the pass through is not working as it will mess up the AMF format - * We yet to find a viable solution for pass through to work - * throw Exception to provent the useage of pass through - for(int i = offset; i < objectBytes.length; i++) - { - byte b = objectBytes[i]; - out.writeByte(b); - } - */ - throw new UnsupportedOperationException("Pass through does not work, throw exception to provent us using the mechanism."); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/TraitsInfo.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/TraitsInfo.java b/core/src/flex/messaging/io/amf/TraitsInfo.java deleted file mode 100644 index ccf4011..0000000 --- a/core/src/flex/messaging/io/amf/TraitsInfo.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * 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 flex.messaging.io.amf; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * AVM+ Serialization optimizes object serialization by - * serializing the traits of a type once, and then - * sending only the values of each instance of the type - * as it occurs in the stream. - * - * - */ -public class TraitsInfo -{ - private final String className; - private final boolean dynamic; - private final boolean externalizable; - private List<String> properties; - - public TraitsInfo(String className) - { - this(className, false, false, 10); - } - - public TraitsInfo(String className, int initialCount) - { - this(className, false, false, initialCount); - } - - public TraitsInfo(String className, boolean dynamic, boolean externalizable, int initialCount) - { - this(className, dynamic, externalizable, new ArrayList<String>(initialCount)); - } - - public TraitsInfo(String className, boolean dynamic, boolean externalizable, List<String> properties) - { - if (className == null) - className = ""; - - this.className = className; - this.properties = properties; - this.dynamic = dynamic; - this.externalizable = externalizable; - } - - public boolean isDynamic() - { - return dynamic; - } - - public boolean isExternalizable() - { - return externalizable; - } - - public int length() - { - return properties != null? properties.size() : 0; - } - - public String getClassName() - { - return className; - } - - public void addProperty(String name) - { - if (properties == null) - properties = new ArrayList<String>(); - properties.add(name); - } - - public void addAllProperties(Collection props) - { - if (properties == null) - properties = new ArrayList<String>(); - properties.addAll(props); - } - - public String getProperty(int i) - { - return properties != null? properties.get(i) : null; - } - - public List<String> getProperties() - { - return properties; - } - - public boolean equals(Object obj) - { - if (obj == this) - { - return true; - } - - if (obj instanceof TraitsInfo) - { - TraitsInfo other = (TraitsInfo)obj; - - if (!this.className.equals(other.className)) - { - return false; - } - - if (!(this.dynamic == other.dynamic)) - { - return false; - } - - List thisProperties = this.properties; - List otherProperties = other.properties; - - if (thisProperties != otherProperties) - { - int thisCount = thisProperties.size(); - - if (thisCount != otherProperties.size()) - { - return false; - } - - for (int i = 0; i < thisCount; i++) - { - Object thisProp = thisProperties.get(i); - Object otherProp = otherProperties.get(i); - if (thisProp != null && otherProp != null && !thisProp.equals(otherProp)) - return false; - } - } - - return true; - } - - return false; - } - - /** - * Instances of types with the same classname and number of properties may - * return the same hash code, however, an equality test will fully - * test whether they match exactly on individual property names. - * @return int the hash code of the TraitsInfo object - */ - public int hashCode() - { - int size = properties != null? properties.size() : 0; - int c = className.hashCode(); - c = dynamic ? c << 2 : c << 1; - c = c | (size << 24); - return c; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/client/AMFConnection.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/client/AMFConnection.java b/core/src/flex/messaging/io/amf/client/AMFConnection.java deleted file mode 100644 index eae4ca3..0000000 --- a/core/src/flex/messaging/io/amf/client/AMFConnection.java +++ /dev/null @@ -1,926 +0,0 @@ -/* - * 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 flex.messaging.io.amf.client; - -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.Proxy; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import flex.messaging.MessageException; -import flex.messaging.io.amf.ActionContext; -import flex.messaging.io.amf.ActionMessage; -import flex.messaging.io.amf.AmfTrace; -import flex.messaging.io.amf.MessageBody; -import flex.messaging.io.amf.MessageHeader; -import flex.messaging.io.ClassAliasRegistry; -import flex.messaging.io.MessageDeserializer; -import flex.messaging.io.MessageIOConstants; -import flex.messaging.io.SerializationContext; -import flex.messaging.io.amf.AmfMessageSerializer; -import flex.messaging.io.amf.AmfMessageDeserializer; -import flex.messaging.io.amf.client.exceptions.ClientStatusException; -import flex.messaging.io.amf.client.exceptions.ServerStatusException; - -/** - * A Java alternative to the native flash.net.NetConnection class for - * sending AMF formatted requests over HTTP or HTTPS. - * AMFConnection in Actionscript. AMF connection automatically handles cookies - * by looking for cookie headers and setting the cookies in subsequent request. - * - * AMF connection class is not thread safe. - */ -public class AMFConnection -{ - //-------------------------------------------------------------------------- - // - // Public Static Variables - // - //-------------------------------------------------------------------------- - - public static final String COOKIE = "Cookie"; - public static final String COOKIE2 = "Cookie2"; - public static final String COOKIE_SEPERATOR = ";"; - public static final String COOKIE_NAMEVALUE_SEPERATOR = "="; - public static final String SET_COOKIE = "Set-Cookie"; - public static final String SET_COOKIE2 = "Set-Cookie2"; - - //-------------------------------------------------------------------------- - // - // Private Static Variables - // - //-------------------------------------------------------------------------- - - private static int DEFAULT_OBJECT_ENCODING = MessageIOConstants.AMF3; - private static String HTTP_HEADER_NAME_CONTENT_TYPE = "Content-Type"; - - //-------------------------------------------------------------------------- - // - // Public Static Methods - // - //-------------------------------------------------------------------------- - - /** - * Registers a custom alias for a class name bidirectionally. - * - * @param alias The alias for the class name. - * @param className The concrete class name. - */ - public static void registerAlias(String alias, String className) - { - ClassAliasRegistry registry = ClassAliasRegistry.getRegistry(); - registry.registerAlias(alias, className); - registry.registerAlias(className, alias); - } - - //-------------------------------------------------------------------------- - // - // Constructor - // - //-------------------------------------------------------------------------- - - /** - * Creates a default AMF connection instance. - */ - public AMFConnection() - { - } - - //-------------------------------------------------------------------------- - // - // Private Variables - // - //-------------------------------------------------------------------------- - - private ActionContext actionContext; - private boolean connected; - private boolean instantiateTypes = true; - private Proxy proxy; - private int objectEncoding; - private boolean objectEncodingSet = false; - private SerializationContext serializationContext; - private String url; - private URL urlObject; - - //-------------------------------------------------------------------------- - // - // Protected Variables - // - //-------------------------------------------------------------------------- - - /** - * List of AMF message headers. - */ - protected List<MessageHeader> amfHeaders; - - /** - * An AMF connection may have an AMF header processor where AMF headers - * can be passed to as they are encountered in AMF response messages. - */ - protected AMFHeaderProcessor amfHeaderProcessor; - - /** - * Used internally by AMF serialization code to log debug info. - */ - protected AmfTrace amfTrace; - - /** - * A map of cookie names and values that are used to keep track of cookies. - */ - protected Map<String, String> cookies; - - /** - * Map of Http request header names and values. - */ - protected Map<String,String> httpRequestHeaders; - - /** - * Sequentially incremented counter used to generate a unique responseURI - * to match response messages to responders. - */ - protected int responseCounter; - - /** - * The URL connection used to make AMF formatted HTTP and HTTPS requests for - * this connection. - */ - protected HttpURLConnection urlConnection; - - /** - * A buffered input stream that wraps the input stream of the underlying - * url connection. This is returned in server and client exceptions as part - * of the HTTP response info. - */ - protected BufferedInputStream urlConnectionInputStream; - - //-------------------------------------------------------------------------- - // - // Properties - // - //-------------------------------------------------------------------------- - - //---------------------------------- - // amfHeaderProcessor - //---------------------------------- - - /** - * Returns the AMF header processor associated with the AMF connection. AMF - * header processor is same as NetConnection's client property. - * See flash.net.NetConnection#client. - * - * @return The AMF header processor associated with the AMF connection. - */ - public AMFHeaderProcessor getAMFHeaderProcessor() - { - return amfHeaderProcessor; - } - - /** - * Sets the AMF header processor associated with the AMF connection. - * - * @param amfHeaderProcessor The AMF header processor to set. - */ - public void setAMFHeaderProcessor(AMFHeaderProcessor amfHeaderProcessor) - { - this.amfHeaderProcessor = amfHeaderProcessor; - } - - //---------------------------------- - // amfTrace - //---------------------------------- - - /** - * Returns the <tt>AmfTrace</tt> associated with the AMF connection. - * - * @return The <tt>AmfTrace</tt> associated with the AMF connection. - */ - public AmfTrace getAmfTrace() - { - return amfTrace; - } - - /** - * Sets the <tt>AmfTrace</tt> associated with the AMF connection. - * - * @param amfTrace The <tt>AmfTrace</tt> associated with the AMF connection. - */ - public void setAmfTrace(AmfTrace amfTrace) - { - this.amfTrace = amfTrace; - } - - //---------------------------------- - // defaultObjectEncoding - //---------------------------------- - - /** - * The default object encoding for all AMFConnection instances. This - * controls which version of AMF is used during serialization. The default - * is AMF 3. See flash.net.ObjectEncoding#DEFAULT - * - * @return The default object encoding of the AMF connection. - */ - public static int getDefaultObjectEncoding() - { - return DEFAULT_OBJECT_ENCODING; - } - - /** - * Sets the default object encoding of the AMF connection. - * - * @param value The value to set the default object encoding to. - */ - public static void setDefaultObjectEncoding(int value) - { - DEFAULT_OBJECT_ENCODING = value; - } - - //---------------------------------- - // instantiateTypes - //---------------------------------- - - /** - * Returns instantiateTypes property. InstantiateTypes property determines - * whether type information will be used to instantiate a new instance. - * If set to false, types will be deserialized as flex.messaging.io.ASObject - * instances with type information retained but not used to create an instance. - * Note that types in the flex.* package (and any subpackage) will always be - * instantiated. The default is true. - * - * @return The instantitateTypes property. - */ - public boolean isInstantiateTypes() - { - return instantiateTypes; - } - - /** - * Sets the instantiateTypes property. - * - * @param instantiateTypes The value to set the instantiateTypes property to. - */ - public void setInstantiateTypes(boolean instantiateTypes) - { - this.instantiateTypes = instantiateTypes; - } - - //---------------------------------- - // objectEncoding - //---------------------------------- - - /** - * The object encoding for this AMFConnection sets which AMF version to - * use during serialization. If set, this version overrides the - * defaultObjectEncoding. - * - * @return The object encoding for the AMF connection. - */ - public int getObjectEncoding() - { - if (!objectEncodingSet) - return getDefaultObjectEncoding(); - return objectEncoding; - } - - /** - * Sets the object encoding for the AMF connection. - * - * @param objectEncoding The value to set the object encoding to. - */ - public void setObjectEncoding(int objectEncoding) - { - this.objectEncoding = objectEncoding; - objectEncodingSet = true; - } - - //---------------------------------- - // proxy - //---------------------------------- - - /** - * Returns the <tt>Proxy</tt> this AMF connection is using; - * <code>null</code> by default. - * - * @return The <tt>Proxy</tt> this AMF connection is using. - */ - public Proxy getProxy() - { - return proxy; - } - - /** - * Sets the <tt>Proxy</tt> that this AMF connection will use. - * Set to <code>null</code> to clear out any existing proxy setting that - * should no longer be used. - * - * @param proxy The <tt>Proxy</tt> this AMF connection will use. - */ - public void setProxy(Proxy proxy) - { - this.proxy = proxy; - } - - //---------------------------------- - // url - //---------------------------------- - - /** - * Returns the HTTP or HTTPS url for the AMF connection. - * - * @return The HTTP or HTTPs url for the AMF connection. - */ - public String getUrl() - { - return url; - } - - //-------------------------------------------------------------------------- - // - // Public Methods - // - //-------------------------------------------------------------------------- - - /** - * Adds an AMF packet-level header which is sent with every request for - * the life of this AMF connection. - * - * @param name The name of the header. - * @param mustUnderstand Whether the header must be processed or not. - * @param data The value of the header. - */ - public void addAmfHeader(String name, boolean mustUnderstand, Object data) - { - if (amfHeaders == null) - amfHeaders = new ArrayList<MessageHeader>(); - - MessageHeader header = new MessageHeader(name, mustUnderstand, data); - amfHeaders.add(header); - } - - /** - * Add an AMF packet-level header with mustUnderstand=false, which is sent - * with every request for the life of this AMF connection. - * - * @param name The name of the header. - * @param data The value of the header. - */ - public void addAmfHeader(String name, Object data) - { - addAmfHeader(name, false, data); - } - - /** - * Removes any AMF headers found with the name given. - * - * @param name The name of the header(s) to remove. - * - * @return true if a header existed with the given name. - */ - public boolean removeAmfHeader(String name) - { - boolean exists = false; - if (amfHeaders != null) - { - for (Iterator<MessageHeader> iterator = amfHeaders.iterator(); iterator.hasNext();) - { - MessageHeader header = iterator.next(); - if (name.equals(header.getName())) - { - iterator.remove(); - exists = true; - } - } - } - return exists; - } - - /** - * Removes all AMF headers. - */ - public void removeAllAmfHeaders() - { - if (amfHeaders != null) - amfHeaders = null; - } - - /** - * Adds a Http request header to the underlying connection. - * - * @param name The name of the Http header. - * @param value The value of the Http header. - */ - public void addHttpRequestHeader(String name, String value) - { - if (httpRequestHeaders == null) - httpRequestHeaders = new HashMap<String,String>(); - - httpRequestHeaders.put(name, value); - } - - /** - * Removes the Http header found with the name given. - * - * @param name The name of the Http header. - * - * @return true if a header existed with the given name. - */ - public boolean removeHttpRequestHeader(String name) - { - boolean exists = false; - if (httpRequestHeaders != null) - { - Object previousValue = httpRequestHeaders.remove(name); - exists = (previousValue != null); - } - return exists; - } - - /** - * Removes all Http request headers. - */ - public void removeAllHttpRequestHeaders() - { - if (httpRequestHeaders != null) - httpRequestHeaders = null; - } - - /** - * Makes an AMF request to the server. A connection must have been made - * prior to making a call. - * - * @param command The method to call on the server. - * @param arguments Arguments for the method. - * - * @return The result of the call. - * - * @throws ClientStatusException If there is a client side exception. - * @throws ServerStatusException If there is a server side exception. - */ - public Object call(String command, Object ... arguments) throws ClientStatusException , ServerStatusException - { - if (!connected) - { - String message = "AMF connection is not connected"; - ClientStatusException cse = new ClientStatusException(message, ClientStatusException.AMF_CALL_FAILED_CODE); - throw cse; - } - - String responseURI = getResponseURI(); - - // TODO: Support customizable batching of messages. - ActionMessage requestMessage = new ActionMessage(getObjectEncoding()); - - if (amfHeaders != null) - { - for (MessageHeader header : amfHeaders) - requestMessage.addHeader(header); - } - - MessageBody amfMessage = new MessageBody(command, responseURI, arguments); - requestMessage.addBody(amfMessage); - - // Setup for AMF message serializer - actionContext.setRequestMessage(requestMessage); - ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); - AmfMessageSerializer amfMessageSerializer = new AmfMessageSerializer(); - amfMessageSerializer.initialize(serializationContext, outBuffer, amfTrace); - - try - { - amfMessageSerializer.writeMessage(requestMessage); - Object result = send(outBuffer); - return result; - } - catch (Exception e) - { - if (e instanceof ClientStatusException) - throw (ClientStatusException)e; - if (e instanceof ServerStatusException) - throw (ServerStatusException)e; - // Otherwise, wrap into a ClientStatusException. - throw new ClientStatusException(e, ClientStatusException.AMF_CALL_FAILED_CODE, generateHttpResponseInfo()); - } - finally - { - try - { - outBuffer.close(); - } - catch (IOException ignore){} - } - } - - /** - * Closes the underlying URL connection, sets the url to null, and clears - * the cookies. - */ - public void close() - { - // Clear the cookies. - if (cookies != null) - cookies.clear(); - - // Clear the URL connection and URL. - if (urlConnection != null) - { - urlConnection.disconnect(); - urlConnection = null; - } - url = null; - urlObject = null; - - serializationContext = null; - connected = false; - } - - /** - * Connects to the URL provided. Any previous connections are closed. - * - * @param connectUrl The url to connect to. - * - * @throws ClientStatusException If there is a client side exception. - */ - public void connect(String connectUrl) throws ClientStatusException - { - if (connected) - close(); - - url = connectUrl; - - // Try to encode the url in case it has spaces etc. - String encodedUrl = null; - try - { - URL raw = new URL(url); - URI uri = new URI(raw.getProtocol(), raw.getUserInfo(), raw.getHost(), raw.getPort(), raw.getPath(), raw.getQuery(), null); - encodedUrl = uri.toString(); - } - catch (Exception e) - { - // NOWARN - } - - try - { - urlObject = new URL(encodedUrl != null? encodedUrl : url); - - serializationContext = new SerializationContext(); - 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; - internalConnect(); - } - catch (IOException e) - { - ClientStatusException exception = new ClientStatusException(e, ClientStatusException.AMF_CONNECT_FAILED_CODE); - throw exception; - } - } - - //-------------------------------------------------------------------------- - // - // Protected Methods - // - //-------------------------------------------------------------------------- - - /** - * Generates the HTTP response info for the server status exception. - * - * @return The HTTP response info for the server status exception. - */ - protected HttpResponseInfo generateHttpResponseInfo() - { - HttpResponseInfo httpResponseInfo = null; - try - { - if (urlConnection != null) - { - int responseCode = urlConnection.getResponseCode(); - String responseMessage = urlConnection.getResponseMessage(); - httpResponseInfo = new HttpResponseInfo(responseCode, responseMessage, urlConnectionInputStream); - } - } - catch (IOException ignore) - { - } - return httpResponseInfo; - } - - /** - * Generates and returns the response URI. - * - * @return The response URI. - */ - protected String getResponseURI() - { - String responseURI = "/" + responseCounter; - responseCounter++; - return responseURI; - } - - /** - * An internal method that sets up the underlying URL connection. - * - * @throws IOException If an exception is encountered during URL connection setup. - */ - protected void internalConnect() throws IOException - { - if (proxy == null) - urlConnection = (HttpURLConnection)urlObject.openConnection(); - else - urlConnection = (HttpURLConnection)urlObject.openConnection(proxy); - - urlConnection.setDoOutput(true); - setHttpRequestHeaders(); - serializationContext.instantiateTypes = instantiateTypes; - actionContext = new ActionContext(); - connected = true; - } - - /** - * Processes the HTTP response headers and body. - */ - protected Object processHttpResponse(InputStream inputStream) throws ClassNotFoundException, IOException, ClientStatusException, ServerStatusException - { - processHttpResponseHeaders(); - return processHttpResponseBody(inputStream); - } - - /** - * Processes the HTTP response body. - */ - protected Object processHttpResponseBody(InputStream inputStream) - throws ClassNotFoundException, IOException, ClientStatusException, - ServerStatusException - { - if (urlConnectionInputStream != null) - urlConnectionInputStream.close(); - urlConnectionInputStream = new BufferedInputStream(inputStream); - // Mark the first 2 bytes so that the stream can be reset in case it - // contains non-AMF data. - urlConnectionInputStream.mark(2); - ActionMessage message = new ActionMessage(); - actionContext.setRequestMessage(message); - MessageDeserializer deserializer = new AmfMessageDeserializer(); - deserializer.initialize(serializationContext, urlConnectionInputStream, amfTrace); - try - { - deserializer.readMessage(message, actionContext); - } - catch (MessageException me) - { - // Means the stream contained non-AMF data, reset the stream and throw. - if (AmfMessageDeserializer.CODE_VERSION_MISMATCH.equals(me.getCode())) - { - urlConnectionInputStream.reset(); - String errorMessage = "Unsupported AMF version"; - throw new ClientStatusException(errorMessage, ClientStatusException.AMF_CALL_FAILED_CODE, generateHttpResponseInfo()); - } - throw me; - } - return processAmfPacket(message); - } - - /** - * Processes the HTTP response headers. - */ - protected void processHttpResponseHeaders() - { - Map<String, List<String>> headers = urlConnection.getHeaderFields(); - for (Map.Entry<String, List<String>> element : headers.entrySet()) - { - String headerName = element.getKey(); - List<String> headerValues = element.getValue(); - for (String headerValue : headerValues) - { - if (SET_COOKIE.equals(headerName) || COOKIE.equals(headerName) - || SET_COOKIE2.equals(headerName) || COOKIE2.equals(headerName)) - processSetCookieHeader(headerValue); - } - } - } - - /** - * Processes the AMF packet. - */ - protected Object processAmfPacket(ActionMessage packet) throws ServerStatusException - { - processAmfHeaders(packet.getHeaders()); - return processAmfBody(packet.getBodies()); - } - - /** - * Processes the AMF headers by dispatching them to an AMF header processor, - * if one exists. - */ - protected void processAmfHeaders(ArrayList<MessageHeader> headers) - { - // No need to process headers if there's no AMF header processor. - if (amfHeaderProcessor == null) - return; - - for (MessageHeader header : headers) - amfHeaderProcessor.processHeader(header); - } - - /** - * Processes the AMF body. Note that this method won't work if batching of - * AMF messages is supported at some point but for now we are guaranteed to - * have a single message. - */ - protected Object processAmfBody(ArrayList<MessageBody> messages) throws ServerStatusException - { - for (MessageBody message : messages) - { - String targetURI = message.getTargetURI(); - - if (targetURI.endsWith(MessageIOConstants.RESULT_METHOD)) - { - return message.getData(); - } - else if (targetURI.endsWith(MessageIOConstants.STATUS_METHOD)) - { - String exMessage = "Server error"; - HttpResponseInfo responseInfo = generateHttpResponseInfo(); - ServerStatusException exception = new ServerStatusException(exMessage, message.getData(), responseInfo); - throw exception; - } - } - return null; // Should not happen. - } - - /** - * Writes the output buffer and processes the HTTP response. - */ - protected Object send(ByteArrayOutputStream outBuffer) throws ClassNotFoundException, IOException, ClientStatusException, ServerStatusException - { - // Every Http request needs a new HttpURLConnection, hence the internalConnect. - internalConnect(); - - outBuffer.writeTo(urlConnection.getOutputStream()); - outBuffer.flush(); - outBuffer.close(); - - // Process the response - return processHttpResponse(urlConnection.getInputStream()); - } - - /** - * Processes the incoming set-cookie headers. - * - * @param headerValue The value of the set-cookie header. - */ - protected void processSetCookieHeader(String headerValue) - { - String cookie = headerValue; - if (cookie.indexOf(COOKIE_SEPERATOR) > 0) - cookie = headerValue.substring(0, cookie.indexOf(COOKIE_SEPERATOR)); - String name = cookie.substring(0, cookie.indexOf(COOKIE_NAMEVALUE_SEPERATOR)); - String value = cookie.substring(cookie.indexOf(COOKIE_NAMEVALUE_SEPERATOR) + 1, cookie.length()); - if (cookies == null) - cookies = new HashMap<String, String>(); - cookies.put(name, value); - } - - /** - * Sets the Http request headers, including the cookie headers. - */ - protected void setHttpRequestHeaders() - { - setHttpRequestCookieHeader(); - if (httpRequestHeaders != null) - { - for (Map.Entry<String, String> element : httpRequestHeaders.entrySet()) - { - String key = element.getKey(); - String value = element.getValue(); - urlConnection.setRequestProperty(key, value); - } - } - // Always set valid Content-Type header (overrides any user-defined Content-Type). - urlConnection.setRequestProperty(HTTP_HEADER_NAME_CONTENT_TYPE, flex.messaging.io.MessageIOConstants.AMF_CONTENT_TYPE); - } - - /** - * Sets the Http request cookie headers. - */ - protected void setHttpRequestCookieHeader() - { - if (cookies == null) - return; - - // Set the cookies, if any. - StringBuffer cookieHeaderValue = null; - for (Map.Entry<String, String> element : cookies.entrySet()) - { - String name = element.getKey(); - String value = element.getValue(); - if (cookieHeaderValue == null) // First cookie - cookieHeaderValue = new StringBuffer(name + COOKIE_NAMEVALUE_SEPERATOR + value); - else - cookieHeaderValue.append(COOKIE_SEPERATOR + " " + name + COOKIE_NAMEVALUE_SEPERATOR + value); - } - if (cookieHeaderValue != null) - urlConnection.setRequestProperty(COOKIE, cookieHeaderValue.toString()); - } - - //-------------------------------------------------------------------------- - // - // Inner Classes - // - //-------------------------------------------------------------------------- - - /** - * An inner class to represent the HTTP response associated with the exception. - */ - public static class HttpResponseInfo - { - private int responseCode; - private String responseMessage; - private InputStream responseInputStream; - - /** - * Creates an HTTP response info with the HTTP code, message, and the - * input stream. - * - * @param responseCode The HTTP response code. - * @param responseMessage the HTTP message. - * @param responseInputStream The underlying input stream. - */ - public HttpResponseInfo(int responseCode, String responseMessage, InputStream responseInputStream) - { - this.responseCode = responseCode; - this.responseMessage = responseMessage; - this.responseInputStream = responseInputStream; - } - - /** - * Returns the HTTP response code. - * - * @return The HTTP response code. - */ - public int getResponseCode() - { - return responseCode; - } - - /** - * Returns the HTTP response message. - * - * @return The HTTP response message. - */ - public String getResponseMessage() - { - return responseMessage; - } - - /** - * Returns the underlying response input stream. - * - * @return The underlying response input stream. - */ - public InputStream getResponseInputStream() - { - return responseInputStream; - } - - /** - * Returns a String representation of the HTTP response info. - * - * @return A String representation of the HTTP response info. - */ - @Override - public String toString() - { - return "HttpResponseInfo " + "\n\tcode: " + responseCode - + "\n\tmessage: " + responseMessage; - } - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/client/AMFHeaderProcessor.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/client/AMFHeaderProcessor.java b/core/src/flex/messaging/io/amf/client/AMFHeaderProcessor.java deleted file mode 100644 index 6d63cb8..0000000 --- a/core/src/flex/messaging/io/amf/client/AMFHeaderProcessor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 flex.messaging.io.amf.client; - -import flex.messaging.io.amf.MessageHeader; - -/** - * An AMF connection may have an AMF header processor where AMF headers can be - * passed to as they are encountered in AMF response messages. - */ -public interface AMFHeaderProcessor -{ - /** - * The method that will be invoked by the AMF connection when an AMF header - * is encountered. - * - * @param header The AMF header. - */ - void processHeader(MessageHeader header); -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/client/exceptions/ClientStatusException.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/client/exceptions/ClientStatusException.java b/core/src/flex/messaging/io/amf/client/exceptions/ClientStatusException.java deleted file mode 100644 index 0f01dd9..0000000 --- a/core/src/flex/messaging/io/amf/client/exceptions/ClientStatusException.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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 flex.messaging.io.amf.client.exceptions; - -import flex.messaging.io.amf.client.AMFConnection.HttpResponseInfo; - - -/** - * Client status exceptions are thrown by the AMF connection when a client side - * error is encountered such as when a connect or call attempt fails due to - * wrong url on the client. - */ -public class ClientStatusException extends Exception -{ - private static final long serialVersionUID = 1412675397183129614L; - - /** - * Exception codes. - */ - public static final String AMF_CALL_FAILED_CODE = "AMFConnection.Call.Failed"; - public static final String AMF_CONNECT_FAILED_CODE = "AMFConnection.Connect.Failed"; - - private String code; - private HttpResponseInfo httpResponseInfo; - - /** - * Creates a client status exception with the supplied throwable and code. - * - * @param t The throwable instance used to create the exception. - * @param code The code of the exception. - */ - public ClientStatusException(Throwable t, String code) - { - super(t); - this.code = code; - } - - /** - * Creates a client status exception with the supplied message and code. - * - * @param message The message of the exception. - * @param code The code of the exception. - */ - public ClientStatusException(String message, String code) - { - super(message); - this.code = code; - } - - /** - * Creates a client status exception with the supplied message, code, - * and http response info. - * - * @param message The message of the exception. - * @param code The code of the exception. - * @param httpResponseInfo The HTTP response info object that represents - * the HTTP response returned with the exception. - */ - public ClientStatusException(String message, String code, HttpResponseInfo httpResponseInfo) - { - this(message, code); - this.httpResponseInfo = httpResponseInfo; - } - - /** - * Creates a client status exception with the supplied message, code, - * and http response info. - * - * @param t The throwable instance used to create the exception. - * @param code The code of the exception. - * @param httpResponseInfo The HTTP response info object that represents - * the HTTP response returned with the exception. - */ - public ClientStatusException(Throwable t, String code, HttpResponseInfo httpResponseInfo) - { - this(t, code); - this.httpResponseInfo = httpResponseInfo; - } - - /** - * Returns the code of the exception. - * - * @return The code of the exception. - */ - public String getCode() - { - return code; - } - - /** - * Returns the HTTP response info of the exception. - * - * @return The HTTP response info of the exception. - */ - public HttpResponseInfo getHttpResponseInfo() - { - return httpResponseInfo; - } - - /** - * Returns a String representation of the exception. - * - * @return A String that represents the exception. - */ - @Override - public String toString() - { - return "ClientStatusException " - + "\n\tmessage: " + getMessage() - + "\n\tcode: " + code; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/client/exceptions/ServerStatusException.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/client/exceptions/ServerStatusException.java b/core/src/flex/messaging/io/amf/client/exceptions/ServerStatusException.java deleted file mode 100644 index 5c3f473..0000000 --- a/core/src/flex/messaging/io/amf/client/exceptions/ServerStatusException.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 flex.messaging.io.amf.client.exceptions; -import flex.messaging.io.amf.client.AMFConnection.HttpResponseInfo; - -/** - * Server status exceptions are thrown by the AMF connection when a server side - * error is encountered. - */ -public class ServerStatusException extends Exception -{ - private static final long serialVersionUID = -5441048669770997132L; - - private Object data; - private HttpResponseInfo httpResponseInfo; - - /** - * Creates a server status exception with the supplied message and data. - * - * @param message The message of the exception. - * @param data The data of the exception which is usually an AMF result or - * status message. - */ - public ServerStatusException(String message, Object data) - { - this(message, data, null); - } - - /** - * Creates a server status exception with the supplied message, data, and - * HTTP response info object. - * - * @param message The message of the exception. - * @param data The data of the exception which is usually an AMF result or - * status message. - * @param httpResponseInfo The HTTP response info object that represents - * the HTTP response returned with the exception. - */ - public ServerStatusException(String message, Object data, HttpResponseInfo httpResponseInfo) - { - super(message); - this.data = data; - this.httpResponseInfo = httpResponseInfo; - } - - /** - * Returns the data of the exception. - * - * @return The data of the exception. - */ - public Object getData() - { - return data; - } - - /** - * Returns the HTTP response info of the exception. - * - * @return The HTTP response info of the exception. - */ - public HttpResponseInfo getHttpResponseInfo() - { - return httpResponseInfo; - } - - /** - * Returns a String representation of the exception. - * - * @return A String that represents the exception. - */ - @Override - public String toString() - { - String temp = "ServerStatusException " + "\n\tdata: " + data; - if (httpResponseInfo != null) - temp += "\n\tHttpResponseInfo: " + httpResponseInfo; - return temp; - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/client/exceptions/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/client/exceptions/package-info.java b/core/src/flex/messaging/io/amf/client/exceptions/package-info.java deleted file mode 100644 index 6a74063..0000000 --- a/core/src/flex/messaging/io/amf/client/exceptions/package-info.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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 flex.messaging.io.amf.client.exceptions; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/client/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/client/package-info.java b/core/src/flex/messaging/io/amf/client/package-info.java deleted file mode 100644 index b35fb16..0000000 --- a/core/src/flex/messaging/io/amf/client/package-info.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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 flex.messaging.io.amf.client; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/amf/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/amf/package-info.java b/core/src/flex/messaging/io/amf/package-info.java deleted file mode 100644 index 1a88b9a..0000000 --- a/core/src/flex/messaging/io/amf/package-info.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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 flex.messaging.io.amf; \ No newline at end of file