#Path regex expression in RESTful server - java

I'm writing a RESTful Java server with CXF framework.
How do I can write a #Path Regular Expression in order to obtain any URI finished in "/action" value?

Not sure if its /action/*, /*/action, or /*/action/* you want?. Anyway here goes:
1) /action/* can be matched by
#Path("/action/{search:.*}")<br>
doStuff(#PathParam("search") List<PathSegment> list)
In this example, a request like GET /action/order/2/price will be served by the doStuff() method where list can be used to get to all the path segments in order/2/price captured by the regular expression.
2) /*/action can be matched by (WARNING untested)
#Path("/{search:.*}/action")
findStuff(#PathParam("search") List<PathSegment> list)
In this example, a request like GET /item/2/action will be served by the findStuff() method where list can be used to get to all the path segments in item/2 captured by the regular expression.
3) /*/action/* Here I believe you are out of luck (feel free to correct me if I am wrong), for further info check this blog post.

Related

Path variable having special characters like # in Spring boot

I'm using Spring Boot 2.4.6. For delete APIs getting 405 method not found. My endpoint is like: beauty/v1/sites/addressTemplates/:templateId
Path variable: ##$%#
Can someone please suggest what can be done to make this behavior as not complaining for 405? Please direct me to other questions in case I'm missing something.
I guess that your issue has nothing to do with Spring. Maybe you are trying to compose the whole URL by using reserved characters.
In a URL, a hash mark, number sign, or pound sign ( # ) points a browser to a specific spot in a page or website. It is used to separate the URI of an object from a fragment identifier. Source.
Which means that an URL which looks like:
beauty/v1/sites/addressTemplates/##$%#
is not exactly what you imagine it to be because # is interpreted in a special way. What you have to do is to percent encode the "special" path variable so it will look like this at the end:
beauty/v1/sites/addressTemplates/%23%40%24%25%23
Then Spring will not complain anymore and will resolve properly the endpoint.

Spark-Java: Different Path Strings Map to Same Get Method

I am running into a problem where two distinct paths are mapping to the same resource. Please let me know why the following 2 paths are mapping to the same path:
get("/test/:idtest/:idsimple", (request, response) -> "");
get("/test/all/:idtest", (request, response) -> "");
Following two call map to the same:
curl -X GET -i http://localhost:4567/test/2/3
curl -X GET -i http://localhost:4567/test/all/5
Thanks
The reason for these two requests to be mapped to the first route is the order you defined them. Spark Java documentation mentions here that:
Routes are matched in the order they are defined. The first route that matches the request is invoked.
When you call http://localhost:4567/test/2/3 Java Spark would try to match it first with the first route you defined "/test/:idtest/:idsimple":
The variable idtest would be matched to 2
The variable idsimple would be matched to 3
When you call http://localhost:4567/test/all/5 Java Spark would try to match it first with the first route you defined again:
The variable idtest would be matched to all
The variable idsimple would be matched to 5
So both of them match and therefore mapped to this route.
If you change the order of the routes definitions, then "/test/all/:idtest" will be the first path to match against and then calling http://localhost:4567/test/all/5 would be mapped to the right route, while calling http://localhost:4567/test/2/3 would fail the first one and would be mapped to the second.

Retrofit migration to 2.0

While migrating to Retrofit it's a nightmare to remove all service calls containing callbacks. I made use of Structural Search and Replace, but i've to repeat templates due to varied number of arguments for a method call. My templates are as follows,
Search template
$MethodType$ $methodName$(
$paramtype1$ $param1$,
$paramtype2$ $param2$,
Callback<$type$> callback);
Replace template
Call<$type$> $methodName$(
$paramtype1$ $param1$,
$paramtype2$ $param2$);
I used number fo parameters to address all service call we have. Was wondering if there is any way to write a search template that would find all methods that has "Callback callback" as a parameter.
It's possible to use a search template like this
$MethodType$ $methodName$($paramtype$ $param$, Callback<$type$> $callback$);
Click Edit Variables... and give $param$ an Occurrences count of 0,∞. This will find all methods with a last parameter of type Callback and zero or more other parameters.
Use the following replacement template
Call<$type$> $methodName$($paramtype$ $param$);

How to call solr analysis api in java?

Is there a way to call solrs analysis api in java using solr-core and get the analyzed tokens.
Analysis api takes fieldName or fieldType and values and give the analyzed tokens.
Is there a way to get those tokens from java?
I found the following link: FieldAnalysisRequestHandler, But I could not get any examples to use it.
In the Admin UI (for which the FieldAnalysisRequestHandler is meant) you can call it by selecting a core and then go to the "Analysis" entry.
See https://cwiki.apache.org/confluence/x/UYDxAQ or https://cwiki.apache.org/confluence/x/FoDxAQ for that.
From a client (which I guess you mean, as you tagged this question with solrj) you need to call the correct URL.
Typically the FieldAnalysisRequestHandler is bound to /analysis/field, see your solrconfig.xml.
From Solrj it should work like this:
SolrQuery query = new SolrQuery();
solrQuery.setRequestHandler("/analysis/field");
solrQuery.set("analysis.fieldtype", "mytype");
solrQuery.set("analysis.fieldvalue", "myval");
QueryResponse solrResponse = solrServer.query(solrQuery);
But it doesn't seem like there's a great support for this in Solrj, probably because it's meant to be called from the Solr Admin UI as mentioned.

Is the "api" part of a Web API route considered by Android's Uri.Builder as part of the authority or a path?

I've tried both of these:
builder.scheme("http").authority("10.0.2.2:28642").appendPath("api").appendPath("DeliveryItems").appendPath("PostArgsAndXMLFileAsStr").
builder.scheme("http").authority("10.0.2.2:28642/api").appendPath("DeliveryItems").appendPath("PostArgsAndXMLFileAsStr").
...and although for other reasons the code is not working yet, I'm wondering which way is right:
.authority("10.0.2.2:28642").appendPath("api").
-or:
authority("10.0.2.2:28642/api").
?
The "authority" portion of a URI identifies who's responsible for specifying the semantics of the path portion. This is usually a host/port combination and can optionally include a username/password (as in http://user:pass#host:port/somepage).
Wikipedia has more details on the grammar of URIs.

Categories