This blog will list steps that required to be configured in order to consume OData service in agentry client by using Java.

I am targeting Agentry Client 6.1.0/WPF 6.1.3 & Agentry Server 6.1.0 for development.


1.  Create and configure an object to hold data that is returned/exposed by web service as shown below.Object1.png

2. Create a collection to fetch data for the objects that we created in step 1.

3. Create a fetch for this collection as shown below.

   Fetch1.png

(Note : I have configured this fetch as non-main fetch since its invoked by user and need to capture

username and password for consuming OData service and that are being passed as fetch parameters

to back-end)

4. Since user is required to enter username and password (passed as fetch parameters)

    I have configured a Fetch screen as shown below.

  /wp-content/uploads/2015/03/fetchscreen1_664167.png

5.  Now create an action that will be executed on button click to initiate this fetch.

     Add a transmit step and configure it to initiate this Fetch.


6. Configure a server exchange step for this fetch as usual procedure.(as shown below)

    This step is created by using Java System Connection.

Serverexstep1.png

7. This step will refer to our java class that is extended from com.syclo.sap.Steplet class.Which calls a Stephandler to

handle that request and will directly call a web-service as shown in the code snaps below.

Also create a pojo class (here Flight.java) having properties to hold data exposed by web-service. This pojo class is extended from com.syclo.sap.SAPObject class as usual.


Code for Steplet:


import com.syclo.agentry.AgentryException;

import com.syclo.agentry.BusinessLogicException;

import com.syclo.agentry.FetchSession;

import com.syclo.sap.Steplet;

public class FlightCarrOdataSteplet extends Steplet{

       public FlightCarrOdataSteplet(FetchSession session)

                     throws AgentryException, BusinessLogicException {

              super(session);

       }

       @Override

       public boolean execute() throws AgentryException {

              try

              {

                     FlightCarrOdataStephandler handler = new FlightCarrOdataStephandler(this._user);

                     this._returnData = createSAPObjectArray(new Flight(), handler.getFlightCarriers());

              }

              catch(Throwable e)

              {

                     throwExceptionToClient(e);

              }

             

              return true;

       }

      

}


Code for Step Handler :


import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import java.util.ArrayList;

import javax.xml.bind.DatatypeConverter;

import com.syclo.agentry.AgentryException;

import com.syclo.sap.SAPObject;

import com.syclo.sap.StepHandler;

import com.syclo.sap.User;


public class FlightCarrOdataStephandler extends StepHandler{

            User u = null;

            public FlightCarrOdataStephandler(User u)

       {

                     super(u);

                     this.u = u;

       }

      

             public ArrayList<? extends SAPObject> getFlightCarriers() throws AgentryException

       {

          ArrayList<SAPObject> recs = new ArrayList();

                  try

          {

                     //Specify your service URL here

                             String uri =http://xyz.abc.pqr:8000/sap/opu/odata/sap/ZFLIGHT /FlightSet?$format=json;

                     URL url = new URL(uri);

                     HttpURLConnection conn = (HttpURLConnection) url.openConnection();

                     conn.setRequestMethod(“GET”);

                     conn.setRequestProperty(“Accept”, “application/json”);

                     conn.setRequestProperty(“Accept-Encoding”,“identity”);

                     String encode = this.u.getString(“fetch.Username”) + “:” + this.u.getString(“fetch.Password”);

                     String auth = “Basic “ + DatatypeConverter.printBase64Binary(encode.getBytes());

                     conn.setRequestProperty(“Authorization”,auth);

                     BufferedReader inputReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

                  

                     StringBuilder sb = new StringBuilder();

                     String inline = “”;

                     

                                       while ((inline = inputReader.readLine()) != null) {

                        sb.append(inline);

                     }

                     org.json.JSONObject obj = new org.json.JSONObject(sb.toString());

                     org.json.JSONArray arr1 = obj.getJSONObject(“d”).getJSONArray(“results”);

                                       for(int i=0;i<arr1.length();i++)

                     {               

                           Flight fl = new Flight();

                           fl.setCarrid(arr1.getJSONObject(i).getString(“CAID”));

                           fl.setCoid(arr1.getJSONObject(i).getString(“CONID”));

                           fl.setFname(arr1.getJSONObject(i).getString(“FLGN”));

                           fl.setAname(arr1.getJSONObject(i).getString(“FLLN”));

                           recs.add(fl);

                      }

                                

               }

                           catch(Throwable e)

               {

                                    this.u.rethrowException(e, false);

               }

              return recs;

       }

}

8. Now sync your Agentry client and consume this web service as shown below./wp-content/uploads/2015/03/client1_664179.png

9.  This will ask user to enter credentials for consuming targeted web service.

     We have designed a fetch screen to capture Username ans password as shown below.

     This username and password will be passed as fetch parameters to backend.

/wp-content/uploads/2015/03/client2_664180.png

If all steps are configured correctly then it will consume targeted web service and will show result as below./wp-content/uploads/2015/03/client3_664190.png

(Note: This blog do not mention steps to create OData web service, but lists Agentry Steps to consume OData service.

Agentry “System connection” is assumed to be of type Java connection and user has done all

required configs in JavaBE.ini)

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Stephen Streeter

    Just to point out if you use SMP 3 SP05 or later, there is a OData system connection so you don’t need to use the Java Code to connect to the backend.

    (0) 
    1. AK K Post author

      Thanks Stephen for that update,

      Actually i am supporting an application which is WorkManager 6.0 on SMP 2.3 where i got to implement this scenario.I thought it would be help-full to those who are still working with SMP 2.3.

      Also i am going to suggest another approach that we are following right now.That’s why it says Part-1.

      Thanks once again.

      Regards,

      AK

      (0) 

Leave a Reply