cancel
Showing results for 
Search instead for 
Did you mean: 

HttpAdapterException: STATUS_CODE_NOT_OK- 500 Internal Server Error

0 Kudos

Hello Experts,

This requirement is regards to IDOC to HTTP_AAE(.csv multiform data) scenario.

While delivering the message from SAP ECC to Http server via EAI SAP PI 7.5 facing below error.

HttpAdapterException: STATUS_CODE_NOT_OK- 500 Internal Server Error MP: exception caught with cause com.sap.aii.adapter.http.api.HttpAdapterException: STATUS_CODE_NOT_OK- 500 Internal Server Error

Exception caught by adapter framework: STATUS_CODE_NOT_OK- 500 Internal Server Error

Transmitting the message to endpoint <local> using connection AFW failed, due to: com.sap.aii.adapter.http.api.HttpAdapterException: STATUS_CODE_NOT_OK- 500 Internal Server Error

Kindly provide your valuable inputs. Many Thanks..!

arrezende
Active Participant

Hi Narendra,

Please, see the SAP Note 2645568 - HTTP_AAE adapter gives STATUS_CODE_NOT_OK - 500 error

0 Kudos

Hi Alexandre Rezende,

I have gone through the SAP Note 2645568 : But i couldn't find the solution, PFA.

sugata_bagchi2
Active Contributor
0 Kudos

could you please share the target HTML page? how it looks like?

0 Kudos

Hi Sugata,

This API will update S3 bucket and upload data passed it.

POST

Host:

Authorization:

Cache-Control: no-cache

Postman-Token: 40d10c88-3f4f-387d-6dca-a87582be7ae6

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW ------

WebKitFormBoundary7MA4YWxkTrZu0gW

Content-Disposition: form-data; name="file"; filename="AIL_INV_20180111_150116.csv"

Content-Type: application/vnd.ms-excel

------WebKitFormBoundary7MA4YWxkTrZu0gW

Content-Disposition: form-data; name=""

------WebKitFormBoundary7MA4YWxkTrZu0gW--

Accepted Solutions (1)

Accepted Solutions (1)

sugata_bagchi2
Active Contributor
0 Kudos

Hello Narendra,

Use the below module in your receiver HTTP adapter -

When tested, I can see the reply from HTTP server with the file name we passed-

Please also check with your target server if they were able to process the data.

Thanks

Sugata

Answers (11)

Answers (11)

former_member607993
Contributor
0 Kudos

Hello,

In HTTP_AAE receiver channel under Advanced Tab set the Additional parameters as below:

preferredContentTypeHeader true

Also under General Tab in request details tick the 'Set form' and name the main payload parameter name as 'file' and tick the 'Set Multipart' and 'Keep Attachments'.

0 Kudos

Hello Rajesh,

This was very helpful too. Thanks.

former_member499364
Participant

how was this resolved?

sugata_bagchi2
Active Contributor
0 Kudos

can you share your ID module and receiver channel configuration?

0 Kudos

Hi Sugata,

Please find the details.

File name is inappropriate.

sugata_bagchi2
Active Contributor
0 Kudos

Hi Narendra,

The UDF code I have shared earlier can be used in the java mapping.

You can create the java mapping to create multipart data. did you try the trace HTTP option?

Thanks

Sugata

0 Kudos

Hi Sugata,

Do proceed on this HTTP traces, Updation of AS Java to the latest patch version is required ?

0 Kudos

Hi Sugata,

Now message is delivered successfully without using any java mapping. Only ID Module configuration and setting up ASMA in ESR.

But filename is not reading. It is getting delivered as MainDocument and not going as AIL_INV_IDOCcreatedDate_IDOCcreatedTime

HTTP_CLIENT : 5161 REQUEST:

------=_Part_546_1040778488.1554801212614

Content-Type: multipart/form-data;

Content-ID: <payload-bf322c1c5aa711e9cdd20000001e93ee@sap.com>

Content-Description: MainDocument

Content-Disposition: form-data; name="file"; filename="MainDocument" SKUId,EANNumber,Warehouse,Quantity,UOM,Cost,Entity,TransactionType

USPOLI781,987980007333,1200,1,PC,98,ALBL,NA

------=_Part_546_1040778488.1554801212614--

Path:

ALBLMT/SOH/local/AIL_MainDocument

headers:

DynamicConfiguration conf2 = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System", "HeaderFieldOne"); conf2.put(key1,fileName); return "";

sugata_bagchi2
Active Contributor
0 Kudos

Hello Narendra,

At this point, I am clueless :-). Because , I tried the same approach and it worked for me.

According to your API call to S3- I can see from the below raw HTTP data -

POST

Host:

Authorization:

Cache-Control: no-cache

Postman-Token: 40d10c88-3f4f-387d-6dca-a87582be7ae6

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW ------

WebKitFormBoundary7MA4YWxkTrZu0gW

Content-Disposition: form-data; name="file"; filename="AIL_INV_20180111_150116.csv"

Content-Type: application/vnd.ms-excel

------WebKitFormBoundary7MA4YWxkTrZu0gW

Content-Disposition: form-data; name=""

------WebKitFormBoundary7MA4YWxkTrZu0gW--

you have two parameters at your target HTTP / web form - file and name. and it worked even though you did not provide the key/value pair for name. Which means it is not mandatory.

could you please try tracing the HTTP log for this interface? you can trace the HTTP error and download the log from NWA. Please set up the same using the SAP note -

2157425 - New Feature: Client side HTTP Tracing for HTTP_AAE adapter

Please configure and run the scenario and collect the trace. Let me know the log details.

Thanks

Sugata

0 Kudos

Hi Sugata,

I'm still clueless how it worked for you. I've been challenged and couldn't able to crack this scenario.

I had investigated thoroughly line by line with xpi inspector traces wherein the error is expectioned with STATUS_CODE_NOT_OK- 500 Internal Server Error only.

0 Kudos

Hi Sugata,

Please refer the below link, is it achievable in PI 7.5 ? wherein content /mime types are generated via Java mapping

https://blogs.sap.com/2014/09/12/html-form-upload-using-http-plain-adapter-with-java-mapping/

sugata_bagchi2
Active Contributor
0 Kudos

Also try the above approach without selecting the setform check box-

Like below -

0 Kudos

Hi Sagata,

It isn't working. Facing same error 500 http issue.

sugata_bagchi2
Active Contributor
0 Kudos

Also check if the Network is open from your PI system to their HTTP system, or if you need to install any certs in PI.

0 Kudos

Hi Sugata,

There is no issue from a network/infra standpoints.

HTTP channel ping works fine in PI. As well the target server works completely fine with status HTTP 200 OK.

sugata_bagchi2
Active Contributor
0 Kudos

Hi Narendra,
As I have mentioned earlier you have to create only 1 operation mapping , in that 1step graphical mapping will be IDoc to XML mapping and 2nd step graphical mapping will be to create attachment using the UDF and assign some value to the target field.

could you please also let us know the details of target HTTP web page ? how the HTTP form looks like? a screenshot will do. I have tested the same way I have descried earlier and it worked.

Thanks

Sugata

0 Kudos

Hi Sugata,

First mapping idoc to xml one to one mapping.

Coming to second mapping do we need to concatenate and send the input as below and map to 'file' ??

ARW27210,1,GT0,EA,INR,87822210012,NA,11

0 Kudos

Hi Sagata,

It isn't working. Facing same error 500 http issue.

sugata_bagchi2
Active Contributor
0 Kudos

Hello Narendra,
As you have to send the actual data as a file, you have to convert the XML into CSV and create an attachment in the mapping itself. As your scenario is an IDoc to HTTP. I think it is a simple Async scenario, if you are expecting a response back from the target HTTP server then you have to use the request response bean and replace interface configurations in your receiver channel. As of now I am considering this as a Async scenario where you have to send the payload as a csv file and a text value as the HTTP body.

Please try the following steps-

1. Create two target data types and message types - 1st data and message type will be your actual payload structure- Records. The 2nd data type and message type will be a single field.

Something like this -

2. Create two message Mappings- 1st mapping is the actual mapping for IDoc to 1st target structure, you already have this one. the 2nd mapping is the one where you have to create the CSV from the XML output generated from the 1st mapping and assign the csv file as an attachment to the XI message.In this mapping your source structure will the 1st message type (with Record nodes) and target structure will be the 2nd message type with single field you have created.
in the 2nd step mapping you have to create an UDF to convert the XML to csv and create an attachment. please adjust the code below with your 1st structure's field names and use it - in this UDF you have to pass all the fields as source-

AbstractTrace trace = container.getTrace();
String header = "Name,Id,Email"; // field names from your first structure
String content = header + "\n";
String mimeType= "application/vnd.ms-excel;charset="+ "\"" + "uft-8" + "\"";
String filename = "Attachment.csv";// you can dynamically set this

for(int i =0; i< Name.length; i++)
{

        // adjust the below line with your field names from first structure
        content = content + Name[i] +"," +Id[i] + ","+ Email[i]  + "\n";  
    
}
trace.addInfo(content); 
//Create attachment with CSV data
try
{
    GlobalContainer globalContainer = container.getGlobalContainer();
    OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
    Attachment attachments = outputAttachments.create(filename, mimeType, content.getBytes()); 
    outputAttachments.setAttachment(attachments);
    result.addValue("filePath"); // you can dynamically set this
} catch (Exception e)
{
    result.addValue(e.toString());
}

3. create the Operation mapping with these 2 message mappings - 1st mmaping will be actual transformation and 2nd mapping will be creating the attachment and CSV file. In your operation mapping the target service interface should have the message type of single field.

4. go to integration directory and setup your receiver HTTP_AAE channel as below -

Here, note is the target HTTP form field name, you can replace as per your scenario-

5. That's all, you do not have to use message transformation bean in the receiver HTTP adapter.
6. In the UDF you can see, I have given a static filename and a constant value to the payload parameter. You can dynamically set the file name and HTTP body (payload value) in your first mapping . for this , you can add two extra field in your first structure and store the file name and payload value there- which can be passed into the second mapping UDF.

7. Once this is setup you can see the message monitoring - the payload will be the value you specify as http payload body and there will be the attachment-

Hope this will help. Please let me know if you are able to process messages succefully.

Thanks

Sugata

0 Kudos

Hi Sugata,

I had tried the same way. Still facing the same issue.

4/4/2019 03:25:42.675 PMInformationMP: processing local module localejbs/sap.com/com.sap.aii.adapter.http/HttpAdapterBean4/4/2019 03:25:43.139 PMErrorError in processing caused by: com.sap.aii.adapter.http.api.HttpAdapterException: STATUS_CODE_NOT_OK- 500 Internal Server Error4/4/2019 03:25:43.139 PMErrorMP: exception caught with cause com.sap.aii.adapter.http.api.HttpAdapterException: STATUS_CODE_NOT_OK- 500 Internal Server Error
0 Kudos

Message mapper 1

0 Kudos

Message mapper 1

Message mapper 2

2 operational mappers.

1 operational mapping from idoc to soap

second operational mapping from soap to http.

code:

0 Kudos

Message mapper 1

Idoc to xml with concatenate commas after each field.

Message mapper 2

MAPPER 1 inputs passed to UDF

2 operational mappers:

1 operational mapping from idoc to soap

second operational mapping from soap to http_AAE.

code:

HTTP Communication

config

0 Kudos

Hi Sugata,

By the way what is file path and are your referring response payload.

This is asynchronous scenario wherein below are the body parameters. A quick example from PostMan,

Ryan-Crosby
Active Contributor
0 Kudos

Hi Narenda,

Error code 500 indicates a problem on the HTTP server side so you will need to find more information about the problem on that end. Once you get more detail surrounding the root cause then you can take the appropriate action to make the necessary changes in your integration scenario.

Regards,

Ryan Crosby

0 Kudos

Hi Ryan,

There is no issue at server side. Same is working perfectly fine in POSTMAN and there is no network/infra issues.

Ryan-Crosby
Active Contributor
0 Kudos

If it were the same you wouldn't be experiencing a problem. You should review error code 500 to understand what it means - try as you might to resolve it from the client end but without knowing the exact issue you will need to get lucky to happen across the root cause.

sugata_bagchi2
Active Contributor
0 Kudos

Hi Narendra,
As per your screenshot, I think you are trying to send the payload after the content conversion - the csv file as an attachment and the file path as HTTP body, is this correct?

did you swapped the payload to set the csv file as attachment? I can see you have only used the MessageTransformation Bean to convert the XML from mapping.

And I think, to set the attachment name dynamically you need some adapter module after the conversion is done.

Thanks

Sugata

0 Kudos

Hi Sugata,

Yes - the csv file as an attachment and the file path as HTTP body.

I haven't used any swap only the MessageTransformation Bean module.

Also let me know the additional adapter module required for this interface configuration.

0 Kudos

Please find the snapshot. Thanks!

0 Kudos

Hi Sugata,

Yes, the csv file as an attachment and the file path as HTTP body.

sugata_bagchi2
Active Contributor
0 Kudos

Hello Narendra,
Please check the following points -

1. how do you want to send the data to the receiver ? if it is only a simple POST then you do not have to use the setForm or multipart.

2. if you are sending data to target as a form based data then the main payload should be defined in the receiver channel according to the form input for the target HTML form. The payload will be passed to that input parameter. And in this case the content type should be application/x-www-form-urlencoded. In this case the entire payload will be mapped to the target HTML form input.

3. In your UDF, the Adapter attribute namespace is using for File and REST, for HTTP adapter, it is

http://sap.com/xi/XI/System

And the paramters are URLParamOne,URLParamTwo etc. until PramaSix.

Thanks

Sugata

0 Kudos

Hello Sugata,

Regards point no 1, this is not a simple POST method and it works only with multi form-data content-type. Please find below snapshot:

regards point no 2, it is not working with content type 'application/x-www-form-urlencoded' and please find the API correct code snippets below:

regards point no 3, the attribute namespace is corrected in ASMA UDF and resent the message but though facing same error i.e.

DynamicConfiguration conf1 = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "filename"); String filename=conf1.get(key1); DynamicConfiguration conf2 = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey key2 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System", "filename"); filename = "AIL_INV_" + CREDAT + "_" + CRETIM + ".csv"; conf2.put(key2,filename); return filename;

Error:

Transmitting the message to endpoint <local> using connection AFW failed, due to: com.sap.aii.adapter.http.api.HttpAdapterException: STATUS_CODE_NOT_OK- 500 Internal Server Error

There is no URL parameters and API has only body parameters.

key - file

value - AIL_INV_20190402_105412.csv

file upload in form-data content-type