Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Flex application using LCDS to access Java Data

Former Member
0 Likes
1,030

Hi experts.

I'm currentrly working on a Flex application that connects to the SAP system to retrieve some data.

This connection is made through the JCo (to be able to use RFC), and thus I'm using LCDS to map the Java results to the Flex application.

I made a Flex/Java project in Eclipse.

I'm properly using the JCo in my Java class (I do retrieve the data I want from SAP).

In ConnexionManager.java, I have a public static JCoTable all() function that returns a table.

Here are my different sources:

Flex_JCo_Test.mxml


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF">
	
	<mx:RemoteObject id="srv" destination="cnxMngr"/>
	
	<mx:DataGrid dataProvider="{srv.results}" width="100%" height="100%"/> 

	<mx:Button label="Get Data" click="srv.all()"/>	
		
</mx:Application>

remoting-config.xml


<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" 
    class="flex.messaging.services.RemotingService">

    <adapters>
        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
    </adapters>

    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>
    
    <destination id="cnxMngr">
        <properties>
            <source>connexionJCo.ConnexionManager</source>
            <scope>application</scope>
        </properties>
        <adapter ref="java-object"/>
    </destination>

</service>

And this is the error I'm getting:



[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://localhost/WebContent/messagebroker/amf'"]
	at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:220]
	at mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:53]
	at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
	at mx.messaging::ChannelSet/faultPendingSends()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1482]
	at mx.messaging::ChannelSet/channelFaultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:975]
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at mx.messaging::Channel/connectFailed()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\Channel.as:997]
	at mx.messaging.channels::PollingChannel/connectFailed()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:354]
	at mx.messaging.channels::AMFChannel/statusHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:390]

I'm using the lcds.war provided with the lcds. And I kept the default settings for the channels.

I really don't have a clue on what I'm doing wrong.

Thanks for your help.

Regards,

C.

Edited by: Cristina CHEN MA on Sep 22, 2009 4:35 PM

5 REPLIES 5
Read only

Former Member
0 Likes
748

I don't know what's wrong, but the markups in my sources are not working. Sorry

Read only

0 Likes
748

Hi.

I solved my problem by starting from scratch.

I was using the tomcat provided by the LCDS when installing it. Thus, I had no control over the java runtime that was used by the server, which was different from the one I was using to compile my java project.

The solution was simply installing a LCDS without server. Having a standalone tomcat. And define in Eclipse and Tomcat the same java runtime.

Regards,

C.

Read only

0 Likes
748

Hi crist,

Could please tell me how u connect SAP system from java class using eclipse.

Regards,

Arun

Read only

0 Likes
748

Hi Vgarun.

You can find some very helpfull "how to" about connecting to sap system via a Java Class.

Check this out:

[http://help.sap.com/saphelp_nw04/helpdata/en/35/42e13d82fcfb34e10000000a114084/frameset.htm]

And just to get you started, here you have part of my Java code.

You'll have to change the system data according to your system.

And the function getTableResult is an example of how call a function.

public class JcoTest{
	static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
	static{
	    Properties connectProperties = new Properties();
	    //System data
	    connectProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER,  "/H/xxx.xxx.xxx.xxx/H/");
		connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "sap-ecc.xxxxxx.xxx");
		connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "xx");
		//User data
		connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "xxx");
		connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "xxxxxxxx");
		connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "xxxxxx");
		connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");
		//Pool data
		connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
		connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,    "10");
		//Create data file with all the properties
		createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
		
	}

	static void createDataFile(String name, String suffix, Properties properties){
	    File cfg = new File(name+"."+suffix);
		if(!cfg.exists()){
		    try{
		        FileOutputStream fos = new FileOutputStream(cfg, false);
		        properties.store(fos, "for tests only !");
		    fos.close();
			}catch (Exception e){
			    throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
	        }
	    }
	}
	
	/*
	 * Establish connection
	 */
	public static void connectUsingPool() throws JCoException{
	    JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
	    destination.ping();
	}

	/*
	 * Get data
	 */
	public static JCoTable getTableResult() throws JCoException{
		// Connection
	    JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
	    
	    // Call function BAPI_FLIGHT_GETLIST
	    JCoFunction function = destination.getRepository().getFunction("BAPI_FLIGHT_GETLIST");
		if(function == null)
		    throw new RuntimeException("BAPI_FLIGHT_GETLIST not found in SAP.");
		// Get import parameters
		function.getImportParameterList().setValue("AIRLINE", "AA");
		try{
			// Execute function
		    function.execute(destination);
		}catch(AbapException e){
		    System.out.println(e.toString());
		    return null;
		}
		
		// Get table RETURN to check error messages
		JCoTable returnTable = function.getTableParameterList().getTable("RETURN");
		if (! (returnTable.getString("TYPE").equals("")||returnTable.getString("TYPE").equals("S")))
		   throw new RuntimeException(returnTable.getString("MESSAGE"));

		// Get result table FLIGHT_LIST
		JCoTable codes = function.getTableParameterList().getTable("FLIGHT_LIST");
		return codes;	

	}
}

Hope this helps 😃

Regards,

C.

Read only

0 Likes
748

Sorry for the layout, the "code" markup is not working....