001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.util;
020
021import lucee.runtime.exp.PageException;
022import lucee.runtime.net.amf.CFMLProxy;
023import lucee.runtime.op.Caster;
024import flex.messaging.FlexContext;
025import flex.messaging.MessageException;
026import flex.messaging.config.ConfigMap;
027import flex.messaging.messages.Message;
028import flex.messaging.messages.RemotingMessage;
029import flex.messaging.services.ServiceAdapter;
030
031public class BlazeDSImpl implements BlazeDS {
032        
033
034        private ConfigMap properties;
035
036
037        public Object invoke(ServiceAdapter serviceAdapter, Message message){
038                
039                
040        //RemotingDestination remotingDestination = (RemotingDestination)serviceAdapter.getDestination();
041        RemotingMessage remotingMessage = (RemotingMessage)message;
042        //FactoryInstance factoryInstance = remotingDestination.getFactoryInstance();
043        /*
044        print.out("className:"+remotingMessage.getSource());
045        print.out("methodName:"+remotingMessage.getOperation());
046        print.out("params:");
047        print.out(remotingMessage.getParameters().toArray());
048         */      
049        try {
050                        Object rtn = new CFMLProxy().invokeBody(
051                                        null,properties, 
052                                        FlexContext.getServletContext(),
053                                        FlexContext.getServletConfig(), 
054                                        FlexContext.getHttpRequest(), 
055                                        FlexContext.getHttpResponse(), 
056                                        remotingMessage.getSource(), 
057                                        remotingMessage.getOperation(), 
058                                        remotingMessage.getParameters());
059                        
060                return rtn;
061                } 
062        catch (Exception e) {
063                e.printStackTrace();// TODO
064                String msg=e.getMessage();
065                
066                MessageException me = new MessageException(Caster.toClassName(e) + " : " + msg);
067                me.setRootCause(e);
068            me.setCode("Server.Processing");
069            me.setRootCause(e);
070            
071            if(e instanceof PageException){
072                PageException pe=(PageException) e;
073                me.setDetails(pe.getDetail());
074                me.setMessage(pe.getMessage());
075                me.setCode(pe.getErrorCode());
076            }
077            
078            throw me;
079                }
080    }
081
082
083        /**
084         * @see lucee.runtime.util.BlazeDS#init(flex.messaging.config.ConfigMap)
085         */
086        public void init(ConfigMap properties) {
087                this.properties=properties;
088        }
089}