SendPushToUser Client not authorized

0 votes

Hello,

I write a servlet to send push when requested.

I use this code :

            App42API.initialize(ConfigValues.APP42_API, ConfigValues.APP42_KEY);            
            App42API.setLoggedInUser("XXX");
            PushNotificationService pushService = App42API.buildPushNotificationService();
            LogService lgs = App42API.buildLogService();
            lgs.debug("Start sending Message to user :" + user, "PushServlet");
            PushNotification pushNotificationObj = pushService.sendPushMessageToUser(user, msg);

But I ALWAY RECEIVE the error

{"app42Fault":{"httpErrorCode":401,"appErrorCode":1401,"message":"UnAuthorized Access","details":"Client is not authorized"}}

What is Wrong ?

The Api and key are constant and I use it and the user autentication and work.

I need to wait after APP42Api.Initialize ?

I Disable the "Replay Attack" for prevent time errors but never change, alway get the same error.

I see you examples but look like this.

Can you help me ?

Best regards

 

asked Apr 26, 2017 in Java by odf (37 points)

1 Answer

0 votes
Hello odf,

Could you please share following informations:

1. ConfigValues

2. Is your app ACL enabled

It will help us to debug the problem you are facing.

Thanks.
answered Apr 28, 2017 by rajeev.etc (1,660 points)
Hello
The two variables are:
 public static final String APP42_API = "5e45adde426369cfdadb6d91d050f39725d5f81664fbfcdc1c57XXXXXXXXXXX";
 public static final String APP42_KEY = "7202e3779a4de70dde6185b7c17db63138986390b9a603e524fdXXXXXXXXXXXX";

I mask the last character for security reasons.
What you mean about "Is your app ACL enabled" ? Where I can check it ?

Actually I use the same code in PHP and work fine, but I need to transport to Java.
This is the code in PHP
App42API::initialize($APP42_API, $APP42_KEY);
App42API::setLoggedInUser("XXXXX");
$logService = App42API::buildLogService();
$pushNotificationService = App42API::buildPushNotificationService();
$logService->debug("Start sending Message to user :" . $user, "sendNotifyUser2");
$pushNotification = $pushNotificationService->sendPushMessageToUser($user, $messageAfterAddSlahes );


This code in PHP work fine, but the same code in Java I get the client autorization error, is very strange this.

Can I help you in something ? I can Enable debug message ?
Best regards
Hello,
I produce the complete http transaction log,
I change key and user for security:
[mpl.conn.DefaultClientConnectionOperator]  - Connecting to api.shephertz.com/138.91.191.179:443
[e.http.client.protocol.RequestAddCookies]  - CookieSpec selected: best-match
[pache.http.impl.client.DefaultHttpClient]  - Attempt 1 to execute request
[e.http.impl.conn.DefaultClientConnection]  - Sending request: POST /cloud/1.0/push/sendMessage/XXXXX? HTTP/1.1
[org.apache.http.wire                    ]  - >> "POST /cloud/1.0/push/sendMessage/XXXXX? HTTP/1.1[\r][\n]"
[org.apache.http.wire                    ]  - >> "Content-Type: application/json[\r][\n]"
[org.apache.http.wire                    ]  - >> "Accept: application/json[\r][\n]"
[org.apache.http.wire                    ]  - >> "signature: Y5nR0Nn%2FOZFcCDsaRZ%2Fk4Lw0cws%3D[\r][\n]"
[org.apache.http.wire                    ]  - >> "version: 1.0[\r][\n]"
[org.apache.http.wire                    ]  - >> "SDKName: Java[\r][\n]"
[org.apache.http.wire                    ]  - >> "timeStamp: 2017-04-28T13:14:46.440Z[\r][\n]"
[org.apache.http.wire                    ]  - >> "apiKey: 5e45adde426369cfdadb6d91d050f39725d5f81664fbfcdc1c57aXXXXXXXXXXXXXXXXXXX[\r][\n]"
[org.apache.http.wire                    ]  - >> "Content-Length: 137[\r][\n]"
[org.apache.http.wire                    ]  - >> "Host: api.shephertz.com[\r][\n]"
[org.apache.http.wire                    ]  - >> "Connection: Keep-Alive[\r][\n]"
[org.apache.http.wire                    ]  - >> "[\r][\n]"
[org.apache.http.headers                 ]  - >> POST /cloud/1.0/push/sendMessage/XXXXX? HTTP/1.1
[org.apache.http.headers                 ]  - >> Content-Type: application/json
[org.apache.http.headers                 ]  - >> Accept: application/json
[org.apache.http.headers                 ]  - >> signature: Y5nR0Nn%2FOZFcCDsaRZ%2Fk4Lw0cws%3D
[org.apache.http.headers                 ]  - >> version: 1.0
[org.apache.http.headers                 ]  - >> SDKName: Java
[org.apache.http.headers                 ]  - >> timeStamp: 2017-04-28T13:14:46.440Z
[org.apache.http.headers                 ]  - >> apiKey: 5e45adde426369cfdadb6d91d050f39725d5f81664fbfcdc1c57aXXXXXXXXXXXXXXXXXXX
[org.apache.http.headers                 ]  - >> Content-Length: 137
[org.apache.http.headers                 ]  - >> Host: api.shephertz.com
[org.apache.http.headers                 ]  - >> Connection: Keep-Alive
[org.apache.http.wire                    ]  - >> "{"app42":{"push":{"message":{"payload":"Questo [0xc3][0xa8] un mesaggio di test e prova","expiry":"2017-04-28T13:14:46.441Z","userName":"XXXXX"}}}}"
[org.apache.http.wire                    ]  - << "HTTP/1.1 401 Unauthorized[\r][\n]"
[org.apache.http.wire                    ]  - << "Server: Apache-Coyote/1.1[\r][\n]"
[org.apache.http.wire                    ]  - << "Access-Control-Allow-Origin: *[\r][\n]"
[org.apache.http.wire                    ]  - << "Access-Control-Allow-Credentials: true[\r][\n]"
[org.apache.http.wire                    ]  - << "Access-Control-Allow-Methods : GET, POST,HEAD, OPTIONS,PUT, DELETE[\r][\n]"
[org.apache.http.wire                    ]  - << "Access-Control-Allow-Headers: Content-Type,Accept,apiKey,signature,timeStamp,sessionId,adminKey,fbAccessToken,dataACL,geoTag,selectKeys,SDKName,deviceId,event,version,userList,deletePermanent,loggedInUser,dbCredentials,metaQuery,emailAuth,orderByDescending,orderByAscending,jsonObject,offset,max,dataEncoding,like,emailVerification,userProfile,customName,userName,tag,template,isAttachScoreId,setFBImageDimension,X-Access-Token, X-Application-Name, X-Request-Sent-Time,Custom-Headers,outputCollection,description,groupMetaInfo,jsonQuery,pageMaxRecords,pageOffset,pushIdentifier,isUpdate,attachmentUrl,senderName,replyTo,senderAlias,channelName[\r][\n]"
[org.apache.http.wire                    ]  - << "Access-Control-Max-Age: 10[\r][\n]"
[org.apache.http.wire                    ]  - << "Cache-Control: no-cache[\r][\n]"
[org.apache.http.wire                    ]  - << "app42Fault: 401[\r][\n]"
[org.apache.http.wire                    ]  - << "message: {"app42Fault":{"httpErrorCode":401,"appErrorCode":1401,"message":"UnAuthorized Access","details":"Client is not authorized"}}[\r][\n]"
[org.apache.http.wire                    ]  - << "Content-Type: application/json[\r][\n]"
[org.apache.http.wire                    ]  - << "Transfer-Encoding: chunked[\r][\n]"
[org.apache.http.wire                    ]  - << "Date: Fri, 28 Apr 2017 13:14:46 GMT[\r][\n]"
[org.apache.http.wire                    ]  - << "[\r][\n]"
[e.http.impl.conn.DefaultClientConnection]  - Receiving response: HTTP/1.1 401 Unauthorized
[org.apache.http.headers                 ]  - << HTTP/1.1 401 Unauthorized
[org.apache.http.headers                 ]  - << Server: Apache-Coyote/1.1
[org.apache.http.headers                 ]  - << Access-Control-Allow-Origin: *
[org.apache.http.headers                 ]  - << Access-Control-Allow-Credentials: true
[org.apache.http.headers                 ]  - << Access-Control-Allow-Methods : GET, POST,HEAD, OPTIONS,PUT, DELETE
[org.apache.http.headers                 ]  - << Access-Control-Allow-Headers: Content-Type,Accept,apiKey,signature,timeStamp,sessionId,adminKey,fbAccessToken,dataACL,geoTag,selectKeys,SDKName,deviceId,event,version,userList,deletePermanent,loggedInUser,dbCredentials,metaQuery,emailAuth,orderByDescending,orderByAscending,jsonObject,offset,max,dataEncoding,like,emailVerification,userProfile,customName,userName,tag,template,isAttachScoreId,setFBImageDimension,X-Access-Token, X-Application-Name, X-Request-Sent-Time,Custom-Headers,outputCollection,description,groupMetaInfo,jsonQuery,pageMaxRecords,pageOffset,pushIdentifier,isUpdate,attachmentUrl,senderName,replyTo,senderAlias,channelName
[org.apache.http.headers                 ]  - << Access-Control-Max-Age: 10
[org.apache.http.headers                 ]  - << Cache-Control: no-cache
[org.apache.http.headers                 ]  - << app42Fault: 401
[org.apache.http.headers                 ]  - << message: {"app42Fault":{"httpErrorCode":401,"appErrorCode":1401,"message":"UnAuthorized Access","details":"Client is not authorized"}}
[org.apache.http.headers                 ]  - << Content-Type: application/json
[org.apache.http.headers                 ]  - << Transfer-Encoding: chunked
[org.apache.http.headers                 ]  - << Date: Fri, 28 Apr 2017 13:14:46 GMT
[pache.http.impl.client.DefaultHttpClient]  - Connection can be kept alive indefinitely
[pache.http.impl.client.DefaultHttpClient]  - Target requested authentication
[lient.DefaultTargetAuthenticationHandler]  - Authentication schemes in the order of preference: [negotiate, NTLM, Digest, Basic]
[lient.DefaultTargetAuthenticationHandler]  - Challenge for negotiate authentication scheme not available
[lient.DefaultTargetAuthenticationHandler]  - Challenge for NTLM authentication scheme not available
[lient.DefaultTargetAuthenticationHandler]  - Challenge for Digest authentication scheme not available
[lient.DefaultTargetAuthenticationHandler]  - Challenge for Basic authentication scheme not available
[pache.http.impl.client.DefaultHttpClient]  - Authentication error: Unable to respond to any of these challenges: {}
[org.apache.http.wire                    ]  - << "7d[\r][\n]"
[org.apache.http.wire                    ]  - << "{"app42Fault":{"httpErrorCode":401,"appErrorCode":1401,"message":"UnAuthorized Access","details":"Client is not authorized"}}"
[org.apache.http.wire                    ]  - << "[\r][\n]"
[org.apache.http.wire                    ]  - << "0[\r][\n]"
[org.apache.http.wire                    ]  - << "[\r][\n]"
[e.http.impl.conn.SingleClientConnManager]  - Releasing connection org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@74d46dc3
Hi Odf,

Are you passing any special character or non-english character in the message?

Thanks.
Hello,
this is the text
"Questo è un mesaggio di test e prova"
Is this the problem ?
Best regards
I remove the "è" character and push start ok.
How I can send messages using italian charset ?
Best regards.
I try also with
HashMap<String, String> otherMetaHeaders = new HashMap<>();  
otherMetaHeaders.put("dataEncoding", "true");              
pushService.setOtherMetaHeaders(otherMetaHeaders);

but did not resolve the problem.
I make a lot of test.
You Java Library have a Bug in When use utf-8 text.
The same message with php SDk work fine.
Java Library did not WORK.
Best regards
Hi,
I am forwarding this to production team to check if following code is not working for you:
HashMap<String, String> otherMetaHeaders = new HashMap<>();  
otherMetaHeaders.put("dataEncoding", "true");              
pushService.setOtherMetaHeaders(otherMetaHeaders);

I will update you asap.

Thanks.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...