Spring MVC - respecting double slash in REST request - rest

Lets say I have the following two REST endpoints built with Spring MVC (v.4):
1. [GET] /cars/make/{make}
2. [GET] /cars/make/{make}/model
And the following requests:
1. curl -X GET -H "Accept: application/json" "http://localhost/cars/make//model"
2. curl -X GET -H "Accept: application/json" "http://localhost/cars/make/%20/model"
The two requests will match the first endpoint (with path variable make having a value of model. Is it possible to change the matcher to match on the second endpoint with make being an empty string or whitespace?
I've been able to override the default Spring AntPathMatcher to not trim tokens, thus fixing the issue with the second request. However I'm not sure how to modify it so that it strictly respects the 2 backslashes with no whitespace in between. Is this possible?

Related

How to pass a parameter to a Spring Cloud Function?

I'm following the Spring Cloud Function tutorial.
In the example, they are calling the revert bean with this command:
curl localhost:8080/reverseString -H "Content-Type: text/plain" -d "abc"
I like to call the endpoint from a browser/postman as a GET request.
So I was looking to orchestrate a URL with a query parameter, that may look like localhost:8080/reverseString?input=abc
But:
It is not clear to me what should be the name of the parameter?
Seems like no matter what method name we put, they all get HTTP 200 response, with no response body. reverseStringggg, reve ...
You can pass it as localhost:8080/reverseString/abc
That said, I've raise the issue to explicitly support http parameters - https://github.com/spring-cloud/spring-cloud-function/issues/864

Rest API to get list of artifacts from Nexus OSS 3.x Repository

I have created a raw repository in Nexus 3.x and I'm able to upload artifacts to the same. Now I want get the list of all artifacts residing inside that repo using Rest API.
Any help is appreciated.
in the current Nexus3.14.0-04 the REST API has become final (no longer "beta") and the curl you need is:
curl -X GET "http://localhost:8081/service/rest/v1/components?repository=central" -H "accept: application/json"
this will return each "component" (group, name, version) with all its assets = each individual file (pom, sha1, md5, jar) who constitue the component
The result is a JSON string.
If instead you want to perform a COMPONENTS search - based on a groupId, artifactId - you can use this curl:
curl -X GET "http://localhost:8081/service/rest/v1/search?repository=central&format=maven2&maven.groupId=com.fasterxml.jackson.core&maven.artifactId=jackson-core&maven.extension=jar" -H "accept: application/json"
this returns COMPONENTS with child ASSETS.
The variant to retrieve only the ASSETS, without grouping them by COMPONENT, is GET /service/rest/v1/search/assets?repository=central&format=maven2&maven.groupId=com.fasterxml.jackson.core&maven.artifactId=jackson-core&maven.extension=jar
You can use the - still in beta - new API for Nexus. It's available by default on the version 3.3.0 and more: http://localhost:8082/swagger-ui/
Basically, you retrieve the json output from this URL: http://localhost:8082/service/siesta/rest/beta/assets?repositoryId=YOURREPO
Only 10 records will be displayed at a time and you will have to use the continuationToken provided to request the next 10 records for your repository by calling: http://localhost:8082/service/siesta/rest/beta/assets?continuationToken=46525652a978be9a87aa345bdb627d12&repositoryId=YOURREPO
More information here: http://blog.sonatype.com/nexus-repository-new-beta-rest-api-for-content

What is the equivalent to --cacerts in Scala or Java?

In my development and qa environments, I will be hitting a rest endpoint using internally signed certs. The policy where I work is to put internal certs in a separate bundle on our Linux servers.
The following works perfectly well in curl:
curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" --negotiate --cacert /etc/pki/tls/out-internal-bundle.pem -u : "https://<dev or qa root>/api/profile/8461869a8b6e4558b20b14411337440b"
My actual client for this endpoint is written in Scala, however. Currently I'm making my call using scala.io.Source:
val url = s"$baseUrl/data-profiler/$id"
using(Source.fromURL(url)) { source => {
val result = source.mkString
val jsonAst = result.parseJson
jsonAst.convertTo[Job]
}}
I would like to figure out how, in my dev and qa environments, to use our internal bundle. Anyone doing that in Scala or Java?
You need to configure the "truststore" used by the JVM, with the "javax.net.ssl.trustStore" option when you launch java, i.e.
java -Djavax.net.ssl.trustStore=/etc/pki/tls/out-internal-bundle.jks ...
(sbt will take the same -D argument if you are using SBT to launch your app)
You'll need to get your CA certs into JKS format.
See:
Curl cacert to Java HttpClient equivalent
https://docs.oracle.com/cd/E19509-01/820-3503/6nf1il6er/index.html
http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#X509TrustManager
I would entirely recommend you to use Gatling for this kind of things. Gatling is a really cool framework for load-testing and it provides support for many protocols like jms, jdbc, and of course http among others. Please take a look on it here http://gatling.io/#/ (This framework is build on Scala) and it provides support for the things that you are searching for

Cannot set more than one Meta data with OpenStack Swift Object

I am trying to set metadata with a Object stored in Swift Container. I am using following command (note that my container is 'container1' and object is 'employee.json':
curl -X POST -H "X-Auth-Token:$TOKEN" -H 'X-Object-Meta-metadata1: value' $STORAGE_URL/container1/employee.json
It works fine with one metadata. But whenever, I am trying to set more than one metadata issuing several curl commands, only the last metadata value is actually set.
I think, there should not be a limit that you can set only one metadata for a swift object. Am I doing anything wrong?
FYI: I am using Havana release of Openstack Swift.
Thank you.
I think, I have figured it out... Its my bad that I did not read documentation sincerely.
It [1] says, "A POST request will delete all existing metadata added with a previous PUT/POST."
So, I tried this and it worked...
curl -X POST -H "X-Auth-Token:$TOKEN" -H 'X-Object-Meta-p1:[P1]' -H 'X-Object-Meta-p2:[P1]' $STORAGE_URL/container1/employee.json
Here, instead of two POST requests, now I have set multiple metadata in a single POST request.
Again, thanks.
Ref:
http://docs.openstack.org/api/openstack-object-storage/1.0/content/update-object-metadata.html

How do I consume a sparql endpoint - such as DBPedia in an iphone app

I am looking for tutorials on how to consume and parse data from a sparql endpoint such as DBPedia. I am new to semantic web and rdf and sparql. Would I just treat the response as XML and use one of the many third party xml parsers to read rdf input?
A link to a good tutorial for consuming sparql endpoints on the iphone would be great
You send the query as a HTTP GET request, and parse the result (usually XML or JSON, you can request either) using an XML or JSON parser.
For example the query:
http://dbpedia.org/sparql?query=SELECT+DISTINCT+?concept+WHERE+{+?s+a+?concept+}+LIMIT+50
Will run the SPARQL query:
SELECT DISTINCT ?concept
WHERE {
?s a ?concept .
} LIMIT 50
And return the results in XML.
You can test this in curl with:
$ curl -g 'http://dbpedia.org/sparql?query=SELECT+DISTINCT+?concept+WHERE+{+?s+a+?concept+}+LIMIT+50'
If you set the Accept: header you can control the return type, e.g. in curl:
$ curl -g -H 'Accept: application/json' 'http://dbpedia.org/sparql?query=SELECT+DISTINCT+?concept+WHERE+{+?s+a+?concept+}+LIMIT+50'