How do I do Presto Connect for Java calls inside of EMML?

chriswarner
chriswarner's picture
User offline. Last seen 6 days 1 hour ago. Offline
Joined: 08/22/2008
Points: 1377

Matt asked me this one in the halls today...

'How do I do Presto Connect for Java calls inside of EMML? I know I need to include the Presto Connect jars but what would I need to do in order to make a jump request inside of EMML and paramaterize the request so it can be requested and paginated through the mashup?'

0
Your rating: None
girish
girish's picture
User offline. Last seen 4 weeks 6 hours ago. Offline
Joined: 09/22/2008
Points: 70

It's pretty easy!

1. (presto_home )/connectors/api/java/prestoconnect_for_java.zip has everything you need to use PC4J

2. extract and copy prestoconnect.jar to /webapps/presto/WEB-INF/lib directory

Next step is to write EMMLs to invoke PrestoConnect APIs I have included 2 samples below.

First one is simple one, invoking a Presto Platform service to "get list of all services" registered so far and the second one invokes a "Yahoo Local"

REST service by passing parameters like zip, query and results.

  <?xml version="1.0"?> <mashup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.jackbe.com/2008-03-01/EMMLSchema ../src/schemas/EMMLSpec.xsd" name="PrestoConnectEMML">      <operation name="invoke">     <output name="result" type="document"></output>     <variable name="resultXml" type="string"></variable>      <script type="text/javascript">
        <![CDATA[
                var serverAddress = "http://localhost:8080/presto/edge/api";
                var factory= new Packages.com.jackbe.presto.connect.ConnectionFactory();
                var connection = factory.create(serverAddress);
                var authToken = connection.login("admin", "adminadmin");
                var request = new Packages.com.jackbe.presto.connect.JUMPRequest();
                var constants = new Packages.com.jackbe.presto.connect.common.PrestoConstants();

                request.setVersion(constants.JUMP_PROTOCOL_1_1);
                request.setSid("RDSService");
                request.setOid("getListOfAllServices");
                request.setSvcVersion("0.1");
                request.setHeaderParameter(
                                constants.JUMP_REQUEST_HEADER_RESULT_FORMAT,
                                constants.JUMP_RESULT_FORMAT_XML);
                request.setHeaderParameter(
                                constants.JUMP_RESPONSE_AUTH_TOKEN,
                                authToken);
     
                var response = connection.invoke(request);
                resultXml = response.getResponse();

]]>
</script> <assign fromvariable="resultXml" outputvariable="result"></assign> </operation>

</mashup>   

Once you have EMMLs in place, you can either test them without publishing or you can publish them as mashup service and invoke it as a service. To invoke without publishing,
1. go to (presto_home) /mashupclient/bin

2. emml.sh -u -p -f pc4j_YahooLocalREST_js.emml -url http://localhost:8080/presto/edge/api

To publish and invoke it as a service,

1. go to (presto_home) /mashupclient/bin

2. emmlpub.sh -u -p -f pc4j_YahooLocalREST_js.emml -url http://localhost:8080/presto/edge/api

3. now, you can invoke the service thru REST api or use it in Wires for mashing up with other services http://localhost:8080/presto/edge/api/rest/YahooLocalMashup/invoke?presto_username=$session/username&presto_password=$session/password

- Girish@JackBe