Sei sulla pagina 1di 10

Java client proxy scenario in PI/XI

By Rachit Sehgal, CSC India


Scenario Introduction
In this article we explore a business scenario that involves sending a request from a JSP page to SAP
NW PI 7.0, which forwards the request to a database and fetches the response. The request contains
the username and transaction and the corresponding data is returned to JSP as response.
Logical Flow of the Business Scenario
1. Request is sent from a JSP page.
2. The request invokes a Java application class (developed by user for proxy invocation) that is
deployed along with the EAR project (which includes the generated proxy beans/classes) in
the SAP J2EE Engine.
3. The Java application class performs a lookup for the required client bean in the SAP J2EE
Engine and sends the request data.
4. This client bean uses the generated proxy classes and forwards the message to Java Proxy
Runtime.
5. The Java Proxy Runtime of the J2EE Engine forwards the request to the messaging system.
6. The messaging system forwards the request to the Integration Server of SAP Exchange
Infrastructure using the HTTP URLhttp://<server>:<ABAP-http
port>/sap/xi/engine?type=entry
7. Configuration steps like sender agreement, receiver determination, interface determination,
and interface mapping are performed.
8. The message is routed to the Adapter Framework using HTTP URLhttp://<server>:<J2EE-
http port>/MessagingSystem/receive/AFW/XI
9. In the Adapter Engine the channels and agreements are read and then the respective
communication channel using the JDBC adapter (in this business scenario) forwards the
request message to the receiver database.
10. Response is routed back to the sender Java application after the steps like interface mapping
(response message mapping).
11. The Java application routes the response to the JSP page that initiated the request
Development Steps
Integration Builder Design Time
1. Define Data Types, Messages Type for the following Message Mappings
Request Message Mapping -- JDBC_Select_File_Req_To_JDBC_Req_MM_HTTP
Response Message Mapping -- JDBC_Select_JDBC_Res_To_JDBC_Res_HTTP
Request Message Mapping

Response Message Mapping

2. Interface Mapping



3. Generating the Java Proxies for the Outbound Message Interface
Generate the Java proxies using Java Proxy Generation, select the outbound message interface.
(User_Sync_MI_HTTP)

Generated Classes and Beans

Integration Builder Configuration Time
Sender Agreement: Create a sender agreement
Receiver Determination: Create the receiver determination using the database business system.
Interface Determination & Mapping: Create the interface determination and the interface mapping
using the mapping of design time.
Receiver Agreement: Create the receiver agreement using the JDBC adapter communication
channel.
Create an EJB Module Project Using NW Developer Studio
<ejb-jar>
<description>EJB JAR description</description>
<display-name>EJB JAR</display-name>
<enterprise-beans>
<session>
<ejb-name>UserSyncMIHTTP_PortTypeBean</ejb-name>
<home>psharma51Testarea.UserSyncMIHTTP_PortTypeHome</home>
<remote>psharma51Testarea.UserSyncMIHTTP_PortTypeRemote</remote>
<local-
home>psharma51Testarea.UserSyncMIHTTP_PortTypeLocalHome</local-home>
<local>psharma51Testarea.UserSyncMIHTTP_PortTypeLocal</local>
<ejb-class>psharma51Testarea.UserSyncMIHTTP_PortTypeBean</ejb-
class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
Here psharma51Testarea is actually the namespace in the design time where message interfaces
have been developed.
In the EJB project it (psharma51Testarea) is the package that includes all the classes that are
generated. Along with generated classes, a Java class needs to be developed that will invoke this
proxy bean. This application class can be included in the same EJB project.
JNDI Name
<ejb-j2ee-engine>
<enterprise-beans>
<enterprise-bean>
<ejb-name>UserSyncMIHTTP_PortTypeBean</ejb-name>
<jndi-name>JavaProxy</jndi-name>
<session-props/>
</enterprise-bean>
</enterprise-beans>
</ejb-j2ee-engine>
Finally, create the Java archive of the EJB module project.
Java Class ProxyCall
package psharma51Testarea;
import java.util.*;
import javax.naming.*;
import javax.rmi.*;
import com.sap.aii.proxy.xiruntime.core.MessageSpecifier;
public class ProxyCall
{

String str = "";

JDBCSelectFileTrgDTHTTP_Type response;

UserSyncMIHTTP_PortTypeHome queryOutHome;
UserSyncMIHTTP_PortTypeRemote queryOutRemote;
ArrayList abc = new ArrayList();


public JDBCSelectFileTrgDTHTTP_Type getResult(String material)
{
try{
Context ctx = null;
Properties p = new Properties();

p.put(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.Initial
ContextFactoryImpl");
p.put(Context.PROVIDER_URL, "server ip:java port");
p.put(Context.SECURITY_PRINCIPAL, "username");
p.put(Context.SECURITY_CREDENTIALS, "password");
ctx = new InitialContext(p);
str=str+"a";
Object ref = ctx.lookup("JavaProxy"); // JNDI Name
str=str+"b";

// Cast to Home interface
queryOutHome =
(UserSyncMIHTTP_PortTypeHome)PortableRemoteObject.narrow(ref,UserSyncMIHTTP
_PortTypeHome.class);

// Get Remote interface
queryOutRemote = queryOutHome.create();
str=str+"c";

JDBCSelectFileSrcDTHTTP_Type reqtype = new
JDBCSelectFileSrcDTHTTP_Type();
reqtype.setBNAME("Rac"); // TP Name
reqtype.setOPERATION("EQ"); // Transaction

str=str+"d";


//Call the Java proxy and get the return parameters
//initialise the Message Specifier
//queryOutRemote.$messageSpecifier();
MessageSpecifier msg = queryOutRemote.$messageSpecifier();
str=str+"e123";
msg.setSenderService("JavaProxy_BS");
queryOutRemote.$messageSpecifier(msg);
str=str+"f333";

// response = queryOutLocal.userSyncMIHTTP1(reqtype);
response = queryOutRemote.userSyncMIHTTP(reqtype);
str=str+"gggggg";

}

catch(Exception ex)
{
ex.printStackTrace();
str=str+ex.getMessage();
}
return response;
//return str;

}

public ArrayList getName()
{

JDBCSelectFileTrgDTHTTP_Type.ROW_List b = new
JDBCSelectFileTrgDTHTTP_Type.ROW_List();
b = response.get_as_listROW();

int i = b.size();
String a = "";
ArrayList l = new ArrayList();

for (int j=0; j<i; j++)
{
JDBCSelectFileTrgDTHTTP_Type.ROW_Type c =
b.getROW(j);
a = c.getBNAME();
l.add(a);
}

return l;
}
}
Create a Web Module Project
Create a web module project (ProxyWeb).
Create 2 JSP pages UserClient jsp page sends username and transaction and UserDisplay jsp page
displays the corresponding name as response. Finally, create the web archive (WAR) for the above
project.
UserDisplay jsp
<HTML>
<%@ page language="java" import="psharma51Testarea.*"%>
<jsp:useBean id="user" class="psharma51Testarea.testing" scope="session"/>
<jsp:setProperty name="user" property="*"/>
<BODY>
<%
JDBCSelectFileTrgDTHTTP_Type resp = user.getResult("ABC");
ArrayList value = user.getName();
for (int i=0; i< value.size(); i++)
{
String name = (String)value.get(i);
}
%>
</BODY>
</HTML>
web.xml
<web-app>
<display-name>WEB APP</display-name>
<description>WEB APP description</description>
<servlet>
<servlet-name>UserDisplay.jsp</servlet-name>
<jsp-file>/UserDisplay.jsp</jsp-file>
</servlet>
</web-app>
Create the war file of the above Web Module Project
Create an Enterprise Application Project
Create an Enterprise Application project (ProxyEAR) add the above EJB and web module projects to
this EAR.
The following dependencies must be declared in the application-j2ee-engine.xml
<application-j2ee-engine>
<reference reference-type="weak">
<reference-target
provider-name="sap.com"
target-type="library">com.sap.aii.proxy.xiruntime
</reference-target>
</reference>
<reference reference-type="weak">
<reference-target
provider-name="sap.com"
target-type="library">com.sap.aii.messaging.runtime
</reference-target>
</reference>
<reference reference-type="weak">
<reference-target
provider-name="sap.com"
target-type="library">com.sap.xi.util.misc
</reference-target>
</reference>
<reference reference-type="weak">
<reference-target
provider-name="sap.com"
target-type="library">com.sap.guid
</reference-target>
</reference>
<provider-name>sap.com</provider-name>
<fail-over-enable
mode="disable"/>
</application-j2ee-engine>
Finally, deploy the EAR file into the SAP J2EE engine.
Test the scenario by invoking the JSP page. Give the user name and transaction and it should return
the corresponding data as its response.

Potrebbero piacerti anche