cancel
Showing results for 
Search instead for 
Did you mean: 

Rest OData service queries

Former Member
0 Kudos

Hi,

  I am implementing a Odata model for rest service (as shown below)  for SMP 3.0 SP07. The Odata model development is done on Kepler and Api tools version is 1.4.1.

   The service code structure looks like below

Base URL to access this service is : https://localhost:8080/javaservice/webresources/notification

--------------------------------------------------------------------------------------------------------------------------------------------------------

......

@Path("/notification")

public class notificationservice {

  ....

  //Notification get METHOD

  @GET

  @Path("/{customerno}/{emailid}")

  @Produces("text/plain")

  public Response notify(@PathParam("customerno") String customerNo,

  @PathParam("emailid") String emailID) throws IOException,

  SQLException, PropertyVetoException, URISyntaxException {

  if (validateUSer(emailID, customerNo))

  return Response.status(200).build();

  else

  return Response.status(401).build();

  }

  @POST

  @Produces("text/plain")

  @Consumes(MediaType.APPLICATION_XML)

  public Response updateuser(String registrationMsg) throws SQLException {

  if (processUpdate())

  return Response.status(201).build();

  else

  return Response.status(500).build();

  }

}

-----------------------------------------------------------------------------------------------------------------------------------------------------------

I have built a OData model with name Notification and Entity Sets as Notifications.

Following are my queries as to how to access this service and send data to this service via Get and POST

The Odata service is connected as backend endpoint for application com.odata.test and the URL for access to the Odata service is a below

http://localhost:8087/com.odata.test/Notifications

Questions :

1. What should be the Request URL in the OData model for Read and POST operation ?

2. What will the url to send data via Get and Post method via SMP application com.odata.test ?

I have read Carlos Roggan's blogs and it unfortunately didn't help to resolve the issues mentioned above.

Kindly provide suggestions to resolve the issue.

Regards,

Amit

Accepted Solutions (1)

Accepted Solutions (1)

midhun_vp
Active Contributor
0 Kudos

Hi Amit,

I am assuming that you are looking for the device code.

Odata is a standard hence there will not be any code change when Odata service is exposed from IGW. The end point URL will be always same only you need to change the method of the request as given below:

Ex:

oHeaders['Authorization'] = authStr;

//oHeaders['X-SMP-APPCID'] = applicationContext.applicationConnectionId;    //this header is provided by the logon plugin

       

        var request = {

            headers : oHeaders,

            requestUri : getEndPointURL() + "/Products",

            method : "POST",

            data : params

        };

        OData.request(request, read, errorCallback);

If you are using SMP SDK you could follow these blogs to understand how the operations are done.

Android native app:

Kapsel Hybrid App:

Regards,Midhun

SAP Technology RIG

Former Member
0 Kudos

Thanks Midhun and JK.

I am having no trouble in connecting to the Rest service via SMP IGW, I am using Chrome Rest client for the same.

The debug points setup for checking if the data sent from Rest client via SMP is reaching the service that is where I am having trouble.

I have gone through the Links that JK has mentioned and after trying those I posted the question.

As mentioned is the original question I am not sure where the problem is; the code is as per the original question, the OData model Entity set name is Notifications with two property NotificationID and status.

  While setting up the data source in Eclipse I have use the source URL as /javaservice/webresources/notification/{customerno}/{emailid}

and Destination in the SMP Gateway cockpit points to http://localhost:8080

And using rest client I have used the below URL with Get method to reach the service

http://localhost:8087/com.odata.test/Notifications('Amit')/amit@in.com

and it fails to send the data to the service it reaches the breakpoint after webservice basic authentication is successful. I have also tried single parameter URL as well e.g.

/javaservice/webresources/notification/{customerno}

And using rest client I have used the below URL with Get method to reach the service

http://localhost:8087/com.odata.test/Notifications('Amit')

and the value received in the @PathParam is {customerno} and not 'Amit'

kindly suggest any approaches to resolve this issue.

midhun_vp
Active Contributor
0 Kudos

Hi Amit,

If you defined a query in IGW and you need data based on the value you are passing, you could use custom script.

Write script to get the header values and map it to input.

Example is given below. Here I am getting the username, password and companyId from the header and mapping it to input.


function processRequestData(message) {

importPackage(java.lang);

importPackage(java.util); importPackage(org.apache.olingo.odata2.api.processor); importPackage(com.sap.gateway.ip.core.customdev.logging);

// Getting the header values passed with the request

var context = message.getHeaders().get("odatacontext");

var companyId = context.getRequestHeaders().get("companyId").get(0);

var username = context.getRequestHeaders().get("username").get(0);

var password = context.getRequestHeaders().get("password").get(0);

parentMap = new LinkedHashMap();

childMap = new LinkedHashMap();

childMap.put("key:companyId", companyId);

childMap.put("key:username", username);

childMap.put("key:password", password);

parentMap.put("key:credential", childMap);

message.setBody(parentMap);

return message;

}

Hence while testing from a rest client you need to pass the input in the headers as given below instead of embedding it with URL.

From a mobile app you need to do the same, add header while you make a request.

Regards,Midhun

SAP Technology RIG

Former Member
0 Kudos

Hi Midhun/JK,

Thanks for the information.

  I was able to resolve the issue Jeff's help.

Following is the solution for everyone's benefit

1. For POST service I have removed the Path params and accepting that as a part of POST data.

2. For the Get service the following changes are done

     1. In the OData model in have used the following as relative path for data selection

               /javaservice/webresources/notification/{customerno}/{emailid}

         Also while creating the OData Entity model I have used customerno and emailid as properties and made them keys.

  

     2. Managed the response using custom code.

     3. While using the service via SMP application I am using the following URL

eg : http://localhost:8087/com.odata.test/Notifications(customerno='12345',emailid ='a@gmail.com' )

Regards,

Amit

Answers (2)

Answers (2)

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Amit,

Sometimes back i tried with REST service for QUERY operation , have a look at it once.


1. What should be the Request URL in the OData model for Read and POST operation ?

For READ: https://smpserver:port/gateway/odata/sap/projectname;v=1/EntitySet(' input value')

     Header: Authorization: smp credentials

For POST: first request for X-CSRF-TOKEN in GET request, pass it with further request for POST. Check 14 & 15 steps here.


2. What will the url to send data via Get and Post method via SMP application com.odata.test

I will suggest you to have a look at

Regards,

JK

Former Member
0 Kudos

Hi Experts,

          Any suggestions will be helpful.

Thanks,

Amit