Posts: 204
Threads: 51
Joined: Mar 2018
Reputation:
3
Location: Bryan, TX
Howdy All!
I am exposing my web reservation system to Viator and I need to implement a REST api around my internal classes.
I have written content handlers for each REST api call with the appropriate path.
I am using Advanced REST Client to test my application running as a service.
I put my URL and method to POST. I copy my XML for processing into the Body of the request and issue it.
From within the C++ Builder IDE, I set and get a breakpoint on handler's Execute().
I can't see anywhere in the THttpRequest object where the content passed in is.
How do I read / fetch it from within my event?
Thanks in advance,
Shane
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
Content Handlers.... are you using them already?
function xxx.Execute(aRequest: THttpRequest; aReply: THttpReply;
const aPathname: string; aSession: TIWApplication; aParams: TStrings): Boolean;
if aRequest.CommandType = hcPost then begin
with TStreamReader.Create(aRequest.PostStream) do try
xJSON := ReadToEnd;
finally Free; end;
Posts: 204
Threads: 51
Joined: Mar 2018
Reputation:
3
Location: Bryan, TX
11-25-2019, 10:19 PM
(This post was last modified: 11-26-2019, 02:55 AM by ShaneStump.)
Howdy Jose!
I am NOT attaching an XML file. I am putting it into the body of the request.
The Request->Files->Count is zero any how (I had already checked that).
I have tried several things with Advanced Rest Client and when I look at the RawHeaders property of THttpRequest, the last one lists as "content-length: 2500".
I can't figure out how to get the content. The content is an XML stream like below:
<?xml version="1.0" encoding="UTF-8"?>
<BookingRequest xmlns="http://toursgds.com/api/01">
<ApiKey>{AD7276FB-9F98-4495-BB1A-E24E99B82E06}</ApiKey>
<ResellerId>12345</ResellerId>
<SupplierId>67890</SupplierId>
<ExternalReference>10051374722992645</ExternalReference>
<Timestamp>2019-11-13T12:43:44.014Z</Timestamp>
<Parameter>
<Name>CompanyID</Name>
<Value>75</Value>
</Parameter>
<Parameter>
<Name>CustomerID</Name>
<Value>19229</Value>
</Parameter>
<Extension>
<any/>
</Extension>
<BookingReference>000000028</BookingReference>
<TravelDate>2019-11-25</TravelDate>
<SupplierProductCode>HIC</SupplierProductCode>
<Location>Kingston, CA</Location>
<TourOptions>
<SupplierOptionCode>HIC</SupplierOptionCode>
<SupplierOptionName>Heart of the Islands Cruise</SupplierOptionName>
<TourDepartureTime>12:30:00</TourDepartureTime>
<TourDuration>PT3H</TourDuration>
<Option>
<Name>Location</Name>
<Value>CW</Value>
</Option>
<Option>
<Name>Resource</Name>
<Value>IQ</Value>
</Option></TourOptions>
<CurrencyCode>USA</CurrencyCode>
<Amount>250.00</Amount>
<Traveller>
<TravellerIdentifier>1</TravellerIdentifier>
<TravellerTitle>Mr</TravellerTitle>
<GivenName>Shane</GivenName>
<Surname>Stump</Surname>
<AgeBand>ADULT</AgeBand>
<LeadTraveller>true</LeadTraveller>
</Traveller>
<Traveller>
<TravellerIdentifier>2</TravellerIdentifier>
<TravellerTitle>Mrs</TravellerTitle>
<GivenName>Sandi</GivenName>
<Surname>Stump</Surname>
<AgeBand>ADULT</AgeBand>
<LeadTraveller>false</LeadTraveller>
</Traveller>
<Traveller>
<TravellerIdentifier>3</TravellerIdentifier>
<TravellerTitle>Miss</TravellerTitle>
<GivenName>Cassie</GivenName>
<Surname>Stump</Surname>
<AgeBand>ADULT</AgeBand>
<LeadTraveller>false</LeadTraveller>
</Traveller>
<TravellerMix>
<Adult>3</Adult>
<Child>0</Child>
<Youth>0</Youth>
<Infant>0</Infant>
<Senior>0</Senior>
<Total>3</Total>
</TravellerMix>
<SpecialRequirement>Special Requirement</SpecialRequirement>
<SupplierNote>Customer notes</SupplierNote>
<AdditionalRemarks>
<Remark>Additional remarks #1.</Remark>
<Remark>Additional remarks #2.</Remark>
</AdditionalRemarks>
<ContactDetail>
<ContactType>MOBILE</ContactType>
<ContactName>Shane Stump </ContactName>
<ContactValue>US+1 123-456-7890</ContactValue>
</ContactDetail>
<ContactEmail>MSG-8b17fa92-7b35-4fdb-9f18-f8a69252e019+BR-999999999@expmessaging.tripadvisor.com</ContactEmail>
<AvailabilityHoldReference></AvailabilityHoldReference>
</BookingRequest>
The stream is 2500 bytes.
How do I get it?
Thanks in advance,
Shane
Posts: 204
Threads: 51
Joined: Mar 2018
Reputation:
3
Location: Bryan, TX
Good morning,
I sure hope I get an answer before long as I have a conference call with my board in 4 hours and I have to give a timeframe on this.
I just need to know if I can do this in IW or if I need to look for a different solution.
Thanks,
Shane
Posts: 204
Threads: 51
Joined: Mar 2018
Reputation:
3
Location: Bryan, TX
Thanks.
I will have a further look after my board gives me a colonoscopy this morning?.
All the best,
Shane
Posts: 204
Threads: 51
Joined: Mar 2018
Reputation:
3
Location: Bryan, TX
11-26-2019, 03:13 PM
(This post was last modified: 11-26-2019, 03:22 PM by ShaneStump.)
Jose,
It is working in Delphi example but not in my C++ application. The handler gets executed, but the content isn't there.
I will need to see if there is anything else changed or if the is a compatibility with C++ Builder.
Thanks,
Shane
Howdy All!
I figured out the DIFFERENCE in the example / my code!
In the ServerController, need to add the following line to my ConfigBase event:
RegisterContentType(L"application/xml");
Now it works!
Thanks for the help,
Shane