Sample Code for Accessing Web Services with REST
Sample Java code that shows a complete Sabre Web Services request in a plug-in follows.
Request with json payload
// Set url to the correct Sabre Web Services action name
String url = "/v1/lists/utilities/aircraft/equipment?aircraftcode=TU5";
HTTPMethod method = HTTPMethod.GET;
AuthTokenType authTokenType = AuthTokenType.SESSIONLESS;
String contentType="application/json";
String payload=...
// Retrieve a reference to ISRWCommunication
ISRWCommunication com = Activator.getDefault().getServiceReference(ISRWCommunication.class);
// Create the request
Rest2SgRequest request = new Rest2SgRequest();
request.setUrl(url);
request.setHttpMethod(method);
request.setAuthTokenType(authTokenType);
request.setContentType(contentType);
request.setPayload(payload);
// Send the request
Rest2SgServiceClient client = new Rest2SgServiceClient(com);
ClientResponse <Rest2SgResponse> rsp = client.send(request);
// Retrieve the response
if (rsp.isSuccess()) {
Rest2SgResponse response = rsp.getPayload();
// Response for the sent request
String responseBody = response.getResponseBody();
}
Request with path parameters
// Set path to the correct Sabre Web Services action name
String url = "/v1/historical/flights/DFW/seasonality?pointofsalecountry=US";
HTTPMethod method = HTTPMethod.GET;
AuthTokenType authTokenType = AuthTokenType.SESSIONLESS;
// Retrieve a reference to ISRWCommunication
ISRWCommunication com = Activator.getDefault().getServiceReference(ISRWCommunication.class);
// Create the request
Rest2SgRequest request = new Rest2SgRequest();
request.setUrl(url);
request.setHttpMethod(method);
request.setAuthTokenType(authTokenType);
// Send the request
Rest2SgServiceClient client = new Rest2SgServiceClient(com);
ClientResponse <Rest2SgResponse> rsp = client.send(request);
// Retrieve the response
if (rsp.isSuccess()) {
Rest2SgResponse response = rsp.getPayload();
// Response for the sent request
String responseBody = response.getResponseBody();
}
Corresponding
Authorization
entries in redapp.xml
<Authorization name="com.sabre.edge.cf.rest2sg.Rest2Sg">
<Action name="/v1/lists/utilities/aircraft/equipment" threshold="1" />
<Action name="/v1/historical/flights/{destination}/seasonality" threshold="1" />
</Authorization>