How to create OpenAPI schema components programmatically using OpenAPI4J parser? - java

I need to create an OpenAPI JSON file programmatically as my endpoints have a one-to-one mapping with the tables in the database. I need to create the components (Schemas) which needs to be referenced in response object. I am not able to create the OAI3Context object as I do not have a URL which needs to be passed as argument.
OpenAPI4J Maven entry in my pom.xml:
<!-- https://mvnrepository.com/artifact/org.openapi4j/openapi-parser -->
<dependency>
<groupId>org.openapi4j</groupId>
<artifactId>openapi-parser</artifactId>
<version>1.0.7</version>
</dependency>
Sample openapi.json file which I want to make programatically:
{
"openapi": "3.0.2",
"info": {
"contact": {
"email": "johndoe#TEST.com",
"name": "John Doe",
"url": "https://www.TEST.com/api/support"
},
"description": "TEST API based on the OpenAPI 3.0.2 specification.",
"license": {
"name": "TEST Inc",
"url": "https://www.TEST.com/licences/LICENSE-2.0.html"
},
"termsOfService": "https://www.TEST.com/api/terms",
"title": "TEST API - OpenAPI 3.0.2",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:8080/TEST-REST/api/",
"description": "descirption1"
}
],
"tags": [
{
"name": "connection",
"description": "Connection management API ",
"externalDocs": {
"description": "Connection management API",
"url": "http://www.TEST.com"
}
},
{
"name": "REST API",
"description": "TEST's non-crud APIs",
"externalDocs": {
"description": "TEST's non-crud APIs",
"url": "http://www.TEST.com"
}
},
{
"name": "objects",
"description": "TEST CRUD Operations on selected table",
"externalDocs": {
"description": "CRUD API TEST TEST. Can be done on selected tables",
"url": "http://www.TEST.com"
}
}
],
"paths": {
"/rest/authenticate": {
"description": "authenticate and get a token",
"summary": "authenticate and get a connection token",
"get": {
"tags": [
"connection"
],
"operationId": "authenticate",
"parameters": [
{
"required": true,
"schema": {
"description": "TEST datasource to connect to",
"type": "string"
},
"in": "query",
"name": "username"
},
{
"required": true,
"schema": {
"description": "password of the user",
"type": "string"
},
"in": "query",
"name": "password"
},
{
"required": true,
"schema": {
"description": "TEST datasource to connect to",
"type": "string"
},
"in": "query",
"name": "datasource"
},
{
"required": true,
"schema": {
"description": "TEST Service to connect to",
"type": "string"
},
"in": "query",
"name": "service"
},
{
"required": false,
"schema": {
"description": "User role",
"type": "string"
},
"in": "query",
"name": "role"
}
],
"responses": {
"200": {
"description": "Successful Connection",
"content": {
"application/json": {
"schema": {
"$ref" : "#/components/schemas/connection"
}
},
"application/xml": {
"schema": {
"$ref" : "#/components/schemas/connection"
}
}
}
},
"405": {
"description": "Invalid input"
}
}
}
}
},
"components": {
"schemas": {
"connection": {
"required": [
"connid"
],
"type": "object",
"properties": {
"connid": {
"type": "string",
"example": "TEST1_107c5a8c1799d4cf8bb5ce295ab38954"
}
}
}
}
}
}
My Java code:
package vish.api.test2;
import org.openapi4j.core.exception.EncodeException;
import org.openapi4j.parser.model.SerializationFlag;
import org.openapi4j.parser.model.v3.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
public class OpenAPICreator {
public static void main(String[] args) {
try {
OpenApi3 openApi3 = new OpenApi3();
openApi3.setOpenapi("3.0.2");
Info info = new Info();
openApi3.setInfo(info);
info.setTitle("vish API - OpenAPI 3.0.2");
info.setDescription("vish API based on the OpenAPI 3.0.2 specification.");
info.setTermsOfService("https://www.vish.com/api/terms");
Contact contact = new Contact();
contact.setName("Avik Chatterjee");
contact.setEmail("achatterjee#vish.com");
contact.setUrl("https://www.vish.com/api/support");
info.setContact(contact);
Components components = new Components();
Schema schema = new Schema();
components.setSchema("test", schema);
Schema schema2 = new Schema();
schema.setProperty("test2", schema2);
openApi3.setComponents(components);
String canonicalRef = schema2.getCanonicalRef();
System.out.println("canonicalRef = " + canonicalRef);
License license = new License();
license.setName("vish Inc");
license.setUrl("https://www.vish.com/licences/LICENSE-2.0.html");
info.setLicense(license);
info.setVersion("1.0.0");
ExternalDocs externalDocs = new ExternalDocs();
externalDocs.setDescription("vish API Description");
externalDocs.setUrl("https://www.vish.com");
Server server1 = new Server();
server1.setDescription("descirption1");
server1.setUrl("http://localhost:8080/LIMS-REST/api/");
/* Server server2 = new Server();
server2.setDescription("test diff descirption1");
server2.setUrl("http://localhost:8080/LIMS-REST/api/");*/
ArrayList<Server> serverArrayList = new ArrayList<>();
serverArrayList.add(server1);
//serverArrayList.add(server2);
openApi3.setServers(serverArrayList);
Tag connectionTag = new Tag();
Tag restTag = new Tag();
Tag objectsTag = new Tag();
List<Tag> tagList = new ArrayList<>();
tagList.add(connectionTag);
tagList.add(restTag);
tagList.add(objectsTag);
connectionTag.setName("connection");
connectionTag.setDescription("Connection management API ");
ExternalDocs authDocs = new ExternalDocs();
authDocs.setDescription("Connection management API");
authDocs.setUrl("http://www.vish.com");
connectionTag.setExternalDocs(authDocs);
restTag.setName("REST API");
restTag.setDescription("vish's non-crud APIs");
ExternalDocs listWFDocs = new ExternalDocs();
listWFDocs.setDescription("vish's non-crud APIs");
listWFDocs.setUrl("http://www.vish.com");
restTag.setExternalDocs(listWFDocs);
objectsTag.setName("objects");
objectsTag.setDescription("vish CRUD Operations on selected table");
ExternalDocs crudDocs = new ExternalDocs();
crudDocs.setDescription("CRUD API vish LIMS. Can be done on selected tables");
crudDocs.setUrl("http://www.vish.com");
objectsTag.setExternalDocs(crudDocs);
openApi3.setTags(tagList);
Schema connectionSchema = new Schema();
// connectionSchema.setre
// connectionSchema.setReference(oai3Context, new URL("http://localhost:8080/TEST-REST/"), "connection" );
components.setSchema("connection", connectionSchema);
connectionSchema.setType("Object");
Schema connIdSchema = new Schema();
connectionSchema.setType("string");
connectionSchema.setExample("TEST1_107c5a8c1799d4cf8bb5ce295ab38954");
connectionSchema.setProperty("connid", connIdSchema);
Path authPath = new Path();
Operation authOps = new Operation();
authPath.setOperation("get", authOps);
authPath.setDescription("authenticate and get a token");
authPath.setSummary("authenticate and get a connection token");
authOps.addTag(connectionTag.getName());
authOps.setOperationId("authenticate");
Parameter username = new Parameter();
username.setName("username");
username.setIn("query");
username.setRequired(true);
Schema userSchema = new Schema();
userSchema.setDescription("TEST datasource to connect to");
userSchema.setType("string");
username.setSchema(userSchema);
authOps.addParameter(username);
Parameter password = new Parameter();
password.setName("password");
password.setIn("query");
password.setRequired(true);
password.setRequired(true);
Schema pwdSchema = new Schema();
pwdSchema.setDescription("password of the user");
pwdSchema.setType("string");
password.setSchema(pwdSchema);
authOps.addParameter(password);
Parameter database = new Parameter();
database.setName("datasource");
database.setIn("query");
database.setRequired(true);
Schema dbSchema = new Schema();
dbSchema.setDescription("TEST datasource to connect to");
dbSchema.setType("string");
database.setSchema(dbSchema);
authOps.addParameter(database);
Parameter service = new Parameter();
service.setName("service");
service.setIn("query");
service.setRequired(true);
Schema serviceSchema = new Schema();
serviceSchema.setDescription("TEST Service to connect to");
serviceSchema.setType("string");
service.setSchema(serviceSchema);
authOps.addParameter(service);
Parameter role = new Parameter();
role.setName("role");
role.setIn("query");
role.setRequired(false);
Schema roleSchema = new Schema();
roleSchema.setDescription("User role");
roleSchema.setType("string");
role.setSchema(roleSchema);
authOps.addParameter(role);
Response resp_200 = new Response();
resp_200.setDescription("Successful Connection");
MediaType mediaType = new MediaType();
Schema resp200Schema = new Schema();
// resp200Schema.setReference(oai3Context, new URL("http://localhost:8080/TEST-REST/"), "connection");
mediaType.setSchema(resp200Schema);
resp_200.setContentMediaType("application/json", mediaType);
authOps.setResponse("200", resp_200);
Map<String, Path> pathMap = new HashMap<>();
pathMap.put("/rest/authenticate", authPath);
// pathMap.put("/rest/close", closePath);
openApi3.setPaths(pathMap);
SerializationFlag outAsJson = SerializationFlag.OUT_AS_JSON;
EnumSet<SerializationFlag> enumSet = EnumSet.of(outAsJson);
String openAPIJson = openApi3.toString(enumSet);
SerializationFlag outAsYaml = SerializationFlag.OUT_AS_YAML;
EnumSet<SerializationFlag> enumYamlSet = EnumSet.of(outAsYaml);
String yaml = openApi3.toString(enumYamlSet);
FileOutputStream fos1 = new FileOutputStream(new File("vish1.json"));
FileOutputStream fos2 = new FileOutputStream(new File("vish1.yaml"));
fos1.write(openAPIJson.getBytes(StandardCharsets.UTF_8));
fos2.write(yaml.getBytes(StandardCharsets.UTF_8));
// System.out.println("gson way = \n" + gson.toJson(openApi3) );
} catch (EncodeException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
To sum up, how do I create the following programmatically without creating an OpenAPI3Context and refer the component in my 'responses'?
"components": {
"schemas": {
"connection": {
"required": [
"connid"
],
"type": "object",
"properties": {
"connid": {
"type": "string",
"example": "TEST1_107c5a8c1799d4cf8bb5ce295ab38954"
}
}
}
}
}

Related

How to create Index with mapping using new Java Api ElasticSearch(8.0.1)

I am trying to create an index in ElasticSearch 8.0.1 with java. The problem is Index is created but the mapping does not. Here is my code;
final RestClient restClient = RestClient
.builder(new HttpHost(hostName, port, "https"))
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(provider))
.build();
final ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
final ElasticsearchClient client = new ElasticsearchClient(transport);
final JsonpMapper mapper = client._transport().jsonpMapper();
JsonParser parser = mapper.jsonProvider().createParser(new StringReader(Files.readString(Paths.get(mappingFile), Charsets.UTF_8)));
client.indices().create(builder ->
builder.index(indexName).mappings(TypeMapping._DESERIALIZER.deserialize(parser, mapper)));
When I debug I saw TypeMapping._DESERIALIZER.deserialize(parser, mapper) returns null so I assume problem is about my mapping file. When i try to create my index from postman with the same mapping there is no problem. Here is my mapping file;
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"asciifolding",
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"placeOfBirths.country": {
"type": "text",
"term_vector": "yes",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"gender": {
"type": "text",
"term_vector": "yes",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"deviceId": {
"type": "text",
"term_vector": "yes",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
There are no errors. Just the index has no mappings. What am I missing ?

How to insert data into Avro Union/Map type

Hi I'm trying to fill my record based on Avro schema using GenericRecord. But all the time when I'm trying to parse it by:
public static boolean validateJson(String json, Schema schema) throws Exception {
InputStream input = new ByteArrayInputStream(json.getBytes());
DataInputStream din = new DataInputStream(input);
try {
DatumReader reader = new GenericDatumReader(schema);
Decoder decoder = DecoderFactory.get().jsonDecoder(schema, din);
reader.read(null, decoder);
return true;
} catch (AvroTypeException e) {
System.out.println(e.getMessage());
return false;
}
}
I'm getting "not a Union type."
schema.avsc
"type": "record",
"namespace": "com.acme",
"name": "Test",
"fields": [
{ "name": "Country", "type": "string" },
{ "name": "eventContextMetadata", "type": ["null", {"type": "map", "values": "string" }]}
]
}
Do someone know how to put this:
{ "name": "eventContextMetadata", "type": ["null", {"type": "map", "values": "string" }]}
into Record:
avroRecord.put("eventContextMetadata", ??????); or difernd method.
and how to create a Map and Union?

Problem with quotas from google cloud endpoint framework for Java

I'm developing a simple api with GAE standard and Cloud Endpoint to test the available quota feature.
Here's the Java Code using the EndPoint Framework annotation:
package com.example.skeleton;
import com.google.api.server.spi.config.*;
#Api(
name = "simpleapi",
version = "v1",
limitDefinitions = {
#ApiLimitMetric(
name = "read-requests",
displayName = "Read requests",
limit = 10
)
}
)
public class MyApi {
#ApiMethod(
name = "hellosecuredWithQuotas",
path = "hellosecuredWithQuotas",
httpMethod = ApiMethod.HttpMethod.GET,
apiKeyRequired= AnnotationBoolean.TRUE,
metricCosts = {
#ApiMetricCost(
name ="read-requests",
cost = 1
)
}
)
public Message helloSecuredWithQuotas(#Named("name") String name) {
return new Message("hello " + name);
}
}
So given the #Api annotations the quotas is 10 requests per minute.
I deploy the App in GAE.
I Generate the OpenAPI json file (see below for the generated content) and deploy it to Cloud Endpoint using gcloud CLI.
Finally I use the generated client to call the endpoint in a loop which is calling the endpoint more than 10 times per minute.
... but unfortunately I never receive the expected "HTTP status code of 429 Too Many Requests".
public class App {
public static void main(String []args) throws IOException {
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
Simpleapi simpleapi = new Simpleapi.Builder(httpTransport, jsonFactory, null)
.setApplicationName("test")
.build();
for (int i = 0; i < 1000 ; i++) {
Message titi = simpleapi.hellosecuredWithQuotas("foobar" + System.currentTimeMillis()).setKey("my-api-key-here").execute();
System.out.println(titi.getMessage());
}
}
}
Here is the generated openapi.json file:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "my-project-name-here.appspot.com"
},
"host": "my-project-name-here.appspot.com",
"basePath": "/_ah/api",
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/simpleapi/v1/hellosecuredWithQuotas": {
"get": {
"operationId": "SimpleapiHelloSecuredWithQuotas",
"parameters": [
{
"name": "name",
"in": "query",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/Message"
}
}
},
"security": [
{
"api_key": []
}
],
"x-google-quota": {
"metricCosts": {
"read-requests": 10
}
}
}
}
},
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"name": "key",
"in": "query"
}
},
"definitions": {
"Message": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
},
"x-google-management": {
"metrics": [
{
"name": "read-requests",
"valueType": "INT64",
"metricKind": "GAUGE"
}
],
"quota": {
"limits": [
{
"name": "read-requests",
"metric": "read-requests",
"values": {
"STANDARD": 10
},
"unit": "1/min/{project}",
"displayName": "Read requests"
}
]
}
}
}
I was able to get this to work by setting the limit value in the ApiLimitMetric configuration to a value 100 or greater. If you'd like to have a maximum of 10 requests per minute, you should set the limit to 100 and the cost value in the ApiMetricCost configuration on the method to 10. This would give you the same ratio of 1/10 as listed in your original post.

Spring Rest Web service returning 415

I have Spring web service from the following. JSON for swagger
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Extended User Management API",
"description": "This is communicate with an extended user management webservice to test the swagger API for learning"
},
"schemes": [
"http"
],
"basePath": "/UserManagement/rest/UserService",
"host": "127.0.0.1:8089",
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"paths": {
"/users": {
"get": {
"responses": {
"200": {
"description": "An array of users",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/addUser": {
"post": {
"summary": "Add an additional user",
"description": "This service is used to add and additional user to the list of users.",
"parameters": [
{
"name": "user_id",
"in": "query",
"description": "Unique id of the user to be added.",
"required": true,
"type": "integer",
"format": "int32"
},
{
"name": "name",
"in": "query",
"description": "Name of the user to be added.",
"required": true,
"type": "string"
},
{
"name": "profession",
"in": "query",
"description": "Profession of the user to be added.",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK"
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"User": {
"type": "object",
"properties": {
"user_id": {
"type": "integer",
"format": "int32",
"description": "This is unique id that is assigned to each user."
},
"name": {
"type": "string",
"description": "This is the name of the user"
},
"profession": {
"type": "string",
"description": "This is the profession that the user holds"
}
}
},
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"fields": {
"type": "string"
}
}
}
}
}
I generated the code and resolved all the error in the project. The I got the application to run in Spring boot main with out any problems. The issue that I'm facing now is that on accessing the get web service "/users", I'm getting an error from the service.
I tried debugging the spring application I came to find that the intended service is not even hit. The code for service is given below.
#javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringCodegen", date = "2016-10-24T09:36:32.738Z")
#Api(value = "users", description = "the users API")
public interface UsersApi {
#ApiOperation(value = "", notes = "", response = User.class, responseContainer = "List", tags={ })
#ApiResponses(value = {
#ApiResponse(code = 200, message = "An array of users", response = User.class),
#ApiResponse(code = 200, message = "Unexpected error", response = User.class) })
#RequestMapping(value = "/users",
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.GET)
ResponseEntity<List<User>> usersGet();
}
Implementation of this interface is given below
#javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringCodegen", date = "2016-10-24T09:36:32.738Z")
#Controller
public class UsersApiController implements UsersApi {
UserDao udao = new UserDao();
public ResponseEntity<List<User>> usersGet() {
return new ResponseEntity<List<User>>(udao.getAllUsers(), HttpStatus.OK);
}
}
Can please some one tell me what is the mistake that I made so that I can solve this.
Well you are using an unsupported media type as the exception says.
Have a look at your #RequestMapping annotation:
#RequestMapping(value = "/users",
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.GET)
ResponseEntity<List<User>> usersGet();
Either you remove the consumes key or you support the Content-Type in your GET request.
Edit: maybe it would be a better option to remove the consumes key. I don't think it is a good idea to consume any json in a GET request.

Parse Json String (Feed RSS file) in Android

How can I parse this piece of JSON code?
{
"direction": "ltr",
"id": "feed/http => //www.theverge.com/rss/full.xml",
"title": "The Verge - All Posts",
"continuation": "CLKM0OyU0rYC",
"self": [
{
" href": "https => //cloud.feedly.com/reader/3/stream/contents/feed%2Fhttp%3A%2F%2Fwww.theverge.com%2Frss%2Ffull.xml?n=20&unreadOnly=true"
}
],
"alternate": [
{
"href": "http://www.theverge.com/",
"type": "text/html"
}
],
"updated": 1367539068016,
"items": [
{
"id": "entryId",
"unread": true,
"categories": [
{
"id": "user/c805fcbf-3acf-4302-a97e-d82f9d7c897f/category/tech",
"label": "tech"
}
],
"tags": [
{
"id": "user/c805fcbf-3acf-4302-a97e-d82f9d7c897f/tag/inspiration",
"label": "inspiration"
}
],
"title": "NBC's reviled sci-fi drama 'Heroes' may get a second lease on life as Xbox Live exclusive",
"published": 1367539068016,
"updated": 1367539068016,
"crawled": 1367539068016,
"alternate": [
{
"href": "http://www.theverge.com/2013/4/17/4236096/nbc-heroes-may-get-a-second-lease-on-life-on-xbox-live",
"type": "text/html"
}
],
"content": {
"direction": "ltr",
"content": "..."
},
"author": "Nathan Ingraham",
"origin": {
"streamId": "feed/http://www.theverge.com/rss/full.xml",
"title": "The Verge - All Posts",
"htmlUrl": "http://www.theverge.com/"
},
"engagement": 15
},
{
"id": "entryId2",
"unread": true,
"categories": [
{
"id": "user/c805fcbf-3acf-4302-a97e-d82f9d7c897f/category/tech",
"label": "tech"
}
],
"tags": [
{
"id": "user/c805fcbf-3acf-4302-a97e-d82f9d7c897f/tag/inspiration",
"label": "inspiration"
}
],
"title": "Senate rejects bipartisan gun control measure for background checks despite broad public support",
"published": 1367539068016,
"updated": 1367539068016,
"crawled": 1367539068016,
"alternate": [
{
"href": "http://www.theverge.com/2013/4/17/4236136/senate-rejects-gun-control-amendment",
"type": "text/html"
}
],
"content": {
"direction": "ltr",
"content": "...html content..."
},
"author": "T.C. Sottek",
"origin": {
"streamId": "feed/http://www.theverge.com/rss/full.xml",
"title": "The Verge - All Posts",
"htmlUrl": "http://www.theverge.com/"
},
"engagement": 39
}
]
}
That is my solution but it doesn't work... what is my error? thanks
try{
//JSONArray elements = new JSONArray (response);
JSONObject json=new JSONObject(response);
JSONArray elements = json.getJSONArray("items");
Log.d(TAG, "Elemenenti numero" +elements.length());
// Getting Array of Contacts
// looping through All Contacts
for(int i = 0; i < elements.length(); i++){
JSONObject c = elements.getJSONObject(i);
// Storing each json item in variable
String identifier = c.getString("id");
String title = c.getString("title");
String link = c.getString("originId");
String data = c.getString("published");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date date=new Date();
try {
date = format.parse(data);
System.out.println(date);
} catch (Exception e) {
e.printStackTrace();
}
JSONObject summaryObj= c.getJSONObject("summary");
String summary = summaryObj.getString("content");
JSONObject contentObj= c.getJSONObject("content");
String content = contentObj.getString("content");
JSONObject sourceObj= c.getJSONObject("origin");
String source = contentObj.getString("title");
if (summary.length()==0 && content.length()!=0) summary=content;
if (content.length()==0 && summary.length()!=0) content=summary;
String image=this.getFirstImage(content);
FeedItem toAdd=new FeedItem(identifier, title, link, date, null, summary, content, image, source);
toAdd.toString();
}
}catch (JSONException e) {
e.printStackTrace();
}
JSONObject summaryObj= c.getJSONObject("summary");
There is no element called summary, you may try
if(c.has("summary")) {
JSONObject summaryObj= c.getJSONObject("summary");
}
if that doesn't work, please post your stacktrace, (logcat)
You don't have any tag named "originID". but you are trying to get String from it.
Similarly,you don't have tag "summary" also but you are trying to get JSONObject from it.

Categories