Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member208808
Active Participant

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.

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.

  

(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.

 

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.

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.

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.

If all steps are configured correctly then it will consume targeted web service and will show result as below.

(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)

2 Comments
Labels in this area