Java client proxy scenario in PI/XI

...Previous

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.InitialContextFactoryImpl");
	  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.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image