How to pass a "url with parameters" as a url parameter in GWT - gwt

I am calling a servlet from GWT client code using RequestBuilder.
In the request (a POST) I am passing some request data
builder.sendRequest(postData, new RequestCallback()....
In the postData I have a url parameter called "returnToUrl"
This "returnToUrl" has url parameters, and would be like this
returnToUrl = "http://my.server/add?pn=a&pd=b";
When I pass it to the servlet, the second (and later) parameters (pd=b in my example) get interpreted as request parameters for the servlet, not as part of the returnToUrl parameter, and hence get lost....
It is being URL encoded, but of course that doesn't change the '?' and '&' characters.
Any help much appreciated!

You need to encode your data in GWT.
Take a look at the URL class to do this:
http://google-web-toolkit.googlecode.com/svn/javadoc/2.4/com/google/gwt/http/client/URL.html
escpecially at encodeQueryString which basically has the same behaviour as encodeURIComponent in javascript.

Related

Jmeter parameter without name in REST method

Hello i have GET method that URL example is:
http://localhost:8050/programs/b3cb6a0f-5d29-4744-a7e8-5fa0099dab18
Where the last String is just programId that I set as parameter in HTTP Request.
JMeter is kinda confused and the respond in raw request is:
GET http://localhost:8050/
GET data:
b3cb6a0f-5d29-4744-a7e8-5fa0099dab18
but there's just 404 in response data.
I can just delete parameter and write /programs/b3cb6a0f-5d29-4744-a7e8-5fa0099dab18 in path instead of /programs/ and everything works perfectly fine. IMO it's awful way. I'd prefer do it with parameter.
Write in path the parameter as /programs/${programId}.
This is part of the path and not parameter, parameters in GET request are different than POST see http methods
path/mypage?param1=value1&param2=value2

Why is GorillaMux not allowing me to pass in a URL as a parameter?

I'm building a URL shortener API and I'm trying to pass a URL into a function using GorillaMux. The route handler is like so:
router.HandleFunc("/new/{url}", createURL)
The only thing is, if I pass in: https://www.google.com (as in localhost:8080/new/https://www.google.com) then it responds with 404 page not found and the URL is changed to https:/www.google.com.
I've tried adding a regexp pattern in with the {url} bit like so: {url:[a-zA-Z0-9/]+} but that didn't seem to work and seems a bit overkill since I'm checking the url is correct elsewhere.
You need to encode it so that the slash in the parameter was not confused as a part of the url:
localhost:8080/new/https%3A%2F%2Fwww.google.com

Jersey web service non-ascii characters

I am new to REST and jersey. I wrote a simple RESTful Web Service using Jersey 1.17 API. The Web service accepts data through POST method. When I pass data having non-ascii characters, it does not read them correctly.
#POST
#Path("hello")
#Consumes(MediaType.APPLICATION_FORM_URLENCODED + ";charset=UTF-8")
public Response hello(#FormParam("message") String message) {
System.out.println(message);
return Response.status(200).entity("hello" + message).build();
}
When I pass data having non-ascii characters in parameter 'message' it does not print it correctly.
curl --data "message=A função, Ãugent" http://localhost:8080/search/hello/
POST method prints "A fun??o, ?ugent"
I do not think Jersey is caring about the charset that is defined at #Consumes. I guess Jersey simply uses the request.getParameter method that uses the encoding of the request to resolve parameters.
You have many options to set the encoding:
In case the servlet container supports, set the default encoding of the connector
Set the default encoding of the jvm to UTF8
Create a Servlet Filter that catches this call and call request.setCharacterEncoding("UTF8"); In this case you must ensure that setCharacterEncoding is called before any other getter function (like getParameter) as the character encoding is set during the first get call on the request.
Do a transform on the parameter value by hand. You can get the ServletRequest and query the encoding. After that you can say:
new String(message.getBytes(currentEncoding), "UTF8");
In your case I would prefer the third one.

Send a special parameter via RequestBuilder POST on GWT

I am a beginner of GWT.
In my application, i need to post parameter which of value is a URL such like a following string.
'http://h.com/a.php?code=186&cate_code=MV&album=acce'
As you can see it, it includes character sequences '&cat_code='.
As i know, &parametername=value is form of one parameter!...
Because of this, a PHP file on my server side, only receives a following string,
'http://hyangmusic.com/Ticket_View.php?code=186'
How could i do in this situation... i want to receive a full URL as parameter on the server side PHP.
Please help me.
Thanks in advance.
my code.
String name = "John";
String url = "http://h.com/a.php?code=186&cate_code=MV&album=acce";
String parameter = "name="+name+"&url="+url;
builder.setHeader("Content-Type","application/x-www-form-urlencoded");
builder.sendRequest(parameter,
new RequestCallback() {
}
Use URL.encodeQueryString(url) so that your & is turned into a %26 (26 being the hexadecimal representation of the UTF-8 encoding of &)

Parsing response from the WSDL

I've generated the web service client in eclipse for the OpenCalais WSDL using the "develop" client type. Actually I was following this post so not really going in detail. Now when I get the results this way: new CalaisLocator().getcalaisSoap().enlighten(key, content, requestParams);, I get the String object, containing the response XML. Sure it's possible to parse that XML, but I think there must be some way to do it automatically, e.g. getting the response object in the form of some list whatsoever?
The response from the SOAP interface is already parsed. The englighten() method returns an XML string. When you call it with SOAP, this response is wrapped within even more XML. The SOAP library already parses the outer SOAP XML and returns the result of the enlighten() method, which is also XML.