
To interface with the selected SAP service through an HTTP Destination that points to an SAP NetWeaver Gateway server, you can call the generated proxy classes from your application.
You need to create the user interface for rendering your application.
The following are examples of a portal component that calls the generated classes and methods of an SAP service that handles flights, named RMTSAMPLEFLIGHTService :
Create an instance of the SAP service using the pre-configured destination name:
String destinationName = "MyDest";
RMTSAMPLEFLIGHTService proxy = new RMTSAMPLEFLIGHTService(destinationName);
Filter the flight collection according to airline:
List<Flight> flightCollection = service.getFlightCollection("$filter=carrid eq 'AA'");
response.getWriter().write("Number of flights in the collection: " + flightCollection.size());
Create a booking object and provide the booking information for a specific flight of the carrier:
Booking booking = new Booking();
booking.setcarrid("AA");
booking.setconnid("0017");
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
Date fldate = formatter.parse("20110420");
booking.setfldate(fldate);
booking.setCUSTOMID("00004617");
booking.setCOUNTER("00000000");
booking.setAGENCYNUM("00000325");
booking.setPASSNAME("Example Passenger Name1");
Create a new booking in the booking collection for a specific flight. It returns the newly created booking entry with additional information, for example, the booking ID, and prints the booking ID of the newly created booking entry:
Booking booking2 = service.createBookingCollectionEntry(booking);
response.getWriter().write("success: booking id: " + booking2.getbookid());
Update a booking entry by providing a new passenger name. If successful, it gets the booking entry and prints the updated passenger name:
booking2.setPASSNAME("Example Passenger Name2");
boolean updateSuccess = service.updateBookingCollectionEntry(booking2);
if (updateSuccess)
{
Booking booking3 = service.getBookingCollectionEntry(booking2.getcarrid(), booking2.getconnid(), booking2.getfldate(), booking2.getbookid());
response.getWriter().write("booking3: " + booking3.getPASSNAME());
Delete a booking entry and print the status:
boolean deletedSuccess = service.deleteBookingCollectionEntry(booking3.getcarrid(), booking3.getconnid(), booking3.getfldate(), booking3.getbookid());
if (deletedSuccess)
{
response.getWriter().write("Deleted");
}
Get the booking collection of a specific flight (navigation property) and print all the passenger names:
List<Booking> bookingCollection = service.getFlightCollectionEntry(booking.getcarrid(), booking.getconnid(), fldate).flightBookings();
for (Booking bookingEntry : bookingCollection) {
response.getWriter().write("Passenger name - " + bookingEntry.getPASSNAME());
}
Get the flights between specific dates for a specific destination:
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
Date date = formatter.parse("20110420");
List<Flight> availableFlights = RMTSAMPLEFLIGHTService.getInstance().GetAvailableFlights(date, date, "NEW YORK", "SAN FRANCISCO");
response.getWriter().write(availableFlights.size());
The following are examples of a portal component that calls the generated classes and methods of an SAP service named Workflow , which obtains a list of workflow tasks from the SAP NetWeaver Gateway server:
Get a list of workflow tasks from the SAP NetWeaver Gateway server:
List<WorkflowTask> taskList = service.getWorkflowTaskCollection();
Get the attachment of the first task in the task list:
Attachment taskAttachment = taskList.get(1).Attachments().get(1);
Get the byte buffer of a media resource:
byte[] bytes = service.getMediaResourceBytes(taskAttachment.getMediaResource());
After getting the byte buffer, you need to use the media resource according to your needs. For example, if the media resource type is a GIF, then write the byte buffer to a GIF file.
Handling Errors and Exceptions
In your application, you need to handle errors and exceptions thrown by the proxy, using ProxyException .
catch (ProxyException e) {
response.getWriter().write(e.getMessage());
}