cancel
Showing results for 
Search instead for 
Did you mean: 

Making request error from android via sap gateway services

0 Kudos

hi,

i'm getting following error while work with post gateway service from the android. HTTP request error. I'm using the following code to update the data via POST gateway service.

mParameters = new SDMConnectivityParameters();

mParameters.setUserName(<username>);

mParameters.setUserPassword(<password>);

mPreferences = new SDMPreferences(_context, Utility.getLogger());

ISDMRequestManager mRequestManager = new SDMRequestManager(Utility.getLogger(), mPreferences, mParameters, 3, mSecurity);

ISDMRequest request = new SDMBaseRequest();

request.setListener(this);

request.setRequestUrl(_serviceURL);

request.setRequestMethod(ISDMRequest.REQUEST_METHOD_POST);

request.setPriority(ISDMRequest.PRIORITY_HIGH);

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

headers.put("Content-Type", "application/atom+xml");

headers.put("X-Requested-With", "XMLHttpRequest");

request.setHeaders(headers);

request.setData(requestBody.getBytes());

request.setRequestUrl(_serviceURL);

mRequestManager.makeRequest(request);

_response = "pending";

while (true)

{

                              if (_response != "pending")

   {

     break;

   }

                    }

                    if (_response.equalsIgnoreCase("error"))

                    {

                              ThrowServiceException(_ISDMRequestStateElement);

                    }

                    else if (_response.equalsIgnoreCase("error400"))

                    {

                              throw new CustomException(respBody);

                    }

                     return _response;

Accepted Solutions (0)

Answers (2)

Answers (2)

sujith_prathap
Advisor
Advisor
0 Kudos

Hi Pavan,

I have a few questions?

1) Does the request you are trying to POST work in the REST client?

2) Does your gateway support XCSRF tokens? If, so then this must be enabled in your code as a header before doing a POST operation.

Former Member
0 Kudos

Hi Pavan,

    Kindly post the error message that you are getting when sending this request.

Regards,

Deepika.

0 Kudos

Here is the error Deepika,

11-20 16:05:19.874: D/dalvikvm(1245): GC_CONCURRENT freed 766K, 6% free 15270K/16135K, paused 79ms+153ms, total 541ms

11-20 16:05:20.143: I/Choreographer(1245): Skipped 158 frames!  The application may be doing too much work on its main thread.

11-20 16:05:20.374: I/Choreographer(1245): Skipped 30 frames!  The application may be doing too much work on its main thread.

11-20 16:05:22.723: D/SDMConnectivity(1245): Starting connection handler instance(s).

11-20 16:05:22.723: D/SDMConnectivity(1245): Connection handler is 'com.sap.mobile.lib.sdmconnectivity.SocketConnectionHandler' threads=2

11-20 16:05:22.954: I/SDMConnectivity(1245): Entering SDMREquestManager.getRequest()

11-20 16:05:22.965: I/SDMConnectivity(1245): Exiting SDMREquestManager.getRequest() with a request.

11-20 16:05:22.965: D/SDMConnectivity(1245): adding backend language to url: http://.....

11-20 16:05:23.023: D/SDMConnectivity(1245): Automatically adding HTTP header 'X-Request-With:X'

11-20 16:05:28.964: W/xyAuthenticationHandler(1245): Authentication scheme ntlm not supported

11-20 16:05:34.903: D/SDMConnectivity(1245): performRequest returns with status 407

11-20 16:05:34.903: D/ServicePut onError(1245): pending

11-20 16:05:34.903: D/Approve/Reject After Update(1245): Http request error

11-20 16:05:34.903: I/Choreographer(1245): Skipped 3179 frames!  The application may be doing too much work on its main thread.

Former Member
0 Kudos

Hi Pavan,

the error may be due to any one of the below two reasons:

1. The authentication parameters (username/password) being sent during POST might be wrong.

2. The collection on which you are trying POST might not support the POST operation.

You can verify the authentication credentials or whether the POST operation is enabled on the collection by tring the same operations using REST client.

Regards,

Sachin

0 Kudos

Hi Sachin,

I'm passing the right credentials and successfully doing this POST operation via firefox (rest client). While proceeding from source hitting with the above error.

Thanks for reply 🙂

Pavan

Former Member
0 Kudos

Hi Pavan,

    Since you are telling it works from the REST client, it would be good to cross check the xml body that is being sent through the source with the body that is given in the REST client. So, please check the value of the "requestbody" variable used in

     request.setData(requestBody.getBytes());

Also, the headers and the url on which this request is being fired by having some log statements. In the code which is given i could not see how the requestBody is being initialized.

Hope this helps.

Regards,

Deepika.

0 Kudos

Hi Deepika,

There is no problem with payload(requestBody). I tested, its working fine. I'm adding same headers where i'm using in firefox (rest client).

Pavan

rohith_deraje
Advisor
Advisor
0 Kudos

Hi Pavan,

are you able to perform GET request successfully? If not,  I s8uggest you to verify your application code against code given @ http://scn.sap.com/docs/DOC-27410.

If GET is already working for you, please enable the payload loggin. Perform a POST request and revert back with logs.

Steps:

1. Domain>>DomainName>>Log>>Settings>>New >> Enter a name

2.Select "Application Connection" and chose your User

3. Select "payload" and chose "request response"

4. Select "Enable after creation"

Save the settings.

Change the log level at Server>>Logs>>Unwired Server>>Settings>>Proxy>>Debug.

Fire a new request from your application.

Under Domain>>DomainName>>Log>>General>>Proxy, click on retrive to display the latest logs:

Regards

Rohith