Hi people,

As can be seen from this commit, I have been updating the RSA to be able to
communicate with the Amdatu RSA. While there is still more work to do, this
is a start.

This commit however breaks the SHM implementation. And I am not sure if the
current HTTP implementation is the best way to do it. Basically the change
here is that the request method is now part of the data and not separate
anymore. Eg for http this was part of the URL
(http://.../service/id/name/method)
and now in the data (http://.../service/id/name with json: { "m":
"methodSignature", "a": ["arg1","arg2"] }).

While from a data point of view, this is no problem, I am not sure if the
API should reflect this change.

What do you guys think?



2014-07-25 19:04 GMT+08:00 <abroekh...@apache.org>:

> Author: abroekhuis
> Date: Fri Jul 25 11:04:19 2014
> New Revision: 1613384
>
> URL: http://svn.apache.org/r1613384
> Log:
> CELIX-129, CELIX-130: Update HTTP RSAAdmin and added initial directory for
> Configured discovery.
>
> Modified:
>     celix/trunk/remote_services/CMakeLists.txt
>
> celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h
>
> celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
>
> celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
>     celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c
>
> celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
>
> celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h
>
> celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
>
> celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
>
> Modified: celix/trunk/remote_services/CMakeLists.txt
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/CMakeLists.txt?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> --- celix/trunk/remote_services/CMakeLists.txt (original)
> +++ celix/trunk/remote_services/CMakeLists.txt Fri Jul 25 11:04:19 2014
> @@ -35,6 +35,7 @@ if (REMOTE_SERVICE_ADMIN)
>      add_subdirectory(remote_service_admin_shm)
>      add_subdirectory(discovery_slp)
>      add_subdirectory(discovery_bonjour)
> +    add_subdirectory(discovery_configured)
>      add_subdirectory(discovery_shm)
>
>      add_subdirectory(calculator_service)
>
> Modified:
> celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> ---
> celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h
> (original)
> +++
> celix/trunk/remote_services/calculator_endpoint/private/include/calculator_endpoint_impl.h
> Fri Jul 25 11:04:19 2014
> @@ -36,7 +36,7 @@ celix_status_t calculatorEndpoint_create
>
>  celix_status_t calculatorEndpoint_setService(remote_endpoint_pt endpoint,
> void *service);
>
> -celix_status_t calculatorEndpoint_handleRequest(remote_endpoint_pt
> endpoint, char *request, char *data, char **reply);
> +celix_status_t calculatorEndpoint_handleRequest(remote_endpoint_pt
> endpoint, char *data, char **reply);
>
>  celix_status_t calculatorEndpoint_add(remote_endpoint_pt endpoint, char
> *data, char **reply);
>  celix_status_t calculatorEndpoint_sub(remote_endpoint_pt endpoint, char
> *data, char **reply);
>
> Modified:
> celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> ---
> celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
> (original)
> +++
> celix/trunk/remote_services/calculator_endpoint/private/src/calculator_endpoint_impl.c
> Fri Jul 25 11:04:19 2014
> @@ -51,17 +51,21 @@ celix_status_t calculatorEndpoint_setSer
>  }
>
>  /**
> - * Request: http://host:port/services/{service}/{request}
> + * Request: http://host:port/services/{service}
>   */
> -celix_status_t calculatorEndpoint_handleRequest(remote_endpoint_pt
> endpoint, char *request, char *data, char **reply) {
> +celix_status_t calculatorEndpoint_handleRequest(remote_endpoint_pt
> endpoint, char *data, char **reply) {
>         celix_status_t status = CELIX_SUCCESS;
> +       json_error_t jsonError;
> +    json_t *root = json_loads(data, 0, &jsonError);
> +    const char *sig;
> +    json_unpack(root, "{s:s}", "m", &sig);
>
> -       printf("CALCULATOR_ENDPOINT: Handle request \"%s\" with data
> \"%s\"\n", request, data);
> -       if (strcmp(request, "add") == 0) {
> +       printf("CALCULATOR_ENDPOINT: Handle request \"%s\" with data
> \"%s\"\n", sig, data);
> +       if (strcmp(sig, "add(DD)D") == 0) {
>                 calculatorEndpoint_add(endpoint, data, reply);
> -       } else if (strcmp(request, "sub") == 0) {
> +       } else if (strcmp(sig, "sub(DD)D") == 0) {
>                 calculatorEndpoint_sub(endpoint, data, reply);
> -       } else if (strcmp(request, "sqrt") == 0) {
> +       } else if (strcmp(sig, "sqrt(D)D") == 0) {
>                 calculatorEndpoint_sqrt(endpoint, data, reply);
>         } else {
>                 status = CELIX_ILLEGAL_ARGUMENT;
> @@ -70,10 +74,6 @@ celix_status_t calculatorEndpoint_handle
>         return status;
>  }
>
> -/**
> - * data = { "a" : 1.1, "b" : 2.4 }
> - * reply = 3.5
> - */
>  celix_status_t calculatorEndpoint_add(remote_endpoint_pt endpoint, char
> *data, char **reply) {
>         celix_status_t status = CELIX_SUCCESS;
>         json_error_t jsonError;
> @@ -85,7 +85,7 @@ celix_status_t calculatorEndpoint_add(re
>         } else {
>                 double a;
>                 double b;
> -               json_unpack(root, "{s:f, s:f}", "arg0", &a, "arg1", &b);
> +               json_unpack(root, "{s:[ff]}", "a", &a, &b);
>
>                 if (endpoint->service != NULL) {
>                         double result;
> @@ -116,7 +116,7 @@ celix_status_t calculatorEndpoint_sub(re
>         } else {
>                 double a;
>                 double b;
> -               json_unpack(root, "{s:f, s:f}", "arg0", &a, "arg1", &b);
> +               json_unpack(root, "{s:[ff]}", "a", &a, &b);
>
>                 if (endpoint->service != NULL) {
>                         double result;
> @@ -146,7 +146,7 @@ celix_status_t calculatorEndpoint_sqrt(r
>                 status = CELIX_ILLEGAL_ARGUMENT;
>         } else {
>                 double a;
> -               json_unpack(root, "{s:f}", "arg0", &a);
> +               json_unpack(root, "{s:[f]}", "a", &a);
>
>                 if (endpoint->service != NULL) {
>                         double result;
>
> Modified:
> celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> ---
> celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
> (original)
> +++
> celix/trunk/remote_services/calculator_proxy/private/src/calculator_proxy_impl.c
> Fri Jul 25 11:04:19 2014
> @@ -56,18 +56,21 @@ celix_status_t calculatorProxy_create(ap
>         return status;
>  }
>
> +// { "m": "" "a":["arg1", "arg2"] }
>  celix_status_t calculatorProxy_add(calculator_pt calculator, double a,
> double b, double *result) {
>         celix_status_t status = CELIX_SUCCESS;
>
>         if (calculator->endpoint != NULL) {
>                 json_t *root;
> -               root = json_pack("{s:f, s:f}", "arg0", a, "arg1", b);
> +               root = json_pack("{s:s, s:[ff]}", "m", "add(DD)D", "a", a,
> b);
>
>                 char *data = json_dumps(root, 0);
>                 char *reply = calloc(128, sizeof(char));
>                 int replyStatus = 0;
>
> -               calculator->sendToCallback(calculator->sendToHandler,
> calculator->endpoint, "add", data, &reply, &replyStatus);
> +               printf("Send: %s\n", data);
> +
> +               calculator->sendToCallback(calculator->sendToHandler,
> calculator->endpoint, data, &reply, &replyStatus);
>
>                 if (status == CELIX_SUCCESS) {
>                         json_error_t jsonError;
> @@ -86,13 +89,13 @@ celix_status_t calculatorProxy_sub(calcu
>         celix_status_t status = CELIX_SUCCESS;
>         if (calculator->endpoint != NULL) {
>                 json_t *root;
> -               root = json_pack("{s:f, s:f}", "arg0", a, "arg1", b);
> +               root = json_pack("{s:s, s:[ff]}", "m", "sub(DD)D", "a", a,
> b);
>
>                 char *data = json_dumps(root, 0);
>                 char *reply = calloc(128, sizeof(char));
>                 int replyStatus = 0;
>
> -               calculator->sendToCallback(calculator->sendToHandler,
> calculator->endpoint, "sub", data, &reply, &replyStatus);
> +               calculator->sendToCallback(calculator->sendToHandler,
> calculator->endpoint, data, &reply, &replyStatus);
>
>                 if (status == CELIX_SUCCESS) {
>                         json_error_t jsonError;
> @@ -110,13 +113,13 @@ celix_status_t calculatorProxy_sqrt(calc
>         celix_status_t status = CELIX_SUCCESS;
>         if (calculator->endpoint != NULL) {
>                 json_t *root;
> -               root = json_pack("{s:f}", "arg0", a);
> +               root = json_pack("{s:s, s:[f]}", "m", "sqrt(D)D", "a", a);
>
>                 char *data = json_dumps(root, 0);
>                 char *reply = calloc(128, sizeof(char));
>                 int replyStatus;
>
> -               calculator->sendToCallback(calculator->sendToHandler,
> calculator->endpoint, "sqrt", data, &reply, &replyStatus);
> +               calculator->sendToCallback(calculator->sendToHandler,
> calculator->endpoint, data, &reply, &replyStatus);
>
>                 if (status == CELIX_SUCCESS) {
>                         json_error_t jsonError;
>
> Modified:
> celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> --- celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c
> (original)
> +++ celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c
> Fri Jul 25 11:04:19 2014
> @@ -479,6 +479,7 @@ static void discovery_resolveAddCallback
>                 endpoint->serviceId = serviceId == NULL? 0 :
> atol(serviceId);
>                 endpoint->service = properties_get(props, "objectClass");
>                 endpoint->properties = props;
> +               endpoint->frameworkUUID = endpointFrameworkUuid;
>
>                 entry->pool = childPool;
>                 entry->endpointDescription = endpoint;
>
> Modified:
> celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> ---
> celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
> (original)
> +++
> celix/trunk/remote_services/remote_service_admin/private/include/remote_service_admin_impl.h
> Fri Jul 25 11:04:19 2014
> @@ -45,7 +45,7 @@ struct import_reference {
>  celix_status_t remoteServiceAdmin_create(apr_pool_t *pool,
> bundle_context_pt context, remote_service_admin_pt *admin);
>  celix_status_t remoteServiceAdmin_destroy(remote_service_admin_pt admin);
>
> -celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa,
> endpoint_description_pt endpointDescription, char *methodSignature, char
> *request, char **reply, int* replyStatus);
> +celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa,
> endpoint_description_pt endpointDescription, char *methodSignature, char
> **reply, int* replyStatus);
>
>  celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt
> admin, char *serviceId, properties_pt properties, array_list_pt
> *registrations);
>  celix_status_t
> remoteServiceAdmin_removeExportedService(export_registration_pt
> registration);
>
> Modified:
> celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> ---
> celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h
> (original)
> +++
> celix/trunk/remote_services/remote_service_admin/public/include/remote_endpoint.h
> Fri Jul 25 11:04:19 2014
> @@ -34,7 +34,7 @@ typedef struct remote_endpoint *remote_e
>  struct remote_endpoint_service {
>         remote_endpoint_pt endpoint;
>         celix_status_t (*setService)(remote_endpoint_pt endpoint, void
> *service);
> -       celix_status_t (*handleRequest)(remote_endpoint_pt endpoint, char
> *request, char *data, char **reply);
> +       celix_status_t (*handleRequest)(remote_endpoint_pt endpoint, char
> *data, char **reply);
>  };
>
>  typedef struct remote_endpoint_service *remote_endpoint_service_pt;
>
> Modified:
> celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> ---
> celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
> (original)
> +++
> celix/trunk/remote_services/remote_service_admin/public/include/remote_proxy.h
> Fri Jul 25 11:04:19 2014
> @@ -32,7 +32,7 @@
>
>  #define OSGI_RSA_REMOTE_PROXY_FACTORY  "remote_proxy_factory"
>
> -typedef celix_status_t (*sendToHandle)(void *handler,
> endpoint_description_pt endpointDescription, char *methodSignature, char
> *request, char **reply, int* replyStatus);
> +typedef celix_status_t (*sendToHandle)(void *handler,
> endpoint_description_pt endpointDescription, char *request, char **reply,
> int* replyStatus);
>
>  typedef struct remote_proxy_service *remote_proxy_service_pt;
>
>
> Modified:
> celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
> URL:
> http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c?rev=1613384&r1=1613383&r2=1613384&view=diff
>
> ==============================================================================
> ---
> celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
> (original)
> +++
> celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
> Fri Jul 25 11:04:19 2014
> @@ -28,6 +28,7 @@
>
>  #include <apr_strings.h>
>  #include <apr_uuid.h>
> +#include <uuid/uuid.h>
>  #include <apr_network_io.h>
>
>  #include <curl/curl.h>
> @@ -166,9 +167,9 @@ static int remoteServiceAdmin_callback(s
>                         strncpy(service, rest, pos);
>                         service[pos] = '\0';
>
> -//                     printf("Got service %s, interfaceStart is %s and
> callStart is %s\n", service, interfaceStart, callStart);
> +                       printf("Got service %s, interfaceStart is %s and
> callStart is %s\n", service, interfaceStart, callStart);
>
> -                       char *request = callStart+1;
> +//                     char *request = callStart+1;
>
>                         const char *lengthStr = mg_get_header(conn, (const
> char *) "Content-Length");
>                         int datalength = apr_atoi64(lengthStr);
> @@ -176,6 +177,8 @@ static int remoteServiceAdmin_callback(s
>                         mg_read(conn, data, datalength);
>                         data[datalength] = '\0';
>
> +                       printf("%s\n", data);
> +
>                         hash_map_iterator_pt iter =
> hashMapIterator_create(rsa->exportedServices);
>                         while (hashMapIterator_hasNext(iter)) {
>                                 hash_map_entry_pt entry =
> hashMapIterator_nextEntry(iter);
> @@ -186,7 +189,7 @@ static int remoteServiceAdmin_callback(s
>                                         long serviceId = atol(service);
>                                         if (serviceId ==
> export->endpointDescription->serviceId) {
>                                                 char *reply = NULL;
> -
> export->endpoint->handleRequest(export->endpoint->endpoint, request, data,
> &reply);
> +
> export->endpoint->handleRequest(export->endpoint->endpoint, data, &reply);
>                                                 if (reply != NULL) {
>                                                         mg_printf(conn,
> "%s", ajax_reply_start);
>                                                         mg_printf(conn,
> "%s", reply);
> @@ -201,7 +204,7 @@ static int remoteServiceAdmin_callback(s
>         return 1;
>  }
>
> -celix_status_t remoteServiceAdmin_handleRequest(remote_service_admin_pt
> rsa, char *service, char *request, char *data, char **reply) {
> +celix_status_t remoteServiceAdmin_handleRequest(remote_service_admin_pt
> rsa, char *service, char *data, char **reply) {
>         hash_map_iterator_pt iter =
> hashMapIterator_create(rsa->exportedServices);
>         while (hashMapIterator_hasNext(iter)) {
>                 hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
> @@ -210,7 +213,7 @@ celix_status_t remoteServiceAdmin_handle
>                 for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
>                         export_registration_pt export =
> arrayList_get(exports, expIt);
>                         if (strcmp(service,
> export->endpointDescription->service) == 0) {
> -
> export->endpoint->handleRequest(export->endpoint->endpoint, request, data,
> reply);
> +
> export->endpoint->handleRequest(export->endpoint->endpoint, data, reply);
>                         }
>                 }
>         }
> @@ -403,20 +406,23 @@ celix_status_t remoteServiceAdmin_create
>         apr_pool_create(&childPool, admin->pool); //TODO pool should be
> destroyed after when endpoint is removed
>
>         *description = apr_palloc(childPool, sizeof(*description));
> -//     *description = malloc(sizeof(*description));
>         if (!*description) {
>                 status = CELIX_ENOMEM;
>         } else {
>                 char *uuid = NULL;
>                 status = bundleContext_getProperty(admin->context, (char
> *)OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
>                 if (status == CELIX_SUCCESS) {
> +//                 char uuid[37];
> +//                 uuid_t uid;
> +//            uuid_generate(uid);
> +//            uuid_unparse(uid, uuid);
> +//
> +//            printf("%s\n", uuid);
> +
>                         (*description)->properties = endpointProperties;
>                         (*description)->frameworkUUID = uuid;
>                         (*description)->serviceId =
> apr_atoi64(properties_get(serviceProperties, (char *)
> OSGI_FRAMEWORK_SERVICE_ID));
> -                       (*description)->id = apr_pstrdup(childPool,
> "TODO"); // does not work, txt record to big ?? --> apr_pstrcat(childPool,
> uuid, "-", (*description)->serviceId, NULL);
> -//                     char *id = apr_pstrcat(childPool, uuid, "-",
> properties_get(serviceProperties, (char *) OSGI_FRAMEWORK_SERVICE_ID),
> NULL);
> -//                     printf("ID %s\n", id);
> -//            (*description)->id = id;
> +                       (*description)->id = apr_pstrdup(childPool,
> properties_get(serviceProperties, (char *) OSGI_FRAMEWORK_SERVICE_ID)); //
> Should be uuid
>                         (*description)->service = interface;
>                 }
>         }
> @@ -502,7 +508,7 @@ celix_status_t remoteServiceAdmin_remove
>
>
>
> -celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa,
> endpoint_description_pt endpointDescription, char *methodSignature, char
> *request, char **reply, int* replyStatus) {
> +celix_status_t remoteServiceAdmin_send(remote_service_admin_pt rsa,
> endpoint_description_pt endpointDescription, char *request, char **reply,
> int* replyStatus) {
>
>      struct post post;
>      post.readptr = request;
> @@ -514,7 +520,7 @@ celix_status_t remoteServiceAdmin_send(r
>
>      char *serviceUrl = properties_get(endpointDescription->properties,
> ".ars.alias");
>      printf("CALCULATOR_PROXY: URL: %s\n", serviceUrl);
> -    char *url = apr_pstrcat(rsa->pool, serviceUrl, "/", methodSignature,
> NULL);
> +    char *url = apr_pstrcat(rsa->pool, serviceUrl, NULL);
>
>      celix_status_t status = CELIX_SUCCESS;
>      CURL *curl;
>
>
>


-- 
With kind regards,

Alexander Broekhuis

Reply via email to