change baseurl with okhttp - java

Recently,When I plan to rewrite mine company program. I use the RxJava+OkHttp+Retrofit. But I have a problem.
Our application has only one access interface which can provide the base address for all modules. The format is as follows.
My intention is to dynamically replace baseurl with interceptors, the code reads as follows:
That's my code but I found a question,the converted URL becomes so:
www.xxapi.com:80/authorize/login/{#version code} (This is wrong).
This is wrong. This version field should be behind the base address.The correct url like this:
www.xxapi.com:80/{#version code}/authorize/login (This is right).
I've tried many ways, and I can't change the location of the version field.
I really don't know how to go on,I'm sorry.

Replace the call to addPathSegment(version) with a call to setPathSegment(0, version).
https://square.github.io/okhttp/3.x/okhttp/okhttp3/HttpUrl.Builder.html#setPathSegment-int-java.lang.String-

Related

How do I respond to tickets with camel Jira Producer?

I'm following the examples here -> https://github.com/apache/camel-k-examples. Working on 05-knative-source-jira
When running this integration, I'm able to read and log new jira issues just fine, I fall down when I try to use info from the ticket, or respond to the ticket with the jira addComment producer.
I've tried just putting a static ticket number in for the IssueKey option, but I get build errors and can't even get the producer to run.
I've tried tinkering with the URI...
Ex: Changing URI to -> .to("jira://addComment?IssueKey=EQ-7") returns below on build
No signature of method: org.apache.camel.builder.ValueBuilder.to() is applicable for argument types: (String) values: [jira://addComment&IssueKey=EQ-7]
I've tried this with both ? and &, as well as adding properties to the URI with similar results.
I feel like I'm missing something pretty fundamental, so any docs pointers would be well appreciated.
Full integration here
// camel-k: language=groovy
from('knative:channel/jira')
.unmarshal()
.json()
.log('Recieved: ${body}')
.to('direct:ticket')
from("direct:ticket")
.setBody().simple("testing")
.to("jira://addComment?IssueKey=EQ-7")
I ended up sorting through enough docs to find the answer. I'll share details just for others who might find this (or if I google it again).
The key was to
a) Set the required headers for the issue key. Seting headers examples
b) Ensure that my properties are set correctly. I used a configmap to set my properties, and then referenced them as shown below in the URI. I believe this should also be possible through DSL but URI was easiest for me to just get working.
Functional Integration below.
from("direct:ticket")
.setHeader("IssueKey").simple('${body["key"]}')
.setBody().simple("We've recieved the ticket -- we'll update you soon!")
.to("jira://addComment?jiraUrl={{url}}&consumerKey={{consumer_key}}&accessToken={{access_token}}&privateKey={{private_key}}&verificationCode={{verification_code}}")

Is there any substitute for UrlUtil.encodeQuery/URIUtil.decode?

I have an url, that contains Russian symbols and for encoding/decoding I use URIUtil.encodeQuery/decode. For example this piece of code
String url =
"https://dom.sakh.com/flat/sell?s[layout][]=102 серия&s[layout][]=138 серия&s[layout][]=306 серия&s[layout][]=97 серия&s[layout][]=97-С серия&s[layout][]=брежневка&s[layout][]=гостинка&s[layout][]=индивидуальная&s[layout][]=новая пл.&s[layout][]=сталинка&s[layout][]=хрущевка&s[price][min]=0&s[price][max]=10000000000";
System.out.println(URIUtil.encodeQuery(url));
It will display the following string
https://dom.sakh.com/flat/sell?s%5Blayout%5D%5B%5D=102%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=138%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=306%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=97%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=97-%D0%A1%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=%D0%B1%D1%80%D0%B5%D0%B6%D0%BD%D0%B5%D0%B2%D0%BA%D0%B0&s%5Blayout%5D%5B%5D=%D0%B3%D0%BE%D1%81%D1%82%D0%B8%D0%BD%D0%BA%D0%B0&s%5Blayout%5D%5B%5D=%D0%B8%D0%BD%D0%B4%D0%B8%D0%B2%D0%B8%D0%B4%D1%83%D0%B0%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F&s%5Blayout%5D%5B%5D=%D0%BD%D0%BE%D0%B2%D0%B0%D1%8F%20%D0%BF%D0%BB.&s%5Blayout%5D%5B%5D=%D1%81%D1%82%D0%B0%D0%BB%D0%B8%D0%BD%D0%BA%D0%B0&s%5Blayout%5D%5B%5D=%D1%85%D1%80%D1%83%D1%89%D0%B5%D0%B2%D0%BA%D0%B0&s%5Bprice%5D%5Bmin%5D=0&s%5Bprice%5D%5Bmax%5D=5000000000
And if I apply a method URIUtil.decode to this url i will get back:
https://dom.sakh.com/flat/sell?s[layout][]=102 серия&s[layout][]=138 серия&s[layout][]=306 серия&s[layout][]=97 серия&s[layout][]=97-С серия&s[layout][]=брежневка&s[layout][]=гостинка&s[layout][]=индивидуальнаяs[layout][]=новая пл.&s[layout][]=сталинка&s[layout][]=хрущевка&s[price][min]=0&s[price][max]=10000000000
But these methods are a bit old (httpclient's (3.1) URIUtil.encodeQuery() is gone in org.apache.httpcomponents (4.4.1) and i am trying to replace thsese methods). So my question is how to change my code saving the behavior? What to use? Provide an example, please, if it is possible.

Can't get the routes object in play framework to show my custom route

I'm attempting to do a reverse lookup on a route I've created.
The route is defined as such in my routes file:
POST /login controllers.Web.Application.authenticate
However, when I try to do a reverse on it in a form I made, I can't seem to find it. I'm attempting to do a reverse like this:
#helper.form(action = routes.login())) {
rest of the form here...
}
However, the login appears in red in intellij and when attempting to run the program, I get the following error:
play.sbt.PlayExceptions$CompilationException: Compilation error[value login is not a member of object controllers.routes]
I've attempted recompiling the project multiple times and looking around the docs, but it's just not working... Any ideas?
So, an interesting thing happened recently and I found a way to point to the original structure properly. To do so, rather than writing:
routes.Web.Application.authenticate()
As Tyler suggested, I was supposed to write:
Web.routes.Application.authenticate()
Which is totally counter-intuitive and all, but that allows me to use the original package structure.
Edit:
As we discovered in the comments, the reverse router doesn't seem to like sub packages. You should remove the Web part of your package, and move everything up a level, then change the code to be this:
#helper.form(action = routes.Application.authenticate())) {
rest of the form here...
}
Original answer:
You need to refer to the controller function, and not the name of the route, so it should look something like this:
#helper.form(action = routes.Web.Application.authenticate())) {
rest of the form here...
}

Why is my variable of type ListUsersRequest not realizing it has a method called withFilter(String)?

So I am in java trying to connect to my AWS Cognito User pool and load a user with a given uuid. I have succesfully loaded all the users in the user pool but now want to load only one with a specific uuid. To do this I must create a ListUsersRequest object and set it's userPoolId and filter. I would do this like so:
ListUsersRequest listUsersRequest = new ListUsersRequest();
listUsersRequest.withUserPoolId("us-east-1_m86wIbRdI");
listUsersRequest.withFilter("sub=97aca512-d186-4fb0-a74a-737s1f4361e5");
But this is being VERY strange. Eclipse tells me withFilter(String) is not a method that belongs to the ListUsersRequest type. This is not true, the documentation and every example I have found tell me withFilter is a method on the class. Is there another way to do this or is the documentation I am looking at deprecated or something?
I tried this which looked like it could be an alternate to the filter but while it runs fineit doesn't do any filter and just returns all users.
listUsersRequest.putCustomQueryParameter("sub", "97aca512-d186-4fb0-a74a-737s1f4361e5");
This is my import line:
import com.amazonaws.services.cognitoidp.model.ListUsersRequest;
any idea?
Are you sure you are importing the right class, because there are 2 classes with that name:
The one you want (and has the right methods):
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/cognitoidp/model/ListUsersRequest.html
And another one:
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/identitymanagement/model/ListUsersRequest.html
If you import the right one, are you sure you have the latest version of the SDK ?

SVNKIT=> SVNUpdateClient.doCheckout method - pegRevision?

I am using SVNKit to checkout svn base repository. Earlier I was using checkout to head for that purpose I was using SVNRevision.HEAD. It was working fine without issue.
below is the syntax of same and revision.Head was used in case of checkout to Head.
doCheckout(SVNURL url,File dstPath,SVNRevision pegRevision,SVNRevision revision, boolean recursive)
but let say if I have to checkout to a specific revision for example 27988, what should be value of pegRevision parameter ?
I am confused please help, I tried HEAD/BASE for pegrevision and also same 27988 etc but it gives error like URL not exist etc .
Just an update, problem was with my code revision was going as 0 always due to some logic issue hence SVN URL was not found and giving error. I tried now with HEAD as pegRevision and 27988 revision works just fine. Thanks!
Well, first, you have to specify an SVNRevision, not an integer.
long targetRev = 27988;
SVNRevision revision = SVNRevision.create( targetRev );
doCheckout(...
As for pegRevision, you almost certainly want SVNRevision.HEAD. As the docs specify, it is:
the revision at which url will be firstly seen in the repository to
make sure it's the one that is needed
So, HEAD is usually sufficient. When it's not, things get complicated (and very specific), see the svn book.

Categories