Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
sajith_p
Participant

How to create SOAP to RFC PI interface with Java Mapping


SAP PO server: 7.4 SP14



Summary


This article will explain you clear step by step procedure to implement SOAP to RFC synchronous scenario.

Author: Sajith P, SAP PO Consultant

Introduction


This document will explain the Soap to RFC communication scenario using SAP PI. At sender side SOAP adapter is used and receiver side RFC adapter is used to update the record in the SAP ECC via an RFC. A user defined function (UDF) mapping java class is used here to read the data from a database table based on the input request Id. If the record is syndicated in ECC, we can know the response send back by the RFC.

In this document I am trying to read the data from the FLIGHT_SAVE db table w.r.to the input request id and pass this data to the RFC to syndicate in ECC. The Request id value will be pass as input to the java mapping UDF and it will read the record from DB table, and this data will send to RFC.

The Java mapping class receives the input as XML data and it will be converted as object. Based on this java program will fetch the data from the DB table and this will be converted as output XML data format. JAXB Marshaller and Unmarshaller java classes are used here to convert XML to Object and Object to XML.

Pre-requisites



  • SAP PO 7.4 SP13 is used for this example.

  • Oracle DB Server 11G is used in this scenario.

  • Data base table FLIGHT_SAVE with Request Id as primary key, and other fields, airline id, connect id, flight date, price, currency, currency iso, plane type.

  • JDBC Custom Data source in SAP PO server to connect to the DB.

  • SAP ECC connection details and RFC BAPI_FLIGHT_SAVEREPLICA


 

Solution Diagram



Operation Mapping Diagram



Integrated Configuration Diagram



Integration Repository


Import the software component. Create below Enterprise Services Repository objects under this software component.

Name Space


Create the Name Space - http://javamaptest.com


Folder


Create the folder – FLIGHT_TEST.


Imported Objects


Import the RFC BAPI_FLIGHT_SAVEREPLICA

Go to Imported ObjectsàRight Click and import the RFC BAPI_FLIGHT_SAVEREPLICA.

Please note, the RFC should be remote enabled in ECC.


Data Types


Create Flight_Rquest data type with input Request_ID and Teset_Run elements.


Message Type


Create the message type MT_Flight_Request and assign the data type Flight_Rquest.


Export the Message Type XSD


Export the RFC Message Type


Service Interface


Create the outbound interface

Request Message Type: MT_Flight_Request

Response Message Type: BAPI_FLIGHT_SAVEREPLICA.Response


Create the inbound interface

Request Message Type: BAPI_FLIGHT_SAVEREPLICA

Response Message Type: BAPI_FLIGHT_SAVEREPLICA.Response


Java Mapping User Define Function


Java mapping will be doing below tasks

  1. Read the input MT_Flight_Request XML.

  2. Convert the input MT_Flight_Request XML data to java object

  3. Based on the input data, read data from DB table(s)

  4. Convert the data object from DB to output BAPI_FLIGHT_SAVEREPLICA XML file.


Steps to create Java mapping Jar file


Create a Java Project



Note: Use jdk in the JRE System library instead of jre.
Add XPI Mapping Libraries to the project by right click on the project and select Build path and Add Libraries.


Copy the imported MT_Flight_Request.xsd and BAPI_FLIGHT_SAVEREPLICA.xsd in the project folder.


Generate the JAXB classes: Right Click on the imported .xsd file and go to Generate à JAXB Classes



This will generate the java classes under the corresponding packages provided.



Please note: As my NWDS 7.3 SP13 was not supporting generating the JAXB classes, so as a workaround, I have used Eclipse Mars to generate JAXB classes and copy paste these classes in NWDS java project folder
Now create the JAXBMarshaler and JAXBMarshaler java class files


Create the DTO for DB table


Create the java class for read data from DB and set to DTO


Create the FlightJavaMapping java class to transform the input xml MT_Flight_Request.xml to output  BAPI_FLIGHT_SAVEREPLICA.xml

package com.flight.mapping.jaxb;

import java.io.InputStream;

import java.io.OutputStream;

import java.math.BigDecimal;

import com.flight.marsheler.jaxb.JAXBMarshaler;

import com.flight.marsheler.jaxb.JAXBUnMarshaler;

import com.flight.request.jaxb.FlightRequest;

import com.flight.response.jaxb.BAPIFLIGHTSAVEREPLICA;

import com.flight.response.jaxb.BAPISFLREP;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class FlightJavaMapping extends AbstractTransformation{

@SuppressWarnings("unchecked")

@Override

public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {

try {

InputStream inputstream = transformationInput.getInputPayload().getInputStream();

OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

FlightRequest flightRequest = new FlightRequest();

//Read Input from input XML file

JAXBUnMarshaler<FlightRequest> jaxbUnMarshaler = new JAXBUnMarshaler<FlightRequest>(inputstream, flightRequest);

flightRequest = jaxbUnMarshaler.getUnmarshalledObject();

String reqID = flightRequest.getRequestID();

String testRun = flightRequest.getTestRun();

ReadDataFromDB readDataFromDB = new ReadDataFromDB();

FlightSaveDto flightSaveDto = new FlightSaveDto();

flightSaveDto = readDataFromDB.getDataFromDB(reqID);

//Set output XML

BAPIFLIGHTSAVEREPLICA bapiflightsavereplica = new BAPIFLIGHTSAVEREPLICA();

BAPISFLREP bapisflrep = new BAPISFLREP();

bapisflrep.setAIRLINEID(flightSaveDto.getAIRLINEID());

bapisflrep.setCONNECTID(flightSaveDto.getCONNECTID());

bapisflrep.setFLIGHTDATE(flightSaveDto.getFLIGHTDATE());

bapisflrep.setPRICE(new BigDecimal(flightSaveDto.getPRICE()));

bapisflrep.setCURR(flightSaveDto.getCURR());

bapisflrep.setCURRISO(flightSaveDto.getCURR_ISO());

bapisflrep.setPLANETYPE(flightSaveDto.getPLANETYPE());

bapiflightsavereplica.setFLIGHTDATA(bapisflrep);

bapiflightsavereplica.setTESTRUN(testRun);

JAXBMarshaler jaxbMarshaler = new JAXBMarshaler<BAPIFLIGHTSAVEREPLICA>();

String outPutXMLString = jaxbMarshaler.marshalJAXBToXMLString(bapiflightsavereplica);

outputstream.write(outPutXMLString.getBytes());

} catch (Exception exception) {

getTrace().addDebugMessage(exception.getMessage());

throw new StreamTransformationException(exception.toString());

}

}

}
Export the java project as jar file


Check below while export as jar.



Create the Imported Archive in ESR



Import Java mapping Jar file in the Imported Archive ESR object



Select the FlightJavaMapping.class file.



Message Mapping for Response


Create Message mapping ESR object



Create Operation Mapping



In the Request, select the Mapping program type as Java class and use the imported archive ESR object.



Use the MM_Flight_Request_Res message mapping in the response



All the ESR objects for this interface


Integration Directory


In the Integration directory below items needs to be created and configured

Business Component request side



Communication channel for Sender: Adapter Type SOAP



Communication channel for Receiver: Adapter Type RFC



Business Component configuration

Receiver



Sender

Integrated Configuration



Inbound Processing



Receiver

Receiver Interface

Outbound Processing

Get the WSDL link for the PI interface create





Next part of the document will explain, how to implement this interface in BPM automated activity

Thank you

Sajith P

SAP PO (PI, BPM, BRM) Consultant
1 Comment
Labels in this area