Show TOC

Background documentationUsing the Gateway Proxy Locate this document in the navigation structure

 

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.

Note Note

You need to create the user interface for rendering your application.

End of the note.

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:

    Example Example

    1. String destinationName = "MyDest";
      RMTSAMPLEFLIGHTService proxy = new RMTSAMPLEFLIGHTService(destinationName);
      
    End of the code.
  • Filter the flight collection according to airline:

    Example Example

    1. List<Flight>  flightCollection = service.getFlightCollection("$filter=carrid eq 'AA'");
      response.getWriter().write("Number of flights in the collection: " + flightCollection.size());
      
    End of the code.
  • Create a booking object and provide the booking information for a specific flight of the carrier:

    Example Example

    1. 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");
      
    End of the code.
  • 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:

    Example Example

    1. Booking booking2 = service.createBookingCollectionEntry(booking);
      response.getWriter().write("success: booking id: " + booking2.getbookid());
      
    End of the code.
  • Update a booking entry by providing a new passenger name. If successful, it gets the booking entry and prints the updated passenger name:

    Example Example

    1. 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());
      
    End of the code.
  • Delete a booking entry and print the status:

    Example Example

    1. boolean deletedSuccess = service.deleteBookingCollectionEntry(booking3.getcarrid(), booking3.getconnid(), booking3.getfldate(), booking3.getbookid());
      if (deletedSuccess)
      {
      response.getWriter().write("Deleted");
      }
      
    End of the code.
  • Get the booking collection of a specific flight (navigation property) and print all the passenger names:

    Example Example

    1. List<Booking> bookingCollection = service.getFlightCollectionEntry(booking.getcarrid(), booking.getconnid(), fldate).flightBookings();
      for (Booking bookingEntry : bookingCollection) {
      response.getWriter().write("Passenger name - " + bookingEntry.getPASSNAME());
      }
      
    End of the code.
  • Get the flights between specific dates for a specific destination:

    Example Example

    1. 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());
      
    End of the code.

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:

    Example Example

    1. List<WorkflowTask> taskList = service.getWorkflowTaskCollection();
    End of the code.
  • Get the attachment of the first task in the task list:

    Example Example

    1. Attachment taskAttachment = taskList.get(1).Attachments().get(1);
    End of the code.
  • Get the byte buffer of a media resource:

    Example Example

    1. byte[] bytes = service.getMediaResourceBytes(taskAttachment.getMediaResource());
      
    End of the code.

    Note Note

    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.

    End of the note.
Handling Errors and Exceptions

In your application, you need to handle errors and exceptions thrown by the proxy, using ProxyException.

Example Example

  1. catch (ProxyException e) {
      response.getWriter().write(e.getMessage());
    }
    
End of the code.