http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/endpoints/amf/SerializationFilter.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/endpoints/amf/SerializationFilter.java b/core/src/flex/messaging/endpoints/amf/SerializationFilter.java deleted file mode 100644 index c15ab89..0000000 --- a/core/src/flex/messaging/endpoints/amf/SerializationFilter.java +++ /dev/null @@ -1,480 +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.endpoints.amf; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.Charset; - -import javax.servlet.http.HttpServletRequest; - -import flex.messaging.FlexContext; -import flex.messaging.MessageException; -import flex.messaging.io.MessageDeserializer; -import flex.messaging.io.MessageIOConstants; -import flex.messaging.io.MessageSerializer; -import flex.messaging.io.SerializationContext; -import flex.messaging.io.SerializationException; -import flex.messaging.io.amf.ASObject; -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.log.Log; -import flex.messaging.log.LogCategories; -import flex.messaging.log.Logger; -import flex.messaging.messages.ErrorMessage; -import flex.messaging.messages.Message; -import flex.messaging.messages.MessagePerformanceInfo; -import flex.messaging.util.ExceptionUtil; -import flex.messaging.util.StringUtils; - - -/** - * Filter for serializing and deserializing action messages. - */ -public class SerializationFilter extends AMFFilter -{ - //-------------------------------------------------------------------------- - // - // Private Static Constants - // - //-------------------------------------------------------------------------- - - private static final Charset UTF8_CHARSET = Charset.forName("UTF-8"); - - // Error codes. - private static final int UNHANDLED_ERROR = 10306; - private static final int REQUEST_ERROR = 10307; - private static final int RESPONSE_ERROR = 10308; - - //-------------------------------------------------------------------------- - // - // Constructor - // - //-------------------------------------------------------------------------- - - /** - * Constructs a <tt>SerializationFilter</tt>. - * - * @param logCategory Log category to use in logging. If <code>null</code>, the default values is <code>Endpoint.General</code>. - */ - public SerializationFilter(String logCategory) - { - if (logCategory == null) - logCategory = LogCategories.ENDPOINT_GENERAL; - logger = Log.getLogger(logCategory); - } - - //-------------------------------------------------------------------------- - // - // Variables - // - //-------------------------------------------------------------------------- - - /** - * Used to log serialization/deserialization messages. - */ - private Logger logger; - - //-------------------------------------------------------------------------- - // - // Public Methods - // - //-------------------------------------------------------------------------- - - @Override - public void invoke(final ActionContext context) throws IOException - { - boolean success = false; - - // Additional AMF packet tracing is enabled only at the debug logging level - // and only if there's a target listening for it. - AmfTrace debugTrace = Log.isDebug() && logger.hasTarget()? new AmfTrace() : null; - - // Create an empty ActionMessage object to hold our response - context.setResponseMessage(new ActionMessage()); - SerializationContext sc = SerializationContext.getSerializationContext(); - - try - { - // Deserialize the input stream into an "ActionMessage" object. - MessageDeserializer deserializer = sc.newMessageDeserializer(); - - // Set up the deserialization context - HttpServletRequest req = FlexContext.getHttpRequest(); - InputStream in = req.getInputStream(); - - // Determine whether the request is coming from a Javascript client. - // If so, convert stream from UTF-8 to raw hex before AMF deserialization. - String contentType = req.getContentType(); - boolean jsClient = (contentType != null && contentType.startsWith(MessageIOConstants.CONTENT_TYPE_PLAIN)); - if (jsClient) - { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(in, UTF8_CHARSET)); - int currentByte = -1; - while ((currentByte = reader.read()) != -1) - { - if (currentByte == 256) - currentByte = 0; - outputStream.write(currentByte); - } - - if (outputStream.size() > 0) - in = new ByteArrayInputStream(outputStream.toByteArray()); - } - - deserializer.initialize(sc, in, debugTrace); - - // record the length of the input stream for performance metrics - int reqLen = FlexContext.getHttpRequest().getContentLength(); - context.setDeserializedBytes(reqLen); - - // set up the incoming MPI info if it is enabled - if(context.isMPIenabled()) - { - MessagePerformanceInfo mpi = new MessagePerformanceInfo(); - mpi.recordMessageSizes = context.isRecordMessageSizes(); - mpi.recordMessageTimes = context.isRecordMessageTimes(); - if(context.isRecordMessageTimes()) - mpi.receiveTime = System.currentTimeMillis(); - if(context.isRecordMessageSizes()) - mpi.messageSize =reqLen; - - context.setMPII(mpi); - } - - ActionMessage m = new ActionMessage(); - context.setRequestMessage(m); - deserializer.readMessage(m, context); - success = true; - } - catch (Throwable t) - { - handleDeserializationException(context, t, logger); - } - finally - { - // Use the same ActionMessage version for the response - ActionMessage respMsg = context.getResponseMessage(); - respMsg.setVersion(context.getVersion()); - - if (debugTrace != null) - logger.debug(debugTrace.toString()); - } - - try - { - if (success) - { - next.invoke(context); - } - } - catch (Throwable t) - { - unhandledError(context, t); - } - finally - { - // serialize output - if (context.getStatus() != MessageIOConstants.STATUS_NOTAMF) - { - ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); - ActionMessage respMesg = context.getResponseMessage(); - - // Additional AMF packet tracing is enabled only at the debug logging level - // and only if there's a target listening for it. - debugTrace = Log.isDebug() && logger.hasTarget()? new AmfTrace() : null; - - try - { - // overhead calculation is only necessary when MPI is enabled - long serializationOverhead=0; - if(context.isRecordMessageTimes()) - { - // set server send time - context.getMPIO().sendTime = System.currentTimeMillis(); - if(context.isRecordMessageSizes()) - serializationOverhead = System.currentTimeMillis(); - } - MessageSerializer serializer = sc.newMessageSerializer(); - serializer.initialize(sc, outBuffer, debugTrace); - serializer.writeMessage(respMesg); - - // keep track of serializes bytes for performance metrics - context.setSerializedBytes(outBuffer.size()); - - // serialized message again after adding info if mpio with sizing is enabled - if(context.isRecordMessageSizes()) - { - try - { - context.getMPIO().messageSize = outBuffer.size(); - - // reset server send time - if(context.isRecordMessageTimes()) - { - serializationOverhead = System.currentTimeMillis() - serializationOverhead; - context.getMPIO().addToOverhead(serializationOverhead); - context.getMPIO().sendTime = System.currentTimeMillis(); - } - - // reserialize the message now that info has been added - outBuffer = new ByteArrayOutputStream(); - respMesg = context.getResponseMessage(); - serializer.initialize(sc, outBuffer, debugTrace); - serializer.writeMessage(respMesg); - } - catch(Exception e) - { - if (Log.isDebug()) - logger.debug("MPI set up error: " + e.toString()); - } - } - context.setResponseOutput(outBuffer); - } - catch (Exception e) - { - handleSerializationException(sc, context, e, logger); - } - finally - { - if (debugTrace != null) - logger.debug(debugTrace.toString()); - } - } - } - } - - /** - * This static method provides a common way for deserialization errors to be - * handled. It attempts to provide the client with useful information about - * deserialization failure. - * - * @param actionContext The action context. - * @param t The throwable that needs to be handled. - * @param logger The logger to which to log messages. - * @throws IOException - */ - public static void handleDeserializationException(ActionContext actionContext, Throwable t, Logger logger) throws IOException - { - if (t instanceof EOFException) - { - actionContext.setStatus(MessageIOConstants.STATUS_NOTAMF); - } - else if (t instanceof IOException) - { - if (Log.isDebug()) - logger.debug("IOException reading message - client closed socket before sending the message?"); - - throw (IOException)t; - } - else - { - actionContext.setStatus(MessageIOConstants.STATUS_ERR); - - // Create a single message body to hold the error - MessageBody responseBody = new MessageBody(); - if (actionContext.getMessageNumber() < actionContext.getRequestMessage().getBodyCount()) - responseBody.setTargetURI(actionContext.getRequestMessageBody().getResponseURI()); - - // If the message couldn't be deserialized enough to know the version, set the current version here - if (actionContext.getVersion() == 0) - actionContext.setVersion(ActionMessage.CURRENT_VERSION); - - // append the response body to the output message - actionContext.getResponseMessage().addBody(responseBody); - - String message; - MessageException methodResult; - if (t instanceof MessageException) - { - methodResult = (MessageException)t; - message = methodResult.getMessage(); - } - else - { - //Error deserializing client message. - methodResult = new SerializationException(); - methodResult.setMessage(REQUEST_ERROR); - methodResult.setRootCause(t); - message = methodResult.getMessage(); - } - responseBody.setData(methodResult.createErrorMessage()); - responseBody.setReplyMethod(MessageIOConstants.STATUS_METHOD); - - if (Log.isError()) - logger.error(message + StringUtils.NEWLINE + ExceptionUtil.toString(t)); - } - - } - - /** - * This static method provides a common way for serialization errors to be - * handled. It attempts to provide the client with useful information about - * the serialization failure. When there is a serialization failure, there is - * no way to tell which response failed serialization, so it adds a new response - * with the serialization failure for each of the corresponding requests. - * - * @param serializer The serializer that generated the error. - * @param serializationContext The serialization context. - * @param actionContext The action context. - * @param t The throwable that needs to be handled. - * @param logger The logger to which to log error messages. - */ - public static void handleSerializationException(SerializationContext serializationContext, - ActionContext actionContext, Throwable t, Logger logger) - { - ActionMessage responseMessage = new ActionMessage(); - actionContext.setResponseMessage(responseMessage); - - int bodyCount = actionContext.getRequestMessage().getBodyCount(); - for (actionContext.setMessageNumber(0); actionContext.getMessageNumber() < bodyCount; actionContext.incrementMessageNumber()) - { - MessageBody responseBody = new MessageBody(); - responseBody.setTargetURI(actionContext.getRequestMessageBody().getResponseURI()); - actionContext.getResponseMessage().addBody(responseBody); - - Object methodResult; - - if (t instanceof MessageException) - { - methodResult = ((MessageException)t).createErrorMessage(); - } - else - { - String message = "An error occurred while serializing server response(s)."; - if (t.getMessage() != null) - { - message = t.getMessage(); - if (message == null) - message = t.toString(); - } - - methodResult = new MessageException(message, t).createErrorMessage(); - } - - if (actionContext.isLegacy()) - { - if (methodResult instanceof ErrorMessage) - { - ErrorMessage error = (ErrorMessage)methodResult; - ASObject aso = new ASObject(); - aso.put("message", error.faultString); - aso.put("code", error.faultCode); - aso.put("details", error.faultDetail); - aso.put("rootCause", error.rootCause); - methodResult = aso; - } - else if (methodResult instanceof Message) - { - methodResult = ((Message)methodResult).getBody(); - } - } - else - { - try - { - Message inMessage = actionContext.getRequestMessageBody().getDataAsMessage(); - if (inMessage.getClientId() != null) - ((ErrorMessage)methodResult).setClientId(inMessage.getClientId().toString()); - - if (inMessage.getMessageId() != null) - { - ((ErrorMessage)methodResult).setCorrelationId(inMessage.getMessageId()); - ((ErrorMessage)methodResult).setDestination(inMessage.getDestination()); - } - } - catch (MessageException ignore){} - } - - responseBody.setData(methodResult); - responseBody.setReplyMethod(MessageIOConstants.STATUS_METHOD); - } - - if (Log.isError() && logger != null) - logger.error("Exception occurred during serialization: " + ExceptionUtil.toString(t)); - - // Serialize the error messages - ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); - AmfTrace debugTrace = Log.isDebug() && logger.hasTarget()? new AmfTrace() : null; - MessageSerializer serializer = serializationContext.newMessageSerializer(); - serializer.initialize(serializationContext, outBuffer, debugTrace); - - try - { - serializer.writeMessage(actionContext.getResponseMessage()); - actionContext.setResponseOutput(outBuffer); - } - catch (IOException e) - { - //Error serializing response - MessageException ex = new MessageException(); - ex.setMessage(RESPONSE_ERROR); - ex.setRootCause(e); - throw ex; - } - } - - //-------------------------------------------------------------------------- - // - // Private Methods - // - //-------------------------------------------------------------------------- - - /** - * An unhandled error happened somewhere between the SerializationFilter and the - * ErrorFilter... we ignore all request bodies and attempt to send back a single response - * body to the client. It will not make it back to a custom responder, but the NetConnection - * Debugger will show the event. - */ - private void unhandledError(ActionContext context, Throwable t) - { - ActionMessage responseMessage = new ActionMessage(); - context.setResponseMessage(responseMessage); - - MessageBody responseBody = new MessageBody(); - responseBody.setTargetURI(context.getRequestMessageBody().getResponseURI()); - - context.getResponseMessage().addBody(responseBody); - - MessageException methodResult; - - if (t instanceof MessageException) - { - methodResult = (MessageException)t; - } - else - { - // An unhandled error occurred while processing client request(s). - methodResult = new SerializationException(); - methodResult.setMessage(UNHANDLED_ERROR); - methodResult.setRootCause(t); - } - - responseBody.setData(methodResult); - responseBody.setReplyMethod(MessageIOConstants.STATUS_METHOD); - - logger.info(t.getMessage()); - } -}
http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/endpoints/amf/SessionFilter.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/endpoints/amf/SessionFilter.java b/core/src/flex/messaging/endpoints/amf/SessionFilter.java deleted file mode 100644 index a8b36cb..0000000 --- a/core/src/flex/messaging/endpoints/amf/SessionFilter.java +++ /dev/null @@ -1,81 +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.endpoints.amf; - -import flex.messaging.FlexContext; -import flex.messaging.io.amf.ActionContext; -import flex.messaging.io.amf.MessageHeader; -import flex.messaging.io.MessageIOConstants; - -import java.io.IOException; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * This filter detects whether a request URL is decorated with a ;jessionid token - * in the event that the client does not support cookies. In that case, an AppendToGatewayUrl - * header with jsessionid as its value is added to the response message. - */ -public class SessionFilter extends AMFFilter -{ - public SessionFilter() - { - } - - public void invoke(final ActionContext context) throws IOException - { - next.invoke(context); - - try - { - HttpServletRequest request = FlexContext.getHttpRequest(); - HttpServletResponse response = FlexContext.getHttpResponse(); - - StringBuffer reqURL = request.getRequestURL(); - - if (reqURL != null) - { - if (request.getQueryString() != null) - reqURL.append('?').append(request.getQueryString()); - - String oldFullURL = reqURL.toString().trim(); - String encFullURL = response.encodeURL(oldFullURL).trim(); - - String sessionSuffix = null; - - // It's ok to lower case here as URLs must be in ASCII - int pos = encFullURL.toLowerCase().indexOf(";jsessionid"); - if (pos > 0) - { - StringBuffer sb = new StringBuffer(); - sb.append(encFullURL.substring(pos)); - sessionSuffix = sb.toString(); - } - - if (sessionSuffix != null && oldFullURL.indexOf(sessionSuffix) < 0) - { - context.getResponseMessage().addHeader(new MessageHeader(MessageIOConstants.URL_APPEND_HEADER, true /*mustUnderstand*/, sessionSuffix)); - } - } - } - catch (Throwable t) - { - //Nothing more we can do... don't send 'URL Append' AMF header. - } - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/endpoints/amf/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/endpoints/amf/package-info.java b/core/src/flex/messaging/endpoints/amf/package-info.java deleted file mode 100644 index 5428732..0000000 --- a/core/src/flex/messaging/endpoints/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.endpoints.amf; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/endpoints/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/endpoints/package-info.java b/core/src/flex/messaging/endpoints/package-info.java deleted file mode 100644 index f47eb5b..0000000 --- a/core/src/flex/messaging/endpoints/package-info.java +++ /dev/null @@ -1,17 +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.endpoints; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/factories/JavaFactory.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/factories/JavaFactory.java b/core/src/flex/messaging/factories/JavaFactory.java deleted file mode 100644 index e488919..0000000 --- a/core/src/flex/messaging/factories/JavaFactory.java +++ /dev/null @@ -1,296 +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.factories; - -import flex.messaging.FlexFactory; -import flex.messaging.DestructibleFlexFactory; -import flex.messaging.FlexSession; -import flex.messaging.FlexContext; -import flex.messaging.FactoryInstance; -import flex.messaging.MessageBroker; -import flex.messaging.FlexSessionListener; -import flex.messaging.config.ConfigMap; -import flex.messaging.config.ConfigurationException; -import flex.messaging.services.ServiceException; - -import flex.messaging.config.ConfigurationManager; -import flex.messaging.log.Log; -import flex.messaging.util.StringUtils; -import flex.messaging.util.ExceptionUtil; - -import javax.servlet.ServletContext; - -/** - * This class implements the FlexFactory interface to constructs Flex messaging - * components. The JavaFactory uses the class name, specified as the source - * attribute to determine the class for instances. The scope attribute can be one of - * session, application or request to determine its lifecycle. If you - * use application or session, you can specify the optional attribute-id - * parameter to control the name of the key for storing the component. Two destinations - * using the same attribute-id will use the same component. The component is stored - * in the ServletContext (for application scoped components) and in the - * session (for session scoped components) so you can use these components in your - * JSP as well. - */ -public class JavaFactory implements FlexFactory, DestructibleFlexFactory -{ - private static final String ATTRIBUTE_ID = "attribute-id"; - - private static final int SINGLETON_ERROR = 10656; - private static final int SESSION_NOT_FOUND = 10652; - private static final int INVALID_CLASS_FOUND = 10654; - - /** - * - * Default constructor - */ - public JavaFactory() - { - } - - /** - * This method can be used to provide additional configuration parameters - * for the initializing this factory instance itself. - */ - public void initialize(String id, ConfigMap configMap) {} - - /** - * This method is called when we initialize the definition of an instance which - * will be looked up by this factory. It should validate that the properties - * supplied are valid to define an instance. Any valid properties used for - * this configuration must be accessed to avoid warnings about unused - * configuration elements. If your factory is only used for application - * scoped components, you do not need to implement this method as the lookup - * method itself can be used to validate its configuration. - */ - public FactoryInstance createFactoryInstance(String id, ConfigMap properties) - { - JavaFactoryInstance instance = new JavaFactoryInstance(this, id, properties); - - if (properties == null) - { - // Use destination id as the default attribute id to prevent unwanted sharing. - instance.setSource(instance.getId()); - instance.setScope(SCOPE_REQUEST); - instance.setAttributeId(id); - } - else - { - instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId())); - instance.setScope(properties.getPropertyAsString(SCOPE, SCOPE_REQUEST)); - // Use destination id as the default attribute id to prevent unwanted sharing. - instance.setAttributeId(properties.getPropertyAsString(ATTRIBUTE_ID, id)); - } - - if (instance.getScope().equalsIgnoreCase(SCOPE_APPLICATION)) - { - try - { - MessageBroker mb = FlexContext.getMessageBroker(); - ServletContext ctx = mb != null? mb.getServletContext() : null; - if (ctx == null) // Should not be the case; just in case. - return instance; - - synchronized (ctx) - { - Object inst = ctx.getAttribute(instance.getAttributeId()); - if (inst == null) - { - inst = instance.createInstance(); - ctx.setAttribute(instance.getAttributeId(), inst); - } - else - { - Class configuredClass = instance.getInstanceClass(); - Class instClass = inst.getClass(); - if (configuredClass != instClass && - !configuredClass.isAssignableFrom(instClass)) - { - ServiceException e = new ServiceException(); - e.setMessage(INVALID_CLASS_FOUND, new Object[] { - instance.getAttributeId(), "application", instance.getId(), - instance.getInstanceClass(), inst.getClass()}); - e.setCode("Server.Processing"); - throw e; - } - } - instance.applicationInstance = inst; - - // increment attribute-id reference count on MB - mb.incrementAttributeIdRefCount(instance.getAttributeId()); - } - } - catch (Throwable t) - { - ConfigurationException ex = new ConfigurationException(); - ex.setMessage(SINGLETON_ERROR, new Object[] { instance.getSource(), id }); - ex.setRootCause(t); - - if (Log.isError()) - Log.getLogger(ConfigurationManager.LOG_CATEGORY).error(ex.getMessage() + StringUtils.NEWLINE + ExceptionUtil.toString(t)); - - throw ex; - } - } - else if(instance.getScope().equalsIgnoreCase(SCOPE_SESSION)) - { - // increment attribute-id reference count on MB for Session scoped instances - MessageBroker mb = FlexContext.getMessageBroker(); - if (mb != null) - mb.incrementAttributeIdRefCount(instance.getAttributeId()); - } - return instance; - } - - /** - * Returns the instance specified by the source - * and properties arguments. For the factory, this may mean - * constructing a new instance, optionally registering it in some other - * name space such as the session or JNDI, and then returning it - * or it may mean creating a new instance and returning it. - * This method is called for each request to operate on the - * given item by the system so it should be relatively efficient. - * <p> - * If your factory does not support the scope property, it report an error - * if scope is supplied in the properties for this instance. - * </p> - * - * @param inst the FactoryInstance to lookup. - * @return the constructed and initialized component for this factory instance. - */ - public Object lookup(FactoryInstance inst) - { - JavaFactoryInstance factoryInstance = (JavaFactoryInstance) inst; - Object instance; - - if (factoryInstance.getScope().equalsIgnoreCase(SCOPE_APPLICATION)) - { - instance = factoryInstance.applicationInstance; - } - else if (factoryInstance.getScope().equalsIgnoreCase(SCOPE_SESSION)) - { - // See if an instance already exists in this http session first - FlexSession session = FlexContext.getFlexSession(); - if (session != null) - { - instance = session.getAttribute(factoryInstance.getAttributeId()); - if (instance != null) - { - Class configuredClass = factoryInstance.getInstanceClass(); - Class instClass = instance.getClass(); - if (configuredClass != instClass && - !configuredClass.isAssignableFrom(instClass)) - { - ServiceException e = new ServiceException(); - e.setMessage(INVALID_CLASS_FOUND, new Object[] { - factoryInstance.getAttributeId(), - "session", - factoryInstance.getId(), - factoryInstance.getInstanceClass(), instance.getClass()}); - e.setCode("Server.Processing"); - throw e; - } - } - else - { - // none exists - create it the first time for each session - instance = factoryInstance.createInstance(); - session.setAttribute(factoryInstance.getAttributeId(), instance); - } - } - else - instance = null; - - if (instance == null) - { - ServiceException e = new ServiceException(); - e.setMessage(SESSION_NOT_FOUND, new Object[] {factoryInstance.getId()}); - e.setCode("Server.Processing"); - throw e; - } - } - else - { - instance = factoryInstance.createInstance(); - } - return instance; - } - - /** - * This method is called when a component using this factory is being destroyed. - * When appropriate, it frees up resources that were used by the factory instance - * and are no longer needed - * - * @param inst The FactoryInstance to be cleaned up - */ - public void destroyFactoryInstance(FactoryInstance inst) - { - JavaFactoryInstance factoryInstance = (JavaFactoryInstance) inst; - - // if we are stopping a destination with an Application or Session scoped assembler, we may - // have to remove the assembler from the ServletContext or Session - if (factoryInstance != null) - { - MessageBroker mb = FlexContext.getMessageBroker(); - String attributeId = factoryInstance.getAttributeId(); - - if (FlexFactory.SCOPE_APPLICATION.equals(factoryInstance.getScope())) - { - ServletContext ctx = mb.getServletContext(); - if (ctx == null) // Should never be the case, but just in case. - return; - - synchronized (ctx) - { - // remove from ServletContext if reference count is zero - int refCount = (mb != null) ? mb.decrementAttributeIdRefCount(attributeId) : 0; - if (refCount <= 0) - { - // remove assembler from servlet context - ctx.removeAttribute(attributeId); - } - } - } - else if (FlexFactory.SCOPE_SESSION.equals(factoryInstance.getScope())) - { - FlexSession session = FlexContext.getFlexSession(); - - // if this is being stopped during runtime config, we should have a session available to us - // However, if this is being stopped on MessageBroker shutdown, we will not have a session - // but do not need to worry about clean up in that case as the entire session will be cleaned up - if (session == null) - return; - - // remove from Session if reference count is zero - int refCount = (mb != null) ? mb.decrementAttributeIdRefCount(attributeId) : 0; - if (refCount <= 0) - { - // remove assembler from servlet context - session.removeAttribute(attributeId); - } - } - - // Remove this instance from Session created listeners - // Only helps if listener was created by the factory, but this is common (aka assembler classes) - if (factoryInstance.applicationInstance instanceof FlexSessionListener) - { - FlexSession.removeSessionCreatedListener((FlexSessionListener) factoryInstance.applicationInstance); - } - } - } -} - http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/factories/JavaFactoryInstance.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/factories/JavaFactoryInstance.java b/core/src/flex/messaging/factories/JavaFactoryInstance.java deleted file mode 100644 index 700545a..0000000 --- a/core/src/flex/messaging/factories/JavaFactoryInstance.java +++ /dev/null @@ -1,146 +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.factories; - -import flex.messaging.Destination; -import flex.messaging.FactoryInstance; -import flex.messaging.FlexConfigurable; -import flex.messaging.FlexContext; -import flex.messaging.FlexFactory; -import flex.messaging.FlexSession; -import flex.messaging.MessageBroker; -import flex.messaging.config.ConfigMap; -import flex.messaging.util.ClassUtil; - -/** - * This class is used by the <code>JavaFactory</code> to store the configuration - * for an instance created by the <code>JavaFactory</code>. There is one of these for - * each destination currently since only destinations create these components. - * - * @see flex.messaging.factories.JavaFactory - */ - -public class JavaFactoryInstance extends FactoryInstance -{ - Object applicationInstance = null; - Class javaClass = null; - String attributeId; - - /** - * Constructs a <code>JavaFactoryInstance</code>, assigning its factory, id, - * and properties. - * - * @param factory The <code>JavaFactory</code> that created this instance. - * @param id The id for the <code>JavaFactoryInstance</code>. - * @param properties The properties for the <code>JavaFactoryInstance</code>. - */ - public JavaFactoryInstance(JavaFactory factory, String id, ConfigMap properties) - { - super(factory, id, properties); - } - - /** - * Sets the attribute id for the <code>JavaFactoryInstance</code>. - * - * @param attributeId The attribute id for the <code>JavaFactoryInstance</code>. - */ - public void setAttributeId(String attributeId) - { - this.attributeId = attributeId; - } - - /** - * Returns the attribute id for the <code>JavaFactoryInstance</code>. - * - * @return attributeId The attribute id for the <code>JavaFactoryInstance</code>. - */ - public String getAttributeId() - { - return attributeId; - } - - /** - * Sets the instance class to null, in addition to updating the - * <code>source</code> property. - */ - @Override public void setSource(String source) - { - super.setSource(source); - if (javaClass != null) - javaClass = null; - } - - /** - * Creates an instance from specified <code>source</code> and initializes - * the instance if it is of <code>FlexConfigurable</code> type. - * - * @return the instance - */ - public Object createInstance() - { - Object inst = ClassUtil.createDefaultInstance(getInstanceClass(), null); - - MessageBroker mb = FlexContext.getMessageBroker(); - if (mb != null) - { - Destination destination = mb.getRegisteredDestination(getId()); - if (destination != null && destination.isInitialized()) - { - if (inst instanceof FlexConfigurable) - ((FlexConfigurable) inst).initialize(getId(), getProperties()); - } - } - - return inst; - } - - /** - * Creates an instance class from specified <code>source</code>. - */ - @Override public Class getInstanceClass() - { - if (javaClass == null) - javaClass = ClassUtil.createClass(getSource(), - FlexContext.getMessageBroker() == null ? this.getClass().getClassLoader() : - FlexContext.getMessageBroker().getClassLoader()); - - return javaClass; - } - - /** - * Updates the session so that these values get replicated to other nodes - * in the cluster. Possibly we should make this configurable? - */ - @Override public void operationComplete(Object instance) - { - if (getScope().equalsIgnoreCase(FlexFactory.SCOPE_SESSION)) - { - FlexSession session = FlexContext.getFlexSession(); - if (session != null && session.isValid()) - { - session.setAttribute(getAttributeId(), instance); - } - } - } - - - @Override public String toString() - { - return "JavaFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope(); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/factories/package-info.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/factories/package-info.java b/core/src/flex/messaging/factories/package-info.java deleted file mode 100644 index 3ce0139..0000000 --- a/core/src/flex/messaging/factories/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.factories; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/AbstractProxy.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/AbstractProxy.java b/core/src/flex/messaging/io/AbstractProxy.java deleted file mode 100644 index 2f29fb6..0000000 --- a/core/src/flex/messaging/io/AbstractProxy.java +++ /dev/null @@ -1,294 +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; - -import java.util.List; -import java.io.Externalizable; -import java.io.Serializable; - -import flex.messaging.MessageException; -import flex.messaging.io.amf.ASObject; -import flex.messaging.log.LogCategories; -import flex.messaging.log.Log; -import flex.messaging.log.Logger; -import flex.messaging.util.ClassUtil; - -/** - * Simple abstract implementation of PropertyProxy's common properties. Specific - * sub-classes need to provide the full implementation focusing on the retrieval - * of the instance traits or "list of properties" and a specific value for - * a given property name. - * - * @see flex.messaging.io.PropertyProxy - * - */ -public abstract class AbstractProxy implements PropertyProxy, Serializable -{ - protected Object defaultInstance; - protected String alias; - protected boolean dynamic; - protected boolean externalizable; - protected boolean includeReadOnly; - protected SerializationDescriptor descriptor; - protected SerializationContext context; - - protected static final String LOG_CATEGORY = LogCategories.ENDPOINT_TYPE; - private static final int CONVERSION_ERROR = 10006; - - protected AbstractProxy(Object defaultInstance) - { - this.defaultInstance = defaultInstance; - if (defaultInstance != null) - alias = defaultInstance.getClass().getName(); - } - - /** {@inheritDoc} */ - public Object getDefaultInstance() - { - return defaultInstance; - } - - /** {@inheritDoc} */ - public void setDefaultInstance(Object instance) - { - defaultInstance = instance; - } - - /** - * A utility method which returns the Class from the given Class name - * using the current type context's class loader. - * - * @param className the class name. - * @return a Class object for the named class. - */ - public static Class getClassFromClassName(String className) - { - TypeMarshallingContext typeContext = TypeMarshallingContext.getTypeMarshallingContext(); - return ClassUtil.createClass(className, typeContext.getClassLoader()); - } - - /** - * A utility method which creates an instance from a given class name. It assumes - * the class has a zero arg constructor. - * @param className the class name - * for a type that is missing on the server, instead of throwing a server resource not found - * exception. - * @return the instance of the named class. - */ - public static Object createInstanceFromClassName(String className) - { - Class<?> desiredClass = getClassFromClassName(className); - return ClassUtil.createDefaultInstance(desiredClass, null, true /*validate*/); - } - - /** {@inheritDoc} */ - public Object createInstance(String className) - { - Object instance; - - if (className == null || className.length() == 0) - { - instance = ClassUtil.createDefaultInstance(ASObject.class, null, true /*validate*/); - } - else if (className.startsWith(">")) // Handle [RemoteClass] (no server alias) - { - instance = ClassUtil.createDefaultInstance(ASObject.class, null, true /*validate*/); - ((ASObject)instance).setType(className); - } - else - { - if (getSerializationContext().instantiateTypes || className.startsWith("flex.")) - return createInstanceFromClassName(className); - - // Just return type info with an ASObject... - instance = ClassUtil.createDefaultInstance(ASObject.class, null, true /*validate*/); - ((ASObject)instance).setType(className); - } - return instance; - } - - /** {@inheritDoc} */ - public List getPropertyNames() - { - return getPropertyNames(getDefaultInstance()); - } - - /** {@inheritDoc} */ - public Class getType(String propertyName) - { - return getType(getDefaultInstance(), propertyName); - } - - /** {@inheritDoc} */ - public Object getValue(String propertyName) - { - return getValue(getDefaultInstance(), propertyName); - } - - /** {@inheritDoc} */ - public void setValue(String propertyName, Object value) - { - setValue(getDefaultInstance(), propertyName, value); - } - - /** {@inheritDoc} */ - public void setAlias(String value) - { - alias = value; - } - - /** {@inheritDoc} */ - public String getAlias() - { - return alias; - } - - /** {@inheritDoc} */ - public void setDynamic(boolean value) - { - dynamic = value; - } - - /** {@inheritDoc} */ - public boolean isDynamic() - { - return dynamic; - } - - /** {@inheritDoc} */ - public boolean isExternalizable() - { - return externalizable; - } - - /** {@inheritDoc} */ - public void setExternalizable(boolean value) - { - externalizable = value; - } - - /** {@inheritDoc} */ - public boolean isExternalizable(Object instance) - { - return instance instanceof Externalizable; - } - - /** {@inheritDoc} */ - public SerializationContext getSerializationContext() - { - return context == null? SerializationContext.getSerializationContext() : context; - } - - /** {@inheritDoc} */ - public void setSerializationContext(SerializationContext value) - { - context = value; - } - - /** {@inheritDoc} */ - public void setIncludeReadOnly(boolean value) - { - includeReadOnly = value; - } - - /** {@inheritDoc} */ - public boolean getIncludeReadOnly() - { - if (includeReadOnly) - { - return true; - } - return getSerializationContext().includeReadOnly; - } - - /** {@inheritDoc} */ - public SerializationDescriptor getDescriptor() - { - return descriptor; - } - - /** {@inheritDoc} */ - public void setDescriptor(SerializationDescriptor descriptor) - { - this.descriptor = descriptor; - } - - /** - * This is called after the serialization finishes. We return the same object - * here... this is an opportunity to replace the instance we use once we have - * gathered all of the state into a temporary object. - * @param instance current instance - * @return Object the instance after complete serialization - */ - public Object instanceComplete(Object instance) - { - return instance; - } - - /** - * Returns the instance to serialize in place of the supplied instance. - * @param instance the instance to serialize - * @return Object the instance - */ - public Object getInstanceToSerialize(Object instance) - { - return instance; - } - - /** {@inheritDoc} */ - @Override - public Object clone() - { - try - { - AbstractProxy clonedProxy= (AbstractProxy) super.clone(); - clonedProxy.setCloneFieldsFrom(this); - return clonedProxy; - } - catch (CloneNotSupportedException e) - { - if (Log.isError()) - { - Logger log = Log.getLogger(LOG_CATEGORY); - log.error("Failed to clone a property proxy: " + toString()); - } - MessageException ex = new MessageException(); - ex.setMessage(CONVERSION_ERROR); - throw ex; - } - } - - /** - * A string including the default instance, class and descriptor info. - * @return debug string. - */ - @Override - public String toString() - { - if (defaultInstance != null) - return "[Proxy(inst=" + defaultInstance + ") proxyClass=" + getClass() + " descriptor=" + descriptor + "]"; - return "[Proxy(proxyClass=" + getClass() + " descriptor=" + descriptor + "]"; - } - - protected void setCloneFieldsFrom(AbstractProxy source) - { - setDescriptor(source.getDescriptor()); - setDefaultInstance(source.getDefaultInstance()); - context = source.context; - includeReadOnly = source.includeReadOnly; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/ArrayCollection.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/ArrayCollection.java b/core/src/flex/messaging/io/ArrayCollection.java deleted file mode 100644 index dd74e6d..0000000 --- a/core/src/flex/messaging/io/ArrayCollection.java +++ /dev/null @@ -1,165 +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; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.ArrayList; -import java.util.Collection; - -/** - * Used to map to client mx.collections.ArrayCollection to java.util.Lists in Java. - */ -public class ArrayCollection extends ArrayList implements Externalizable -{ - private static final long serialVersionUID = 8037277879661457358L; - - private SerializationDescriptor descriptor = null; - - /** - * Default constructor. - */ - public ArrayCollection() - { - super(); - } - - /** - * Creates an <tt>ArrayCollection</tt> with the supplied collection. - * - * @param c Collection. - */ - public ArrayCollection(Collection c) - { - super(c); - } - - /** - * Creates <tt>ArrayCollection</tt> with the supllied inital capacity. - * - * @param initialCapacity The initial capacity. - */ - public ArrayCollection(int initialCapacity) - { - super(initialCapacity); - } - - /** - * Returns the backing Array of the <tt>ArrayCollection</tt>. - * - * @return The backing Array. - */ - public Object[] getSource() - { - return toArray(); - } - - /** - * Sets the serialization descriptor. - * - * @param desc The serialization descriptor. - */ - public void setDescriptor(SerializationDescriptor desc) - { - this.descriptor = desc; - } - - /** - * Sets the source with the supplied Array. - * - * @param s The source Array. - */ - public void setSource(Object[] s) - { - if (s == null) - { - clear(); - return; - } - - if (size() > 0) - clear(); - - for (int i = 0; i < s.length; i++) - add(s[i]); - } - - /** - * Sets the sources with the supplied Collection. - * - * @param s The source Collection. - */ - public void setSource(Collection s) - { - addAll(s); - } - - /** - * Implements {@link Externalizable#readExternal(ObjectInput)} - * - * @param input The object input. - */ - public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException - { - Object s = input.readObject(); - if (s instanceof Collection) - s = ((Collection)s).toArray(); - Object[] source = (Object[])s; - setSource(source); - } - - /** - * Implements {@link Externalizable#writeExternal(ObjectOutput)} - * - * @param output The object output. - */ - public void writeExternal(ObjectOutput output) throws IOException - { - if (descriptor == null) - { - output.writeObject(getSource()); - return; - } - - Object[] source = getSource(); - if (source == null) - { - output.writeObject(null); - return; - } - - for (int i = 0; i < source.length; i++) - { - Object item = source[i]; - if (item == null) - { - source[i] = null; - } - else - { - PropertyProxy proxy = PropertyProxyRegistry.getProxy(item); - proxy = (PropertyProxy)proxy.clone(); - proxy.setDescriptor(descriptor); - proxy.setDefaultInstance(item); - source[i] = proxy; - } - } - output.writeObject(source); - } -} http://git-wip-us.apache.org/repos/asf/flex-blazeds/blob/8315f8fa/core/src/flex/messaging/io/ArrayList.java ---------------------------------------------------------------------- diff --git a/core/src/flex/messaging/io/ArrayList.java b/core/src/flex/messaging/io/ArrayList.java deleted file mode 100644 index b3eeb24..0000000 --- a/core/src/flex/messaging/io/ArrayList.java +++ /dev/null @@ -1,44 +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; - -import java.util.Collection; - -/** - * - */ -public class ArrayList extends ArrayCollection -{ - private static final long serialVersionUID = -2976024728140087328L; - - public ArrayList() - { - super(); - } - - public ArrayList(Collection c) - { - super(c); - } - - public ArrayList(int initialCapacity) - { - super(initialCapacity); - } -}