Entering content frame

This graphic is explained in the accompanying text Examples for Using the Destination Service API Locate the document in its SAP Library structure

The following examples show how to use the Destination service to set up HTTP(S) connections. The first example shows how to establish the connection using an existing destination. The second example shows how to create a destination using Basic Authentication.

Needed Imports

import com.sap.security.core.server.destinations.api.DestinationService;
import com.sap.security.core.server.destinations.api.Destination;
import com.sap.security.core.server.destinations.api.DestinationException;
import com.sap.security.core.server.destinations.api.HTTPDestination;

Note

In addition, your application needs classloader references to tc~sec~destinations~service and tc~sec~destinations~interface. For more information about setting references on the SAP J2EE Engine, see Referencing Other Components.

Establishing an HTTP Connection Using an Existing Destination

The following example shows how to set up a connection to the HTTP destination dst-1. The URL and user authentication information have been stored in the Destination service and have been maintained in the Visual Administrator. The authentication method that is used for the connection depends on the settings in the destination (none, Basic Authentication, X.509 client certificates, or SAP logon tickets). If the URL saved in the destination uses HTTPS, then SSL with server authentication will be used to secure the connection.

Code Example for Establishing an HTTP Connection Using an Existing Destination

    DestinationService dstService = (DestinationService) 
    ctx.lookup(DestinationService.JNDI_KEY);
    
    if (dstService == null)
        throw new NamingException("Destination Service not available");
    
    Destination destination = dstService.getDestination("HTTP","dst-1");
    //for HTTP destination: cast
    HTTPDestination httpDestination = (HTTPDestination) destination;
    //obtain a HTTPUrlConnection from the destinationHttpURLConnection
    httpConnection = httpDestination.getURLConnection();

Creating a New HTTP Destination

The following example shows how to create a new destination dst-2 and store it. All data is stored in the J2EE Engine’s secure storage area. The data is stored encrypted if the SAP Java Cryptographic Toolkit has been installed.

The created destination may be maintained using the Visual Administrator.

Code Example for Creating a New HTTP Destination

    DestinationService dstService = (DestinationService)
    ctx.lookup(DestinationService.JNDI_KEY);
    if (dstService == null)
        throw new NamingException("Destination Service not available");
    
    //Note: this only created the destination
    //it needs to be stored using dstService.storeDestination

    
    HTTPDestination destination = (HTTPDestination)
    dstService.createDestination("HTTP");
    destination.setUrl(url);
    destination.setName(name);
    destination.setUsernamePassword("testuser""abc123");
    dstService.storeDestination("HTTP", destination);

 

 

Leaving content frame