{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • API Design /
avatar image
0
Question by Christian Lopez · Mar 03, 2020 at 05:22 AM · 120 Views java calloutjava

Json payload java callout

Hi,

Seeking some guidance on what would be the best approach. Basically I need to extract a json payload on my java callout and validate it against our own custom validator. The json payload is a list of phone numbers. each phone has a number and extension.

The main challenge i am facing is deserializing the json into my object. after hours of googling I found that apigee prohibits the use of reflections. I was trying to use Gson to do the deserialize.

Code snippet

public ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) {
    try {
        String phonesAsString = messageContext.getVariable("phoneList").toString();
        messageContext.setVariable("PHONES_CONTENT_A", phonesAsString);
        Gson gson = new Gson();
        Phones phones = gson.fromJson(phonesAsString, Phones.class);
        ...
    }
    catch(Exception e) {
        ...     
    }
}

Phones & Phone class

private ArrayList<Phone> phoneList;
~~~~
/** The number. */
private String number;
/** The extension. */
private Integer extension;

Json payload

{
   "phoneList":[
      {
         "number":"+12232222222",
         "extension":1234
      },
      {
         "number":"+12232222222",
         "extension":1234
      }
   ]
}
Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

1 Answer

  • Sort: 
avatar image
0
Best Answer

Answer by Dino-at-Google   · Mar 05, 2020 at 07:43 PM

after hours of googling I found that apigee prohibits the use of reflections.

Yes. I'm sorry it took so much trouble to discover that. That's frustrating. We try to construct the Java callout runtime so that it emits a proper error message to give you a good hint when something fails. And examining the stacktrace of the Exception thrown can help with that. It usually looks like this:

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
 at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
 at java.security.AccessController.checkPermission(AccessController.java:884)
 at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
 at com.apigee.securitypolicy.InternalSecurityManager.checkPermission(InternalSecurityManager.java:85)
 at java.lang.Class.checkMemberAccess(Class.java:2348)
 at java.lang.Class.getDeclaredConstructor(Class.java:2177)
 at com.google.gson.internal.ConstructorConstructor.newDefaultConstructor(ConstructorConstructor.java:101)
 at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:85)
 at com.google.gson.internal.bind.MapTypeAdapterFactory.create(MapTypeAdapterFactory.java:127)
 at com.google.gson.Gson.getAdapter(Gson.java:458)
 at com.google.gson.Gson.fromJson(Gson.java:931)
 at com.google.gson.Gson.fromJson(Gson.java:870)
  ...

But sometimes it's hard to figure out.

To answer your question, I think you can avoid the problem if you use a smaller, less ambitious parser that does not use reflection. That means parsing a generic Map, not a tightly bound class like "Person" or "PhoneList".

This repo shows you more:

https://github.com/DinoChiesa/ApigeeEdge-Java-Json-Parse

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

71 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How does Java Callout policy update the member variables of the Java code? 1 Answer

Java Callout access to File Resources 1 Answer

Problem building Java callout classes via Grunt versus directly on command line 3 Answers

What version of Java is supported for Java callouts? 1 Answer

Setting header value within Java callout. 3 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges