I'm trying to configure a request to http: //where.yahooapis.com/v1/places.q(name_here);count=50?....
Not the best solution, I guess, but I tried
#GET("/v1/{location}")
Places getLocations(#Path("location") String locationName);
and pass there
getLocations("places.q(" + locationName + ");count=50");
But it still doesn't work as the string (); is translated into %28%29%3B.
Can you suggest any solutions? It would be better to dinamycally modify only the name_here part, something like
#GET("/v1/places.q({location});count=50)
If it is not possible how do I have to pass symbols (); so that they are converted correctly?
I just tried
#GET("/v1/places.q({location});count=50")
Places getLocations(#Path("location") String name)
a bit later and it works fine. I thought it will insert something like "/" or modify it, but it does exectly what I need.
Related
I want spring to search an image under path: /upload-dir/ID.jpg
ID is a variable that depends on the object's id.
Ive made something like this:
th:src="|#{/upload-dir/} ${dog.id} .jpg|"
but this is not working at all. I beg for any advice how to make it work :)
You can use the following structure to do so.
th:src="#{'/upload-dir/' + ${dog.id} + '.jpg'}"
I am making a GET request in my java code and the URL that i want to use to perform a GET request is:
http://localhost:1111/sms/v1/222222?startTime=2015-12-29T14%3A00%3A00.000Z&endTime=2015-12-29T15%3A00%3A00.000Z
However it is coming up as:
http://localhost:1111/sms/v1/222222?startTime=2015-12-29T14%253A00%253A00.000Z&endTime=2015-12-29T15%253A00%253A00.000Z
Notice that the following characters are being replaced:
% to %25
How do I make sure my request is sent as I want to specify. My code looks like this:
public static String getRequest(String id, String startTs, String endTs) {
Response response = givenAuthJson("username", "password")
.queryParam("startTime", startTs)
.queryParam("endTime", endTs)
.get(BASE_URL+"/sms/v1/{id}", id);
response
.then()
.spec(responseSpec);
return response.asString();
}
And I call this method as:
.getRequest("222222", "2015-12-29T14%3A00%3A00.000Z","2015-12-29T15%3A00%3A00.000Z");
Can you please give an example or answer using the code given? Thanks.
OK - not sure if I'm allowed to answer my own Q but it is for the benefit of all if someone is doing the same thing as me!
I overcame this problem by adding the following
.urlEncodingEnabled(false)
REFERENCE:
how to handle Special character in query param value in Rest assured
Thanks for all who helped.
This is probably a pretty simple issue but since I'm working with 1.3 IDE I can't use the most common method to do this.
String at_cmd_response = atc.send("AT+CMGS=\"+35111111111\"\r");
I need to introduce a string called number which holds a number like "35191xxxxxxx" in at_cmd_response. To do so, I've seen the String.format method but I can't use it due to my IDE.
Is there another way to do this?
Thanks
Simple String concatenation (+) will work:
String at_cmd_response = atc.send("AT+CMGS=\""+number+"\"\r");
Its looks like you have a modem and want to send some commands... like send a SMS or make a phonecall or similar :-) ...
now to the question:
you need to concatenate the modem command with the parameter
in java those are strings and can be concatenated using the unary operator +
like:
"AT+CMGS=\"+yourPhoneNumber+"\"\r"
example:
String yourPhoneNumber = "+35111111111";
and now call the method
atc.send("AT+CMGS=\" + yourPhoneNumber + \"\r");
I use below code snippets for web element locators in Selenium.
Here variable is quoted with '" + text + "
String text="666";
String subject="Knowledge base '" + text + "' Approval Request";
Also for rest assured,
If I want to parameterize 3f1dd0320a0a0b99000a53f7604a2ef9 value of below URL.
https://pineapples.com/api/sn_sc/v1/fruit/items/3f1dd0320a0a0b99000a53f7604a2ef9/submit_producer
So I declared it in to a variable and using “+sys_ID+” I pass it.
String sys_ID = "3f1dd0320a0a0b99000a53f7604a2ef9";
RestAssured.baseURI = "https://pineapples.com";
RestAssured.basePath = "api/sn_sc/v1/fruits/items/"+sys_ID+"/submit_producer";
I'm passing a String parameter into a java function I wrote.
When I pass the string parameter the method is accepting my parameter as follows
http://mywebsite.com/getCity.php?StateID={"state":"Alabama"}
I want my method to accept my string parameter as follows
http://mywebsite.com/getCity.php?StateID=Alabama
How do I get rid of {"state":"Alabama"}?
Hey Guys,
I'm building an android app. My syntax below is definitely java. I'm going to show you where I'm having trouble. I'm having trouble on the first line of the method so to show you the entire method would be silly.
public JSONArray getDetails(String StateID) {
// this Log.e is showing {"state":"Alabama"}
// how do I get it to show Alabama?
Log.e("StateID= " + " = ", StateID);
}
You've got a JSON object there (and it really should be URL encoded if it's going to live on a URL like that).
Treat it like a JSON object and use JSONObject to decode it. Deal with the checked exception thrown however you see fit.
JSONObject jsonObject = new JSONObject(StateID);
System.out.println(jsonObject.getString("state"));
I'm don't know Java, but the best method would be to deserialize the string into a Java object that had a state property. See: http://www.javacreed.com/gson-deserialiser-example/
Alternatively, you could just do something ugly like this:
StateID.substring(10, StateID.length - 2)
Which should trim {"state":" off the front, and trim "} off of the back.
I've found this guide on internet to publish on Wordpress using XML-RPC inside my Java Project, for example I want a message on my Blog, every time it's specified date.
http://wordpress.rintcius.nl/post/look-how-this-wordpress-post-got-created-from-java
Now, I've followed the guide and I'm trying to let it run but I don't understand yet how exactly parameters for my post works.
For example using the method blogger.NewPost I call:
public Integer post(String contents) throws XmlRpcException {
Object[] params = new Object[] {
blogInfo.getApiKey(),
blogInfo.getBlogId(),
blogInfo.getUserName(),
blogInfo.getPassword(),
contents,
postType.booleanValue()
};
return (Integer) client.execute(POST_METHOD_NAME, params);
}
and my "contents" value is:
[title]Look how this wordpress post got created from java![/title]"
+ "[category]6[/category]"
+ FileUtils.getContentsOfResource("rintcius/blog/post.txt");
(I'm using "[" instead of "<" and "]" instead of ">" that are processed by stackoverflow)
Now, how could I use all parameters in this XML way?
Parameters here: http://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newPost
And, it's the content only a "string" without any tag?
Thanks a lot to all!
Still don't know why it gives me back errors but i think it's only a bit outdated.
Found this other libraries that works perfectly
http://code.google.com/p/wordpress-java/
I advice all to use this since the other one is outdated
Thanks all