Hello guys I have one url for my which is connected through id,
here I am using user_login_id and response is look like this..
{"interestreceived":[{"received_detail_id":2783,"interest_id":1288,"name":"Monali Patel","profile_id":"GM453843",
"image":"","cast":"Not Willing to specify","age":"24","location":"","user_status":"Accept"}]}
Here I have received_detail_id in above JSON,,
now in my next JSON Response
here I am using both ids,and in my code I am using put extra and get extra to pass values
String matchId=this.getIntent().getStringExtra("received_detail_id");
String Id=this.getIntent().getStringExtra("user_login_id");
USER URL:
USER_URL="http://mywebsitename.com/webservice/interestreceiveddetail?version=apps&received_detail_id="+matchId+"&user_login_id="+Id;
Is this right way to do?because I am not getting output
check this it will give you way to how to use putextra and getextra How to use putExtra() and getExtra() for string data
Related
I have a situation where I need to store my SOAP response in a string in case of success.
soap(soapActionBuilder -> soapActionBuilder.client("xyzclient").receive().messageType(MessageType.XML).validate("xapth validation", "Success"));
The above code is working if we receive a success response, but now I need to store that SOAP response in a string and return it.
I am not sure how I can do that. if anyone is having any idea please share, I am new to citrus. Thanks in advance.
If you would like to capture some value from response body, you could use a method extractFromPayload. This methods takes two parameters:
path - path to XML element
variable - to store element into variable for further usage in citrus test.
Sample how to use it:
soap().client("client")
.receive()
.extractFromPayload("//Foo/bar","foobar");
Now you can use variable foobar like this ${foobar}
echo("Extracted var: ${foobar}")
I am using response retrieved from one endpoint as path param in another endpoint.
However, when used in URI, it throws java.net.URISyntaxException: Illegal character in path.
//Post the endpoint
Response resp2 = RestAssured.given().
pathParam("id", build).
log().all().
when().urlEncodingEnabled(false).post("https://abc/{id}");
This is because the value of id used in uri is with double quotes like :-
https://abc/"id".
How can I get rid of these double quotes so as to use the value of id in uri , please advise.
First talk to the developer about this, because the nature of path param (/{id}) is to be replaced by a legitimate value (not enclosed in quotes); something like https://abc/23 or https://abc/param
I would not suggest any work-around for this as this is implemented in a wrong way from REST end point definition. You might go ahead and raise a defect against this.
Taking a shot in the dark here because I feel like the issue could possibly be coming from how you're getting the string from that response. If you're pulling it from a JSON using GSON or similar:
String name = myResponseJsonObject.get("member_name")
System.out.Println(name);
will print
"John"
whereas
String name = myResponseJsonObject.get("member_name").getAsString()
System.out.Println(name);
will give you
John
A small detail but this has tripped me up when using GSON and others when working with JSONs in java.
Thank you John and Mohan for your time , I really appreciate it.
I resolved this issue yesterday evening using Stringof function which removed the double quotes and provided me the String like value.
I have a URL and I want to print in my graphical user interface the ID value after the hashtag.
For example, we have www.site.com/index.php#hello and I want to print hello value on a label in my GUI.
How can I do this using Java in Netbeans?
Simple solution is getRef() in URL class:
URL url = new URL("http://www.anyhost.com/index.php#hello");
jLabel.setText(url.getRef());
EDIT: According to #Henry comment:
I would recommend to use the java.net.URI as it also deals with encoding. The Javadocs say: "Note, the URI class does perform escaping of its component fields in certain circumstances. The recommended way to manage the encoding and decoding of URLs is to use URI, and to convert between these two classes using toURI() and URI.toURL()."
and this comment:
Why not just doing uri.getFragment()
URI uri = new URI("http://www.anyhost.com/index.php#hello");
jLabel.setText(uri.getFragment());
Use the String.split() Method.
public static String getId(string url) {
return url.split("#")[1];
}
String.split() returns an array of Strings that are delimited, or "Split," by the value you pass to it, or in this case #.
Because you want only the string after the #, you can just use the second item in the array that it returns by adding [1] to the end of it.
For more on String.split() go to Tutorials Point.
By the way, the part of the URL you are referencing is the Element ID. It is used to jump to an Element on a webpage.
When I get the UriInfo.getPath(), it returns me getFoo/12345/enable (12345 is the id).
I want to get it as, getFoo/id/enable instead.
Is there a straightforward approach? Or just parse the hell out of it?
Take a look at UrlInfo.getPathSegments(). Might be easier than "parsing the hell out of it." :)
https://jersey.java.net/apidocs/1.8/jersey/javax/ws/rs/core/UriInfo.html#getPathSegments()
Just format your first result and replace numeric value with id.
String path = "getFoo/12345/enable";
System.out.println(path.replaceAll("\\d+", "id"));
Output:
getFoo/id/enable
I have a JSON String stored in a database. In one of my JSP pages, I retrieve this string, and I want to be able to pass the String or the JSON object into Javascript function. The function is simply this for test purposes
function test(h){
alert(h);
}
Now I can retrieve the JSON string from the database fine, I have printed it out to the screen to ensure that it is getting it, however when I pass it in like this
<input type="button"
name="setFontButton"
value="Set"
class="form_btn_primary"
onclick="test('<%=theJSON%>'); return false;"/>
Nothing happens. I used firebug to check what was wrong, and it says there is invalid character.
So I then tried passing in the JSON object like so
Widget widg = mapper.readValue(testing.get(0), Widget.class);
Then pass in it
onclick="test('<%=widg%>'); return false;"/>
Now this will pass in without an error, and it alerts the object name, however I am unable to parse it. Object comes in like with the package name of where the widget class is stored like so
com.package.mode.Widget#ba8af9
I tried using Stringify, but that doesn't seem to work on this Jackson JSON object.
After all that failed, I tried a last resort of taking the String from the database, and encoding it in base64. However, this too fails if I do this
String test = Base64.encode(theString);
and pass that in. However if I do that, print it out to the screen, then copy what is printed out, and send that through it works, so don't quite understand why that is.
So could someone please tell me what I am doing wrong. I have tried soo many different solutions and nothing is working.
The JSON String is stored in database like this
{
"id":1,
"splits":[
{
"texts":[
{
"value":"Test",
"locationX":3,
"locationY":-153,
"font":{
"type":"Normal",
"size":"Medium",
"bold":false,
"colour":"5a5a5a",
"italics":false
}
}
]
}
]
}
Would be very grateful if someone could point me in the direct direction!!
Edit:
Incase anyone else has same problem do this to pass the JSON from JSP to the JS function
<%=theJSON.replaceAll("\"", "\\\'")%>
That allows you to pass the JSON in,
then to get it back in JavaScript to normal JSON format
theJSON = theJSON.replace(/'/g,'"');
Should work fine
I think the combination of double quotes wrapping the onclick and the ones in your JSON may be messing you up. Think of it as if you entered the JSON manually -- it would look like this:
onclick="test('{ "id":1, "splits":[ { "texts":[ { "value":"Test", "locationX":3, "locationY":-153, "font":{ "type":"Normal", "size":"Medium", "bold":false, "colour":"5a5a5a", "italics":false } } ] } ] }'); return false;"
and the opening double quote before id would actually be closing the double quote following onclick= (You should be able to verify this by looking at the page source). Try specifying the onclick as:
onclick='test(\'<%=theJSON%>\'); return false;'
You can follow the following steps
Fetch the jon string
Using the jackson or any other JSON jar file , convert the json string to json array and print the string using out.println.
Call this jsp which prints the json string
check in the firebug , you will be able to see your json .
If the Json string does not print , there can be some problems in your json format.
this is a good website for json beautification , http://jsbeautifier.org/ , really makes the string simple to read .
Thanks
Abhi