Chapter 119. SAP Component The SAP component is a package consisting of ten different SAP components. There are remote function call (RFC) components that support the sRFC, tRFC, and qRFC protocols and there are IDoc components that facilitate communication using messages in IDoc format. The component uses the SAP Java Connector (SAP JCo) library to facilitate bidirectional communication with SAP and the SAP IDoc library to transmit the documents in the Intermediate Document (IDoc) format. 119.1. Dependencies Add the following dependency to your pom.xml for this component: <dependency> <groupId>org.fusesource</groupId> <artifactId>camel-sap-starter</artifactId> <version>4.8.3.redhat-00004</version> </dependency> 119.1.1. Additional platform restrictions for the SAP component Because the SAP component depends on the third-party JCo 3 and IDoc 3 libraries, it can only be installed on the platforms that these libraries support. 119.1.2. SAP JCo and SAP IDoc libraries A prerequisite for using the SAP component is that the SAP Java Connector (SAP JCo) libraries and the SAP IDoc library are installed into the lib/ directory of the Java runtime. You must make sure that you download the appropriate set of SAP libraries for your target operating system from the SAP Service Marketplace. The names of the library files vary depending on the target operating system, as shown below. Table 119.1. Required SAP Libraries SAP Component Linux and UNIX Windows SAP JCo 3 sapjco3.jar libsapjco3.so sapjco3.jar sapjco3.dll SAP IDoc sapidoc3.jar sapidoc3.jar 119.2. URI format There are two different kinds of endpoint provided by the SAP component: the Remote Function Call (RFC) endpoints, and the Intermediate Document (IDoc) endpoints. The URI formats for the RFC endpoints are as follows: The URI formats for the IDoc endpoints are as follows: The URI formats prefixed by sap- endpointKind -destination are used to define destination endpoints (in other words, Camel producer endpoints) and destinationName is the name of a specific outbound connection to an SAP instance. Outbound connections are named and configured at the component level. The URI formats prefixed by sap- endpointKind -server are used to define server endpoints (in other words, Camel consumer endpoints) and serverName is the name of a specific inbound connection from an SAP instance. Inbound connections are named and configured at the component level. The other components of an RFC endpoint URI are as follows: rfcName (Required) In a destination endpoint URI, is the name of the RFC invoked by the endpoint in the connected SAP instance. In a server endpoint URI, is the name of the RFC handled by the endpoint when invoked from the connected SAP instance. queueName Specifies the queue this endpoint sends an SAP request to. The other components of an IDoc endpoint URI are as follows: idocType (Required) Specifies the Basic IDoc Type of an IDoc produced by this endpoint. idocTypeExtension Specifies the IDoc Type Extension, if any, of an IDoc produced by this endpoint. systemRelease Specifies the associated SAP Basis Release, if any, of an IDoc produced by this endpoint. applicationRelease Specifies the associated Application Release, if any, of an IDoc produced by this endpoint. queueName Specifies the queue this endpoint sends an SAP request to. 119.2.1. Options for RFC destination endpoints The RFC destination endpoints ( sap-srfc-destination , sap-trfc-destination , and sap-qrfc-destination ) support the following URI options: Name Default Description stateful false If true , specifies that this endpoint initiates an SAP stateful session transacted false If true , specifies that this endpoint initiates an SAP transaction 119.2.2. Options for RFC server endpoints The SAP RFC server endpoints ( sap-srfc-server and sap-trfc-server ) support the following URI options: Name Default Description stateful false If true , specifies that this endpoint initiates an SAP stateful session. propagateExceptions false (sap-trfc-server endpoint only) If true , specifies that this endpoint propagates exceptions back to the caller in SAP, instead of the exchange's exception handler. 119.2.3. Options for the IDoc List Server endpoint The SAP IDoc List Server endpoint ( sap-idoclist-server ) supports the following URI options: Name Default Description stateful false If true , specifies that this endpoint initiates an SAP stateful session. propagateExceptions false If true , specifies that this endpoint propagates exceptions back to the caller in SAP, instead of the exchange's exception handler. 119.2.4. Summary of the RFC and IDoc endpoints The SAP component package provides the following RFC and IDoc endpoints: sap-srfc-destination Camel SAP Synchronous Remote Function Call Destination Camel component. This endpoint should be used in cases where Camel routes require synchronous delivery of requests to and responses from an SAP system. Note The sRFC protocol used by this component delivers requests and responses to and from an SAP system with best effort . In case of a communication error while sending a request, the completion status of a remote function call in the receiving SAP system remains in doubt . sap-trfc-destination Camel SAP Transactional Remote Function Call Destination Camel component. This endpoint should be used in cases where requests must be delivered to the receiving SAP system at most once . To accomplish this, the component generates a transaction ID, tid , which accompanies every request sent through the component in a route's exchange. The receiving SAP system records the tid accompanying a request before delivering the request; if the SAP system receives the request again with the same tid it will not deliver the request. Thus if a route encounters a communication error when sending a request through an endpoint of this component, it can retry sending the request within the same exchange knowing it will be delivered and executed only once. Note The tRFC protocol used by this component is asynchronous and does not return a response. Thus the endpoints of this component do not return a response message. Note This component does not guarantee the order of a series of requests through its endpoints, and the delivery and execution order of these requests may differ on the receiving SAP system due to communication errors and resends of a request. For guaranteed delivery order, please see the Camel SAP Queued Remote Function Call Destination Camel component. sap-qrfc-destination Camel SAP Queued Remote Function Call Destination Camel component. This component extends the capabilities of the Transactional Remote Function Call Destination camel component by adding in order delivery guarantees to the delivery of requests through its endpoints. This endpoint should be used in cases where a series of requests depend on each other and must be delivered to the receiving SAP system at most once and in order . The component accomplishes the at most once delivery guarantees using the same mechanisms as the Camel SAP Transactional Remote Function Call Destination Camel component. The ordering guarantee is accomplished by serializing the requests in the order they are received by the SAP system to an inbound queue . Inbound queues are processed by the QIN scheduler within SAP. When the inbound queue is activated , the QIN Scheduler will execute the queue requests in order. Note The qRFC protocol used by this component is asynchronous and does not return a response. Thus the endpoints of this component do not return a response message. sap-srfc-server Camel SAP Synchronous Remote Function Call Server Camel component. This component and its endpoints should be used in cases where a Camel route is required to synchronously handle requests from and responses to an SAP system. sap-trfc-server Camel SAP Transactional Remote Function Call Server Camel component. This endpoint should be used in cases where the sending SAP system requires at most once delivery of its requests to a Camel route. To accomplish this, the sending SAP system generates a transaction ID, tid , which accompanies every request it sends to the component's endpoints. The sending SAP system will first check with the component whether a given tid has been received by it before sending a series of requests associated with the tid . The component will check the list of received tid s it maintains, record the sent tid if it is not in that list, and then respond to the sending SAP system, indicating whether or not the tid has already been recorded. The sending SAP system will only then send the series of requests, if the tid has not been previously recorded. This enables a sending SAP system to reliably send a series of requests once to a camel route. sap-idoc-destination Camel SAP IDoc Destination Camel component. This endpoint should be used in cases where a Camel route sends a list of Intermediate Documents (IDocs) to an SAP system. sap-idoclist-destination Camel SAP IDoc List Destination Camel component. This endpoint should be used in cases where a Camel route sends a list of Intermediate documents (IDocs) list to an SAP system. sap-qidoc-destination Camel SAP Queued IDoc Destination Camel component. This component and its endpoints should be used in cases where a Camel route is required to send a list of Intermediate documents (IDocs) to an SAP system in order. sap-qidoclist-destination Camel SAP Queued IDoc List Destination Camel component. This component and its endpoints are used in cases where a camel route sends the Intermediate documents (IDocs) list to an SAP system in order. sap-idoclist-server Camel SAP IDoc List Server Camel component. This endpoint should be used in cases where a sending SAP system requires delivery of Intermediate Document lists to a Camel route. This component uses the tRFC protocol to communicate with SAP as described in the sap-trfc-server-standalone quick start. 119.2.5. SAP RFC destination endpoint An RFC destination endpoint supports outbound communication to SAP, which enable these endpoints to make RFC calls out to ABAP function modules in SAP. An RFC destination endpoint is configured to make an RFC call to a specific ABAP function over a specific connection to an SAP instance. An RFC destination is a logical designation for an outbound connection and has a unique name. An RFC destination is specified by a set of connection parameters called destination data . An RFC destination endpoint will extract an RFC request from the input message of the IN-OUT exchanges it receives and dispatch that request in a function call to SAP. The response from the function call will be returned in the output message of the exchange. Since SAP RFC destination endpoints only support outbound communication, an RFC destination endpoint only supports the creation of producers. 119.2.6. SAP RFC server endpoint An RFC server endpoint supports inbound communication from SAP, which enables ABAP applications in SAP to make RFC calls into server endpoints. An ABAP application interacts with an RFC server endpoint as if it were a remote function module. An RFC server endpoint is configured to receive an RFC call to a specific RFC function over a specific connection from an SAP instance. An RFC server is a logical designation for an inbound connection and has a unique name. An RFC server is specified by a set of connection parameters called server data . An RFC server endpoint will handle an incoming RFC request and dispatch it as the input message of an IN-OUT exchange. The output message of the exchange will be returned as the response of the RFC call. Since SAP RFC server endpoints only support inbound communication, an RFC server endpoint only supports the creation of consumers. 119.2.7. SAP IDoc and IDoc list destination endpoints An IDoc destination endpoint supports outbound communication to SAP, which can then perform further processing on the IDoc message. An IDoc document represents a business transaction, which can easily be exchanged with non-SAP systems. An IDoc destination is specified by a set of connection parameters called destination data . An IDoc list destination endpoint is similar to an IDoc destination endpoint, except that the messages it handles consist of a list of IDoc documents. 119.2.8. SAP IDoc list server endpoint An IDoc list server endpoint supports inbound communication from SAP, enabling a Camel route to receive a list of IDoc documents from an SAP system. An IDoc list server is specified by a set of connection parameters called server data . 119.2.9. Metadata repositories A metadata repository is used to store the following kinds of metadata: Interface descriptions of function modules This metadata is used by the JCo and ABAP runtimes to check RFC calls to ensure the type-safe transfer of data between communication partners before dispatching those calls. A repository is populated with repository data. Repository data is a map of named function templates. A function template contains the metadata describing all the parameters and their typing information passed to and from a function module and has the unique name of the function module it describes. IDoc type descriptions This metadata is used by the IDoc runtime to ensure that the IDoc documents are correctly formatted before being sent to a communication partner. A basic IDoc type consists of a name, a list of permitted segments, and a description of the hierarchical relationship between the segments. Some additional constraints can be imposed on the segments: a segment can be mandatory or optional; and it is possible to specify a minimum/maximum range for each segment (defining the number of allowed repetitions of that segment). SAP destination and server endpoints thus require access to a repository, in order to send and receive RFC calls and in order to send and receive IDoc documents. For RFC calls, the metadata for all function modules invoked and handled by the endpoints must reside within the repository; and for IDoc endpoints, the metadata for all IDoc types and IDoc type extensions handled by the endpoints must reside within the repository. The location of the repository used by a destination and server endpoint is specified in the destination data and the server data of their respective connections. In the case of an SAP destination endpoint, the repository it uses typically resides in an SAP system and it defaults to the SAP system it is connected to. This default requires no explicit configuration in the destination data. Furthermore, the metadata for the remote function call that a destination endpoint makes will already exist in a repository for any existing function module that it calls. The metadata for calls made by destination endpoints thus require no configuration in the SAP component. On the other hand, the metadata for function calls handled by server endpoints do not typically reside in the repository of an SAP system and must instead be provided by a repository residing in the SAP component. The SAP component maintains a map of named metadata repositories. The name of a repository corresponds to the name of the server to which it provides metadata. 119.3. Configuration The SAP component maintains three maps to store destination data, server data, and repository data. The destination data store and the server data store are configured on a special configuration object, SapConnectionConfiguration , which automatically gets injected into the SAP component (in the context of Blueprint XML configuration or Spring XML configuration files). The repository data store must be configured directly on the relevant SAP component. 119.3.1. Configuration Overview The SAP component maintains three maps to store destination data, server data, and repository data. The component's property, destinationDataStore , stores destination data keyed by destination name, the property, serverDataStore , stores server data keyed by server name and the property, repositoryDataStore , stores repository data keyed by repository name. These configurations must be passed to the component during its initialization. Example The following example shows how to configure a sample destination data store and a sample server data store in a Blueprint XML file. The sap-configuration bean (of type SapConnectionConfiguration ) will automatically be injected into any SAP component that is used in this XML file. 119.3.2. Destination Configuration The configurations for destinations are maintained in the destinationDataStore property of the SAP component. Each entry in this map configures a distinct outbound connection to an SAP instance. The key for each entry is the name of the outbound connection and is used in the destinationName component of a destination endpoint URI as described in the URI format section. The value for each entry is a destination data configuration object - org.fusesource.camel.component.sap.model.rfc.impl.DestinationDataImpl - that specifies the configuration of an outbound SAP connection. Sample destination configuration The following Blueprint XML code shows how to configure a sample destination with the name, quickstartDest . For example, after configuring the destination as shown in the preceding Blueprint XML file, you could invoke the BAPI_FLCUST_GETLIST remote function call on the quickstartDest destination using the following URI: 119.3.2.1. Interceptor for tRFC and qRFC destinations The preceding sample destination configuration shows the instantiation of a CurrentProcessorDefinitionInterceptStrategy object. This object installs an interceptor in the Camel runtime, which enables the Camel SAP component to keep track of its position within a Camel route while it is handling RFC transactions. Important This interceptor is critically important for transactional RFC destination endpoints (such as sap-trfc-destination and sap-qrfc-destination ) and must be installed in the Camel runtime for outbound transactional RFC communication to be properly managed. The Destination RFC Transaction Handlers issues warnings into the Camel log if the strategy is not found at runtime. In this situation the Camel runtime will need to be re-provisioned and restarted to properly manage outbound transactional RFC communication. 119.3.2.2. Log on and authentication options The following table lists the log on and authentication options for configuring a destination in the SAP destination data store: Name Default Value Description client SAP client, mandatory log on parameter. user log on user, log on parameter for password based authentication. aliasUser log on user alias, can be used instead of log on user. userId User identity used for log on to the ABAP AS. Used by the JCo runtime, if the destination configuration uses SSO/assertion ticket, certificate, current user ,or SNC environment for authentication. The user ID is mandatory, if neither user nor user alias is set. This ID will never be sent to the SAP backend, it will be used by the JCo runtime locally. passwd log on password, log on parameter for password based authentication. lang log on language, if not defined, the default user language is used. mysapsso2 Use the specified SAP Cookie Version 2 as a log on ticket for SSO based authentication. x509cert Use the specified X509 certificate for certificate based authentication. lcheck Postpone the authentication until the first call - 1 (enable). Used in special cases only. useSapGui Use a visible, hidden, or do not use SAP GUI codePage Additional log on parameter to define the codepage used to convert the log on parameters. Used in special cases only. getsso2 Order an SSO ticket after log on, the obtained ticket is available in the destination attributes. denyInitialPassword If set to 1 , using initial passwords will lead to an exception (default is 0 ). 119.3.2.3. Connection options The following table lists the connection options for configuring a destination in the SAP destination data store: Name Default Value Description saprouter SAP Router string for connection to systems behind a SAP Router. SAP Router string contains the chain of SAP Routers and theirs port numbers and has the form: (/H/<host>[/S/<port>])+ . sysnr System number of the SAP ABAP application server, mandatory for a direct connection. ashost SAP ABAP application server, mandatory for a direct connection. mshost SAP message server, mandatory property for a load balancing connection. msserv SAP message server port, optional property for a load balancing connection. In order to resolve the service names sapmsXXX a lookup in etc/services is performed by the network layer of the operating system. If using port numbers instead of symbolic service names, no lookups are performed and no additional entries are needed. gwhost Allows specifying a concrete gateway, which should be used for establishing the connection to an application server. If not specified, the gateway on the application server is used. gwserv Should be set, when using gwhost. Allows specifying the port used on that gateway. If not specified, the port of the gateway on the application server is used. In order to resolve the service names sapgwXXX a lookup in etc/services is performed by the network layer of the operating system. If using port numbers instead of symbolic service names, no lookups are performed and no additional entries are needed. r3name System ID of the SAP system, mandatory property for a load balancing connection. group Group of SAP application servers, mandatory property for a load balancing connection. network LAN Set this value depending on the network quality between JCo and your target system to optimize performance. The valid values are LAN or WAN (which is relevant for fast serialization only). If you set the network configuration option to WAN , a slower but more efficient compression algorithm is used and the data is analyzed for further compression options. If you set the network configuration to LAN a very fast compression algorithm is used and data analysis is performed only at a very basic level. When you set the LAN option, the compression ratio is not as efficient but the network transfer time is considered to be less significant. The default setting is LAN . serializationFormat rowBased The valid values are rowBased or columnBased . For fast serialization columnBased must be set. The default serialization setting is rowBased . 119.3.2.4. Connection pool options The following table lists the connection pool options for configuring a destination in the SAP destination data store: Name Default Value Description peakLimit 0 Maximum number of active outbound connections that can be created for a destination simultaneously. A value of 0 allows an unlimited number of active connections. Otherwise, if the value is less than the value of jpoolCapacity , it will be automatically increased to this value. Default setting is the value of poolCapacity , or in case of poolCapacity not being specified as well, the default is 0 (unlimited). poolCapacity 1 Maximum number of idle outbound connections kept open by the destination. A value of 0 has the effect that there is no connection pooling (default is 1 ). expirationTime Time in milliseconds after which a free connection held internally by the destination can be closed. expirationPeriod Period in milliseconds after which the destination checks the released connections for expiration. maxGetTime Maximum time in milliseconds to wait for a connection, if the maximum allowed number of connections has already been allocated by the application. 119.3.2.5. Secure network connection options The following table lists the secure network options for configuring a destination in the SAP destination data store: Name Default Value Description sncMode Secure network connection (SNC) mode, 0 (off) or 1 (on). sncPartnername SNC partner, for example: p:CN=R3, O=XYZ-INC, C=EN . sncQop SNC level of security: 1 to 9 . sncMyname Own SNC name. Overrides the environment settings. sncLibrary Path to the library that provides the SNC service. 119.3.2.6. Repository options The following table lists the repository options for configuring a destination in the SAP destination data store: Name Default Value Description repositoryDest Specifies the destination which is used as a repository. repositoryUser If a repository destination is not set, and this property is set, it is used as user for repository calls. This enables you to use a different user for repository lookups. repositoryPasswd The password for a repository user. Mandatory, if a repository user is used. repositorySnc (Optional) If SNC is used for this destination, it is possible to turn it off for repository connections, if this property is set to 0 . Default setting is the value of jco.client.snc _mode. For special cases only. repositoryRoundtripOptimization Enable the RFC_METADATA_GET API, which provides the repository data in one single round trip. 1 Activates use of RFC_METADATA_GET in ABAP System. 0 Deactivates RFC_METADATA_GET in ABAP System. If the property is not set, the destination initially does a remote call to check whether RFC_METADATA_GET is available. If it is available, the destination will use it. Note: If the repository is already initialized (for example, because it is used by some other destination), this property does not have any effect. Generally, this property is related to the ABAP System, and should have the same value on all destinations pointing to the same ABAP System. See note 1456826 for backend prerequisites. 119.3.2.7. Trace configuration options The following table lists the trace configuration options for configuring a destination in the SAP destination data store: Name Default Value Description trace Enable/disable RFC trace ( 0 or 1 ). cpicTrace Enable/disable CPIC trace [0..3] . 119.3.3. Server Configuration The configurations for servers are maintained in the serverDataStore property of the SAP component. Each entry in this map configures a distinct inbound connection from an SAP instance. The key for each entry is the name of the outbound connection and is used in the serverName component of a server endpoint URI as described in the URI format section. The value for each entry is a server data configuration object , org.fusesource.camel.component.sap.model.rfc.impl.ServerDataImpl , which defines the configuration of an inbound SAP connection. Sample server configuration The following Blueprint XML code shows how to create a sample server configuration with the name, quickstartServer . Notice how this example also configures a destination connection, quickstartDest , which the server uses to retrieve metadata from a remote SAP instance. This destination is configured in the server data through the repositoryDestination option. If you do not configure this option, you must create a local metadata repository instead. For example, after configuring the destination as shown in the preceding Blueprint XML file, you could handle the BAPI_FLCUST_GETLIST remote function call from an invoking client, using the following URI: 119.3.3.1. Required options The required options for the server data configuration object are, as follows: Name Default Value Description gwhost Gateway host on which the server connection should be registered. gwserv Gateway service, which is the port on which a registration can be done. In order to resolve the service names sapgwXXX , a lookup in etc/services is performed by the network layer of the operating system. If using port numbers instead of symbolic service names, no lookups are performed and no additional entries are needed. progid The program ID with which the registration is done. Serves as an identifier on the gateway and in the destination in the ABAP system. repositoryDestination Specifies a destination name that the server can use in order to retrieve metadata from a metadata repository hosted in a remote SAP server. connectionCount The number of connections that should be registered at the gateway. 119.3.3.2. Secure network connection options The secure network connection options for the server data configuration object are as follows: Name Default Value Description sncMode Secure network connection (SNC) mode, 0 (off) or 1 (on). sncQop SNC level of security, 1 to 9 . sncMyname SNC name of your server. Overrides the default SNC name. Typically something like p:CN=JCoServer, O=ACompany, C=EN . sncLib Path to library which provides SNC service. If this property is not provided, the value of the jco.middleware.snc_lib property is used instead. 119.3.3.3. Other options The other options for the server data configuration object are, as follows: Name Default Value Description saprouter SAP router string to use for a system protected by a firewall, which can therefore only be reached through a SAProuter, when registering the server at the gateway of that ABAP System. A typical router string is /H/firewall.hostname/H/ . maxStartupDelay The maximum time (in seconds) between two start-up attempts in case of failures. The waiting time is doubled from initially 1 second after each start-up failure until either the maximum value is reached or the server could be started successfully. trace Enable/disable RFC trace ( 0 or 1 ) workerThreadCount The maximum number of threads used by the server connection. If not set, the value for the connectionCount is used as the workerThreadCount . The maximum number of threads can not exceed 99. workerThreadMinCount The minimum number of threads used by server connection. If not set, the value for connectionCount is used as the workerThreadMinCount . 119.3.4. Repository Configuration The configurations for repositories are maintained in the repositoryDataStore property of the SAP Component. Each entry in this map configures a distinct repository. The key for each entry is the name of the repository and this key also corresponds to the name of the server to which this repository is attached. The value of each entry is a repository data configuration object, org.fusesource.camel.component.sap.model.rfc.impl.RepositoryDataImpl , that defines the contents of a metadata repository. A repository data object is a map of function template configuration objects, org.fuesource.camel.component.sap.model.rfc.impl.FunctionTemplateImpl . Each entry in this map specifies the interface of a function module and the key for each entry is the name of the function module specified. Repository data example The following code shows a simple example of configuring a metadata repository: 119.3.4.1. Function template properties The interface of a function module consists of four parameter lists by which data is transferred back and forth to the function module in an RFC call. Each parameter list consists of one or more fields, each of which is a named parameter transferred in an RFC call. The following parameter lists and exception list are supported: The import parameter list contains parameter values sent to a function module in an RFC call; The export parameter list contains parameter values that are returned by a function module in an RFC call; The changing parameter list contains parameter values sent to and returned by a function module in an RFC call; The table parameter list contains internal table values sent to and returned by a function module in an RFC call. The interface of a function module also consists of an exception list of ABAP exceptions that may be raised when the module is invoked in an RFC call. A function template describes the name and type of parameters in each parameter list of a function interface and the ABAP exceptions thrown by the function. A function template object maintains five property lists of metadata objects, as described in the following table. Property Description importParameterList A list of list field metadata objects, org.fusesource.camel.component.sap.model.rfc.impl.ListFieldMeataDataImpl . Specifies the parameters sent in an RFC call to a function module. changingParameterList A list of list field metadata objects, org.fusesource.camel.component.sap.model.rfc.impl.ListFieldMeataDataImpl . Specifies the parameters sent and returned in an RFC call to and from a function module. exportParameterList A list of list field metadata objects, org.fusesource.camel.component.sap.model.rfc.impl.ListFieldMeataDataImpl . Specifies the parameters returned in an RFC call from a function module. tableParameterList A list of list field metadata objects, org.fusesource.camel.component.sap.model.rfc.impl.ListFieldMeataDataImpl . Specifies the table parameters that are sent and returned in an RFC call to and from a function module. exceptionList A list of ABAP exception metadata objects, org.fusesource.camel.component.sap.model.rfc.impl.AbapExceptionImpl . Specifies the ABAP exceptions potentially raised in an RFC call of the function module. Function template example The following example shows an outline of how to configure a function template: 119.3.4.2. List field metadata properties A list field metadata object, org.fusesource.camel.component.sap.model.rfc.impl.ListFieldMeataDataImpl , specifies the name and type of a field in a parameter list. For an elementary parameter field ( CHAR , DATE , BCD , TIME , BYTE , NUM , FLOAT , INT , INT1 , INT2 , DECF16 , DECF34 , STRING , XSTRING ), the following table lists the configuration properties that may be set on a list field metadata object: Name Default Value Description name - The name of the parameter field. type - The parameter type of the field. byteLength - The field length in bytes for a non-Unicode layout. This value depends on the parameter type. unicodeByteLength - The field length in bytes for a Unicode layout. This value depends on the parameter type. decimals 0 The number of decimals in field value. Required for parameter types BCD and FLOAT. optional false If true , the field is optional and need not be set in an RFC call. Note that all elementary parameter fields require that the name , type , byteLength , and unicodeByteLength properties be specified in the field metadata object. In addition, the BCD , FLOAT , DECF16 , and DECF34 fields require the decimal property to be specified in the field metadata object. For a complex parameter field of type TABLE or STRUCTURE , the following table lists the configuration properties that may be set on a list field metadata object: Name Default Value Description name - The name of the parameter field. type - The parameter type of the field. recordMetaData - The metadata for the structure or table. A record metadata object, org.fusesource.camel.component.sap.model.rfc.impl.RecordMetaDataImpl , is passed to specify the fields in the structure or table rows. optional false If true , the field is optional and need not be set in a RFC call. Note All complex parameter fields require that the name , type , and recordMetaData properties be specified in the field metadata object. The value of the recordMetaData property is a record field metadata object, org.fusesource.camel.component.sap.model.rfc.impl.RecordMetaDataImpl , which specifies the structure of a nested structure or the structure of a table row. Elementary list field metadata example The following metadata configuration specifies an optional, 24-digit packed BCD number parameter with two decimal places named TICKET_PRICE : Complex list field metadata example The following metadata configuration specifies a required TABLE parameter named CONNINFO with a row structure specified by the connectionInfo record metadata object: 119.3.4.3. Record metadata properties A record metadata object, org.fusesource.camel.component.sap.model.rfc.impl.RecordMetaDataImpl , specifies the name and contents of a nested STRUCTURE or the row of a TABLE parameter. A record metadata object maintains a list of record field metadata objects, org.fusesource.camel.component.sap.model.rfc.impl.FieldMetaDataImpl , which specifies the parameters that reside in the nested structure or table row. The following table lists configuration properties that may be set on a record metadata object: Name Default Value Description name - The name of the record. recordFieldMetaData - The list of record field metadata objects, org.fusesource.camel.component.sap.model.rfc.impl.FieldMetaDataImpl . Specifies the fields contained within the structure. Note All properties of the record metadata object are required. Record metadata example The following example shows how to configure a record metadata object: 119.3.4.4. Record field metadata properties A record field metadata object, org.fusesource.camel.component.sap.model.rfc.impl.FieldMetaDataImpl , specifies the name and type of a parameter field within a structure. A record field metadata object is similar to a parameter field metadata object, except that the offsets of the individual field locations within the nested structure or table row must be additionally specified. The non-Unicode and Unicode offsets of an individual field must be calculated and specified from the sum of non-Unicode and Unicode byte lengths of the preceding fields in the structure or row. Note The failure to properly specify the offsets of fields in nested structures and table rows will cause the field storage of parameters in the underlying JCo and ABAP runtimes to overlap and prevent the proper transfer of values in RFC calls. For an elementary parameter field ( CHAR , DATE , BCD , TIME , BYTE , NUM , FLOAT , INT , INT1 , INT2 , DECF16 , DECF34 , STRING , XSTRING ), the following table lists the configuration properties that may be set on a record field metadata object: Name Default Value Description name - The name of the parameter field. type - The parameter type of the field. byteLength - The field length in bytes for a non-Unicode layout. This value depends on the parameter type. unicodeByteLength - The field length in bytes for a Unicode layout. This value depends on the parameter type. byteOffset - The field offset in bytes for non-Unicode layout. This offset is the byte location of the field within the enclosing structure. unicodeByteOffset - The field offset in bytes for Unicode layout. This offset is the byte location of the field within the enclosing structure. decimals 0 The number of decimals in field value; only required for parameter types BCD and FLOAT . For a complex parameter field of type TABLE or STRUCTURE , the following table lists the configuration properties that may be set on a record field metadata object: Name Default Value Description name - The name of the parameter field. type - The parameter type of the field. byteOffset - The field offset in bytes for non-Unicode layout. This offset is the byte location of the field within the enclosing structure. unicodeByteOffset - The field offset in bytes for Unicode layout. This offset is the byte location of the field within the enclosing structure. recordMetaData - The metadata for the structure or table. A record metadata object, org.fusesource.camel.component.sap.model.rfc.impl.RecordMetaDataImpl , is passed to specify the fields in the structure or table rows. Elementary record field metadata example The following metadata configuration specifies a DATE field parameter named ARRDATE located 85 bytes into the enclosing structure in the case of a non-Unicode layout and located 170 bytes into the enclosing structure in the case of a Unicode layout. Complex record field metadata example The following metadata configuration specifies a STRUCTURE field parameter named FLTINFO with a structure specified by the flightInfo record metadata object. The parameter is located at the beginning of the enclosing structure in both the case of a non-Unicode and Unicode layout. 119.4. Message Headers The SAP component supports the following message headers: Header Description CamelSap.scheme The URI scheme of the last endpoint to process the message. Use one of the following values: sap-srfc-destination sap-trfc-destination sap-qrfc-destination sap-srfc-server sap-trfc-server sap-idoc-destination sap-idoclist-destination sap-qidoc-destination sap-qidoclist-destination sap-idoclist-server CamelSap.destinationName The destination name of the last destination endpoint to process the message. CamelSap.serverName The server name of the last server endpoint to process the message. CamelSap.queueName The queue name of the last queuing endpoint to process the message. CamelSap.rfcName The RFC name of the last RFC endpoint to process the message. CamelSap.idocType The IDoc type of the last IDoc endpoint to process the message. CamelSap.idocTypeExtension The IDoc type extension, if any, of the last IDoc endpoint to process the message. CamelSap.systemRelease The system release, if any, of the last IDoc endpoint to process the message. CamelSap.applicationRelease The application release, if any, of the last IDoc endpoint to process the message. 119.5. Exchange Properties The SAP component adds the following exchange properties: Property Description CamelSap.destinationPropertiesMap A map containing the properties of each SAP destination encountered by the exchange. The map is keyed by destination name and each entry is a java.util.Properties object containing the configuration properties of that destination. CamelSap.serverPropertiesMap A map containing the properties of each SAP server encountered by the exchange. The map is keyed by server name and each entry is a java.util.Properties object containing the configuration properties of that server. 119.6. Message Body for RFC 119.6.1. Request and response objects An SAP endpoint expects to receive a message with a message body containing an SAP request object and will return a message with a message body containing an SAP response object. SAP requests and responses are fixed map data structures containing named fields with each field having a predefined data type. Note that the named fields in an SAP request and response are specific to an SAP endpoint, with each endpoint defining the parameters in the SAP request and response it will accept. An SAP endpoint provides factory methods to create the request and response objects that are specific to it. 119.6.2. Structure objects Both SAP request and response objects are represented in Java as a structure object which supports the org.fusesource.camel.component.sap.model.rfc.Structure interface. This interface extends both the java.util.Map and org.eclipse.emf.ecore.EObject interfaces. The field values in a structure object are accessed through the field's getter methods in the map interface. In addition, the structure interface provides a type-restricted method to retrieve field values. Structure objects are implemented in the component runtime using the Eclipse Modeling Framework (EMF) and support that framework's EObject interface. Instances of a structure object have attached metadata which define and restrict the structure and contents of the map of fields it provides. This metadata can be accessed and introspected using the standard methods provided by EMF. Please refer to the EMF documentation for further details. Note Attempts to get a parameter not defined on a structure object will return null. Attempts to set a parameter not defined on a structure will throw an exception as well as attempts to set the value of a parameter with an incorrect type. As discussed in the following sections, structure objects can contain fields that contain values of the complex field types, STRUCTURE , and TABLE . Note It is unnecessary to create instances of these types and add them to the structure. Instances of these field values are created on demand if necessary when accessed in the enclosing structure. 119.6.3. Field types The fields that reside within the structure object of an SAP request or response may be either elementary or complex . An elementary field contains a single scalar value, whereas a complex field will contain one or more fields of either an elementary or complex type. 119.6.3.1. Elementary field types An elementary field may be a character, numeric, hexadecimal or string field type. The following table summarizes the types of elementary fields that may reside in a structure object: Field Type Corresponding Java Type Byte Length Unicode Byte Length Number Decimals Digits Description CHAR java.lang.String 1 to 65535 1 to 65535 - ABAP Type 'C': Fixed sized character string DATE java.util.Date 8 16 - ABAP Type 'D': Date (format: YYYYMMDD) BCD java.math.BigDecimal 1 to 16 1 to 16 0 to 14 ABAP Type 'P': Packed BCD number. A BCD number contains two digits per byte. TIME java.util.Date 6 12 - ABAP Type 'T': Time (format: HHMMSS) BYTE byte[] 1 to 65535 1 to 65535 - ABAP Type 'X':Fixed sized byte array NUM java.lang.String 1 to 65535 1 to 65535 - ABAP Type 'N': Fixed sized numeric character string FLOAT java.lang.Double 8 8 0 to 15 ABAP Type 'F': Floating point number INT java.lang.Integer 4 4 - ABAP Type 'I': 4-byte Integer INT2 java.lang.Integer 2 2 - ABAP Type 'S': 2-byte Integer INT1 java.lang.Integer 1 1 - ABAP Type 'B': 1-byte Integer DECF16 java.match.BigDecimal 8 8 16 ABAP Type 'decfloat16': 8 -byte Decimal Floating Point Number DECF34 java.math.BigDecimal 16 16 34 ABAP Type 'decfloat34': 16-byte Decimal Floating Point Number STRING java.lang.String 8 8 - ABAP Type 'G': Variable length character string XSTRING byte[] 8 8 - ABAP Type 'Y': Variable length byte array 119.6.3.2. Character field types A character field contains a fixed sized character string that may use either a non-Unicode or Unicode character encoding in the underlying JCo and ABAP runtimes. Non-Unicode character strings encode one character per byte. Unicode character strings are encoded in two bytes using UTF-16 encoding. Character field values are represented in Java as java.lang.String objects and the underlying JCo runtime is responsible for the conversion to their ABAP representation. A character field declares its field length in its associated byteLength and unicodeByteLength properties, which determine the length of the field's character string in each encoding system. CHAR A CHAR character field is a text field containing alphanumeric characters and corresponds to the ABAP type C. NUM A NUM character field is a numeric text field containing numeric characters only and corresponds to the ABAP type N. DATE A DATE character field is an 8 character date field with the year, month and day formatted as YYYYMMDD and corresponds to the ABAP type D. TIME A TIME character field is a 6 character time field with the hours, minutes and seconds formatted as HHMMSS and corresponds to the ABAP type T. 119.6.3.3. Numeric field types A numeric field contains a number. The following numeric field types are supported: INT An INT numeric field is an integer field stored as a 4-byte integer value in the underlying JCo and ABAP runtimes and corresponds to the ABAP type I. An INT field value is represented in Java as a java.lang.Integer object. INT2 An INT2 numeric field is an integer field stored as a 2-byte integer value in the underlying JCo and ABAP runtimes and corresponds to the ABAP type S. An INT2 field value is represented in Java as a java.lang.Integer object. INT1 An INT1 field is an integer field stored as a 1-byte integer value in the underlying JCo and ABAP runtimes value and corresponds to the ABAP type B. An INT1 field value is represented in Java as a java.lang.Integer object. FLOAT A FLOAT field is a binary floating point number field stored as an 8-byte double value in the underlying JCo and ABAP runtimes and corresponds to the ABAP type F. A FLOAT field declares the number of decimal digits that the field's value contains in its associated decimal property. In the case of a FLOAT field, this decimal property can have a value between 1 and 15 digits. A FLOAT field value is represented in Java as a java.lang.Double object. BCD A BCD field is a binary coded decimal field stored as a 1 to 16 byte packed number in the underlying JCo and ABAP runtimes and corresponds to the ABAP type P. A packed number stores two decimal digits per byte. A BCD field declares its field length in its associated byteLength and unicodeByteLength properties. In the case of a BCD field, these properties can have a value between 1 and 16 bytes, and both properties will have the same value. A BCD field declares the number of decimal digits that the field's value contains in its associated decimal property. In the case of a BCD field, this decimal property can have a value between 1 and 14 digits. A BCD field value is represented in Java as a java.math.BigDecimal . DECF16 A DECF16 field is a decimal floating point stored as an 8-byte IEEE 754 decimal64 floating point value in the underlying JCo and ABAP runtimes and corresponds to the ABAP type decfloat16 . The value of a DECF16 field has 16 decimal digits. The value of a DECF16 field is represented in Java as java.math.BigDecimal . DECF34 A DECF34 field is a decimal floating point stored as a 16-byte IEEE 754 decimal128 floating point value in the underlying JCo and ABAP runtimes and corresponds to the ABAP type decfloat34 . The value of a DECF34 field has 34 decimal digits. The value of a DECF34 field is represented in Java as java.math.BigDecimal . 119.6.3.4. Hexadecimal field types A hexadecimal field contains raw binary data. The following hexadecimal field types are supported: BYTE A BYTE field is a fixed sized byte string stored as a byte array in the underlying JCo and ABAP runtimes and corresponds to the ABAP type X. A BYTE field declares its field length in its associated byteLength and unicodeByteLength properties. In the case of a BYTE field, these properties can have a value between 1 and 65535 bytes and both properties will have the same value. The value of a BYTE field is represented in Java as a byte[] object. 119.6.3.5. String field types A string field references a variable length string value. The length of that string value is not fixed until runtime. The storage for the string value is dynamically created in the underlying JCo and ABAP runtimes. The storage for the string field itself is fixed and contains only a string header. STRING A STRING field refers to a character string stored in the underlying JCo and ABAP runtimes as an 8-byte value. It corresponds to the ABAP type G. The value of the STRING field is represented in Java as a java.lang.String object. XSTRING An XSTRING field refers to a byte string stored in the underlying JCo and ABAP runtimes as an 8-byte value. It corresponds to the ABAP type Y. The value of the STRING field is represented in Java as a byte[] object. 119.6.3.6. Complex field types A complex field may be either a structure or table field type. The following table summarizes these complex field types. Field Type Corresponding Java Type Byte Length Unicode Byte Length Number Decimals Digits Description STRUCTURE org.fusesource.camel.component.sap.model.rfc.Structure Total of individual field byte lengths Total of individual field Unicode byte lengths - ABAP Type 'u' & 'v': Heterogeneous Structure TABLE org.fusesource.camel.component.sap.model.rfc.Table Byte length of row structure Unicode byte length of row structure - ABAP Type 'h': Table 119.6.3.7. Structure field types A STRUCTURE field contains a structure object and is stored in the underlying JCo and ABAP runtimes as an ABAP structure record. It corresponds to either an ABAP type u or v . The value of a STRUCTURE field is represented in Java as a structure object with the interface org.fusesource.camel.component.sap.model.rfc.Structure . 119.6.3.8. Table field types A TABLE field contains a table object and is stored in the underlying JCo and ABAP runtimes as an ABAP internal table. It corresponds to the ABAP type h . The value of the field is represented in Java by a table object with the interface org.fusesource.camel.component.sap.model.rfc.Table . 119.6.3.9. Table objects A table object is a homogeneous list data structure containing rows of structure objects with the same structure. This interface extends both the java.util.List and org.eclipse.emf.ecore.EObject interfaces. The list of rows in a table object is accessed and managed using the standard methods defined in the list interface. In addition, the table interface provides two factory methods for creating and adding structure objects to the row list. Table objects are implemented in the component runtime using the Eclipse Modeling Framework (EMF) and support that framework's EObject interface. Instances of a table object have attached metadata which define and restrict the structure and contents of the rows it provides. This metadata can be accessed and introspected using the standard methods provided by EMF. Please refer to the EMF documentation for further details. Note Attempts to add or set a row structure value of the wrong type will throw an exception. 119.7. Message Body for IDoc 119.7.1. IDoc message type When using one of the IDoc Camel SAP endpoints, the type of the message body depends on which particular endpoint you are using. For a sap-idoc-destination endpoint or a sap-qidoc-destination endpoint, the message body is of Document type: For a sap-idoclist-destination endpoint, a sap-qidoclist-destination endpoint, or a sap-idoclist-server endpoint, the message body is of DocumentList type: 119.7.2. The IDoc document model For the Camel SAP component, an IDoc document is modeled using the Eclipse Modeling Framework (EMF), which provides a wrapper API around the underlying SAP IDoc API. The most important types in this model are: The Document type represents an IDoc document instance. In outline, the Document interface exposes the following methods: The following kinds of method are exposed by the Document interface: Methods for accessing the control record Most of the methods are for accessing or modifying field values of the IDoc control record. These methods are of the form AttributeName , where AttributeName is the name of a field value. Method for accessing the document contents The getRootSegment method provides access to the document contents (IDoc data records), returning the contents as a Segment object. Each Segment object can contain an arbitrary number of child segments, and the segments can be nested to an arbitrary degree. Note, however, that the precise layout of the segment hierarchy is defined by the particular IDoc type of the document. When creating (or reading) a segment hierarchy, therefore, you must be sure to follow the exact structure as defined by the IDoc type. The Segment type is used to access the data records of the IDoc document, where the segments are laid out in accordance with the structure defined by the document's IDoc type. In outline, the Segment interface exposes the following methods: The getChildren(String segmentType) method is particularly useful for adding new (nested) children to a segment. It returns an object of type, SegmentList , which is defined as follows: Hence, to create a data record of E1SCU_CRE type, you could use Java code like the following: 119.7.3. How an IDoc is related to a Document object According to the SAP documentation, an IDoc document consists of the following main parts: Control record The control record (which contains the metadata for the IDoc document) is represented by the attributes on the Document object. Data records The data records are represented by the Segment objects, which are constructed as a nested hierarchy of segments. You can access the root segment through the Document.getRootSegment method. Status records In the Camel SAP component, the status records are not represented by the document model. But you do have access to the latest status value through the status attribute on the control record. Example of creating a Document instance The following example shows how to create an IDoc document with the IDoc type, FLCUSTOMER_CREATEFROMDATA01 , using the IDoc model API in Java. Example 119.1. Creating an IDoc Document in Java 119.8. Document attributes IDoc Document Attributes table shows the control record attributes that you can set on the Document object. Table 119.2. IDoc Document Attributes Attribute Length SAP Field Description archiveKey 70 ARCKEY EDI archive key client 3 MANDT Client creationDate 8 CREDAT Date IDoc was created creationTime 6 CRETIM Time IDoc was created direction 1 DIRECT Direction eDIMessage 14 REFMES Reference to message eDIMessageGroup 14 REFGRP Reference to message group eDIMessageType 6 STDMES EDI message type eDIStandardFlag 1 STD EDI standard eDIStandardVersion 6 STDVRS Version of EDI standard eDITransmissionFile 14 REFINT Reference to interchange file iDocCompoundType 8 DOCTYP IDoc type iDocNumber 16 DOCNUM IDoc number iDocSAPRelease 4 DOCREL SAP Release of IDoc iDocType 30 IDOCTP Name of basic IDoc type iDocTypeExtension 30 CIMTYP Name of extension type messageCode 3 MESCOD Logical message code messageFunction 3 MESFCT Logical message function messageType 30 MESTYP Logical message type outputMode 1 OUTMOD Output mode recipientAddress 10 RCVSAD Receiver address (SADR) recipientLogicalAddress 70 RCVLAD Logical address of receiver recipientPartnerFunction 2 RCVPFC Partner function of receiver recipientPartnerNumber 10 RCVPRN Partner number of receiver recipientPartnerType 2 RCVPRT Partner type of receiver recipientPort 10 RCVPOR Receiver port (SAP System, EDI subsystem) senderAddress SNDSAD Sender address (SADR) senderLogicalAddress 70 SNDLAD Logical address of sender senderPartnerFunction 2 SNDPFC Partner function of sender senderPartnerNumber 10 SNDPRN Partner number of sender senderPartnerType 2 SNDPRT Partner type of sender senderPort 10 SNDPOR Sender port (SAP System, EDI subsystem) serialization 20 SERIAL EDI/ALE: Serialization field status 2 STATUS Status of IDoc testFlag 1 TEST Test flag 119.8.1. Setting document attributes in Java When setting the control record attributes in Java, the usual convention for Java bean properties is followed. That is, a name attribute can be accessed through the getName and setName methods, for getting and setting the attribute value. For example, the iDocType , iDocTypeExtension , and messageType attributes can be set as follows on a Document object: 119.8.2. Setting document attributes in XML When setting the control record attributes in XML, the attributes must be set on the idoc:Document element. For example, the iDocType , iDocTypeExtension , and messageType attributes can be set as follows: 119.9. Transaction Support 119.9.1. BAPI transaction model The SAP Component supports the BAPI transaction model for outbound communication with SAP. A destination endpoint with a URL containing the transacted option set to true will, if necessary, initiate a stateful session on the outbound connection of the endpoint and register a Camel Synchronization object with the exchange. This synchronization object will call the BAPI service method BAPI_TRANSACTION_COMMIT and end the stateful session when the processing of the message exchange is complete. If the processing of the message exchange fails, the synchronization object will call the BAPI server method BAPI_TRANSACTION_ROLLBACK and end the stateful session. 119.9.2. RFC transaction model The tRFC protocol accomplishes an AT-MOST-ONCE delivery and processing guarantee by identifying each transactional request with a unique transaction identifier (TID). A TID accompanies each request sent in the protocol. A sending application using the tRFC protocol must identify each instance of a request with a unique TID when sending the request. An application may send a request with a given TID multiple times, but the protocol ensures that the request is delivered and processed in the receiving system at most once. An application may choose to resend a request with a given TID when encountering a communication or system error when sending the request, and is thus in doubt as to whether that request was delivered and processed in the receiving system. By resending a request when encountering a communication error, a client application using the tRFC protocol can thus ensure EXACTLY-ONCE delivery and processing guarantees for its request. 119.9.3. Which transaction model to use? A BAPI transaction is an application level transaction, in the sense that it imposes ACID guarantees on the persistent data changes performed by a BAPI method or RFC function in the SAP database. An RFC transaction is a communication transaction, in the sense that it imposes delivery guarantees (AT-MOST-ONCE, EXACTLY-ONCE, EXACTLY-ONCE-IN-ORDER) on requests to a BAPI method and/or RFC function. 119.9.4. Transactional RFC destination endpoints The following destination endpoints support RFC transactions: sap-trfc-destination sap-qrfc-destination A single Camel route can include multiple transactional RFC destination endpoints, sending messages to multiple RFC destinations and even sending messages to the same RFC destination multiple times. This implies that the Camel SAP component potentially needs to keep track of many transaction IDs (TIDs) for each Exchange object passing along a route. Now if the route processing fails and must be retried, the situation gets quite complicated. The RFC transaction semantics demand that each RFC destination along the route must be invoked using the same TID that was used the first time around (and where the TIDs for each destinations are distinct from each other). In other words, the Camel SAP component must keep track of which TID was used at which point along the route, and remember this information, so that the TIDs can be replayed in the correct order. By default, Camel does not provide a mechanism that enables an Exchange to know where it is in a route. To provide such a mechanism, it is necessary to install the CurrentProcessorDefinitionInterceptStrategy interceptor into the Camel runtime. This interceptor must be installed into the Camel runtime, in order for the Camel SAP component to keep track of the TIDs in a route. 119.9.5. Transactional RFC server endpoints The following server endpoints support RFC transactions: sap-trfc-server When a Camel exchange processing a transactional request encounters a processing error, Camel handles the processing error through its standard error handling mechanisms. If the Camel route processing the exchange is configured to propagate the error back to the caller, the SAP server endpoint that initiated the exchange takes note of the failure and the sending SAP system is notified of the error. The sending SAP system can then respond by sending another transaction request with the same TID to process the request again. 119.10. XML Serialization for RFC SAP request and response objects support an XML serialization format which enable these objects to be serialized to and from an XML document. 119.10.1. XML namespace Each RFC in a repository defines a specific XML namespace for the elements which compose the serialized forms of its Request and Response objects. The form of this namespace URL is as follows: RFC namespace URLs have a common http://sap.fusesource.org/rfc prefix followed by the name of the repository in which the RFC's metadata is defined. The final component in the URL is the name of the RFC itself. 119.10.2. Request and response XML documents An SAP request object will be serialized into an XML document with the root element of that document named Request and scoped by the namespace of the request's RFC. An SAP response object will be serialized into an XML document with the root element of that document named Response and scoped by the namespace of the response's RFC. 119.10.3. Structure fields Structure fields in parameter lists or nested structures are serialized as elements. The element name of the serialized structure corresponds to the field name of the structure within the enclosing parameter list, structure or table row entry it resides. Note that the type name of the structure element in the RFC namespace will correspond to the name of the record metadata object which defines the structure, as in the following example: This distinction will be important when specifying a JAXB bean to marshal and unmarshal the structure. 119.10.4. Table fields Table fields in parameter lists or nested structures are serialized as elements. The element name of the serialized structure will correspond to the field name of the table within the enclosing parameter list, structure, or table row entry it resides. The table element will contain a series of row elements to hold the serialized values of the table's row entries. Note that the type name of the table element in the RFC namespace corresponds to the name of the record metadata object which defines the row structure of the table suffixed by _TABLE . The type name of the table row element in the RFC name corresponds to the name of the record metadata object which defines the row structure of the table, as in the following example: This distinction will be important when specifying a JAXB bean to marshal and unmarshal the structure. 119.10.5. Elementary fields Elementary fields in parameter lists or nested structures are serialized as attributes on the element of the enclosing parameter list or structure. The attribute name of the serialized field corresponds to the field name of the field within the enclosing parameter list, structure, or table row entry it resides, as in the following example: 119.10.6. Date and time formats Date and Time fields are serialized into attribute values using the following format: Date fields will be serialized with only the year, month, day and timezone components set: Time fields will be serialized with only the hour, minute, second, millisecond and timezone components set: 119.11. XML Serialization for IDoc An IDoc message body can be serialized into an XML string format, with the help of a built-in type converter. 119.11.1. XML namespace Each serialized IDoc is associated with an XML namespace, which has the following general format: Both the repositoryName (name of the remote SAP metadata repository) and the idocType (IDoc document type) are mandatory, but the other components of the namespace can be left blank. For example, you could have an XML namespace like the following: 119.11.2. Built-in type converter The Camel SAP component has a built-in type converter, which is capable of converting a Document object or a DocumentList object to and from a String type. For example, to serialize a Document object to an XML string, you can simply add the following line to a route in XML DSL: You can also use this approach to a serialized XML message into a Document object. For example, given that the current message body is a serialized XML string, you can convert it back into a Document object by adding the following line to a route in XML DSL: 119.11.3. Sample IDoc message body in XML format When you convert an IDoc message to a String , it is serialized into an XML document, where the root element is either idoc:Document (for a single document) or idoc:DocumentList (for a list of documents). It shows that a single IDoc document that has been serialized to an idoc:Document element. Example 119.2. IDoc Message Body in XML 119.12. Example 1: Reading Data from SAP This example demonstrates a route that reads FlightCustomer business object data from SAP. The route invokes the FlightCustomer BAPI method, BAPI_FLCUST_GETLIST , using an SAP synchronous RFC destination endpoint to retrieve the data. 119.12.1. Java DSL for route The Java DSL for the example route is as follows: 119.12.2. XML DSL for route And the Spring DSL for the same route is as follows: 119.12.3. createFlightCustomerGetListRequest bean The createFlightCustomerGetListRequest bean is responsible for building an SAP request object in its exchange method that is used in the RFC call of the subsequent SAP endpoint. The following code snippet demonstrates the sequence of operations to build the request object: 119.12.4. returnFlightCustomerInfo bean The returnFlightCustomerInfo bean is responsible for extracting data from the SAP response object in its exchange method that it receives from the SAP endpoint. The following code snippet demonstrates the sequence of operations to extract the data from the response object: 119.13. Example 2: Writing Data to SAP This example demonstrates a route that creates a FlightTrip business object instance in SAP. The route invokes the FlightTrip BAPI method, BAPI_FLTRIP_CREATE , using a destination endpoint to create the object. 119.13.1. Java DSL for route The Java DSL for the example route is as follows: 119.13.2. XML DSL for route And the Spring DSL for the same route is as follows: 119.13.3. Transaction support Note that the URL for the SAP endpoint has the transacted option set to true . When this option is enabled, the endpoint ensures that an SAP transaction session has been initiated before invoking the RFC call. Because this endpoint's RFC creates new data in SAP, this option is necessary to make the route's changes permanent in SAP. 119.13.4. Populating request parameters The createFlightTripRequest and returnFlightTripResponse beans are responsible for populating request parameters into the SAP request and extracting response parameters from the SAP response respectively, following the same sequence of operations as demonstrated in the example. 119.14. Example 3: Handling Requests from SAP This example demonstrates a route which handles a request from SAP to the BOOK_FLIGHT RFC, which is implemented by the route. In addition, it demonstrates the component's XML serialization support, using JAXB to unmarshal and marshal SAP request objects and response objects to custom beans. This route creates a FlightTrip business object on behalf of a travel agent, FlightCustomer . The route first unmarshals the SAP request object received by the SAP server endpoint into a custom JAXB bean. This custom bean is then multicasted in the exchange to three sub-routes, which gather the travel agent, flight connection, and passenger information required to create the flight trip. The final sub-route creates the flight trip object in SAP, as demonstrated in the example. The final sub-route also creates and returns a custom JAXB bean which is marshaled into an SAP response object and returned by the server endpoint. 119.14.1. Java DSL for route The Java DSL for the example route is as follows: 119.14.2. XML DSL for route And the XML DSL for the same route is as follows: 119.14.3. BookFlightRequest bean The following listing illustrates a JAXB bean which unmarshals from the serialized form of an SAP BOOK_FLIGHT request object: 119.14.4. BookFlightResponse bean The following listing illustrates a JAXB bean which marshals to the serialized form of an SAP BOOK_FLIGHT response object: Note The complex parameter fields of the response object are serialized as child elements of the response. 119.14.5. FlightInfo bean The following listing illustrates a JAXB bean which marshals to the serialized form of the complex structure parameter FLTINFO : 119.14.6. ConnectionInfoTable bean The following listing illustrates a JAXB bean which marshals to the serialized form of the complex table parameter, CONNINFO . Note that the name of the root element type of the JAXB bean corresponds to the name of the row structure type suffixed with _TABLE and the bean contains a list of row elements. 119.14.7. ConnectionInfo bean The following listing illustrates a JAXB bean, which marshals to the serialized form of the above tables row elements:

Commands:
<dependency> <groupId>org.fusesource</groupId> <artifactId>camel-sap-starter</artifactId> <version>4.8.3.redhat-00004</version> </dependency>
sap-srfc-destination: destinationName : rfcName sap-trfc-destination: destinationName : rfcName sap-qrfc-destination: destinationName : queueName : rfcName sap-srfc-server: serverName : rfcName [? options ] sap-trfc-server: serverName : rfcName [? options ]
sap-idoc-destination: destinationName : idocType [: idocTypeExtension [: systemRelease [: applicationRelease ]]] sap-idoclist-destination: destinationName : idocType [: idocTypeExtension [: systemRelease [: applicationRelease ]]] sap-qidoc-destination: destinationName : queueName : idocType [: idocTypeExtension [: systemRelease [: applicationRelease ]]] sap-qidoclist-destination: destinationName : queueName : idocType [: idocTypeExtension [: systemRelease [: applicationRelease ]]] sap-idoclist-server: serverName : idocType [: idocTypeExtension [: systemRelease [: applicationRelease ]]][? options ]
<?xml version="1.0" encoding="UTF-8"?> <blueprint ... > <!-- Configures the Inbound and Outbound SAP Connections --> <bean id="sap-configuration" class="org.fusesource.camel.component.sap.SapConnectionConfiguration"> <property name="destinationDataStore"> <map> <entry key="quickstartDest" value-ref="quickstartDestinationData" /> </map> </property> <property name="serverDataStore"> <map> <entry key="quickstartServer" value-ref="quickstartServerData" /> </map> </property> </bean> <!-- Configures an Outbound SAP Connection --> <!-- *** Please enter the connection property values for your environment *** --> <bean id="quickstartDestinationData" class="org.fusesource.camel.component.sap.model.rfc.impl.DestinationDataImpl"> <property name="ashost" value="example.com" /> <property name="sysnr" value="00" /> <property name="client" value="000" /> <property name="user" value="username" /> <property name="passwd" value="passowrd" /> <property name="lang" value="en" /> </bean> <!-- Configures an Inbound SAP Connection --> <!-- *** Please enter the connection property values for your environment ** --> <bean id="quickstartServerData" class="org.fusesource.camel.component.sap.model.rfc.impl.ServerDataImpl"> <property name="gwhost" value="example.com" /> <property name="gwserv" value="3300" /> <!-- The following property values should not be changed --> <property name="progid" value="QUICKSTART" /> <property name="repositoryDestination" value="quickstartDest" /> <property name="connectionCount" value="2" /> </bean> </blueprint>
<?xml version="1.0" encoding="UTF-8"?> <blueprint ... > <!-- Create interceptor to support tRFC processing --> <bean id="currentProcessorDefinitionInterceptor" class="org.fusesource.camel.component.sap.CurrentProcessorDefinitionInterceptStrategy" /> <!-- Configures the Inbound and Outbound SAP Connections --> <bean id="sap-configuration" class="org.fusesource.camel.component.sap.SapConnectionConfiguration"> <property name="destinationDataStore"> <map> <entry key="quickstartDest" value-ref="quickstartDestinationData" /> </map> </property> </bean> <!-- Configures an Outbound SAP Connection --> <!-- *** Please enter the connection property values for your environment *** --> <bean id="quickstartDestinationData" class="org.fusesource.camel.component.sap.model.rfc.impl.DestinationDataImpl"> <property name="ashost" value="example.com" /> <property name="sysnr" value="00" /> <property name="client" value="000" /> <property name="user" value="username" /> <property name="passwd" value="password" /> <property name="lang" value="en" /> </bean> </blueprint>
sap-srfc-destination:quickstartDest:BAPI_FLCUST_GETLIST
<?xml version="1.0" encoding="UTF-8"?> <blueprint ... > <!-- Configures the Inbound and Outbound SAP Connections --> <bean id="sap-configuration" class="org.fusesource.camel.component.sap.SapConnectionConfiguration"> <property name="destinationDataStore"> <map> <entry key="quickstartDest" value-ref="quickstartDestinationData" /> </map> </property> <property name="serverDataStore"> <map> <entry key="quickstartServer" value-ref="quickstartServerData" /> </map> </property> </bean> <!-- Configures an Outbound SAP Connection --> <!-- *** Please enter the connection property values for your environment *** --> <bean id="quickstartDestinationData" class="org.fusesource.camel.component.sap.model.rfc.impl.DestinationDataImpl"> <property name="ashost" value="example.com" /> <property name="sysnr" value="00" /> <property name="client" value="000" /> <property name="user" value="username" /> <property name="passwd" value="passowrd" /> <property name="lang" value="en" /> </bean> <!-- Configures an Inbound SAP Connection --> <!-- *** Please enter the connection property values for your environment ** --> <bean id="quickstartServerData" class="org.fusesource.camel.component.sap.model.rfc.impl.ServerDataImpl"> <property name="gwhost" value="example.com" /> <property name="gwserv" value="3300" /> <!-- The following property values should not be changed --> <property name="progid" value="QUICKSTART" /> <property name="repositoryDestination" value="quickstartDest" /> <property name="connectionCount" value="2" /> </bean> </blueprint>
sap-srfc-server:quickstartServer:BAPI_FLCUST_GETLIST
<?xml version="1.0" encoding="UTF-8"?> <blueprint ... > <!-- Configures the sap-srfc-server component --> <bean id="sap-configuration" class="org.fusesource.camel.component.sap.SapConnectionConfiguration"> <property name="repositoryDataStore"> <map> <entry key="nplServer" value-ref="nplRepositoryData" /> </map> </property> </bean> <!-- Configures a Metadata Repository --> <bean id="nplRepositoryData" class="org.fusesource.camel.component.sap.model.rfc.impl.RepositoryDataImpl"> <property name="functionTemplates"> <map> <entry key="BOOK_FLIGHT" value-ref="bookFlightFunctionTemplate" /> </map> </property> </bean> </blueprint>
<bean id="bookFlightFunctionTemplate" class="org.fusesource.camel.component.sap.model.rfc.impl.FunctionTemplateImpl"> <property name="importParameterList"> <list> </list> </property> <property name="changingParameterList"> <list> </list> </property> <property name="exportParameterList"> <list> </list> </property> <property name="tableParameterList"> <list> </list> </property> <property name="exceptionList"> <list> </list> </property> </bean>
<bean class="org.fusesource.camel.component.sap.model.rfc.impl.ListFieldMetaDataImpl"> <property name="name" value="TICKET_PRICE" /> <property name="type" value="BCD" /> <property name="byteLength" value="12" /> <property name="unicodeByteLength" value="24" /> <property name="decimals" value="2" /> <property name="optional" value="true" /> </bean>
<bean class="org.fusesource.camel.component.sap.model.rfc.impl.ListFieldMetaDataImpl"> <property name="name" value="CONNINFO" /> <property name="type" value="TABLE" /> <property name="recordMetaData" ref="connectionInfo" /> </bean>
<bean id="connectionInfo" class="org.fusesource.camel.component.sap.model.rfc.impl.RecordMetaDataImpl"> <property name="name" value="CONNECTION_INFO" /> <property name="recordFieldMetaData"> <list> </list> </property> </bean>
<bean class="org.fusesource.camel.component.sap.model.rfc.impl.FieldMetaDataImpl"> <property name="name" value="ARRDATE" /> <property name="type" value="DATE" /> <property name="byteLength" value="8" /> <property name="unicodeByteLength" value="16" /> <property name="byteOffset" value="85" /> <property name="unicodeByteOffset" value="170" /> </bean>
<bean class="org.fusesource.camel.component.sap.model.rfc.impl.FieldMetaDataImpl"> <property name="name" value="FLTINFO" /> <property name="type" value="STRUCTURE" /> <property name="byteOffset" value="0" /> <property name="unicodeByteOffset" value="0" /> <property name="recordMetaData" ref="flightInfo" /> </bean>
public class SAPEndpoint ... { public Structure getRequest() throws Exception; public Structure getResponse() throws Exception; }
public interface Structure extends org.eclipse.emf.ecore.EObject, java.util.Map<String, Object> { <T> T get(Object key, Class<T> type); }
public interface Table<S extends Structure> extends org.eclipse.emf.ecore.EObject, java.util.List<S> { /** * Creates and adds a table row at the end of the row list */ S add(); /** * Creates and adds a table row at the index in the row list */ S add(int index); }
org.fusesource.camel.component.sap.model.idoc.Document
org.fusesource.camel.component.sap.model.idoc.DocumentList
org.fusesource.camel.component.sap.model.idoc.Document org.fusesource.camel.component.sap.model.idoc.Segment
// Java package org.fusesource.camel.component.sap.model.idoc; public interface Document extends EObject { // Access the field values from the IDoc control record String getArchiveKey(); void setArchiveKey(String value); String getClient(); void setClient(String value); // Access the IDoc document contents Segment getRootSegment(); }
// Java package org.fusesource.camel.component.sap.model.idoc; public interface Segment extends EObject, java.util.Map<String, Object> { // Returns the value of the '<em><b>Parent</b></em>' reference. Segment getParent(); // Return an immutable list of all child segments <S extends Segment> EList<S> getChildren(); // Returns a list of child segments of the specified segment type. <S extends Segment> SegmentList<S> getChildren(String segmentType); EList<String> getTypes(); Document getDocument(); String getDescription(); String getType(); String getDefinition(); int getHierarchyLevel(); String getIdocType(); String getIdocTypeExtension(); String getSystemRelease(); String getApplicationRelease(); int getNumFields(); long getMaxOccurrence(); long getMinOccurrence(); boolean isMandatory(); boolean isQualified(); int getRecordLength(); <T> T get(Object key, Class<T> type); }
// Java package org.fusesource.camel.component.sap.model.idoc; public interface SegmentList<S extends Segment> extends EObject, EList<S> { S add(); S add(int index); }
Segment rootSegment = document.getRootSegment(); Segment E1SCU_CRE_Segment = rootSegment.getChildren("E1SCU_CRE").add();
// Java import org.fusesource.camel.component.sap.model.idoc.Document; import org.fusesource.camel.component.sap.model.idoc.Segment; import org.fusesource.camel.component.sap.util.IDocUtil; import org.fusesource.camel.component.sap.model.idoc.Document; import org.fusesource.camel.component.sap.model.idoc.DocumentList; import org.fusesource.camel.component.sap.model.idoc.IdocFactory; import org.fusesource.camel.component.sap.model.idoc.IdocPackage; import org.fusesource.camel.component.sap.model.idoc.Segment; import org.fusesource.camel.component.sap.model.idoc.SegmentChildren; // // Create a new IDoc instance using the modeling classes // // Get the SAP Endpoint bean from the Camel context. // In this example, it's a 'sap-idoc-destination' endpoint. SapTransactionalIDocDestinationEndpoint endpoint = exchange.getContext().getEndpoint( "bean: SapEndpointBeanID ", SapTransactionalIDocDestinationEndpoint.class ); // The endpoint automatically populates some required control record attributes Document document = endpoint.createDocument() // Initialize additional control record attributes document.setMessageType("FLCUSTOMER_CREATEFROMDATA"); document.setRecipientPartnerNumber("QUICKCLNT"); document.setRecipientPartnerType("LS"); document.setSenderPartnerNumber("QUICKSTART"); document.setSenderPartnerType("LS"); Segment rootSegment = document.getRootSegment(); Segment E1SCU_CRE_Segment = rootSegment.getChildren("E1SCU_CRE").add(); Segment E1BPSCUNEW_Segment = E1SCU_CRE_Segment.getChildren("E1BPSCUNEW").add(); E1BPSCUNEW_Segment.put("CUSTNAME", "Fred Flintstone"); E1BPSCUNEW_Segment.put("FORM", "Mr."); E1BPSCUNEW_Segment.put("STREET", "123 Rubble Lane"); E1BPSCUNEW_Segment.put("POSTCODE", "01234"); E1BPSCUNEW_Segment.put("CITY", "Bedrock"); E1BPSCUNEW_Segment.put("COUNTR", "US"); E1BPSCUNEW_Segment.put("PHONE", "800-555-1212"); E1BPSCUNEW_Segment.put("EMAIL", " fred@bedrock.com "); E1BPSCUNEW_Segment.put("CUSTTYPE", "P"); E1BPSCUNEW_Segment.put("DISCOUNT", "005"); E1BPSCUNEW_Segment.put("LANGU", "E");
// Java document.setIDocType("FLCUSTOMER_CREATEFROMDATA01"); document.setIDocTypeExtension(""); document.setMessageType("FLCUSTOMER_CREATEFROMDATA");
<?xml version="1.0" encoding="ASCII"?> <idoc:Document iDocType="FLCUSTOMER_CREATEFROMDATA01" iDocTypeExtension="" messageType="FLCUSTOMER_CREATEFROMDATA" ... > </idoc:Document>
http://sap.fusesource.org/rfc/<Repository Name>/<RFC Name>
<?xml version="1.0" encoding="ASCII"?> <BOOK_FLIGHT:Request xmlns:BOOK_FLIGHT="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT"> </BOOK_FLIGHT:Request>
<?xml version="1.0" encoding="ASCII"?> <BOOK_FLIGHT:Response xmlns:BOOK_FLIGHT="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT"> </BOOK_FLIGHT:Response>
<BOOK_FLIGHT:FLTINFO xmlns:BOOK_FLIGHT="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT"> </BOOK_FLIGHT:FLTINFO>
<xs:schema targetNamespace="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT"> xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="FLTINFO_STRUCTURE"> </xs:complexType> </xs:schema>
<BOOK_FLIGHT:CONNINFO xmlns:BOOK_FLIGHT="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT"> <row ... > ... </row> <row ... > ... </row> </BOOK_FLIGHT:CONNINFO>
<xs:schema targetNamespace="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complextType name="CONNECTION_INFO_STRUCTURE_TABLE"> <xs:sequence> <xs:element name="row" minOccures="0" maxOccurs="unbounded" type="CONNECTION_INFO_STRUCTURE"/> <xs:sequence> </xs:sequence> </xs:complexType> <xs:complextType name="CONNECTION_INFO_STRUCTURE"> </xs:complexType> </xs:schema>
<?xml version="1.0" encoding="ASCII"?> <BOOK_FLIGHT:Request xmlns:BOOK_FLIGHT="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT" CUSTNAME="James Legrand" PASSFORM="Mr" PASSNAME="Travelin Joe" PASSBIRTH="1990-03-17T00:00:00.000-0500" FLIGHTDATE="2014-03-19T00:00:00.000-0400" TRAVELAGENCYNUMBER="00000110" DESTINATION_FROM="SFO" DESTINATION_TO="FRA"/>
yyyy-MM-dd'T'HH:mm:ss.SSSZ
DEPDATE="2014-03-19T00:00:00.000-0400"
DEPTIME="1970-01-01T16:00:00.000-0500"
http://sap.fusesource.org/idoc/ repositoryName / idocType / idocTypeExtension / systemRelease / applicationRelease
http://sap.fusesource.org/idoc/MY_REPO/FLCUSTOMER_CREATEFROMDATA01///
<convertBodyTo type="java.lang.String"/>
<convertBodyTo type="org.fusesource.camel.component.sap.model.idoc.Document"/>
<?xml version="1.0" encoding="ASCII"?> <idoc:Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:FLCUSTOMER_CREATEFROMDATA01---="http://sap.fusesource.org/idoc/XXX/FLCUSTOMER_CREATEFROMDATA01///" xmlns:idoc="http://sap.fusesource.org/idoc" creationDate="2015-01-28T12:39:13.980-0500" creationTime="2015-01-28T12:39:13.980-0500" iDocType="FLCUSTOMER_CREATEFROMDATA01" iDocTypeExtension="" messageType="FLCUSTOMER_CREATEFROMDATA" recipientPartnerNumber="QUICKCLNT" recipientPartnerType="LS" senderPartnerNumber="QUICKSTART" senderPartnerType="LS"> <rootSegment xsi:type="FLCUSTOMER_CREATEFROMDATA01---:ROOT" document="/"> <segmentChildren parent="//@rootSegment"> <E1SCU_CRE parent="//@rootSegment" document="/"> <segmentChildren parent="//@rootSegment/@segmentChildren/@E1SCU_CRE.0"> <E1BPSCUNEW parent="//@rootSegment/@segmentChildren/@E1SCU_CRE.0" document="/" CUSTNAME="Fred Flintstone" FORM="Mr." STREET="123 Rubble Lane" POSTCODE="01234" CITY="Bedrock" COUNTR="US" PHONE="800-555-1212" EMAIL="fred@bedrock.com" CUSTTYPE="P" DISCOUNT="005" LANGU="E"/> </segmentChildren> </E1SCU_CRE> </segmentChildren> </rootSegment> </idoc:Document>
from("direct:getFlightCustomerInfo") .to("bean:createFlightCustomerGetListRequest") .to("sap-srfc-destination:nplDest:BAPI_FLCUST_GETLIST") .to("bean:returnFlightCustomerInfo");
<route> <from uri="direct:getFlightCustomerInfo"/> <to uri="bean:createFlightCustomerGetListRequest"/> <to uri="sap-srfc-destination:nplDest:BAPI_FLCUST_GETLIST"/> <to uri="bean:returnFlightCustomerInfo"/> </route>
public void create(Exchange exchange) throws Exception { // Get SAP Endpoint to be called from context. SapSynchronousRfcDestinationEndpoint endpoint = exchange.getContext().getEndpoint("sap-srfc-destination:nplDest:BAPI_FLCUST_GETLIST", SapSynchronousRfcDestinationEndpoint.class); // Retrieve bean from message containing Flight Customer name to // look up. BookFlightRequest bookFlightRequest = exchange.getIn().getBody(BookFlightRequest.class); // Create SAP Request object from target endpoint. Structure request = endpoint.getRequest(); // Add Customer Name to request if set if (bookFlightRequest.getCustomerName() != null && bookFlightRequest.getCustomerName().length() > 0) { request.put("CUSTOMER_NAME", bookFlightRequest.getCustomerName()); } } else { throw new Exception("No Customer Name"); } // Put request object into body of exchange message. exchange.getIn().setBody(request); }
public void createFlightCustomerInfo(Exchange exchange) throws Exception { // Retrieve SAP response object from body of exchange message. Structure flightCustomerGetListResponse = exchange.getIn().getBody(Structure.class); if (flightCustomerGetListResponse == null) { throw new Exception("No Flight Customer Get List Response"); } // Check BAPI return parameter for errors @SuppressWarnings("unchecked") Table<Structure> bapiReturn = flightCustomerGetListResponse.get("RETURN", Table.class); Structure bapiReturnEntry = bapiReturn.get(0); if (bapiReturnEntry.get("TYPE", String.class) != "S") { String message = bapiReturnEntry.get("MESSAGE", String.class); throw new Exception("BAPI call failed: " + message); } // Get customer list table from response object. @SuppressWarnings("unchecked") Table<? extends Structure> customerList = flightCustomerGetListResponse.get("CUSTOMER_LIST", Table.class); if (customerList == null || customerList.size() == 0) { throw new Exception("No Customer Info."); } // Get Flight Customer data from first row of table. Structure customer = customerList.get(0); // Create bean to hold Flight Customer data. FlightCustomerInfo flightCustomerInfo = new FlightCustomerInfo(); // Get customer id from Flight Customer data and add to bean. String customerId = customer.get("CUSTOMERID", String.class); if (customerId != null) { flightCustomerInfo.setCustomerNumber(customerId); } // Put bean into body of exchange message. exchange.getIn().setHeader("flightCustomerInfo", flightCustomerInfo); }
from("direct:createFlightTrip") .to("bean:createFlightTripRequest") .to("sap-srfc-destination:nplDest:BAPI_FLTRIP_CREATE?transacted=true") .to("bean:returnFlightTripResponse");
<route> <from uri="direct:createFlightTrip"/> <to uri="bean:createFlightTripRequest"/> <to uri="sap-srfc-destination:nplDest:BAPI_FLTRIP_CREATE?transacted=true"/> <to uri="bean:returnFlightTripResponse"/> </route>
DataFormat jaxb = new JaxbDataFormat("org.fusesource.sap.example.jaxb"); from("sap-srfc-server:nplserver:BOOK_FLIGHT") .unmarshal(jaxb) .multicast() .to("direct:getFlightConnectionInfo", "direct:getFlightCustomerInfo", "direct:getPassengerInfo") .end() .to("direct:createFlightTrip") .marshal(jaxb);
<route> <from uri="sap-srfc-server:nplserver:BOOK_FLIGHT"/> <unmarshal> <jaxb contextPath="org.fusesource.sap.example.jaxb"/> </unmarshal> <multicast> <to uri="direct:getFlightConnectionInfo"/> <to uri="direct:getFlightCustomerInfo"/> <to uri="direct:getPassengerInfo"/> </multicast> <to uri="direct:createFlightTrip"/> <marshal> <jaxb contextPath="org.fusesource.sap.example.jaxb"/> </marshal> </route>
@XmlRootElement(name="Request", namespace="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT") @XmlAccessorType(XmlAccessType.FIELD) public class BookFlightRequest { @XmlAttribute(name="CUSTNAME") private String customerName; @XmlAttribute(name="FLIGHTDATE") @XmlJavaTypeAdapter(DateAdapter.class) private Date flightDate; @XmlAttribute(name="TRAVELAGENCYNUMBER") private String travelAgencyNumber; @XmlAttribute(name="DESTINATION_FROM") private String startAirportCode; @XmlAttribute(name="DESTINATION_TO") private String endAirportCode; @XmlAttribute(name="PASSFORM") private String passengerFormOfAddress; @XmlAttribute(name="PASSNAME") private String passengerName; @XmlAttribute(name="PASSBIRTH") @XmlJavaTypeAdapter(DateAdapter.class) private Date passengerDateOfBirth; @XmlAttribute(name="CLASS") private String flightClass; }
@XmlRootElement(name="Response", namespace="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT") @XmlAccessorType(XmlAccessType.FIELD) public class BookFlightResponse { @XmlAttribute(name="TRIPNUMBER") private String tripNumber; @XmlAttribute(name="TICKET_PRICE") private BigDecimal ticketPrice; @XmlAttribute(name="TICKET_TAX") private BigDecimal ticketTax; @XmlAttribute(name="CURRENCY") private String currency; @XmlAttribute(name="PASSFORM") private String passengerFormOfAddress; @XmlAttribute(name="PASSNAME") private String passengerName; @XmlAttribute(name="PASSBIRTH") @XmlJavaTypeAdapter(DateAdapter.class) private Date passengerDateOfBirth; @XmlElement(name="FLTINFO") private FlightInfo flightInfo; @XmlElement(name="CONNINFO") private ConnectionInfoTable connectionInfo; }
@XmlRootElement(name="FLTINFO", namespace="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT") @XmlAccessorType(XmlAccessType.FIELD) public class FlightInfo { @XmlAttribute(name="FLIGHTTIME") private String flightTime; @XmlAttribute(name="CITYFROM") private String cityFrom; @XmlAttribute(name="DEPDATE") @XmlJavaTypeAdapter(DateAdapter.class) private Date departureDate; @XmlAttribute(name="DEPTIME") @XmlJavaTypeAdapter(DateAdapter.class) private Date departureTime; @XmlAttribute(name="CITYTO") private String cityTo; @XmlAttribute(name="ARRDATE") @XmlJavaTypeAdapter(DateAdapter.class) private Date arrivalDate; @XmlAttribute(name="ARRTIME") @XmlJavaTypeAdapter(DateAdapter.class) private Date arrivalTime; }
@XmlRootElement(name="CONNINFO_TABLE", namespace="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT") @XmlAccessorType(XmlAccessType.FIELD) public class ConnectionInfoTable { @XmlElement(name="row") List<ConnectionInfo> rows; }
@XmlRootElement(name="CONNINFO", namespace="http://sap.fusesource.org/rfc/nplServer/BOOK_FLIGHT") @XmlAccessorType(XmlAccessType.FIELD) public class ConnectionInfo { @XmlAttribute(name="CONNID") String connectionId; @XmlAttribute(name="AIRLINE") String airline; @XmlAttribute(name="PLANETYPE") String planeType; @XmlAttribute(name="CITYFROM") String cityFrom; @XmlAttribute(name="DEPDATE") @XmlJavaTypeAdapter(DateAdapter.class) Date departureDate; @XmlAttribute(name="DEPTIME") @XmlJavaTypeAdapter(DateAdapter.class) Date departureTime; @XmlAttribute(name="CITYTO") String cityTo; @XmlAttribute(name="ARRDATE") @XmlJavaTypeAdapter(DateAdapter.class) Date arrivalDate; @XmlAttribute(name="ARRTIME") @XmlJavaTypeAdapter(DateAdapter.class) Date arrivalTime; }