cancel
Showing results for 
Search instead for 
Did you mean: 

Unauthorised error while registering for push notification on SMP

11-19-2014 12:36 PM
321 views 7 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hi all,

I'm trying to implement push notification in an android application which is connected to SMP 3.0 SP03 server. I've followed documents available for enabling push notification on SMP. I've successfully registered the device on the GCM server, and have configured SMP with the API key and sender id to enable Android Push notification in it.

I've successfully registered the device on the SMP server. But when I try to register the device for push notification using following code:

https://{ mobile platform URL }/odata/applications/{latest|v1}/{appid}/Connections('{APPCID}') Method : PUT
Header : "Content-Type" = "application/atom+xml"

"X-HTTP-METHOD" = "MERGE" "X-SUP-APPCID" = {APPCID}

<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom"

xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"> <content type="application/xml">

<m:properties>
<
d: AndroidGcmRegistrationId>{GCM registration ID}</d:

AndroidGcmRegistrationId > </m:properties> 
  </content> </entry> 

I get error from SMP saying, "HTTP 401 Unauthorized", although I'm providing same login credentials which I've used to register the application on SMP.

Kindly help.

Regards,

Serveshwar Mishra

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Thanks Jitendra and Ali.

Finally the problem was solved.

Error was in the Content-type,

Instead of using "application/atom+xml" it should be "application/xml"

Regards,

Serveshwar Mishra

Ali_Chalhoub1
Product and Topic Expert
Product and Topic Expert
0 Likes

I am glad it did.

Answers (3)

Answers (3)

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Likes

Please close this thread if your query has been answered.

Ali_Chalhoub1
Product and Topic Expert
Product and Topic Expert
0 Likes

Try this:

Request Type: PUT

Do it as a  post

<?xml version="1.0"encoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<content type="application/xml">

<m:properties>

<d:DeviceType>Android</d:DeviceType>

<d:AndroidGcmPushEnabled m:type="Edm.Boolean">true</d:AndroidGcmPushEnabled>

  <d:AndroidGcmRegistrationId>Paste your GCM registration ID here
</d:AndroidGcmRegistrationId>

</m:properties>

</content>

</entry>

See if that works for you.

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Likes


But when I try to register the device for push notification using following code:

You have to use PUT method in the URL, along with the GCM registration id. Have you got GCM registration id?

Check Registering the Android Client for more info.


Regards,

JK

Former Member
0 Likes

Hi Jitendra,

Yes I've got the registrationId from GCM and am also using PUT method but still getting the same error. Following is the code:

ConnectivitySettings connectivitySettings = ConnectivitySettings.getInstance();

String queryString = "http://" + connectivitySettings.getSUPHost()

  + ":" + connectivitySettings.getSUPPort()

  + "/odata/applications/latest/"

  + connectivitySettings.getSUPAppID() + "/Connections('"

  + mSMPAppConnectionID + "')";


  String GCMRegistrationId =this.restManager.getAppPersistenceManager().getGCMRegistrationId();

  IODataEntry entry = new ODataEntry();

  entry.putPropertyValue("AndroidGcmRegistrationId", GCMRegistrationId);

  String xmlSring = entry.toXMLString();

  IRequest request = new BaseRequest();

  request.setListener(listener);

  request.setPriority(IRequest.PRIORITY_HIGH);

  request.setRequestMethod(IRequest.REQUEST_METHOD_PUT);

  request.setRequestTAG(requestTag);

  request.setRequestUrl(queryString);

  request.setData(xmlSring.getBytes());

  Map<String,String> headers = new HashMap<String,String>();

  headers.put("content-type","application/atom+xml");

  headers.put("X-SUP-APPCID", mSMPAppConnectionID);

  headers.put("X-HTTP-METHOD", "MERGE");

  request.setHeaders(headers);

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Likes

http://scn.sap.com/people/serveshwar.mishra

Can you check PUT operation in REST client first as i shared the screenshot in above comment?

Regards,

JK