Search in sources :

Example 1 with IRemoteCallable

use of org.eclipse.ecf.remoteservice.client.IRemoteCallable in project ecf by eclipse.

the class RestContainerTest method testRegisterRestService.

public void testRegisterRestService() throws Exception {
    IContainer container = createRestContainer(RestConstants.TEST_DE_TARGET);
    Dictionary properties = new Hashtable();
    properties.put("user", "null");
    IRemoteCallable callable = RestCallableFactory.createCallable("methodName", "resourcePath", null, new HttpGetRequestType());
    IRemoteServiceRegistration registration = registerCallable(container, callable, properties);
    assertNotNull(registration);
}
Also used : IRemoteCallable(org.eclipse.ecf.remoteservice.client.IRemoteCallable) Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) HttpGetRequestType(org.eclipse.ecf.remoteservice.rest.client.HttpGetRequestType) IContainer(org.eclipse.ecf.core.IContainer) IRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)

Example 2 with IRemoteCallable

use of org.eclipse.ecf.remoteservice.client.IRemoteCallable 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 3 with IRemoteCallable

use of org.eclipse.ecf.remoteservice.client.IRemoteCallable 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 4 with IRemoteCallable

use of org.eclipse.ecf.remoteservice.client.IRemoteCallable in project ecf by eclipse.

the class TimeServiceRestClientContainer method connect.

@Override
public void connect(ID targetID, IConnectContext connectContext1) throws ContainerConnectException {
    super.connect(targetID, connectContext1);
    // Create the IRemoteCallable to represent
    // access to the ITimeService method.
    IRemoteCallable callable = RestCallableFactory.createCallable("getCurrentTime", ITimeService.class.getName(), null, new HttpGetRequestType(), 30000);
    // Register the callable and associate it with the ITimeService class
    // name
    reg = registerCallables(new String[] { ITimeService.class.getName() }, new IRemoteCallable[][] { { callable } }, null);
}
Also used : IRemoteCallable(org.eclipse.ecf.remoteservice.client.IRemoteCallable) ITimeService(com.mycorp.examples.timeservice.ITimeService) HttpGetRequestType(org.eclipse.ecf.remoteservice.rest.client.HttpGetRequestType)

Example 5 with IRemoteCallable

use of org.eclipse.ecf.remoteservice.client.IRemoteCallable in project ecf by eclipse.

the class Activator method registerCall.

private IRemoteServiceRegistration registerCall() {
    IRemoteCallable callable = RestCallableFactory.createCallable(RSS_PATH, RSS_PATH, null, new HttpGetRequestType());
    registration = registerCallable(callable, null);
    return registration;
}
Also used : IRemoteCallable(org.eclipse.ecf.remoteservice.client.IRemoteCallable) HttpGetRequestType(org.eclipse.ecf.remoteservice.rest.client.HttpGetRequestType)

Aggregations

IRemoteCallable (org.eclipse.ecf.remoteservice.client.IRemoteCallable)9 IRemoteCallParameter (org.eclipse.ecf.remoteservice.client.IRemoteCallParameter)3 HttpGetRequestType (org.eclipse.ecf.remoteservice.rest.client.HttpGetRequestType)3 NotSerializableException (java.io.NotSerializableException)2 Dictionary (java.util.Dictionary)2 Hashtable (java.util.Hashtable)2 Map (java.util.Map)2 IRemoteCall (org.eclipse.ecf.remoteservice.IRemoteCall)2 IRemoteResponseDeserializer (org.eclipse.ecf.remoteservice.client.IRemoteResponseDeserializer)2 IRemoteServiceClientContainerAdapter (org.eclipse.ecf.remoteservice.client.IRemoteServiceClientContainerAdapter)2 RemoteCallParameter (org.eclipse.ecf.remoteservice.client.RemoteCallParameter)2 ITimeService (com.mycorp.examples.timeservice.ITimeService)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IContainer (org.eclipse.ecf.core.IContainer)1 IRemoteServiceRegistration (org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)1 HttpPostRequestType (org.eclipse.ecf.remoteservice.rest.client.HttpPostRequestType)1 HttpPutRequestType (org.eclipse.ecf.remoteservice.rest.client.HttpPutRequestType)1 IEcho (org.eclipse.ecf.tests.remoteservice.rpc.common.IEcho)1 JSONArray (org.json.JSONArray)1