Search in sources :

Example 1 with VCRpcRequest

use of cbit.vcell.message.VCRpcRequest in project vcell by virtualcell.

the class AbstractRpcServerProxy method rpc.

/**
 * Insert the method's description here.
 * Creation date: (12/5/2001 9:39:03 PM)
 * @return java.lang.Object
 * @param methodName java.lang.String
 * @param args java.lang.Object[]
 * @exception java.lang.Exception The exception description.
 */
public Object rpc(RpcServiceType serviceType, String methodName, Object[] args, boolean returnRequired, String[] specialProperties, Object[] specialValues) throws Exception {
    VCRpcRequest vcRpcRequest = new VCRpcRequest(userLoginInfo.getUser(), serviceType, methodName, args);
    // default to 2 minutes.
    int timeoutMS = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.vcellClientTimeoutMS, "120000"));
    return rpcSender.sendRpcMessage(queue, vcRpcRequest, returnRequired, timeoutMS, specialProperties, specialValues, userLoginInfo);
}
Also used : VCRpcRequest(cbit.vcell.message.VCRpcRequest)

Example 2 with VCRpcRequest

use of cbit.vcell.message.VCRpcRequest in project vcell by virtualcell.

the class TestBlobRpcMessages method main.

public static void main(String[] args) throws Exception {
    try {
        PropertyLoader.loadProperties();
        // System.getProperties().setProperty(PropertyLoader.jmsURL,"tcp://nrcamdev5.cam.uchc.edu:61616");
        VCMessagingService messagingService = new VCMessagingServiceActiveMQ();
        messagingService.setDelegate(new SimpleMessagingDelegate());
        // reading message and computing sum
        // create N comsumers
        MyRpcServer myRpcServer = new MyRpcServer();
        for (int i = 0; i < NUM_COMSUMERS; i++) {
            VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellTestQueue.JimQueue);
            VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, rpcMessageHandler, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== RPC Consumer Thread " + i, 1);
            messagingService.addMessageConsumer(rpcConsumer);
        }
        // creating one messageProducer session
        ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
        for (int i = 0; i < NUM_PRODUCERS; i++) {
            sessions.add(messagingService.createProducerSession());
        }
        for (int i = 0; i < NUM_MESSAGES; i++) {
            for (int s = 0; s < NUM_PRODUCERS; s++) {
                VCMessageSession session = sessions.get(s);
                try {
                    // 
                    // create simple RPC request for service "Testing_Service"
                    // 
                    User user = new User("schaff", new KeyValue("17"));
                    byte[] array1 = new byte[20000000];
                    byte[] array2 = new byte[20000000];
                    VCRpcRequest rpcRequest = new VCRpcRequest(user, RpcServiceType.TESTING_SERVICE, "concat", new Object[] { array1, array2 });
                    // 
                    // send request and block for response (or timeout).
                    // RPC invocations don't need commits.
                    // 
                    Object returnValue = session.sendRpcMessage(VCellTestQueue.JimQueue, rpcRequest, true, 20000, null, null, null);
                    // 
                    if (returnValue instanceof byte[]) {
                        System.out.println("concat(byte[" + array1.length + "], byte[" + array2.length + "]) ===> byte[" + (((byte[]) returnValue).length) + "]");
                    } else {
                        System.out.println("unexpected return value of " + returnValue);
                    }
                } catch (VCMessagingInvocationTargetException e) {
                    e.printStackTrace(System.out);
                    System.out.println("the rpc service threw an exception");
                    e.getTargetException().printStackTrace(System.out);
                }
            }
        }
        System.out.println("main program calling closeAll()");
        messagingService.close();
        System.out.println("main program exiting");
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : SimpleMessagingDelegate(cbit.vcell.message.SimpleMessagingDelegate) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCMessageSession(cbit.vcell.message.VCMessageSession) ArrayList(java.util.ArrayList) VCMessagingService(cbit.vcell.message.VCMessagingService) VCRpcRequest(cbit.vcell.message.VCRpcRequest) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessagingServiceActiveMQ(cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler)

Example 3 with VCRpcRequest

use of cbit.vcell.message.VCRpcRequest in project vcell by virtualcell.

the class AbstractRpcServerProxy method rpc.

/**
 * Insert the method's description here.
 * Creation date: (12/5/2001 9:39:03 PM)
 * @return java.lang.Object
 * @param methodName java.lang.String
 * @param args java.lang.Object[]
 * @exception java.lang.Exception The exception description.
 */
public Object rpc(RpcServiceType serviceType, String methodName, Object[] args, boolean returnRequired, String[] specialProperties, Object[] specialValues) throws Exception {
    VCRpcRequest vcRpcRequest = new VCRpcRequest(userLoginInfo.getUser(), serviceType, methodName, args);
    // default to 2 minutes.
    int timeoutMS = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.vcellClientTimeoutMS, "120000"));
    return vcMessagingSession.sendRpcMessage(queue, vcRpcRequest, returnRequired, timeoutMS, specialProperties, specialValues, userLoginInfo);
}
Also used : VCRpcRequest(cbit.vcell.message.VCRpcRequest)

Example 4 with VCRpcRequest

use of cbit.vcell.message.VCRpcRequest in project vcell by virtualcell.

the class VCellApiMain method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        if (args.length != 2) {
            System.out.println("usage: VCellApiMain javascriptDir port");
            System.exit(1);
        }
        File javascriptDir = new File(args[0]);
        if (!javascriptDir.isDirectory()) {
            throw new RuntimeException("javascriptDir '" + args[0] + "' is not a directory");
        }
        // don't validate
        PropertyLoader.loadProperties();
        lg.debug("properties loaded");
        String portString = args[1];
        // was hard-coded at 8080
        Integer port = null;
        try {
            port = Integer.parseInt(portString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new RuntimeException("failed to parse port argument '" + portString + "'", e);
        }
        lg.trace("connecting to database");
        lg.trace("oracle factory (next)");
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        lg.trace("database impl (next)");
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        lg.trace("local db server (next)");
        LocalAdminDbServer localAdminDbServer = new LocalAdminDbServer(conFactory, keyFactory);
        lg.trace("admin db server (next)");
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        lg.trace("messaging service (next)");
        VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new VCMessagingDelegate() {

            @Override
            public void onTraceEvent(String string) {
                System.out.println("Trace: " + string);
            }

            @Override
            public void onRpcRequestSent(VCRpcRequest vcRpcRequest, UserLoginInfo userLoginInfo, VCMessage vcRpcRequestMessage) {
                System.out.println("request sent:");
            }

            @Override
            public void onRpcRequestProcessed(VCRpcRequest vcRpcRequest, VCMessage rpcVCMessage) {
                System.out.println("request processed:");
            }

            @Override
            public void onMessageSent(VCMessage message, VCDestination desintation) {
                System.out.println("message sent:");
            }

            @Override
            public void onMessageReceived(VCMessage vcMessage, VCDestination vcDestination) {
                System.out.println("message received");
            }

            @Override
            public void onException(Exception e) {
                System.out.println("Exception: " + e.getMessage());
                e.printStackTrace();
            }
        });
        lg.trace("rest database service (next)");
        RestDatabaseService restDatabaseService = new RestDatabaseService(databaseServerImpl, localAdminDbServer, vcMessagingService);
        lg.trace("rest event service (next)");
        RestEventService restEventService = new RestEventService(vcMessagingService);
        lg.trace("use verifier (next)");
        UserVerifier userVerifier = new UserVerifier(adminDbTopLevel);
        lg.trace("mongo (next)");
        VCMongoMessage.enabled = true;
        VCMongoMessage.serviceStartup(ServiceName.unknown, port, args);
        System.out.println("setting up server configuration");
        lg.trace("register engine (next)");
        Engine.register(true);
        WadlComponent component = new WadlComponent();
        // Server httpServer = component.getServers().add(Protocol.HTTP, 80);
        // Server httpsServer = component.getServers().add(Protocol.HTTPS, 443);
        // Client httpsClient = component.getClients().add(Protocol.HTTPS);
        // Client httpClient = component.getClients().add(Protocol.HTTP);
        lg.trace("adding FILE protcol");
        @SuppressWarnings("unused") Client httpClient = component.getClients().add(Protocol.FILE);
        lg.trace("adding CLAP protcol");
        @SuppressWarnings("unused") Client clapClient = component.getClients().add(Protocol.CLAP);
        lg.trace("adding CLAP https");
        File keystorePath = new File(PropertyLoader.getRequiredProperty(PropertyLoader.vcellapiKeystoreFile));
        String keystorePassword = PropertyLoader.getSecretValue(PropertyLoader.vcellapiKeystorePswd, PropertyLoader.vcellapiKeystorePswdFile);
        try {
            // 
            // keystorePassword may be encrypted with dbPassword, if it is decypt it.
            // 
            String dbPassword = PropertyLoader.getSecretValue(PropertyLoader.dbPasswordValue, PropertyLoader.dbPasswordFile);
            SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
            SecretKey key = kf.generateSecret(new PBEKeySpec(dbPassword.toCharArray()));
            Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
            pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(new byte[] { 32, 11, 55, 121, 01, 42, 89, 11 }, 20));
            keystorePassword = new String(pbeCipher.doFinal(DatatypeConverter.parseBase64Binary(keystorePassword)));
        } catch (Exception e) {
            System.out.println("password unhashing didn't work - trying clear text password");
            e.printStackTrace();
        }
        Server httpsServer = component.getServers().add(Protocol.HTTPS, port);
        Series<Parameter> parameters = httpsServer.getContext().getParameters();
        parameters.add("keystorePath", keystorePath.toString());
        parameters.add("keystorePassword", keystorePassword);
        parameters.add("keystoreType", "JKS");
        parameters.add("keyPassword", keystorePassword);
        parameters.add("disabledCipherSuites", "SSL_RSA_WITH_3DES_EDE_CBC_SHA " + "SSL_DHE_RSA_WITH_DES_CBC_SHA " + "SSL_DHE_DSS_WITH_DES_CBC_SHA");
        parameters.add("enabledCipherSuites", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA " + "TLS_RSA_WITH_AES_128_CBC_SHA " + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA " + "TLS_RSA_WITH_AES_256_CBC_SHA");
        lg.trace("create config");
        Configuration templateConfiguration = new Configuration();
        templateConfiguration.setObjectWrapper(new DefaultObjectWrapper());
        lg.trace("verify python installation");
        PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.COPASI, PythonPackage.LIBSBML, PythonPackage.THRIFT });
        lg.trace("start Optimization Service");
        OptServerImpl optServerImpl = new OptServerImpl();
        optServerImpl.start();
        lg.trace("create app");
        boolean bIgnoreHostProblems = true;
        boolean bIgnoreCertProblems = true;
        User testUser = localAdminDbServer.getUser(TEST_USER);
        // lookup hashed auth credentials in database.
        UserInfo testUserInfo = localAdminDbServer.getUserInfo(testUser.getID());
        HealthService healthService = new HealthService(restEventService, "localhost", port, bIgnoreCertProblems, bIgnoreHostProblems, testUserInfo.userid, testUserInfo.digestedPassword0);
        AdminService adminService = new AdminService(adminDbTopLevel, databaseServerImpl);
        RpcService rpcService = new RpcService(vcMessagingService);
        WadlApplication app = new VCellApiApplication(restDatabaseService, userVerifier, optServerImpl, rpcService, restEventService, adminService, templateConfiguration, healthService, javascriptDir);
        lg.trace("attach app");
        component.getDefaultHost().attach(app);
        System.out.println("component start()");
        lg.trace("start component");
        component.start();
        System.out.println("component ended.");
        lg.trace("component started");
        lg.trace("start VCell Health Monitoring service");
        healthService.start();
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) WadlComponent(org.restlet.ext.wadl.WadlComponent) User(org.vcell.util.document.User) AdminService(org.vcell.rest.admin.AdminService) Server(org.restlet.Server) LocalAdminDbServer(cbit.vcell.modeldb.LocalAdminDbServer) Configuration(freemarker.template.Configuration) VCMessagingDelegate(cbit.vcell.message.VCMessagingDelegate) OptServerImpl(org.vcell.optimization.OptServerImpl) UserInfo(org.vcell.util.document.UserInfo) VCMessagingService(cbit.vcell.message.VCMessagingService) ConnectionFactory(org.vcell.db.ConnectionFactory) VCDestination(cbit.vcell.message.VCDestination) VCMessage(cbit.vcell.message.VCMessage) HealthService(org.vcell.rest.health.HealthService) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) RestDatabaseService(org.vcell.rest.server.RestDatabaseService) Client(org.restlet.Client) SecretKeyFactory(javax.crypto.SecretKeyFactory) SecretKeyFactory(javax.crypto.SecretKeyFactory) KeyFactory(org.vcell.db.KeyFactory) PBEParameterSpec(javax.crypto.spec.PBEParameterSpec) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) VCRpcRequest(cbit.vcell.message.VCRpcRequest) SecretKey(javax.crypto.SecretKey) RestEventService(org.vcell.rest.events.RestEventService) WadlApplication(org.restlet.ext.wadl.WadlApplication) RpcService(org.vcell.rest.rpc.RpcService) LocalAdminDbServer(cbit.vcell.modeldb.LocalAdminDbServer) Parameter(org.restlet.data.Parameter) Cipher(javax.crypto.Cipher) UserLoginInfo(org.vcell.util.document.UserLoginInfo) File(java.io.File)

Example 5 with VCRpcRequest

use of cbit.vcell.message.VCRpcRequest in project vcell by virtualcell.

the class RpcRestlet method handle.

@Override
public void handle(Request req, Response response) {
    if (req.getMethod().equals(Method.POST)) {
        String destination = null;
        String method = null;
        try {
            VCellApiApplication application = ((VCellApiApplication) getApplication());
            User vcellUser = application.getVCellUser(req.getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
            HttpRequest request = (HttpRequest) req;
            String username = vcellUser.getName();
            String userkey = vcellUser.getID().toString();
            destination = request.getHeaders().getFirstValue("Destination");
            method = request.getHeaders().getFirstValue("Method");
            String returnRequired = request.getHeaders().getFirstValue("ReturnRequired");
            String timeoutMS = request.getHeaders().getFirstValue("TimeoutMS");
            String compressed = request.getHeaders().getFirstValue("Compressed");
            String klass = request.getHeaders().getFirstValue("Class");
            StringBuffer buffer = new StringBuffer();
            buffer.append("username=" + username + ", userkey=" + userkey + ", destination=" + destination + ", method=" + method + "\n");
            buffer.append("returnRequired=" + returnRequired + ", timeoutMS=" + timeoutMS + ", compressed=" + compressed + "\n");
            buffer.append("class=" + klass);
            System.out.println(buffer.toString());
            req.bufferEntity();
            Serializable rpcRequestBodyObject = VCellApiClient.fromCompressedSerialized(req.getEntity().getStream());
            if (!(rpcRequestBodyObject instanceof VCellApiRpcBody)) {
                throw new RuntimeException("expecting post content of type VCellApiRpcBody");
            }
            VCellApiRpcBody rpcBody = (VCellApiRpcBody) rpcRequestBodyObject;
            RpcServiceType st = null;
            VCellQueue queue = null;
            switch(rpcBody.rpcRequest.rpcDestination) {
                case DataRequestQueue:
                    {
                        st = RpcServiceType.DATA;
                        queue = VCellQueue.DataRequestQueue;
                        break;
                    }
                case DbRequestQueue:
                    {
                        st = RpcServiceType.DB;
                        queue = VCellQueue.DbRequestQueue;
                        break;
                    }
                case SimReqQueue:
                    {
                        st = RpcServiceType.DISPATCH;
                        queue = VCellQueue.SimReqQueue;
                        break;
                    }
                default:
                    {
                        throw new RuntimeException("unsupported RPC Destination: " + rpcBody.rpcDestination);
                    }
            }
            VCellApiRpcRequest vcellapiRpcRequest = rpcBody.rpcRequest;
            Object[] arglist = vcellapiRpcRequest.args;
            String[] specialProperties = rpcBody.specialProperties;
            Object[] specialValues = rpcBody.specialValues;
            VCRpcRequest vcRpcRequest = new VCRpcRequest(vcellUser, st, method, arglist);
            VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
            RpcService rpcService = vcellApiApplication.getRpcService();
            Serializable result = rpcService.sendRpcMessage(queue, vcRpcRequest, new Boolean(rpcBody.returnedRequired), specialProperties, specialValues, new UserLoginInfo(username, null));
            byte[] serializedResultObject = VCellApiClient.toCompressedSerialized(result);
            response.setStatus(Status.SUCCESS_OK, "rpc method=" + method + " succeeded");
            response.setEntity(new ByteArrayRepresentation(serializedResultObject));
        } catch (Exception e) {
            getLogger().severe("internal error invoking " + destination + ":" + method + "(): " + e.getMessage());
            e.printStackTrace();
            response.setStatus(Status.SERVER_ERROR_INTERNAL);
            response.setEntity("internal error invoking " + destination + ":" + method + "(): " + e.getMessage(), MediaType.TEXT_PLAIN);
        }
    }
}
Also used : HttpRequest(org.restlet.engine.adapter.HttpRequest) Serializable(java.io.Serializable) User(org.vcell.util.document.User) RpcServiceType(cbit.vcell.message.VCRpcRequest.RpcServiceType) VCellApiRpcBody(org.vcell.api.client.VCellApiClient.VCellApiRpcBody) VCRpcRequest(cbit.vcell.message.VCRpcRequest) VCellApiRpcRequest(org.vcell.api.client.VCellApiRpcRequest) VCellApiApplication(org.vcell.rest.VCellApiApplication) ByteArrayRepresentation(org.restlet.representation.ByteArrayRepresentation) UserLoginInfo(org.vcell.util.document.UserLoginInfo) VCellQueue(cbit.vcell.message.VCellQueue)

Aggregations

VCRpcRequest (cbit.vcell.message.VCRpcRequest)6 User (org.vcell.util.document.User)4 VCMessagingService (cbit.vcell.message.VCMessagingService)3 SimpleMessagingDelegate (cbit.vcell.message.SimpleMessagingDelegate)2 VCMessageSession (cbit.vcell.message.VCMessageSession)2 VCMessagingInvocationTargetException (cbit.vcell.message.VCMessagingInvocationTargetException)2 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)2 VCRpcMessageHandler (cbit.vcell.message.VCRpcMessageHandler)2 UserLoginInfo (org.vcell.util.document.UserLoginInfo)2 VCDestination (cbit.vcell.message.VCDestination)1 VCMessage (cbit.vcell.message.VCMessage)1 VCMessagingDelegate (cbit.vcell.message.VCMessagingDelegate)1 VCMessagingException (cbit.vcell.message.VCMessagingException)1 VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)1 RpcServiceType (cbit.vcell.message.VCRpcRequest.RpcServiceType)1 VCellQueue (cbit.vcell.message.VCellQueue)1 VCMessagingServiceActiveMQ (cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ)1 AdminDBTopLevel (cbit.vcell.modeldb.AdminDBTopLevel)1 DatabaseServerImpl (cbit.vcell.modeldb.DatabaseServerImpl)1 LocalAdminDbServer (cbit.vcell.modeldb.LocalAdminDbServer)1