Re: [Dev] [AM-2.1.0] Issues with client application based on SDK

2018-02-21 Thread Malintha Amarasinghe
Yes as Jason mentioned it seems this is already fixed as a WUM update. The
fix is already added to the support branch [1]

[1]
https://github.com/wso2-support/carbon-apimgt/commit/71f321dd2221e42ba6b0a5b2f7db3ef8002898c0

On Thu, Feb 22, 2018 at 12:19 AM, Malintha Amarasinghe 
wrote:

> Hi Himasha,
>
> This looks like a similar issue like https://github.com/wso2/
> product-apim/issues/1607.
>
> On Wed, Feb 21, 2018 at 8:11 PM, Himasha Guruge  wrote:
>
>> Hi,
>>
>> I'm trying out [1] with Api Manager 2.1.0. I have downloaded the java SDK
>> of PizzaShackAPI and tried to run APIClient main method. At first with the
>> exact same code, I was getting below error.
>>
>>
>> com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
>> Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
>>
>
> Normally we don't need to modify any generated code in the SDK. From the
> above error what it means is the SDK *expects* a payload starting with
> "{" (json object) but it received a payload starting with "[" (json array).
>
> What SDK decides as *expects* is what we define in the swagger: Because
> the SDK is actually generated using the swagger of the API (Chamin's
> article mentions the info in detail).
>
> If we look at the swagger definition of the /menu.
>
>   /menu:
> get:
>   x-auth-type: Application & Application User
>   x-throttling-tier: Unlimited
>   description: Return a list of available menu items
>   parameters: []
>   responses:
> '200':
>   headers: {}
> *  schema:*
> *title: Menu*
> *properties:*
> *  list:*
> *items:*
> *  $ref: '#/definitions/MenuItem'*
> *type: array*
> *type: object*
>
> It specifies the response as { "list" : [ {*menu_item1} , { menu_item2 }
> .. *] } etc. This is a JSON object (starting with "{").
>
> But seems like what you are getting as the actual response from /menu GET
> call is something like this:  [ {*menu_item1} , { menu_item2 } .. *]
>  (without the "list" part). This is a JSON array (starting with "["). This
> violates what we specified in the swagger.
>
> Can you fix the swagger as below from Publisher -> Edit -> Edit Source ->
> Save & Publish API and try generating the SDK from Store and invoking once
> again.
>
>   /menu:
> get:
>   x-auth-type: Application & Application User
>   x-throttling-tier: Unlimited
>   description: Return a list of available menu items
>   parameters: []
>   responses:
> '200':
>   description: OK. List of APIs is returned.
>   headers: {}
> *  schema:*
> *type: array*
> *items:*
> *  $ref: '#/definitions/MenuItem'*
>
> If this works, lets create an issue to track this to fix in a future
> release.
>
> Thanks!
>
>
>>  To sort it out I updated defaultAPI.java code of the SDK, to return a
>> List instead, and it got sorted. (See changes below)
>>
>>  public List menuGet() throws ApiException {
>> ApiResponse resp = menuGetWithHttpInfo();
>> return resp.getData();
>> }
>>
>>
>>public ApiResponse menuGetWithHttpInfo() throws
>> ApiException {
>> com.squareup.okhttp.Call call = menuGetCall(null, null);
>> Type localVarReturnType = new TypeToken(){}.getT
>> ype();
>> return apiClient.execute(call, localVarReturnType);
>> }
>>
>>
>>  However, now I'm getting a response but the menu list is empty. Any idea
>> what could be the issue?
>>
>>
>> [1]https://docs.wso2.com/display/AM210/Write+a+Client+Applic
>> ation+Using+the+SDK#1a97b57b1791422f99d81743523b612e
>>
>> Thanks,
>> Himasha Guruge
>> Senior Software Engineer
>> WS*O2* *Inc.*
>> Mobile: +94 777459299 <+94%2077%20745%209299>
>> himas...@wso2.com
>>
>> ___
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Malintha Amarasinghe
> *WSO2, Inc. - lean | enterprise | middleware*
> http://wso2.com/
>
> Mobile : +94 712383306 <+94%2071%20238%203306>
>



-- 
Malintha Amarasinghe
*WSO2, Inc. - lean | enterprise | middleware*
http://wso2.com/

Mobile : +94 712383306
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [AM-2.1.0] Issues with client application based on SDK

2018-02-21 Thread Malintha Amarasinghe
Hi Himasha,

This looks like a similar issue like
https://github.com/wso2/product-apim/issues/1607.

On Wed, Feb 21, 2018 at 8:11 PM, Himasha Guruge  wrote:

> Hi,
>
> I'm trying out [1] with Api Manager 2.1.0. I have downloaded the java SDK
> of PizzaShackAPI and tried to run APIClient main method. At first with the
> exact same code, I was getting below error.
>
>
> com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
> Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
>

Normally we don't need to modify any generated code in the SDK. From the
above error what it means is the SDK *expects* a payload starting with "{"
(json object) but it received a payload starting with "[" (json array).

What SDK decides as *expects* is what we define in the swagger: Because the
SDK is actually generated using the swagger of the API (Chamin's article
mentions the info in detail).

If we look at the swagger definition of the /menu.

  /menu:
get:
  x-auth-type: Application & Application User
  x-throttling-tier: Unlimited
  description: Return a list of available menu items
  parameters: []
  responses:
'200':
  headers: {}
*  schema:*
*title: Menu*
*properties:*
*  list:*
*items:*
*  $ref: '#/definitions/MenuItem'*
*type: array*
*type: object*

It specifies the response as { "list" : [ {*menu_item1} , { menu_item2 }
.. *] } etc. This is a JSON object (starting with "{").

But seems like what you are getting as the actual response from /menu GET
call is something like this:  [ {*menu_item1} , { menu_item2 } .. *]
 (without the "list" part). This is a JSON array (starting with "["). This
violates what we specified in the swagger.

Can you fix the swagger as below from Publisher -> Edit -> Edit Source ->
Save & Publish API and try generating the SDK from Store and invoking once
again.

  /menu:
get:
  x-auth-type: Application & Application User
  x-throttling-tier: Unlimited
  description: Return a list of available menu items
  parameters: []
  responses:
'200':
  description: OK. List of APIs is returned.
  headers: {}
*  schema:*
*type: array*
*items:*
*  $ref: '#/definitions/MenuItem'*

If this works, lets create an issue to track this to fix in a future
release.

Thanks!


>  To sort it out I updated defaultAPI.java code of the SDK, to return a
> List instead, and it got sorted. (See changes below)
>
>  public List menuGet() throws ApiException {
> ApiResponse resp = menuGetWithHttpInfo();
> return resp.getData();
> }
>
>
>public ApiResponse menuGetWithHttpInfo() throws
> ApiException {
> com.squareup.okhttp.Call call = menuGetCall(null, null);
> Type localVarReturnType = new TypeToken(){}.getType();
> return apiClient.execute(call, localVarReturnType);
> }
>
>
>  However, now I'm getting a response but the menu list is empty. Any idea
> what could be the issue?
>
>
> [1]https://docs.wso2.com/display/AM210/Write+a+Client+
> Application+Using+the+SDK#1a97b57b1791422f99d81743523b612e
>
> Thanks,
> Himasha Guruge
> Senior Software Engineer
> WS*O2* *Inc.*
> Mobile: +94 777459299 <+94%2077%20745%209299>
> himas...@wso2.com
>
> ___
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Malintha Amarasinghe
*WSO2, Inc. - lean | enterprise | middleware*
http://wso2.com/

Mobile : +94 712383306
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [AM-2.1.0] Issues with client application based on SDK

2018-02-21 Thread Chamin Dias
Hi Himasha,

Please refer this article [1]. It has a complete example w.r.t your
requirement. You can try that out and see how it works.

[1]
https://wso2.com/library/articles/2017/03/article-introducing-sdk-support-with-wso2-api-manager/#example

Thanks.

On Wed, Feb 21, 2018 at 9:17 PM, Jason De Silva  wrote:

> Hi Himasha,
>
> I tried this scenario in a wum updated pack referring [1] for the
> pizzashack api and it worked for me OOB. Did you also try it out in a wum
> updated pack?
>
> [1] https://docs.wso2.com/display/AM210/Write+a+Client+
> Application+Using+the+SDK
>
> Regards,
> Jason
>
> Jason De Silva
> *Software Engineer - QA*
> Mobile: +94 (0) 772 097 678
> Email: jas...@wso2.com
> WSO2 Inc. www.wso2.com
> 
>
> On Wed, Feb 21, 2018 at 8:11 PM, Himasha Guruge  wrote:
>
>> Hi,
>>
>> I'm trying out [1] with Api Manager 2.1.0. I have downloaded the java SDK
>> of PizzaShackAPI and tried to run APIClient main method. At first with the
>> exact same code, I was getting below error.
>>
>>
>> com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
>> Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
>>
>>  To sort it out I updated defaultAPI.java code of the SDK, to return a
>> List instead, and it got sorted. (See changes below)
>>
>>  public List menuGet() throws ApiException {
>> ApiResponse resp = menuGetWithHttpInfo();
>> return resp.getData();
>> }
>>
>>
>>public ApiResponse menuGetWithHttpInfo() throws
>> ApiException {
>> com.squareup.okhttp.Call call = menuGetCall(null, null);
>> Type localVarReturnType = new TypeToken(){}.getT
>> ype();
>> return apiClient.execute(call, localVarReturnType);
>> }
>>
>>
>>  However, now I'm getting a response but the menu list is empty. Any idea
>> what could be the issue?
>>
>>
>> [1]https://docs.wso2.com/display/AM210/Write+a+Client+Applic
>> ation+Using+the+SDK#1a97b57b1791422f99d81743523b612e
>>
>> Thanks,
>> Himasha Guruge
>> Senior Software Engineer
>> WS*O2* *Inc.*
>> Mobile: +94 777459299 <+94%2077%20745%209299>
>> himas...@wso2.com
>>
>> ___
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>


-- 
Chamin Dias
Mobile : 0716097455
Email : cham...@wso2.com
LinkedIn : https://www.linkedin.com/in/chamindias
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [AM-2.1.0] Issues with client application based on SDK

2018-02-21 Thread Jason De Silva
Hi Himasha,

I tried this scenario in a wum updated pack referring [1] for the
pizzashack api and it worked for me OOB. Did you also try it out in a wum
updated pack?

[1]
https://docs.wso2.com/display/AM210/Write+a+Client+Application+Using+the+SDK

Regards,
Jason

Jason De Silva
*Software Engineer - QA*
Mobile: +94 (0) 772 097 678
Email: jas...@wso2.com
WSO2 Inc. www.wso2.com


On Wed, Feb 21, 2018 at 8:11 PM, Himasha Guruge  wrote:

> Hi,
>
> I'm trying out [1] with Api Manager 2.1.0. I have downloaded the java SDK
> of PizzaShackAPI and tried to run APIClient main method. At first with the
> exact same code, I was getting below error.
>
>
> com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
> Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
>
>  To sort it out I updated defaultAPI.java code of the SDK, to return a
> List instead, and it got sorted. (See changes below)
>
>  public List menuGet() throws ApiException {
> ApiResponse resp = menuGetWithHttpInfo();
> return resp.getData();
> }
>
>
>public ApiResponse menuGetWithHttpInfo() throws
> ApiException {
> com.squareup.okhttp.Call call = menuGetCall(null, null);
> Type localVarReturnType = new TypeToken(){}.getType();
> return apiClient.execute(call, localVarReturnType);
> }
>
>
>  However, now I'm getting a response but the menu list is empty. Any idea
> what could be the issue?
>
>
> [1]https://docs.wso2.com/display/AM210/Write+a+Client+
> Application+Using+the+SDK#1a97b57b1791422f99d81743523b612e
>
> Thanks,
> Himasha Guruge
> Senior Software Engineer
> WS*O2* *Inc.*
> Mobile: +94 777459299 <+94%2077%20745%209299>
> himas...@wso2.com
>
> ___
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev