replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / android / notification-service / src / main / jni / provider / JniNotificationProvider.cpp
old mode 100644 (file)
new mode 100755 (executable)
index f1a744a..2c4ee96
 
 #include "JniNotificationProvider.h"
 #include "NSProviderService.h"
+#include "NSException.h"
+#include "JniOcRepresentation.h"
 
-static JavaVM *g_jvm = NULL;
+static JavaVM *g_jvm_provider = NULL;
 
 static jobject g_obj_subscriptionListener = NULL;
 static jobject g_obj_syncListener = NULL;
@@ -35,20 +37,22 @@ jclass g_cls_MediaContents;
 jclass g_cls_Topic;
 jclass g_cls_TopicsList;
 jclass g_cls_TopicState;
+jclass g_cls_OcRepresentation;
+jmethodID g_mid_OcRepresentation_N_ctor_bool = NULL;
 
 static JNIEnv *GetJNIEnv(jint *ret)
 {
     JNIEnv *env = NULL;
 
-    *ret = g_jvm->GetEnv((void **) &env, JNI_CURRENT_VERSION);
+    *ret = g_jvm_provider->GetEnv((void **) &env, JNI_CURRENT_VERSION);
     switch (*ret)
     {
         case JNI_OK:
             return env;
         case JNI_EDETACHED:
-            if (g_jvm->AttachCurrentThread(&env, NULL) != JNI_OK)
+            if (g_jvm_provider->AttachCurrentThread(&env, NULL) != JNI_OK)
             {
-                LOGE ("Failed to get the environment");
+                NS_LOGE ("Failed to get the environment");
                 return NULL;
             }
             else
@@ -56,16 +60,17 @@ static JNIEnv *GetJNIEnv(jint *ret)
                 return env;
             }
         case JNI_EVERSION:
-            LOGE ("JNI version is not supported");
+            NS_LOGE ("JNI version is not supported");
+            return NULL;
         default:
-            LOGE ("Failed to get the environment");
+            NS_LOGE ("Failed to get the environment");
             return NULL;
     }
 }
 
-OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
+OIC::Service::NSMessage getNativeMessage(JNIEnv *env, jobject jMsg)
 {
-    LOGD("JNIProviderService: getMessage - IN");
+    NS_LOGD ("JNIProviderService: getMessage - IN");
 
     jclass cls = env->GetObjectClass( jMsg);
 
@@ -73,7 +78,7 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
     jclass cls_messageType = (jclass) (env->NewLocalRef(g_cls_Message_Type));
     if (!cls_messageType)
     {
-        LOGE ("Failed to Get ObjectClass for Message Type");
+        ThrowNSException(JNI_INVALID_VALUE, "Failed to Get ObjectClass for Message Type");
         return nullptr;
     }
     jmethodID mid = env->GetMethodID(cls_messageType, "ordinal", "()I");
@@ -81,25 +86,25 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
                                          "Lorg/iotivity/service/ns/common/Message$MessageType;");
     if (fid_type == NULL)
     {
-        LOGE("Error: jfieldID for message type  is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message type  is null");
         return nullptr;
     }
     jobject jobj = env->GetObjectField( jMsg, fid_type);
     if (jobj == NULL)
     {
-        LOGE("Error: object of field  Message Type is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: object of field  Message Type is null");
         return nullptr;
     }
     jint jtype = env->CallIntMethod(jobj, mid);
     OIC::Service::NSMessage::NSMessageType  type = (OIC::Service::NSMessage::NSMessageType) jtype;
 
-    LOGD("Message Type: %ld\n", (long )type);
+    NS_LOGD ("Message Type: %ld\n", (long )type);
 
     // Message Time
     jfieldID fid_tm = env->GetFieldID( cls, "mTime", "Ljava/lang/String;");
     if (fid_tm == NULL)
     {
-        LOGE("Error: jfieldID for message time is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message time is null");
         return nullptr;
     }
     jstring jtime = (jstring)env->GetObjectField( jMsg, fid_tm);
@@ -110,27 +115,27 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
     }
     else
     {
-        LOGD("Info: messageTitle is null");
+        NS_LOGD ("Info: messageTitle is null");
     }
-    LOGD("Message Time: %s\n", time);
+    NS_LOGD ("Message Time: %s\n", time);
 
     // Message TTL
     jfieldID fid_ttl = env->GetFieldID( cls, "mTTL", "J");
     if (fid_ttl == NULL)
     {
-        LOGE("Error: jfieldID for message ttl is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message ttl is null");
         return nullptr;
     }
-    jlong jttl = (jlong) env->GetObjectField( jMsg, fid_ttl);
-    uint64_t  ttl = jttl;
 
-    LOGD("Message ID: %lld\n", ttl);
+    jlong jttl = (jlong) env->GetLongField( jMsg, fid_ttl);
+    uint64_t  ttl = jttl;
+    NS_LOGD ("TTL: %lld\n", ttl);
 
     // Message Title
     jfieldID fid_title = env->GetFieldID( cls, "mTitle", "Ljava/lang/String;");
     if (fid_title == NULL)
     {
-        LOGE("Error: jfieldID for message title is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message title is null");
         return nullptr;
     }
     jstring jmsgTitle = (jstring)env->GetObjectField( jMsg, fid_title);
@@ -141,15 +146,15 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
     }
     else
     {
-        LOGD("Info: messageTitle is null");
+        NS_LOGD ("Info: messageTitle is null");
     }
-    LOGD("Message Title: %s\n", messageTitle);
+    NS_LOGD ("Message Title: %s\n", messageTitle);
 
     // Message Content Text
     jfieldID fid_body = env->GetFieldID( cls, "mContentText", "Ljava/lang/String;");
     if (fid_body == NULL)
     {
-        LOGE("Error: jfieldID for message context Text is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message context Text is null");
         return nullptr;
     }
     jstring jmsgBody = (jstring)env->GetObjectField( jMsg, fid_body);
@@ -160,15 +165,15 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
     }
     else
     {
-        LOGD("Info: messageBody is null");
+        NS_LOGD ("Info: messageBody is null");
     }
-    LOGD("Message Body: %s\n", messageBody);
+    NS_LOGD ("Message Body: %s\n", messageBody);
 
     // Message Source
     jfieldID fid_source = env->GetFieldID( cls, "mSourceName", "Ljava/lang/String;");
     if (fid_source == NULL)
     {
-        LOGE("Error: jfieldID for message source is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message source is null");
         return nullptr;
     }
     jstring jmsgSource = (jstring)env->GetObjectField( jMsg, fid_source);
@@ -179,15 +184,15 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
     }
     else
     {
-        LOGD("Info: messageSource is null");
+        NS_LOGD ("Info: messageSource is null");
     }
-    LOGD("Message Source: %s\n", messageSource);
+    NS_LOGD ("Message Source: %s\n", messageSource);
 
     // Message Topic
     jfieldID fid_topic = env->GetFieldID( cls, "mTopic", "Ljava/lang/String;");
     if (fid_topic == NULL)
     {
-        LOGE("Error: jfieldID for topic  is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for topic  is null");
         return nullptr;
     }
     jstring jtopic = (jstring)env->GetObjectField( jMsg, fid_topic);
@@ -198,63 +203,146 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
     }
     else
     {
-        LOGD("Info: topic is null");
+        NS_LOGD ("Info: topic is null");
     }
-    LOGD("Topic : %s\n", topic);
+    NS_LOGD ("Topic : %s\n", topic);
 
     // Message MediaContents
     jfieldID fid_media = env->GetFieldID( cls, "mMediaContents",
                                           "Lorg/iotivity/service/ns/common/MediaContents;");
     if (fid_media == NULL)
     {
-        LOGE("Error: jfieldID for MediaContents is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for MediaContents is null");
         return nullptr;
     }
     jobject jmedia = env->GetObjectField( jMsg, fid_media);
+    OIC::Service::NSMediaContents *media = nullptr;
     if (jmedia == NULL)
     {
-        LOGE("Error: jmedia object of MediaContents inside Message is null");
+        NS_LOGD ("Info: jmedia object of MediaContents inside Message is null");
+    }
+    else
+    {
+        jclass cls_MediaContents = (jclass) (env->NewLocalRef(g_cls_MediaContents));
+        if (!cls_MediaContents)
+        {
+            ThrowNSException(JNI_INVALID_VALUE, "Failed to Get ObjectClass for class MediaContents");
+            return nullptr;
+        }
+        jfieldID fid_icon = env->GetFieldID( cls_MediaContents, "mIconImage", "Ljava/lang/String;");
+        if (fid_icon == NULL)
+        {
+            ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for iconImage is null");
+            return nullptr;
+        }
+        jstring jiconImage = (jstring)env->GetObjectField( jmedia, fid_icon);
+        const char *iconImage = "";
+        if (jiconImage)
+        {
+            iconImage = env->GetStringUTFChars( jiconImage, NULL);
+            media = new OIC::Service::NSMediaContents(std::string(iconImage));
+            env->ReleaseStringUTFChars(jiconImage, iconImage);
+        }
+        else
+        {
+            NS_LOGD ("Info: iconImage is null");
+        }
+        env->DeleteLocalRef(cls_MediaContents);
+        NS_LOGD ("iconImage: %s\n", iconImage);
+    }
+
+    // Message ExtraInfo
+    jfieldID fid_extraInfo = env->GetFieldID( cls, "mExtraInfo",
+                             "Lorg/iotivity/base/OcRepresentation;");
+    if (fid_extraInfo == NULL)
+    {
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for mExtraInfo is null");
         return nullptr;
     }
-    jclass cls_MediaContents = (jclass) (env->NewLocalRef(g_cls_MediaContents));
-    if (!cls_MediaContents)
+    jobject jExtraInfo = env->GetObjectField( jMsg, fid_extraInfo);
+    OC::OCRepresentation *representation = nullptr;
+    if (jExtraInfo == NULL)
+    {
+        NS_LOGE ("Error: jExtraInfo object of Message is null");
+    }
+    else
+    {
+        representation = GetHandle<OC::OCRepresentation>(env, jExtraInfo);
+        if (env->ExceptionCheck())
+        {
+            NS_LOGE ("Failed to get native handle from OcRepresentation");
+        }
+        if (!representation)
+        {
+            NS_LOGE ("Failed to get native object OcRepresentation");
+        }
+    }
+
+    // Message Id
+    jfieldID fid_mid = env->GetFieldID( cls, "mMessageId", "J");
+    if (fid_mid == NULL)
     {
-        LOGE ("Failed to Get ObjectClass for class MediaContents");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message mMessageId is null");
         return nullptr;
     }
-    jfieldID fid_icon = env->GetFieldID( cls_MediaContents, "mIconImage", "Ljava/lang/String;");
-    if (fid_icon == NULL)
+
+    jlong jId = (jlong) env->GetLongField( jMsg, fid_mid);
+    uint64_t  jmId = jId;
+    NS_LOGD ("Message Id: %lld\n", jmId);
+
+    // Provider Id
+    jfieldID fid_pid = env->GetFieldID( cls, "mProviderId", "Ljava/lang/String;");
+    if (fid_pid == NULL)
     {
-        LOGE("Error: jfieldID for iconImage is null");
+        ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message mProviderId is null");
         return nullptr;
     }
-    jstring jiconImage = (jstring)env->GetObjectField( jmedia, fid_icon);
-    const char *iconImage = "";
-    if (jiconImage)
+    jstring jProId = (jstring)env->GetObjectField( jMsg, fid_pid);
+    const char *jpId = "";
+    if (jProId)
     {
-        iconImage = env->GetStringUTFChars( jiconImage, NULL);
+        jpId = env->GetStringUTFChars( jProId, NULL);
     }
     else
     {
-        LOGD("Info: iconImage is null");
+        NS_LOGD ("Info: messageSource is null");
     }
+    NS_LOGD ("Provider Id : %s\n", jpId);
+
 
-    LOGD("iconImage: %s\n", iconImage);
+    NSMessage *mesg = new NSMessage;
+    mesg->messageId = jmId;
+    mesg->providerId[0] = '\0';
+    strncat(mesg->providerId, jpId, NS_UTILS_UUID_STRING_SIZE - 1);
 
-    OIC::Service::NSMediaContents *media = new OIC::Service::NSMediaContents(std::string(iconImage));
-    OIC::Service::NSMessage *nsMsg = OIC::Service::NSProviderService::getInstance()->createMessage();
+    mesg->dateTime = nullptr;
+    mesg->title = nullptr;
+    mesg->contentText = nullptr;
+    mesg->sourceName = nullptr;
+    mesg->mediaContents = nullptr;
+    mesg->topic = nullptr;
+    mesg->extraInfo = nullptr;
 
-    nsMsg->setType(type);
-    nsMsg->setTime(std::string(time));
-    nsMsg->setTTL(ttl);
-    nsMsg->setTitle(std::string(messageTitle));
-    nsMsg->setContentText(std::string(messageBody));
-    nsMsg->setSourceName(std::string(messageSource));
-    nsMsg->setMediaContents(media);
-    nsMsg->setTopic(std::string(topic));
+    OIC::Service::NSMessage nsMsg(mesg);
+    NS_LOGD ("Created NSMessage");
+
+    nsMsg.setType(type);
+    nsMsg.setTime(std::string(time));
+    nsMsg.setTTL(ttl);
+    nsMsg.setTitle(std::string(messageTitle));
+    nsMsg.setContentText(std::string(messageBody));
+    nsMsg.setSourceName(std::string(messageSource));
+    if (media != nullptr)
+    {
+        nsMsg.setMediaContents(media);
+    }
+    nsMsg.setTopic(std::string(topic));
+    if (representation != nullptr)
+    {
+        nsMsg.setExtraInfo(*representation);
+    }
 
     env->DeleteLocalRef(cls_messageType);
-    env->DeleteLocalRef(cls_MediaContents);
 
     if (jtime)
     {
@@ -276,77 +364,79 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
     {
         env->ReleaseStringUTFChars(jtopic, topic);
     }
-    if (jiconImage)
-    {
-        env->ReleaseStringUTFChars(jiconImage, iconImage);
-    }
-
-    LOGD("JNIProviderService: getMessage - OUT");
+    delete mesg;
+    NS_LOGD ("JNIProviderService: getMessage - OUT");
     return nsMsg;
 
 }
 
 jobject getJavaMessageType(JNIEnv *env, OIC::Service::NSMessage::NSMessageType type)
 {
-    LOGD ("JNIProviderService: getJavaMessageType - IN");
+    NS_LOGD ("JNIProviderService: getJavaMessageType - IN");
+    jobject messageType = NULL;
     switch (type)
     {
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_ALERT:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
                                           "ALERT", "Lorg/iotivity/service/ns/common/Message$MessageType;");
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                break;
             }
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_NOTICE:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
                                           "NOTICE", "Lorg/iotivity/service/ns/common/Message$MessageType;");
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                break;
             }
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_EVENT:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
                                           "EVENT", "Lorg/iotivity/service/ns/common/Message$MessageType;");
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                break;
             }
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_INFO:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
                                           "INFO", "Lorg/iotivity/service/ns/common/Message$MessageType;");
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                break;
             }
         default:
-            return NULL;
+            {
+                messageType = NULL;
+                break;
+            }
     }
-    LOGD ("JNIProviderService: getJavaMessageType - OUT");
-    return NULL;
+    NS_LOGD ("JNIProviderService: getJavaMessageType - OUT");
+    return messageType;
 }
 
-jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
+jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage message)
 {
-    LOGD ("JNIProviderService: getJavaMessage - IN");
+    NS_LOGD ("JNIProviderService: getJavaMessage - IN");
 
-    LOGD ("id : %llu\n", message->getMessageId());
-    LOGD ("title : %s\n", message->getTitle().c_str());
-    LOGD ("content : %s\n", message->getContentText().c_str());
-    LOGD ("source : %s\n", message->getSourceName().c_str());
+    NS_LOGD ("id : %llu\n", message.getMessageId());
+    NS_LOGD ("title : %s\n", message.getTitle().c_str());
+    NS_LOGD ("content : %s\n", message.getContentText().c_str());
+    NS_LOGD ("source : %s\n", message.getSourceName().c_str());
 
-    jlong jMessageId = (jlong) message->getMessageId();
-    jstring jProviderId = env->NewStringUTF(message->getProviderId().c_str());
-    jstring jTitle = env->NewStringUTF(message->getTitle().c_str());
-    jstring jContentText = env->NewStringUTF(message->getContentText().c_str());
-    jstring jSourceName = env->NewStringUTF(message->getSourceName().c_str());
-    jstring jTopic = env->NewStringUTF(message->getTopic().c_str());
+    jlong jMessageId = (jlong) message.getMessageId();
+    jstring jProviderId = env->NewStringUTF(message.getProviderId().c_str());
+    jstring jTitle = env->NewStringUTF(message.getTitle().c_str());
+    jstring jContentText = env->NewStringUTF(message.getContentText().c_str());
+    jstring jSourceName = env->NewStringUTF(message.getSourceName().c_str());
+    jstring jTopic = env->NewStringUTF(message.getTopic().c_str());
 
-    jstring jTime = env->NewStringUTF(message->getTime().c_str());
-    jlong jTTL = (jlong) message->getTTL();
-
-    jlong pMessage = (long) message;
+    jstring jTime = env->NewStringUTF(message.getTime().c_str());
+    jlong jTTL = (jlong) message.getTTL();
 
     jclass cls_message = (jclass) (env->NewLocalRef(g_cls_Message));
     if (!cls_message)
     {
-        LOGE ("Failed to Get ObjectClass for Message");
+        NS_LOGE ("Failed to Get ObjectClass for Message");
         return NULL ;
     }
     jmethodID mid_message = env->GetMethodID(
@@ -354,28 +444,21 @@ jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
                                 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
     if (!mid_message)
     {
-        LOGE ("Failed to Get MethodID for Message<init>");
+        NS_LOGE ("Failed to Get MethodID for Message<init>");
         return NULL;
     }
     jobject obj_message = env->NewObject(cls_message, mid_message,
                                          jTitle, jContentText, jSourceName);
     if (!obj_message)
     {
-        LOGE ("Failed to Get Java Object for Message");
+        NS_LOGE ("Failed to Get Java Object for Message");
         return NULL;
     }
-    jfieldID fid_nativeHandle = env->GetFieldID(cls_message, "mNativeHandle", "J");
-    if (!fid_nativeHandle)
-    {
-        LOGE("Failed to get nativeHandle for Message");
-        return NULL;
-    }
-    env->SetLongField(obj_message, fid_nativeHandle, pMessage);
 
     jfieldID fid_messageId = env->GetFieldID(cls_message, "mMessageId", "J");
     if (!fid_messageId)
     {
-        LOGE("Failed to get field MessageID for Message");
+        NS_LOGE ("Failed to get field MessageID for Message");
         return NULL;
     }
     env->SetLongField(obj_message, fid_messageId, jMessageId);
@@ -383,7 +466,7 @@ jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
     jfieldID fid_providerId = env->GetFieldID(cls_message, "mProviderId", "Ljava/lang/String;");
     if (!fid_providerId)
     {
-        LOGE("Failed to get field ProviderID for Message");
+        NS_LOGE ("Failed to get field ProviderID for Message");
         return NULL;
     }
     env->SetObjectField(obj_message, fid_providerId, jProviderId);
@@ -391,7 +474,7 @@ jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
     jfieldID fid_time = env->GetFieldID(cls_message, "mTime", "Ljava/lang/String;");
     if (!fid_time)
     {
-        LOGE("Failed to get field Time for Message");
+        NS_LOGE ("Failed to get field Time for Message");
         return NULL;
     }
     env->SetObjectField(obj_message, fid_time, jTime);
@@ -399,7 +482,7 @@ jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
     jfieldID fid_ttl = env->GetFieldID(cls_message, "mTTL", "J");
     if (!fid_ttl)
     {
-        LOGE("Failed to get field TTL for Message");
+        NS_LOGE ("Failed to get field TTL for Message");
         return NULL;
     }
     env->SetLongField(obj_message, fid_ttl, jTTL);
@@ -407,26 +490,26 @@ jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
     jfieldID fid_topic = env->GetFieldID(cls_message, "mTopic", "Ljava/lang/String;");
     if (!fid_topic)
     {
-        LOGE("Failed to get mTopic for Message");
+        NS_LOGE ("Failed to get mTopic for Message");
         return NULL;
     }
     env->SetObjectField(obj_message, fid_topic, jTopic);
 
-    OIC::Service::NSMediaContents *mediaCont = message->getMediaContents();
+    OIC::Service::NSMediaContents *mediaCont = message.getMediaContents();
     if (mediaCont != nullptr)
     {
         jstring jIconImage = env->NewStringUTF(mediaCont->getIconImage().c_str());
         jclass cls_mediaContents = (jclass) (env->NewLocalRef(g_cls_MediaContents));
         if (!cls_mediaContents)
         {
-            LOGE ("Failed to Get ObjectClass for MediaContents");
+            NS_LOGE ("Failed to Get ObjectClass for MediaContents");
             return NULL;
         }
         jmethodID mid_mediaContents = env->GetMethodID(
                                           cls_mediaContents, "<init>", "(Ljava/lang/String;)V");
         if (!mid_mediaContents)
         {
-            LOGE ("Failed to Get MethodID for MediaContents<init>");
+            NS_LOGE ("Failed to Get MethodID for MediaContents<init>");
             return NULL;
         }
         jobject obj_mediaContents = env->NewObject(cls_mediaContents, mid_mediaContents,
@@ -436,121 +519,148 @@ jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
                                      "Lorg/iotivity/service/ns/common/MediaContents;");
         if (!fid_mediaContents)
         {
-            LOGE("Failed to get field mediaContents for Message");
+            NS_LOGE ("Failed to get field mediaContents for Message");
             return NULL;
         }
         env->SetObjectField(obj_message, fid_mediaContents, obj_mediaContents);
 
     }
 
-    jobject jType = getJavaMessageType(env, message->getType());
+    jobject jType = getJavaMessageType(env, message.getType());
     if (jType)
     {
         jfieldID fid_type = env->GetFieldID(cls_message, "mType",
                                             "Lorg/iotivity/service/ns/common/Message$MessageType;");
         if (!fid_type)
         {
-            LOGE("Failed to get field Type for Message");
+            NS_LOGE ("Failed to get field Type for Message");
             return NULL;
         }
         env->SetObjectField(obj_message, fid_type, jType);
     }
 
+    NS_LOGD ("Reading OCRepresentation Object from Native");
+    OC::OCRepresentation *ocRepresentation = new OC::OCRepresentation(message.getExtraInfo());
+    jlong handle = reinterpret_cast<jlong>(ocRepresentation);
+    jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, g_mid_OcRepresentation_N_ctor_bool,
+                              handle, true);
+    if (!jRepresentation)
+    {
+        NS_LOGE ("Failed to create OcRepresentation");
+        delete ocRepresentation;
+    }
+    else
+    {
+        NS_LOGD ("Created OCRepresentation Object from Native");
+    }
+    jfieldID fid_extraInfo = env->GetFieldID(cls_message, "mExtraInfo",
+                             "Lorg/iotivity/base/OcRepresentation;");
+    if (!fid_extraInfo)
+    {
+        NS_LOGE ("Failed to get mExtraInfo for Message");
+        delete ocRepresentation;
+        return NULL;
+    }
+    NS_LOGD ("setting extraInfo field");
+    env->SetObjectField(obj_message, fid_extraInfo, jRepresentation);
+
     env->DeleteLocalRef(cls_message);
-    LOGD ("JNIProviderService: getJavaMessage - OUT");
+    NS_LOGD ("JNIProviderService: getJavaMessage - OUT");
     return obj_message;
 }
 
 jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsState)
 {
-    LOGD("JNIProviderService: getJavaTopicState - IN");
+    NS_LOGD ("JNIProviderService: getJavaTopicState - IN");
 
     // TopicState
     jclass cls_topicState = (jclass) (env->NewLocalRef(g_cls_TopicState));
     if (!cls_topicState)
     {
-        LOGE ("Failed to Get ObjectClass for TopicState Type");
+        NS_LOGE ("Failed to Get ObjectClass for TopicState Type");
         return NULL;
     }
+    jobject topicState = NULL;
 
-    jobject obj_topicState;
     switch (nsState)
     {
         case OIC::Service::NSTopic::NSTopicState::UNSUBSCRIBED:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
                                           "UNSUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
-                obj_topicState = env->GetStaticObjectField(cls_topicState, fieldID);
+                topicState = env->GetStaticObjectField(cls_topicState, fieldID);
+                break;
             }
         case OIC::Service::NSTopic::NSTopicState::SUBSCRIBED:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
                                           "SUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
-                obj_topicState = env->GetStaticObjectField(cls_topicState, fieldID);
+                topicState = env->GetStaticObjectField(cls_topicState, fieldID);
+                break;
+            }
+        default:
+            {
+                topicState = NULL;
+                break;
             }
-
-    }
-    if (obj_topicState == NULL)
-    {
-        LOGE("Error: object of field  TopicState  is null");
     }
-    env->DeleteLocalRef(cls_topicState);
-    LOGD("JNIProviderService: getJavaTopicState - OUT");
-    return obj_topicState;
+
+    NS_LOGD ("JNIProviderService: getJavaTopicState - OUT");
+    return topicState;
 }
 
-jobject getJavaTopicsList(JNIEnv *env, OIC::Service::NSTopicsList *topicList)
+jobject getJavaTopicsList(JNIEnv *env, std::shared_ptr<OIC::Service::NSTopicsList> topicList)
 {
-    LOGD("JNIProviderService: getJavaTopicsList - IN");
+    NS_LOGD ("JNIProviderService: getJavaTopicsList - IN");
     jclass cls_topicList = (jclass) (env->NewLocalRef(g_cls_TopicsList));
     if (!cls_topicList)
     {
-        LOGE ("Failed to Get ObjectClass for TopicsList");
+        NS_LOGE ("Failed to Get ObjectClass for TopicsList");
         return NULL;
     }
     jmethodID mid_topicList = env->GetMethodID(cls_topicList, "<init>", "()V");
     if (!mid_topicList)
     {
-        LOGE ("Failed to Get MethodID for TopicsList<init>");
+        NS_LOGE ("Failed to Get MethodID for TopicsList<init>");
         return NULL;
     }
     jobject obj_topicList = env->NewObject(cls_topicList, mid_topicList);
     if (!obj_topicList)
     {
-        LOGE ("Failed to Get object for TopicsList");
+        NS_LOGE ("Failed to Get object for TopicsList");
         return NULL;
     }
     jmethodID mid_addTopic = env->GetMethodID(cls_topicList, "addTopic",
                              "(Ljava/lang/String;Lorg/iotivity/service/ns/common/Topic$TopicState;)V");
     if (!mid_addTopic)
     {
-        LOGE ("Failed to Get MethodID for addTopic");
+        NS_LOGE ("Failed to Get MethodID for addTopic");
         return NULL;
     }
     for (auto it : topicList->getTopicsList())
     {
-        jobject jState = getJavaTopicState(env, it->getState());
-        std::string topicName = it->getTopicName();
+        jobject jState = getJavaTopicState(env, it.getState());
+        std::string topicName = it.getTopicName();
         jstring jTopicName = env->NewStringUTF(topicName.c_str());
         env->CallVoidMethod(obj_topicList, mid_addTopic, jTopicName, jState);
     }
     env->DeleteLocalRef(cls_topicList);
-    LOGD("JNIProviderService: getJavaTopicsList - OUT");
+    NS_LOGD ("JNIProviderService: getJavaTopicsList - OUT");
     return obj_topicList;
 }
 
 jobject getJavaSyncType(JNIEnv *env, OIC::Service::NSSyncInfo::NSSyncType nsType)
 {
-    LOGD ("JNIProviderService: getJavaSyncType - IN");
+    NS_LOGD ("JNIProviderService: getJavaSyncType - IN");
 
     // SyncType
     jclass cls_SyncType = (jclass) (env->NewLocalRef(g_cls_SyncType));
     if (!cls_SyncType)
     {
-        LOGE ("Failed to Get ObjectClass for SyncType");
+        NS_LOGE ("Failed to Get ObjectClass for SyncType");
         return NULL;
     }
-    jobject syncType;
+    jobject syncType = NULL;
     switch (nsType)
     {
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD:
@@ -558,58 +668,68 @@ jobject getJavaSyncType(JNIEnv *env, OIC::Service::NSSyncInfo::NSSyncType nsType
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
                                           "UNREAD", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
                 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
+                break;
             }
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ :
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
                                           "READ", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
                 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
+                break;
             }
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED :
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
                                           "DELETED", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
                 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
+                break;
+            }
+        default:
+            {
+                syncType = NULL;
+                break;
             }
-
-    }
-
-    if (syncType == NULL)
-    {
-        LOGE("Error: object of field  Synctype  is null");
     }
 
-    env->DeleteLocalRef(cls_SyncType);
-    LOGD ("JNIProviderService: getJavaSyncType - OUT");
+    NS_LOGD ("JNIProviderService: getJavaSyncType - OUT");
     return syncType;
 }
 
 
-void onSubscribeListenerCb(OIC::Service::NSConsumer *consumer)
+void onSubscribeListenerCb(std::shared_ptr<OIC::Service::NSConsumer> consumer)
 {
-    LOGD("JNIProviderService_onSubscribeListenerCb - IN");
+    NS_LOGD ("JNIProviderService_onSubscribeListenerCb - IN");
 
-    jint envRet;
+    jint envRet = 0;;
     JNIEnv *env = GetJNIEnv(&envRet);
-    if (NULL == env) return ;
+    if (NULL == env)
+    {
+        return ;
+    }
 
     jobject jSubscriptionListener = (jobject) env->NewLocalRef(g_obj_subscriptionListener);
     if (!jSubscriptionListener)
     {
-        LOGE ("Failed to Get jSubscriptionListener");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get jSubscriptionListener");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return ;
     }
 
-    LOGD("consumer ID : %s\n", consumer->getConsumerId().c_str());
+    NS_LOGD ("consumer ID : %s\n", consumer->getConsumerId().c_str());
 
     jstring jConsumerId = env->NewStringUTF( consumer->getConsumerId().c_str());
 
     jclass cls_consumer = (jclass) (env->NewLocalRef(g_cls_Consumer));
     if (!cls_consumer)
     {
-        LOGE ("Failed to Get ObjectClass for Consumer");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get ObjectClass for Consumer");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return ;
     }
 
@@ -619,8 +739,11 @@ void onSubscribeListenerCb(OIC::Service::NSConsumer *consumer)
                                  "(Ljava/lang/String;)V");
     if (!mid_consumer)
     {
-        LOGE ("Failed to Get MethodID for Consumer<init>");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get MethodID for Consumer<init>");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return ;
     }
     jobject obj_consumer = env->NewObject( cls_consumer, mid_consumer, jConsumerId);
@@ -628,8 +751,11 @@ void onSubscribeListenerCb(OIC::Service::NSConsumer *consumer)
     jclass cls = env->GetObjectClass( jSubscriptionListener);
     if (!cls)
     {
-        LOGE("Failed to Get ObjectClass of jSubscriptionListener");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get ObjectClass of jSubscriptionListener");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return;
     }
     jmethodID mid = env->GetMethodID(
@@ -638,52 +764,70 @@ void onSubscribeListenerCb(OIC::Service::NSConsumer *consumer)
                         "(Lorg/iotivity/service/ns/provider/Consumer;)V");
     if (!mid)
     {
-        LOGE("Failed to Get MethodID of onConsumerSubscribed");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get MethodID of onConsumerSubscribed");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return;
     }
 
     env->CallVoidMethod( jSubscriptionListener, mid, obj_consumer);
     env->DeleteLocalRef(jSubscriptionListener);
     env->DeleteLocalRef(cls_consumer);
-    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
-    LOGD("JNIProviderService_onSubscribeListenerCb - OUT");
+    if (JNI_EDETACHED == envRet)
+    {
+        g_jvm_provider->DetachCurrentThread();
+    }
+    NS_LOGD ("JNIProviderService_onSubscribeListenerCb - OUT");
     return;
 }
 
-void onSyncInfoListenerCb(OIC::Service::NSSyncInfo *sync)
+void onSyncInfoListenerCb(OIC::Service::NSSyncInfo sync)
 {
-    LOGD("JNIProviderService_onSyncInfoListenerCb - IN");
+    NS_LOGD ("JNIProviderService_onSyncInfoListenerCb - IN");
 
-    jint envRet;
+    jint envRet = 0;;
     JNIEnv *env = GetJNIEnv(&envRet);
-    if (NULL == env) return ;
+    if (NULL == env)
+    {
+        return ;
+    }
 
     jobject jSyncListener = (jobject) env->NewLocalRef(g_obj_syncListener);
     if (!jSyncListener)
     {
-        LOGE ("Failed to Get jSyncListener");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get jSyncListener");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return ;
     }
 
-    LOGD("Sync ID : %ld\n", (long) sync->getMessageId());
-    LOGD("Sync STATE : %d\n", (int) sync->getState());
+    NS_LOGD ("Sync ID : %ld\n", (long) sync.getMessageId());
+    NS_LOGD ("Sync STATE : %d\n", (int) sync.getState());
 
-    jlong jMessageId = (long)  sync->getMessageId();
-    jstring jProviderId = env->NewStringUTF(sync->getProviderId().c_str());
-    jobject syncType = getJavaSyncType(env, sync->getState());
+    jlong jMessageId = (long)  sync.getMessageId();
+    jstring jProviderId = env->NewStringUTF(sync.getProviderId().c_str());
+    jobject syncType = getJavaSyncType(env, sync.getState());
     if (!syncType)
     {
-        LOGE ("Failed to Get syncType for SyncInfo");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get syncType for SyncInfo");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return ;
     }
     jclass cls_SyncInfo = (jclass) (env->NewLocalRef(g_cls_SyncInfo));
     if (!cls_SyncInfo)
     {
-        LOGE ("Failed to Get ObjectClass for SyncInfo");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get ObjectClass for SyncInfo");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return ;
     }
     jmethodID mid_syncInfo = env->GetMethodID(
@@ -692,8 +836,11 @@ void onSyncInfoListenerCb(OIC::Service::NSSyncInfo *sync)
                                  "(JLjava/lang/String;Lorg/iotivity/service/ns/common/SyncInfo$SyncType;)V");
     if (!mid_syncInfo)
     {
-        LOGE ("Failed to Get MethodID for SyncInfo");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get MethodID for SyncInfo");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return ;
     }
 
@@ -701,17 +848,23 @@ void onSyncInfoListenerCb(OIC::Service::NSSyncInfo *sync)
                                            jMessageId, jProviderId, syncType);
     if (!obj_syncInfo)
     {
-        LOGE ("Failed to Get Object for SyncInfo");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
+        NS_LOGE ("Failed to Get Object for SyncInfo");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
         return ;
     }
 
     jclass cls = env->GetObjectClass( jSyncListener);
     if (!cls)
     {
-        LOGE("Failed to Get ObjectClass");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
-        return;
+        NS_LOGE ("Failed to Get ObjectClass");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
+        return ;
     }
     jmethodID mid = env->GetMethodID(
                         cls,
@@ -719,30 +872,35 @@ void onSyncInfoListenerCb(OIC::Service::NSSyncInfo *sync)
                         "(Lorg/iotivity/service/ns/common/SyncInfo;)V");
     if (!mid)
     {
-        LOGE("Failed to Get MethodID");
-        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
-        return;
+        NS_LOGE ("Failed to Get MethodID");
+        if (JNI_EDETACHED == envRet)
+        {
+            g_jvm_provider->DetachCurrentThread();
+        }
+        return ;
     }
     env->CallVoidMethod( jSyncListener, mid, obj_syncInfo);
 
     env->DeleteLocalRef(jSyncListener);
     env->DeleteLocalRef(cls_SyncInfo);
-    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
-
-    LOGD("JNIProviderService: OnSyncInfoListenerCb - OUT");
+    if (JNI_EDETACHED == envRet)
+    {
+        g_jvm_provider->DetachCurrentThread();
+    }
+    NS_LOGD ("JNIProviderService: OnSyncInfoListenerCb - OUT");
     return;
 
 }
 
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart
-(JNIEnv *env, jobject jObj, jobject jSubscriptionListener, jobject jSyncListener, jboolean jPolicy, jstring jUserInfo)
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart
+(JNIEnv *env, jobject jObj, jobject jSubscriptionListener, jobject jSyncListener,
+ jboolean jPolicy, jstring jUserInfo, jboolean jResourceSecurity)
 {
-    LOGD("JNIProviderService: nativeStart - IN");
+    NS_LOGD ("JNIProviderService: nativeStart - IN");
     if (!jSubscriptionListener || !jSyncListener)
     {
-        LOGE("Fail to set listeners");
-        ThrowNSException(NS_ERROR, "Listener cannot be null");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "Listener cannot be null");
+        return;
     }
 
     if (g_obj_subscriptionListener != NULL)
@@ -769,28 +927,29 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat
         std::string userInfo(info);
         cfg.userInfo = userInfo;
     }
+    cfg.resourceSecurity = (bool) jResourceSecurity;
 
     OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->start(cfg);
     if (result != OIC::Service::NSResult::OK)
     {
-        LOGE("Fail to start NSProviderService");
-
+        ThrowNSException((int) result, "Fail to start NSProviderService");
+        return;
     }
 
-    LOGD("JNIProviderService: nativeStart - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeStart - OUT");
+    return;
 }
 
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop
 (JNIEnv *env, jobject jObj)
 {
-    LOGD("JNIProviderService: nativeStop - IN");
+    NS_LOGD ("JNIProviderService: nativeStop - IN");
 
     OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->stop();
     if (result !=  OIC::Service::NSResult::OK)
     {
-        LOGD("Fail to stop NSProvider service");
-        return (jint) result;
+        ThrowNSException((int) result, "Fail to stop NSProviderService");
+        return;
     }
 
     env->DeleteGlobalRef( g_obj_subscriptionListener);
@@ -798,75 +957,72 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat
     g_obj_subscriptionListener = NULL;
     g_obj_syncListener = NULL;
 
-    LOGD("JNIProviderService: nativeStop - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeStop - OUT");
+    return;
 }
 
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage
 (JNIEnv *env, jobject jObj, jobject jMsg)
 {
-    LOGD("JNIProviderService: nativeSendMessage - IN");
+    NS_LOGD ("JNIProviderService: nativeSendMessage - IN");
     if (!jMsg)
     {
-        LOGD("Fail to send notification - Message is null");
-        ThrowNSException(NS_ERROR, "Message cannot be null");
-        return (jint) OIC::Service::NSResult::ERROR;
-    }
-    OIC::Service::NSMessage *nsMsg = getNativeMessage(env, jMsg);
-    if (nsMsg == nullptr)
-    {
-        ThrowNSException(NS_ERROR, "Message didn't have a field ID ");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "Message cannot be null");
+        return;
     }
+    OIC::Service::NSMessage nsMsg = getNativeMessage(env, jMsg);
 
     OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->sendMessage(nsMsg);
     if (result !=  OIC::Service::NSResult::OK)
     {
-        LOGD("Fail to send NSProvider Message");
+        ThrowNSException((int) result, "Fail to send NSProvider Message");
+        return;
     }
-    LOGD("JNIProviderService: nativeSendMessage - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeSendMessage - OUT");
+    return;
 }
 
 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendSyncInfo
 (JNIEnv *env, jobject jObj, jlong messageId , jint syncState)
 {
-    LOGD("JNIProviderService: nativeSendSyncInfo - IN");
-    OIC::Service::NSProviderService::getInstance()->sendSyncInfo( messageId,
-            (OIC::Service::NSSyncInfo::NSSyncType) syncState);
-    LOGD("JNIProviderService: nativeSendSyncInfo - OUT");
+    NS_LOGD ("JNIProviderService: nativeSendSyncInfo - IN");
+    OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->sendSyncInfo(
+                                        messageId,
+                                        (OIC::Service::NSSyncInfo::NSSyncType) syncState);
+    if (result !=  OIC::Service::NSResult::OK)
+    {
+        ThrowNSException((int) result, "Fail to send NSProvider SendSyncInfo");
+        return;
+    }
+    NS_LOGD ("JNIProviderService: nativeSendSyncInfo - OUT");
     return;
 }
 
 JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeCreateMessage
 (JNIEnv *env, jobject jObj)
 {
-    LOGD("JNIProviderService: nativeCreateMessage - IN");
-    OIC::Service::NSMessage* message =
-                      OIC::Service::NSProviderService::getInstance()->createMessage();
-    if(message == nullptr)
-    {
-        ThrowNSException(NS_ERROR, "Couldn't get Native Message");
-        return NULL;
-    }
+    NS_LOGD ("JNIProviderService: nativeCreateMessage - IN");
+    OIC::Service::NSMessage message =
+        OIC::Service::NSProviderService::getInstance()->createMessage();
     jobject jMsg =  getJavaMessage(env, message);
-    if(!jMsg)
+    if (!jMsg)
     {
-        ThrowNSException(NS_ERROR, "Couldn't create Java Message");
+        ThrowNSException(JNI_INVALID_VALUE, "Couldn't create Java Message");
         return NULL;
     }
-    LOGD("JNIProviderService: nativeCreateMessage - OUT");
+    NS_LOGD ("JNIProviderService: nativeCreateMessage - OUT");
     return jMsg;
 }
 
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService
-(JNIEnv *env,jobject jObj, jstring jstr)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService
+(JNIEnv *env, jobject jObj, jstring jstr)
 {
-    LOGD("JNIProviderService: nativeEnableRemoteService - IN");
+    NS_LOGD ("JNIProviderService: nativeEnableRemoteService - IN");
     if (!jstr)
     {
-        ThrowNSException(NS_ERROR, "Server Address Can't be NULL");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
+        return;
     }
 
     const char *address = env->GetStringUTFChars( jstr, NULL);
@@ -876,21 +1032,23 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat
             servAddress);
     if (result !=  OIC::Service::NSResult::OK)
     {
-        LOGE("Fail to Enable Remote Service");
+        ThrowNSException((int) result, "Fail to  Enable Remote Service");
+        return;
     }
     env->ReleaseStringUTFChars(jstr, address);
-    LOGD("JNIProviderService: nativeEnableRemoteService - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeEnableRemoteService - OUT");
+    return;
 }
 
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService
-(JNIEnv *env,jobject jObj, jstring jstr)
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService
+(JNIEnv *env, jobject jObj, jstring jstr)
 {
-    LOGD("JNIProviderService: nativeDisableRemoteService - IN");
+    NS_LOGD ("JNIProviderService: nativeDisableRemoteService - IN");
     if (!jstr)
     {
-        ThrowNSException(NS_ERROR, "Server Address Can't be NULL");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
+        return;
     }
 
     const char *address = env->GetStringUTFChars( jstr, NULL);
@@ -900,21 +1058,57 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat
             servAddress);
     if (result !=  OIC::Service::NSResult::OK)
     {
-        LOGE("Fail to Disable Remote Service");
+        ThrowNSException((int) result, "Fail to  Disable Remote Service");
+        return;
     }
     env->ReleaseStringUTFChars(jstr, address);
-    LOGD("JNIProviderService: nativeDisableRemoteService - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeDisableRemoteService - OUT");
+    return;
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_ns_provider_ProviderService_nativeSubscribeMQService
+(JNIEnv *env, jobject jObj, jstring jserverAddress, jstring jTopicName)
+{
+    NS_LOGD ("JNIProviderService: nativeSubscribeMQService - IN");
+    if (!jserverAddress)
+    {
+        ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
+        return;
+    }
+    if (!jTopicName)
+    {
+        ThrowNSException(JNI_INVALID_VALUE, "TopicName Can't be NULL");
+        return;
+    }
+
+    const char *address = env->GetStringUTFChars( jserverAddress, NULL);
+    std::string servAddress(address);
+    const char *topic = env->GetStringUTFChars( jTopicName, NULL);
+    std::string topicName(topic);
+
+    OIC::Service::NSResult result  =
+        OIC::Service::NSProviderService::getInstance()->subscribeMQService(
+            servAddress, topicName);
+    if (result !=  OIC::Service::NSResult::OK)
+    {
+        ThrowNSException((int) result, "Fail to  Subscribe to MQ Service");
+        return;
+    }
+    env->ReleaseStringUTFChars(jserverAddress, address);
+    env->ReleaseStringUTFChars(jTopicName, topic);
+    NS_LOGD ("JNIProviderService: nativeSubscribeMQService - OUT");
+    return;
 }
 
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic
 (JNIEnv *env, jobject jObj, jstring jTopicName)
 {
-    LOGD("JNIProviderService: nativeRegisterTopic - IN");
+    NS_LOGD ("JNIProviderService: nativeRegisterTopic - IN");
     if (!jTopicName)
     {
-        ThrowNSException(NS_ERROR, "Topic Name Can't be NULL");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "Topic Name Can't be NULL");
+        return;
     }
     const char *name = env->GetStringUTFChars( jTopicName, NULL);
     std::string topicName(name);
@@ -922,20 +1116,21 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat
                                          topicName);
     if (result !=  OIC::Service::NSResult::OK)
     {
-        LOGE("Fail to Register Topic");
+        ThrowNSException((int) result, "Fail to  Register Topic");
+        return;
     }
     env->ReleaseStringUTFChars(jTopicName, name);
-    LOGD("JNIProviderService: nativeRegisterTopic - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeRegisterTopic - OUT");
+    return;
 }
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic
 (JNIEnv *env, jobject jObj, jstring jTopicName)
 {
-    LOGD("JNIProviderService: nativeUnregisterTopic - IN");
+    NS_LOGD ("JNIProviderService: nativeUnregisterTopic - IN");
     if (!jTopicName)
     {
-        ThrowNSException(NS_ERROR, "Topic Name Can't be NULL");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "Topic Name Can't be NULL");
+        return;
     }
     const char *name = env->GetStringUTFChars( jTopicName, NULL);
     std::string topicName(name);
@@ -943,157 +1138,207 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nat
                                          topicName);
     if (result !=  OIC::Service::NSResult::OK)
     {
-        LOGE("Fail to Unregister Topic");
+        ThrowNSException((int) result, "Fail to  Unregister Topic");
+        return;
     }
     env->ReleaseStringUTFChars(jTopicName, name);
-    LOGD("JNIProviderService: nativeUnregisterTopic - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeUnregisterTopic - OUT");
+    return;
 }
 
-JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeGetRegisteredTopicList
+JNIEXPORT jobject JNICALL
+Java_org_iotivity_service_ns_provider_ProviderService_nativeGetRegisteredTopicList
 (JNIEnv *env, jobject jObj)
 {
-    LOGD("JNIProviderService: nativeGetRegisteredTopicList - IN");
+    NS_LOGD ("JNIProviderService: nativeGetRegisteredTopicList - IN");
 
-    OIC::Service::NSTopicsList *topicList  =
+    std::shared_ptr<OIC::Service::NSTopicsList> topicList  =
         OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
     if (topicList == nullptr)
     {
-        ThrowNSException(NS_ERROR, "Topic List doesn't exist");
+        ThrowNSException(JNI_INVALID_VALUE, "Topic List doesn't exist");
         return NULL;
     }
 
     jobject obj_topicList = getJavaTopicsList(env, topicList);
 
-    LOGD("JNIProviderService: nativeGetRegisteredTopicList - OUT");
+    NS_LOGD ("JNIProviderService: nativeGetRegisteredTopicList - OUT");
     return obj_topicList;
 }
 
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription
 (JNIEnv *env,  jobject jObj, jstring jConsumerId, jboolean jAccepted)
 {
-    LOGD("JNIProviderService: nativeAcceptSubscription - IN");
+    NS_LOGD ("JNIProviderService: nativeAcceptSubscription - IN");
     if (!jConsumerId)
     {
-        ThrowNSException(NS_ERROR, "ConsumerId Can't be NULL");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "ConsumerId Can't be NULL");
+        return;
     }
     const char *id = env->GetStringUTFChars( jConsumerId, NULL);
     std::string consumerId(id);
-    LOGD("Consumer ID: %s\n", consumerId.c_str());
+    NS_LOGD ("Consumer ID: %s\n", consumerId.c_str());
 
-    OIC::Service::NSConsumer *consumer =
+    std::shared_ptr<OIC::Service::NSConsumer> consumer =
         OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
     if (consumer)
-        return (jint) consumer->acceptSubscription((bool)jAccepted);
-
-    LOGE("Couldn't find consumer");
-    LOGD("JNIProviderService: nativeAcceptSubscription - OUT");
-    return (jint) OIC::Service::NSResult::ERROR;
+    {
+        OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
+        try
+        {
+            result = consumer->acceptSubscription((bool)jAccepted);
+        }
+        catch (OIC::Service::NSException ex)
+        {
+            ThrowNSException(NATIVE_EXCEPTION, ex.what());
+            return;
+        }
+        if (result !=  OIC::Service::NSResult::OK)
+        {
+            ThrowNSException((int) result, "Fail to  acceptSubscription");
+            return;
+        }
+    }
+    else
+    {
+        NS_LOGE ("Couldn't find consumer");
+        ThrowNSException(JNI_NO_NATIVE_POINTER, "Fail to find native consumer");
+    }
+    return;
 }
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic
 (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName)
 {
-    LOGD("JNIProviderService: nativeSetConsumerTopic - IN");
+    NS_LOGD ("JNIProviderService: nativeSetConsumerTopic - IN");
     if (!jConsumerId || !jTopicName)
     {
-        ThrowNSException(NS_ERROR, "Topic Name or ConsumerId Can't be NULL");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
+        return;
     }
     const char *name = env->GetStringUTFChars( jTopicName, NULL);
     const char *id = env->GetStringUTFChars( jConsumerId, NULL);
     std::string topicName(name);
     std::string consumerId(id);
-    OIC::Service::NSConsumer *nsConsumer =
+    std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
         OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
     if (!nsConsumer)
     {
-        ThrowNSException(NS_ERROR, "Consumer does exists");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
+        return;
+    }
+    OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
+    try
+    {
+        result  = nsConsumer->setTopic(topicName);
+    }
+    catch (OIC::Service::NSException ex)
+    {
+        ThrowNSException(NATIVE_EXCEPTION, ex.what());
+        return;
     }
-    OIC::Service::NSResult result  = nsConsumer->setTopic(topicName);
 
     if (result !=  OIC::Service::NSResult::OK)
     {
-        LOGD("Fail to Select Topic");
+        ThrowNSException((int) result, "Fail to  Select Topic");
+        return;
     }
     env->ReleaseStringUTFChars(jTopicName, name);
     env->ReleaseStringUTFChars(jConsumerId, id);
-    LOGD("JNIProviderService: nativeSetConsumerTopic - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeSetConsumerTopic - OUT");
+    return;
 }
-JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic
+JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic
 (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName)
 {
-    LOGD("JNIProviderService: nativeUnsetConsumerTopic - IN");
+    NS_LOGD ("JNIProviderService: nativeUnsetConsumerTopic - IN");
     if (!jConsumerId || !jTopicName)
     {
-        ThrowNSException(NS_ERROR, "Topic Name or ConsumerId Can't be NULL");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
+        return;
     }
     const char *name = env->GetStringUTFChars( jTopicName, NULL);
     const char *id = env->GetStringUTFChars( jConsumerId, NULL);
     std::string topicName(name);
     std::string consumerId(id);
-    OIC::Service::NSConsumer *nsConsumer =
+    std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
         OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
     if (!nsConsumer)
     {
-        ThrowNSException(NS_ERROR, "Consumer does exists");
-        return (jint) OIC::Service::NSResult::ERROR;
+        ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
+        return;
+    }
+    OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
+    try
+    {
+        result  = nsConsumer->unsetTopic(topicName);
+    }
+    catch (OIC::Service::NSException ex)
+    {
+        ThrowNSException(NATIVE_EXCEPTION, ex.what());
+        return;
     }
-    OIC::Service::NSResult result  = nsConsumer->unsetTopic(topicName);
 
     if (result !=  OIC::Service::NSResult::OK)
     {
-        LOGE("Fail to Unselect Topic");
+        ThrowNSException((int) result, "Fail to  Unselect Topic");
+        return;
     }
     env->ReleaseStringUTFChars(jTopicName, name);
     env->ReleaseStringUTFChars(jConsumerId, id);
-    LOGD("JNIProviderService: nativeUnsetConsumerTopic - OUT");
-    return (jint) result;
+    NS_LOGD ("JNIProviderService: nativeUnsetConsumerTopic - OUT");
+    return;
 }
 
 JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeGetConsumerTopicList
 (JNIEnv *env, jobject jObj, jstring jConsumerId)
 {
-    LOGD("JNIProviderService: nativeGetConsumerTopicList - IN");
+    NS_LOGD ("JNIProviderService: nativeGetConsumerTopicList - IN");
     if (!jConsumerId)
     {
-        ThrowNSException(NS_ERROR, "Topic Name or ConsumerId Can't be NULL");
+        ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
         return NULL;
     }
     const char *id = env->GetStringUTFChars( jConsumerId, NULL);
     std::string consumerId(id);
-    OIC::Service::NSConsumer *nsConsumer =
+    std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
         OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
     if (!nsConsumer)
     {
-        ThrowNSException(NS_ERROR, "Consumer does exists");
+        ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
         return NULL;
     }
     env->ReleaseStringUTFChars(jConsumerId, id);
-    OIC::Service::NSTopicsList *topicList  = nsConsumer->getConsumerTopicList();
+    std::shared_ptr<OIC::Service::NSTopicsList> topicList = nullptr;
+    try
+    {
+        topicList  = nsConsumer->getConsumerTopicList();
+    }
+    catch (OIC::Service::NSException ex)
+    {
+        ThrowNSException(NATIVE_EXCEPTION, ex.what());
+        return NULL;
+    }
     if (topicList == nullptr)
     {
-        ThrowNSException(NS_ERROR, "Topic List doesn't exist");
+        ThrowNSException(JNI_NO_NATIVE_POINTER, "Topic List doesn't exist");
         return NULL;
     }
     jobject obj_topicList = getJavaTopicsList(env, topicList);
-    LOGD("JNIProviderService: nativeGetConsumerTopicList - OUT");
+
+    NS_LOGD ("JNIProviderService: nativeGetConsumerTopicList - OUT");
     return obj_topicList;
 }
 
 // JNI OnLoad
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
 {
-    LOGD("ProviderService_JNI_OnLoad");
-    g_jvm = jvm;
+    NS_LOGD ("ProviderService_JNI_OnLoad");
+    g_jvm_provider = jvm;
 
-    JNIEnv *env;
+    JNIEnv *env = NULL;
     if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
     {
-        LOGE("Failed to get the environment using GetEnv()");
+        NS_LOGE ("Failed to get the environment using GetEnv()");
         return JNI_ERR;
     }
 
@@ -1101,13 +1346,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                               "org/iotivity/service/ns/common/Message");
     if (!localMessage)
     {
-        LOGE("Failed to get local Message class");
+        NS_LOGE ("Failed to get local Message class");
         return JNI_ERR;
     }
     g_cls_Message = (jclass) (env->NewGlobalRef(localMessage));
     if (!g_cls_Message)
     {
-        LOGE("Failed to set Global Message reference");
+        NS_LOGE ("Failed to set Global Message reference");
         return JNI_ERR;
     }
 
@@ -1115,13 +1360,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                                   "org/iotivity/service/ns/common/Message$MessageType");
     if (!localMessageType)
     {
-        LOGE("Failed to get local Message Type class");
+        NS_LOGE ("Failed to get local Message Type class");
         return JNI_ERR;
     }
     g_cls_Message_Type = (jclass) (env->NewGlobalRef(localMessageType));
     if (!g_cls_Message_Type)
     {
-        LOGE("Failed to set Global Message Type reference");
+        NS_LOGE ("Failed to set Global Message Type reference");
         return JNI_ERR;
     }
 
@@ -1129,13 +1374,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                                "org/iotivity/service/ns/provider/Consumer");
     if (!localConsumer)
     {
-        LOGE("Failed to get local Provider class");
+        NS_LOGE ("Failed to get local Provider class");
         return JNI_ERR;
     }
     g_cls_Consumer = (jclass) (env->NewGlobalRef(localConsumer));
     if (!g_cls_Consumer)
     {
-        LOGE("Failed to set Global Provider reference");
+        NS_LOGE ("Failed to set Global Provider reference");
         return JNI_ERR;
     }
 
@@ -1143,13 +1388,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                                "org/iotivity/service/ns/common/SyncInfo");
     if (!localSyncInfo)
     {
-        LOGE("Failed to get local SyncInfo class");
+        NS_LOGE ("Failed to get local SyncInfo class");
         return JNI_ERR;
     }
     g_cls_SyncInfo = (jclass) (env->NewGlobalRef(localSyncInfo));
     if (!g_cls_SyncInfo)
     {
-        LOGE("Failed to set Global SyncInfo reference");
+        NS_LOGE ("Failed to set Global SyncInfo reference");
         return JNI_ERR;
     }
 
@@ -1157,13 +1402,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                                "org/iotivity/service/ns/common/SyncInfo$SyncType");
     if (!localSyncType)
     {
-        LOGE("Failed to get local SyncType enum");
+        NS_LOGE ("Failed to get local SyncType enum");
         return JNI_ERR;
     }
     g_cls_SyncType = (jclass) (env->NewGlobalRef(localSyncType));
     if (!g_cls_SyncType)
     {
-        LOGE("Failed to set Global SyncType reference");
+        NS_LOGE ("Failed to set Global SyncType reference");
         return JNI_ERR;
     }
 
@@ -1171,13 +1416,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                                     "org/iotivity/service/ns/common/MediaContents");
     if (!localMediaContents)
     {
-        LOGE("Failed to get local MediaContents class");
+        NS_LOGE ("Failed to get local MediaContents class");
         return JNI_ERR;
     }
     g_cls_MediaContents = (jclass) (env->NewGlobalRef(localMediaContents));
     if (!g_cls_MediaContents)
     {
-        LOGE("Failed to set Global MediaContents reference");
+        NS_LOGE ("Failed to set Global MediaContents reference");
         return JNI_ERR;
     }
 
@@ -1185,13 +1430,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                             "org/iotivity/service/ns/common/Topic");
     if (!localTopic)
     {
-        LOGE("Failed to get local Topic class");
+        NS_LOGE ("Failed to get local Topic class");
         return JNI_ERR;
     }
     g_cls_Topic = (jclass) (env->NewGlobalRef(localTopic));
     if (!g_cls_Topic)
     {
-        LOGE("Failed to set Global Topic reference");
+        NS_LOGE ("Failed to set Global Topic reference");
         return JNI_ERR;
     }
 
@@ -1199,13 +1444,13 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                                  "org/iotivity/service/ns/common/TopicsList");
     if (!localTopicsList)
     {
-        LOGE("Failed to get local Topic class");
+        NS_LOGE ("Failed to get local Topic class");
         return JNI_ERR;
     }
     g_cls_TopicsList = (jclass) (env->NewGlobalRef(localTopicsList));
     if (!g_cls_TopicsList)
     {
-        LOGE("Failed to set Global TopicsList reference");
+        NS_LOGE ("Failed to set Global TopicsList reference");
         return JNI_ERR;
     }
 
@@ -1213,13 +1458,34 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
                                  "org/iotivity/service/ns/common/Topic$TopicState");
     if (!localTopicState)
     {
-        LOGE("Failed to get local TopicState enum");
+        NS_LOGE ("Failed to get local TopicState enum");
         return JNI_ERR;
     }
     g_cls_TopicState = (jclass) (env->NewGlobalRef(localTopicState));
     if (!g_cls_TopicState)
     {
-        LOGE("Failed to set Global TopicState reference");
+        NS_LOGE ("Failed to set Global TopicState reference");
+        return JNI_ERR;
+    }
+
+    //OcRepresentation
+    jclass localOcRepresentation = env->FindClass("org/iotivity/base/OcRepresentation");
+    if (!localOcRepresentation)
+    {
+        NS_LOGE ("Failed to get local OcRepresentation class");
+        return JNI_ERR;
+    }
+    g_cls_OcRepresentation = (jclass) env->NewGlobalRef(localOcRepresentation);
+    if (!g_cls_OcRepresentation)
+    {
+        NS_LOGE ("Failed to set Global OcRepresentation reference");
+        return JNI_ERR;
+    }
+
+    g_mid_OcRepresentation_N_ctor_bool = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(JZ)V");
+    if (!g_mid_OcRepresentation_N_ctor_bool)
+    {
+        NS_LOGE ("Failed to get Global OcRepresentation Constructor reference");
         return JNI_ERR;
     }
 
@@ -1232,18 +1498,19 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
     env->DeleteLocalRef(localTopic);
     env->DeleteLocalRef(localTopicsList);
     env->DeleteLocalRef(localTopicState);
+    env->DeleteLocalRef(localOcRepresentation);
 
     return NSExceptionInit(env);
 }
 
 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
 {
-    LOGD("ProviderService_JNI_OnUnload");
-    JNIEnv *env;
+    NS_LOGD ("ProviderService_JNI_OnUnload");
+    JNIEnv *env = NULL;
 
     if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
     {
-        LOGE("Failed to get the environment using GetEnv()");
+        NS_LOGE ("Failed to get the environment using GetEnv()");
         return ;
     }
 
@@ -1256,4 +1523,5 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
     env->DeleteGlobalRef(g_cls_Topic);
     env->DeleteGlobalRef(g_cls_TopicsList);
     env->DeleteGlobalRef(g_cls_TopicState);
+    env->DeleteGlobalRef(g_cls_OcRepresentation);
 }