Problem Getting Connected (I think)

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Problem Getting Connected (I think)

Post by emhill »

Very new to HTTPAPI and I have a JSON string I'm attempting to send and am having some issues getting connected or sending the JSON. I've run the JSON data through a verifier and it checked out ok. I also sent the string to the receiving company and they said it looked good to them.

Now here is my RPG code snippet:

Code: Select all

http_xproc(HTTP_POINT_ADDL_HEADER:    
           %paddr(add_headers));      
                                      
rc = http_post(claimurl:              
               %addr(jsonpath: *data):
               %len(jsonpath):        
               resultpath:            
               HTTP_TIMEOUT:          
               HTTP_USERAGENT:        
               'application/json');   
               
P add_headers     B                                      
D                 PI                                     
D  headers                   32767a   varying            
                                                         
D crlf            c                   x'0D25'            
                                                         
 /free                                                   
                                                         
  headers = 'client_id:' + %trim(client_id) + crlf +     
            'client_secret:' + %trim(client_sec) + crlf +
            'X-Request-ID:' + %trim(o_reqid) + crlf;     
                                                         
                                                         
P                 E                                      
 /end-free
  
This is what I get in debug:

Code: Select all

HTTPAPI Ver 1.43 released 2021-04-19
NTLM Ver 1.4.0 released 2014-12-22
OS/400 Ver V7R4M0

http_url_post(): entered
http_persist_open(): entered
http_long_ParseURL(): entered
DNS resolver retrans: 2
DNS resolver retry  : 2
DNS resolver options: x'00000136'
DNS default domain: INDCOMPUTER.COM
DNS server found: 192.168.10.6
DNS server found: 8.8.8.8
DNS server found: 1.1.1.1
Nagle's algorithm (TCP_NODELAY) disabled.
SNI hostname set to: anypoint.mulesoft.com
-------------------------------------------------------------------------------------
Dump of server-side certificate information:
-------------------------------------------------------------------------------------
Cert Validation Code = 6000
-----BEGIN CERTIFICATE-----
MIIF/TCCBOWgAwIBAgIQCJuC+6QP8OglAsSI/RqEETANBgkqhkiG9w0BAQsFADBG
MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRUwEwYDVQQLEwxTZXJ2ZXIg
Q0EgMUIxDzANBg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AEggFsAWoAdwApeb7wnjk5IfBW
c59jpXflvld9nGAK+PlNXSZcJV3HhAAAAXmcTT5FAAAEAwBIMEYCIQCYimDo4Y6a
MHM4Zrlhk0616d4142UUd0QSZ1Cn5zIPawIhAKlZV9VaWCQrrP26g+uzZTeSDL23
nqmcjYczBmqRZaX/AHYAIkVFB1lVJFaWP6Ev8fdthuAjJmOtwEt/XcaDXG7iDwIA
AAF5nE0+ggAABAMARzBFAiANTPac08KfSveRtbseXjPq8cNQx6N4OT9fHvCDLxSU
jQIhAI0zxUAT4cI1MROYD3R4NRASF7LgBA9X9A0V9OpgMuA/AHcAUaOw9f0BeZxW
bbg3eI8MpHrMGyfL956IQpoN/tSLBeUAAAF5nE0+pAAABAMASDBGAiEA4QBpZOKu
QY/6y2luls0C5BlgphEQhVvs4APIRq0DhcwCIQDjzG5CAmBHgPp8wxk3QawabJ5O
78Y4MP/ASvr7PFZJOjANBgkqhkiG9w0BAQsFAAOCAQEAHtwXwaZV0voHmfzHYF/L
SuiXiSYoWXwQ6KGEiuNGQNTDJ5aVF8W7XZjgFbpuSG49sjrS+g69bYjpy3E0ms/O
Z3ykSF2MaeJt6I/F/yWuMs1hYdwZ8WobIwLdx2QZOImCUO7AOYsgxJZaNUKtVgws
NPZoSiBS68GCwxf1ZWdH+GOB0K86pwSrHN58jZJxgKvqLsIBwHCj7cA2vsBOG2Pq
gl4M2BRssAwWRwUvo64+e+RUx02d3RHXjsY0qkGn9JV49u0q+S4VUCPXIqZpBBu4
wQ6Myw2yHAqZCgTO0fiSKvrouIIrrzvRjWJcKh+B67FGpg9oiQIfwafDRM5nsREU
Vg==
-----END CERTIFICATE-----
Serial Number: 08:9B:82:FB:A4:0F:F0:E8:25:02:C4:88:FD:1A:84:11
Common Name: *.anypoint.mulesoft.com
Issuer CN: Amazon
Issuer Country: US
Issuer Org: Amazon
Issuer Org Unit: Server CA 1B
Version: 3
not before: 20210523190000
Unknown Field: 19:00:00 23-05-2021
not after: 20220622185959
Unknown Field: 18:59:59 22-06-2022
pub key alg: 1.2.840.113549.1.1.1
signature algorithm: 1.2.840.113549.1.1.11
Unknown Field: 0382010F003082010A0282010100A991EF24445404CC241DFD3D438BFFE854C86EE0C9C1B2F0EF4597D56F56E9D0C9A59CD84BCC79BE5CE6F6763777B97F8EA99E8180801A0B298AEDC21C80F0502257B06B878420F2CE276FD7F110FBEE49CEBCB242F2284448ADE1D745EF0005394AC62D4EEB0AA2FE7BCED2E6696CA36B9A5E58005D5226308783DE1D83A5DA3A69CB94C5ADD1CDBD4DE566ED13C40CA7E830A4F3B082218EA0FC3DDEA5D36AB3C7FCFA7B8343B6524414A9C27B8FE745931CA458100CE16657A8BEA38FA825469C646447697DFEF1BADD998EB11F7BE11D6D129A50E30509960D24CC054AC6B02E08E5E916A6BE374029CBDAF5A34B859067C6FBAEA768E2B9000D5C4CD1870203010001
Unknown Field: 2048
Unknown Field: C9FB8C434BEE12C010B2BB0B32907376
Unknown Field: 1.2.840.113549.2.5
Unknown Field: 18B8EB388E96D75D53157B505C5F2ACB68E86B83
Unknown Field: F2A65A058455533E1F4B8ADF3D1774F9D711E2AB5BA2846F1BBCB38FD4238841
Unknown Field: 5
Unknown Field: *.anypoint.mulesoft.com
Unknown Field: 0
Unknown Field: 1.3.6.1.5.5.7.3.2
Unknown Field: 1.3.6.1.5.5.7.3.1
Unknown Field: 2.23.140.1.2.1
Unknown Field: http://ocsp.sca1b.amazontrust.com

Protocol Used: TLS Version 1.2
http_persist_post(): entered
http_persist_req(POST) entered.
http_long_ParseURL(): entered
http_long_ParseURL(): entered
do_oper(POST): entered
There are 0 cookies in the cache
POST /mocking/api/v1/sources/exchange/assets/d1bbe75b-3cf4-4bf8-9118-46193638c403/ati-warranty-cloud-experience-api/1.0.30/m/warranties/claims/submit HTTP/1.1
Host: anypoint.mulesoft.com
User-Agent: http-api/1.43
Content-Type: application/json
Content-Length: 48
client_id:03224
client_secret:lmf3yvajxkz
X-Request-ID:DAM55D5LLZ5SH5GK2HUOXX33R3ZAIZ5P


senddoc(): entered
/eric/4WARD/atd_4ward_claim_20210730_144222.json
recvresp(): entered
HTTP/1.1 400 Bad Request
content-security-policy: sandbox;
Content-Type: application/json
Date: Fri, 30 Jul 2021 19:42:23 GMT
ms2-error: MockRequestError
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-content-security-policy: sandbox;
x-envoy-decorator-operation: service.mocking.svc.cluster.local:80/*
x-envoy-upstream-service-time: 941
x-request-id: DAM55D5LLZ5SH5GK2HUOXX33R3ZAIZ5P
Content-Length: 148
Connection: keep-alive


SetError() #13: HTTP/1.1 400 Bad Request
recvresp(): end with 400
recvdoc parms: identity 148
header_load_cookies() entered
recvdoc(): entered
SetError() #0:
recvdoc(): Receiving 148 bytes.
{"code":"REQUEST_VALIDATION_ERROR","message":"Invalid schema for content type application/json. Errors: expected type: JSONObject, found: String. "}
SetError() #13: HTTP/1.1 400 Bad Request
http_close(): entered
It looks like I'm getting connected but I'm not sure what is happening after that? This is a test URL so it is not really checking credentials. Does that error mean anything to anyone?

Thanks!
Scott Klement
Site Admin
Posts: 670
Joined: Sun Jul 04, 2021 5:12 am

Re: Problem Getting Connected (I think)

Post by Scott Klement »

Instead of sending JSON data to the server, you're sending a path name. You need to send them the data that's in the file rather than just the name of the file!

http_post won't do this for you (and I wouldn't recommend using http_post in 2021, anyway... http_post is an old, outdated, way to do things!)

Please consider using http_stmf() or http_req().
Scott Klement
Site Admin
Posts: 670
Joined: Sun Jul 04, 2021 5:12 am

Re: Problem Getting Connected (I think)

Post by Scott Klement »

Based on the code you posted, here's an example of using http_stmf(). As you can see, its actually a little simpler than http_post, and I really think it'll work a lot better for you.

Code: Select all

http_xproc(HTTP_POINT_ADDL_HEADER:
           %paddr(add_headers));

monitor;
  http_stmf( 'POST'
           : claimurl
           : resultpath
           : jsonpath
           : 'application/json');
on-error;
  errorMsg = http_error();
endmon;
 
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: Problem Getting Connected (I think)

Post by emhill »

Just to make sure:

"claimurl" = the URL where I'm sending/receiving data
"resultpath" = the IFS path where I want the returned JSON stored
"jsonpath" = the IFS path where the JSON data to send is stored

Just making sure...

That does seem simpler. Looks like I'm going to be doing a bunch of this going forward so I'm going to get a baptism by fire.

Thanks Scott.
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: Problem Getting Connected (I think)

Post by emhill »

Tried the http_stmf() procedure and got nothing returned but got this in debug:

Got the message - sendraw(): entered

Then the JSON data I sent.

At the bottom of debug I got this:

(GSKit) I/O: Broken pipe.
ssl_error(406): (GSKit) I/O: Broken pipe.
SetError() #55: CommSSL_BlockWrite: send: (GSKit) I/O: Broken pipe.
http_close(): entered

Does this ring a bell?
msddcb
Posts: 21
Joined: Wed Jul 28, 2021 5:12 am

Re: Problem Getting Connected (I think)

Post by msddcb »

I would suggest checking the authorities on the IFS directories first.

Also check the values for resultPath and jsonPath are correct.

Broken pipe means (more or less) that you were disconnected in the middle of writing the data.

Don
Scott Klement
Site Admin
Posts: 670
Joined: Sun Jul 04, 2021 5:12 am

Re: Problem Getting Connected (I think)

Post by Scott Klement »

The "broken pipe" error means that you were disconnected while it was sending or receiving data.
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: Problem Getting Connected (I think)

Post by emhill »

We think it is a certificate issue. Getting with my network folks now.

Thanks!!!
emhill
Posts: 43
Joined: Thu Jul 29, 2021 1:15 pm

Re: Problem Getting Connected (I think)

Post by emhill »

When looking at the debug where it shows my JSON string, it is chopping off some characters at the end. Is there a limit to the size of the outgoing JSON? I think this came to over 177,000 characters. When I decrease the size of the string I don't get the broken pipe error anymore.

Does the http_stmf() procedure have a limit to the outgoing size? If not does anyone see anything wrong with this JSON string?:

Code: Select all

{
    "claim": [
        {
            "identifier": "03224",
            "businessCategoryConfiguration": "ATI",
            "submittalIndicator": "I",
            "repairOutlet": "0113400002",
            "serialNumber": "6511670719",
            "trackingNumber": "M023439398",
            "claimNumber": "",
            "claimType": "Machine",
            "repairOrder": "270871",
            "specialActivityCode": "",
            "campaignTemplateName": "",
            "repairOrderOpenDate": "2021-06-24",
            "laborLastAppliedDate": "2021-07-09",
            "primaryFailedPart": "29556882",
            "primaryFailedPartSerialNumber": "6511670719",
            "dateOfPurchase": "",
            "complaintCode": "EL02",
            "failureCode": "",
            "replacementUnitSerialNumber": "",
            "serviceReplacementIndicator": "",
            "technicianName": "SHANE MORRISON JR",
            "preAuthorizationRequired": "",
            "preAuthorizationReason": "",
            "preAuthorizationComments": "",
            "workPerformedComments": "Test Comments",
            "registrationInfo": {
                "customerInfo": {
                    "customerName": "MOHAWK VALLEY FREIGHTLINER",
                    "street": "PO BOX 201",
                    "city": "YORKVILLE",
                    "state": "NY",
                    "postalCode": "13316",
                    "countryCode": "",
                    "email": "OFFICE@MVFREIGHTLINER.COM",
                    "phone": "3157363330"
                },
                "vehicleInfo": {
                    "preDelivery": "",
                    "inServiceDate": "",
                    "vocationCode": "ST10",
                    "customerAssetNumber": "",
                    "vehicleIdentificationNumber": "3ALACXD21LDLY1373",
                    "vehicleMileage": "10597",
                    "usageUnit": "mi",
                    "engineMake": "",
                    "engineModel": "",
                    "engineYear": "",
                    "executiveOrderDesignation": ""
                }
            },
            "diagnosticCodes": [
                {
                    "lineNumber": "1",
                    "diagnosticCode": "P0715"
                }
            ],
            "serviceParts": [
                {
                    "lineNumber": "1",
                    "failedPartNumber": "29556884",
                    "failePartSerialNumber": "",
                    "replacedPartNumber": "",
                    "partQuantity": "1",
                    "partUnit": "ea"
                }
            ],
            "netItems": [

            ],
            "laborCodes": [
                {
                    "lineNumber": "2",
                    "laborOperationCode": "00096400",
                    "laborTimeActual": "5.0",
                    "laborTimeUnit": "hr",
                    "reason": "Test Reason"
                },
                {
                    "lineNumber": "1",
                    "laborOperationCode": "00096501",
                    "laborTimeActual": "10.0",
                    "laborTimeUnit": "hr",
                    "reason": "Test Reason"
                },
                {
                    "lineNumber": "3",
                    "laborOperationCode": "00096901",
                    "laborTimeActual": "10.0",
                    "laborTimeUnit": "hr",
                    "reason": "Test Reason"
                }
            ],
            "turnAroundData": {
                "dateTimeCustomerRequestedService": "2021-07-07 08:00:00",
                "dateTimeDistributorScheduledService": "2021-07-07 08:00:00",
                "dateTimeOfVehicleArrival": "2021-06-24 09:14:00",
                "dateTimeLaborFirstApplied": "2021-07-07 11:50:00",
                "dateTimeFirstPartOrdered": "2021-06-29 10:42:00",
                "dateTimeLastPartArrived": "2021-07-07 11:00:00",
                "dateTimeLaborLastRecordedOrApplied": "2021-07-09 09:03:00",
                "dateTimeRepairOrderClosed": "2021-07-09 13:32:00",
                "dateTimeCustomerNotified": "2021-07-09 09:56:00",
                "repairOrderOpenDateTime": "2021-06-24 11:10:00"
            }
        }
    ]
}
Scott Klement
Site Admin
Posts: 670
Joined: Sun Jul 04, 2021 5:12 am

Re: Problem Getting Connected (I think)

Post by Scott Klement »

I've not heard of a certificate causing an error like this... It could be a cipher error -- like, a bug in the cryptography is causing things to go awry, so it disconnects. ...but I can't see how it'd be a certificate? The certificate exchange happened at the start, and it was accepted...

At any rate, let us know if you figure it out.
Post Reply