/* * Created on Nov 26, 2005 * * Copyright 2005 CafeSip.org * * Licensed 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 org.cafesip.sipexchange.inservice.server; import java.util.StringTokenizer; import javax.management.MBeanServer; import org.cafesip.sipexchange.common.inservice.shared.CalledAddressTermTrigger; import org.cafesip.sipexchange.common.inservice.shared.ContinueResponse; import org.cafesip.sipexchange.common.inservice.shared.DomainTriggerParamParser; import org.cafesip.sipexchange.common.inservice.shared.RerouteResponse; import org.cafesip.sipexchange.common.inservice.shared.Response; import org.cafesip.sipexchange.common.inservice.shared.TerminateResponse; import org.cafesip.sipexchange.common.inservice.shared.TriggerInfo; import org.jboss.remoting.InvocationRequest; import org.jboss.remoting.ServerInvocationHandler; import org.jboss.remoting.ServerInvoker; import org.jboss.remoting.callback.InvokerCallbackHandler; /** * @author Amit Chatterjee * */ public class ExampleInServiceHandler implements ServerInvocationHandler { /** * A constructor for this class. * * */ public ExampleInServiceHandler() { super(); } /* * @see org.jboss.remoting.ServerInvocationHandler#setMBeanServer(javax.management.MBeanServer) */ public void setMBeanServer(MBeanServer arg0) { } /* * @see org.jboss.remoting.ServerInvocationHandler#setInvoker(org.jboss.remoting.ServerInvoker) */ public void setInvoker(ServerInvoker arg0) { } /* * @see org.jboss.remoting.ServerInvocationHandler#invoke(org.jboss.remoting.InvocationRequest) */ public Object invoke(InvocationRequest req) throws Throwable { TriggerInfo t = (TriggerInfo) req.getParameter(); System.out.println("Received an invoke from a client\n" + TriggerInfo.printTriggerInfo(t)); String param = (String) t.getParam(); if (t instanceof CalledAddressTermTrigger) { param = DomainTriggerParamParser.parse(param).getParam(); } if (param == null) { return terminate("We are unable to process the call at this time because no params are present"); } return processRequest(param); } private Response processRequest(String param) { StringTokenizer tokens = new StringTokenizer(param, "="); if (tokens.countTokens() < 2) { return terminate("An error occured while processing the call - invalid param " + param); } String action = tokens.nextToken(); String aparam = tokens.nextToken(); if (action.equals("disconnect") == true) { System.out.println("Sending terminate response with reason " + aparam); return terminate(aparam); } if (action.equals("continue") == true) { System.out.println("Sending a continue response"); return new ContinueResponse(); } if (action.equals("forward") == true) { RerouteResponse r = new RerouteResponse(); StringTokenizer addresses = new StringTokenizer(aparam, ";"); int count = addresses.countTokens(); String[] addr = new String[count]; for (int i = 0; i < count; i++) { String address = addresses.nextToken(); addr[i] = address; } System.out.println("Sending a forward response with address " + aparam); r.setRerouteAddresses(addr); return r; } if (action.equals("reroute") == true) { System.out.println("Sending a redirect response with address " + aparam); RerouteResponse r = new RerouteResponse(); r.setRedirect(true); String[] addr = new String[1]; addr[0] = aparam; r.setRerouteAddresses(addr); return r; } return terminate("An error occured while processing the call - invalid actions"); } private Response terminate(String reason) { TerminateResponse response = new TerminateResponse(); response.setStatusCode(603); response.setReason(reason); return response; } /* * @see org.jboss.remoting.ServerInvocationHandler#addListener(org.jboss.remoting.callback.InvokerCallbackHandler) */ public void addListener(InvokerCallbackHandler arg0) { } /* * @see org.jboss.remoting.ServerInvocationHandler#removeListener(org.jboss.remoting.callback.InvokerCallbackHandler) */ public void removeListener(InvokerCallbackHandler arg0) { } }