Atlassian Swagger Request Validator - Spring MVC Issue - openapi

I am using atlassian swagger request validator in my springboot application. I tried to configure all the beans as explained in the [official documentation][1]
[1]: https://bitbucket.org/atlassian/swagger-request-validator/src/master/swagger-request-validator-springmvc/. But I am getting the below error
{
"status": 400,
"error": "Bad Request",
"message": "{\r\n \"messages\" : [ {\r\n \"key\" : \"validation.request.body.schema.unknownError\",\r\n \"level\" : \"ERROR\",\r\n \"message\" : \"An error occurred during schema validation - null.\",\r\n \"context\" : {\r\n \"requestPath\" : \"/mybook/mypage/12345/rules/\",\r\n \"apiRequestContentType\" : \"application/json\",\r\n \"location\" : \"REQUEST\",\r\n \"requestMethod\" : \"POST\"\r\n }\r\n } ]\r\n}",
"trace": "com.atlassian.oai.validator.springmvc.InvalidRequestException: {\r\n \"messages\" : [ {\r\n \"key\" : \"validation.request.body.schema.unknownError\",\r\n \"level\" : \"ERROR\",\r\n \"message\" : \"An error occurred during schema validation - null.\",\r\n \"context\" : {\r\n \"requestPath\" : \"/mybook/mypage/12345/rules/\",\r\n \"apiRequestContentType\" : \"application/json\",\r\n \"location\" : \"REQUEST\",\r\n \"requestMethod\" : \"POST\"\r\n }\r\n } ]\r\n}\r\n\tat com.atlassian.oai.validator.springmvc.DefaultValidationReportHandler.createValidationException(DefaultValidationReportHandler.java:96)\r\n\tat com.atlassian.oai.validator.springmvc.DefaultValidationReportHandler.processApiValidationReport(DefaultValidationReportHandler.java:63)\r\n\tat com.atlassian.oai.validator.springmvc.DefaultValidationReportHandler.handleRequestReport(DefaultValidationReportHandler.java:49)\r\n\tat com.atlassian.oai.validator.springmvc.OpenApiValidationInterceptor.preHandle(OpenApiValidationInterceptor.java:96)\r\n\tat org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:136)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1033)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)\r\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:660)\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)\r\n\tat
Any pointers to resolve this issue will be helpful

I believe the issue is with the latest version. I used 2.7x and is working fine

Related

how to solve java.lang.NullPointerException in debezium mongo db source connector?

I am using debezium mongo DB source connector. it works well for create/update but for delete, I want the complete document to filter in target DB. for that I configured my connector with handling mode
"transforms.unwrap.delete.handling.mode" : "rewrite",
but it gives error (screenshot attached)
"Caused by: java.lang.NullPointerException"
though it works well when I do
"transforms.unwrap.delete.handling.mode" : "drop",
but in this case, i get null in value.
I tried below transforms.unwrap.type but get the same result
"transforms.unwrap.type" : "io.debezium.transforms.UnwrapFromEnvelope",
"transforms.unwrap.type" : "io.debezium.connector.mongodb.transforms.UnwrapFromMongoDbEnvelope",
"transforms.unwrap.type" : "io.debezium.transforms.ExtractNewRecordState",
is there any way to get the complete document in the case of delete instead on null
please find attached screenshot of error and complete configuration of connector
{
"name": "inventory-mongo-connector",
"config": {
"connector.class" : "io.debezium.connector.mongodb.MongoDbConnector",
"tasks.max" : "1",
"mongodb.hosts" : "XXXXX",
"mongodb.name" : "YYYY",
"mongodb.user" : "ZZZZ",
"mongodb.password" : "TTTTT",
"database.whitelist" : "maindb",
"collection.whitelist":"maindb.collection1,maindb.collection2",
"database.history.kafka.bootstrap.servers" : "kafka:9092",
"transforms" : "unwrap",
"transforms.unwrap.type" : "io.debezium.transforms.UnwrapFromEnvelope",
"transforms.unwrap.drop.tombstones" : "false",
"transforms.unwrap.delete.handling.mode" : "rewrite",
"transforms.unwrap.operation.header" : "true"
}
}

Oauth2, getting Forbidden error (youtube analytics)

1.- I have created an app
2.- Through Oauth2 I got the token for an user
3.- I try to get the Youbute Analytics for the user's channel that authorized my app. But I have the error 403 (Forbidden). I do not have any clue ... can you help me?
Regards, P.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Forbidden",
"reason" : "forbidden"
} ],
"message" : "Forbidden"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:150)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)

Generic custom error response in Dingo API

I am trying to abstract all my error responses to match my API documentation for developing a good, pragmatic API using Lumen and the Dingo API package:
A JSON error body should provide a few things for the developer - a useful error message, a unique error code (that can be looked up for more details in the docs) and possibly a detailed description. JSON output representation for something like this would look like:
{
"code" : 1234,
"message" : "Something bad happened :(",
"description" : "More details about the error here"
}
At the moment, the Dingo API only provides me with the following response:
{
"message": "Could not create new user.",
"status_code": 422
}
1. How can I add extra fields to all error responses, e.g "description" and "code"
The configuration page shows a possible error format to set on your bootstrap/app.php file but I'm wondering how I can add possible new tags and use these.
I know it's possible using a custom exception and returning a new response:
app('Dingo\Api\Exception\Handler')->register(function (\App\Exceptions\ValidationException $exception) {
return Response::make(['code' => $exception->getCode(), 'message' => $exception->getMessage()], 401);
});
I want to know if this is the best practice to do it like this but on all exceptions (including the default ones of Dingo/Symfony), for example using the configuration parameters: ->setErrorFormat([]);
2. Change validation errors format
Validation errors for PUT, PATCH and POST requests will need a field breakdown. This is best modeled by using a fixed top-level error code for validation failures and providing the detailed errors in an additional errors field, like so:
{
"code" : 1024,
"message" : "Validation Failed",
"errors" : [
{
"code" : 5432,
"field" : "first_name",
"message" : "First name cannot have fancy characters"
},
{
"code" : 5622,
"field" : "password",
"message" : "Password cannot be blank"
}
]
}
Currently, Dingo API provides me the JSON in the following format:
{
"message": "Could not create new user.",
"status_code": 422,
"errors": {
"username": [
"The username field is required."
],
"password": [
"The password field is required."
]
}
}

How to show an entity from in the Wirecloud MapViewer widget

Well I'm trying to show the following entity:
{
"contextResponses" : [
{
"contextElement" : {
"type" : "City",
"isPattern" : "false",
"id" : "Miraflores",
"attributes" : [
{
"name" : "position",
"type" : "coords",
"value" : "-12.119816, -77.028916",
"metadatas" : [
{
"name" : "location",
"type" : "string",
"value" : "WSG84"
}
]
}
]
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
}
Wiring NGSI Source and NGSI Entity to Poi operatiors with MapViewer widget (Insert/Update PoI), with the following settings:
NGSI Source
NGSI server URL: mydirection:1026
NGSI proxy URL: http://mashup.lab.fi-ware.org:3000/
NGSI entities: City
NGSI Attributes: position
NGSI Entity to Poi
Coordinates attribute: position
But nothing shows up in the map! Can somebody help me figure out what the problem is?
Seems your configuration is correct (I'm assuming mydirection:1026 is a full URL, i.e. includes the protocol), but probably your network is filtering port 3000. Try to use http://ngsiproxy.lab.fi-ware.org as NGSI proxy instead of http://mashup.lab.fi-ware.org:3000/.
Indeed, I recommend you to enable https notifications in your context broker instance and use https://ngsiproxy.lab.fi-ware.org instead, especially if you are creating your WireCloud dashboard in an https web page (e.g. https://mashup.lab.fi-ware.org) as using this NGSI proxy will solve some mixed content problems, see:
Chrome: https://support.google.com/chrome/answer/1342714?hl=en
Firefox: https://blog.mozilla.org/tanvi/2013/04/10/mixed-content-blocking-enabled-in-firefox-23/
Update: FIWARE has move from fi-ware.org to fiware.org. The recommended NGSI proxy server is now ngsiproxy.lab.fiware.org (ngsiproxy.lab.fi-ware.org still works).
Three simple steps to start MapViewer on Fiware:
Update the Orion ContextBroker in your system
You should check if the daemons rush and rdis are installed and running in your system
You should create a correct boot sequence in the init.d: redis, rush and contextBroker
After these steps, you can build your viewing interface in Wirecloud using MapViewer, NGSI source and NGSI entity to POI.
You must use structured JSON messages correctly as in the following example:
{ "contextElements":
[
{
"type": "iotdevice","isPattern": "false","id": "edison1", "attributes":
[
{
"name": "temperature",
"type": "string",
"value": "10"
},
{
"name" : "position",
"type" : "coords",
"value" : "-20, 35",
"metadatas" : [
{
"name" : "location",
"type" : "string",
"value" : "WSG84"
}
]
}
]
}
],
"updateAction": "APPEND"
}

Neo4j REST API - create unique node

I am trying to use the REST API to create a unique node. However, I am getting the error about requiring the key 'uri' (see below). Based on the documented examples, this call creates and indexes the newly created node ... so there should not be a 'uri' paramater. My request and response are below. What am I doing wrong?
REQUEST:
http://www.somemachine.com:7474/db/data/index/node/idxHost?unique=get_or_create
{
"key": "name",
"value": "HOST",
"properties": {
"type": "company",
"name": "HOST",
"sequence": 1
}
}
RESPONSE:
state:400, body:
{
"message" : "Missing required key: \"uri\"",
"exception" : "BadInputException",
"fullname" : "org.neo4j.server.rest.repr.BadInputException",
"stacktrace" : [ "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:92)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(RestfulGraphDatabase.java:802)", "java.lang.reflect.Method.invoke(Method.java:601)" ],
"cause" : {
"message" : "Missing required key: \"uri\"",
"exception" : "BadInputException",
"stacktrace" : [ "org.neo4j.server.rest.repr.DefaultFormat.validateKeys(DefaultFormat.java:153)", "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:88)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(RestfulGraphDatabase.java:802)", "java.lang.reflect.Method.invoke(Method.java:601)" ],
"fullname" : "org.neo4j.server.rest.repr.BadInputException"
}
}
Using curl
c:\apps\curl\curl-7.28.1-win64-nossl>curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"key":"name","value":"HOST","propert
ies":{"type":"company","name":"HOST","sequence":1}}' http://www.somemachine.com:7474/db/data/index/node/idxHost?unique=get_or_create
HTTP/1.1 400 Bad Request
Content-Length: 489
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)
{
"message" : "Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io.Str
ingReader#1e70f68; line: 1, column: 2]",
"exception" : "BadInputException",
"stacktrace" : [ "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:92)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(R
estfulGraphDatabase.java:776)", "java.lang.reflect.Method.invoke(Unknown Source)" ]
}
According to the doc, in 1.8 the url ends with '?unique' whereas in 1.9 is '?uniqueness=get_or_create'
I think this may cause your error.
see for 1.8: http://docs.neo4j.org/chunked/stable/rest-api-unique-indexes.html#rest-api-add-a-node-to-an-index-unless-a-node-already-exists-for-the-given-mapping
and 1.9: http://docs.neo4j.org/chunked/milestone/rest-api-unique-indexes.html