Search in sources :

Example 1 with IRemoteCall

use of org.eclipse.ecf.remoteservice.IRemoteCall in project ecf by eclipse.

the class RestPutServiceTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // Create container for service URI
    container = createRestContainer(uri);
    // Get adapter and set authentication info
    IRemoteServiceClientContainerAdapter adapter = (IRemoteServiceClientContainerAdapter) getRemoteServiceClientContainerAdapter(container);
    // Setup authentication
    adapter.setConnectContextForAuthentication(ConnectContextFactory.createUsernamePasswordConnectContext(username, password));
    // Setup response deserializer to do absolutely nothing (return null).  Note this is specific to this service.
    adapter.setResponseDeserializer(new IRemoteResponseDeserializer() {

        public Object deserializeResponse(String endpoint, IRemoteCall call, IRemoteCallable callable, Map responseHeaders, byte[] responseBody) throws NotSerializableException {
            return null;
        }
    });
    // Create callable and register
    IRemoteCallable callable = RestCallableFactory.createCallable(method, resourcePath, new IRemoteCallParameter[] { new RemoteCallParameter("body") }, new HttpPutRequestType(HttpPutRequestType.STRING_REQUEST_ENTITY, "application/xml", -1, "UTF-8"));
    // register callable
    registration = adapter.registerCallables(new IRemoteCallable[] { callable }, null);
}
Also used : IRemoteCallable(org.eclipse.ecf.remoteservice.client.IRemoteCallable) NotSerializableException(java.io.NotSerializableException) IRemoteServiceClientContainerAdapter(org.eclipse.ecf.remoteservice.client.IRemoteServiceClientContainerAdapter) RemoteCallParameter(org.eclipse.ecf.remoteservice.client.RemoteCallParameter) IRemoteCallParameter(org.eclipse.ecf.remoteservice.client.IRemoteCallParameter) IRemoteResponseDeserializer(org.eclipse.ecf.remoteservice.client.IRemoteResponseDeserializer) Map(java.util.Map) IRemoteCall(org.eclipse.ecf.remoteservice.IRemoteCall) HttpPutRequestType(org.eclipse.ecf.remoteservice.rest.client.HttpPutRequestType)

Example 2 with IRemoteCall

use of org.eclipse.ecf.remoteservice.IRemoteCall in project ecf by eclipse.

the class TwitterRemoteServiceTest method createRestResource.

private IRemoteResponseDeserializer createRestResource() {
    return new IRemoteResponseDeserializer() {

        public Object deserializeResponse(String uri, IRemoteCall call, IRemoteCallable callable, Map responseHeaders, byte[] responseBody) throws NotSerializableException {
            try {
                JSONArray timeline = new JSONArray(new String(responseBody));
                List statuses = new ArrayList();
                for (int i = 0; i < timeline.length(); i++) {
                    try {
                        JSONObject jsonObject = timeline.getJSONObject(i);
                        String source = jsonObject.getString("source");
                        String text = jsonObject.getString("text");
                        String createdString = jsonObject.getString("created_at");
                        IUserStatus status = new UserStatus(createdString, source, text);
                        statuses.add(status);
                    } catch (JSONException e) {
                        throw new NotSerializableException("Cannot process response json representation:" + e.getMessage());
                    }
                }
                return (IUserStatus[]) statuses.toArray(new IUserStatus[statuses.size()]);
            } catch (JSONException e) {
                throw new NotSerializableException("JSON array parse exception: " + e.getMessage());
            }
        }
    };
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) IRemoteResponseDeserializer(org.eclipse.ecf.remoteservice.client.IRemoteResponseDeserializer) IRemoteCallable(org.eclipse.ecf.remoteservice.client.IRemoteCallable) NotSerializableException(java.io.NotSerializableException) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) IRemoteCall(org.eclipse.ecf.remoteservice.IRemoteCall)

Example 3 with IRemoteCall

use of org.eclipse.ecf.remoteservice.IRemoteCall in project ecf by eclipse.

the class ReflectiveRemoteServiceHandler method executeMethodInvocationDialog.

protected void executeMethodInvocationDialog(final Class cls, final IRemoteService remoteService) {
    final MethodInvocationDialog mid = new MethodInvocationDialog((Shell) null, cls);
    if (mid.open() == Window.OK) {
        final int timeout = (mid.getTimeout() > 0) ? mid.getTimeout() : 30000;
        final String methodName = mid.getMethod().getName();
        final Object[] methodArgs = mid.getMethodArguments();
        final IRemoteCall remoteCall = new IRemoteCall() {

            public String getMethod() {
                return methodName;
            }

            public Object[] getParameters() {
                return methodArgs;
            }

            public long getTimeout() {
                return timeout;
            }
        };
        final int invokeType = mid.getInvocationType();
        try {
            switch(invokeType) {
                case MethodInvocationDialog.ASYNC_FIRE_AND_GO:
                    remoteService.callAsync(remoteCall);
                    break;
                case MethodInvocationDialog.ASYNC_FUTURE_RESULT:
                    invokeFuture(cls, remoteService, remoteCall);
                    break;
                case MethodInvocationDialog.ASYNC_LISTENER:
                    invokeAsyncListener(cls, remoteService, remoteCall);
                    break;
                case MethodInvocationDialog.OSGI_SERVICE_PROXY:
                    throw new UnsupportedOperationException();
                // break;
                case MethodInvocationDialog.REMOTE_SERVICE_PROXY:
                    throw new UnsupportedOperationException();
                // break;
                case MethodInvocationDialog.SYNCHRONOUS:
                    invokeSync(cls, remoteService, remoteCall);
                    break;
                default:
                    break;
            }
        } catch (final Exception e) {
            showException(e);
        }
    }
}
Also used : MethodInvocationDialog(org.eclipse.ecf.remoteservices.ui.MethodInvocationDialog) ECFException(org.eclipse.ecf.core.util.ECFException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRemoteCall(org.eclipse.ecf.remoteservice.IRemoteCall)

Aggregations

IRemoteCall (org.eclipse.ecf.remoteservice.IRemoteCall)3 NotSerializableException (java.io.NotSerializableException)2 Map (java.util.Map)2 IRemoteCallable (org.eclipse.ecf.remoteservice.client.IRemoteCallable)2 IRemoteResponseDeserializer (org.eclipse.ecf.remoteservice.client.IRemoteResponseDeserializer)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IRemoteCallParameter (org.eclipse.ecf.remoteservice.client.IRemoteCallParameter)1 IRemoteServiceClientContainerAdapter (org.eclipse.ecf.remoteservice.client.IRemoteServiceClientContainerAdapter)1 RemoteCallParameter (org.eclipse.ecf.remoteservice.client.RemoteCallParameter)1 HttpPutRequestType (org.eclipse.ecf.remoteservice.rest.client.HttpPutRequestType)1 MethodInvocationDialog (org.eclipse.ecf.remoteservices.ui.MethodInvocationDialog)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1