How to add arguments without key, to add only value to the body of ConnectionRequest - lwuit

I want to add a Json object to ConnectionRequest as value without key. I know that if use standard addArgument(key,value) -
addArgument("json","{JsonObject}")
in the body of request will be
json={JsonObject}
But I need to add only JsonObject without key and "=" symbol.
{JsonObject}
Is there any standard solution?
One more question Is there any class in Lwuit to create JsonObject similar to json.org.me
Thanks

Sure, just override
protected void buildRequestBody(OutputStream os)
And write whatever you want into the output stream. Don't use the arguments this will replace them anyway.

Related

play framework - redirecting with querystring

I am Using the play Framework 2.7.x
I have a Formular on my controller.list() with a view, let's call it "index". After you click "send" it open's controller.add() where it dos some stuff and then redirects back to controller.list(). If there was an error in the formular (a requiered field was empty) I need the queryString, which was send to controller.add() also redirected to controller.list()
The problem ist that if I do stuff like just passing the request, i get an error that it's not possible to add arguments.
public Result list(Http.Request request)
{
// .... stuff with foo, while foo is an Form<foo> Object
// ... foo.bindFromRequest(request)
ok(views.html.index.render(foo))
}
public Result add(Http.Request request)
{
// not allowed to add request as an argument. only empty is allowed.
return Results.redirect(controllers.routes.Controller.list(request));
}
I would like to just redirect the Form object, so I can handle the error in the controller.list() and not have to generate an extra view for the controller.add(). If I do everything inside controller.list() there is no problem with this code, but I like to use the controller.add() method instead.
Is the an option? except passing every querystring key and value by hand.
After I searched yesterday the half the day, I found something interessting today.
you are not allowed to use a default parameter with =. You have to use an optional default parameter with ?= inside the routes!!!!!
you can implement QueryStringBindable so it's a bit easier to bind the query String. But you still have to bind them "by hand".

What is the proper way to add a map in a REST request

I'm using Google Endpoint and for one of my entities I want to create a POST request that adds a map of properties. What is the right way to do it?
I know Google Endpoint can receive a Collection as a parameter, but I want to add a map (unknown key values).
Should I pass a JSON as a parameter or just add the JSON in the body of the request and extract it from the HttpServletRequest object?
I would avoid passing it as a parameter. You can send it in the body of the request and then use json library to get a python object.
https://docs.python.org/3/library/json.html
Every JSON object is a map, so it looks like the most obvious choice. GSON makes it easy, but you can use other parsers too.
Type type = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> myMap = gson.fromJson("{'k1':'apple','k2':'orange'}", type);

fiddler - can I output requesting client ip/name?

Using the code here shows how to add a column:
http://fiddler2.com/documentation/KnowledgeBase/FiddlerScript/AddColumns
What I'd like to know, though, is the ip (or name) of the client issuing the request. Is that possible to determine?
Thanks,
Ben
I believe you can grab this off Session object that is passed in. So in the code example in the article you link to you would set the value of you column to oS.clientIP.
For convenience the complete code you have to insert into the Handlers class:
public static BindUIColumn("ClientIP")
function ColClientIP(oS: Session){
return oS.clientIP;
}
This is now available from the UI using Customise Columns and the session flag X-clientIP. Now means V5.0.20211 of Fiddler Classic. Probably been there for some time.

Identifying Redirect/Forward Action in Struts2 Incerceptor

I was looking for a way to identify Struts 2 actions which are of type 'Redirect/Forward' in Interceptor, so that I can add some common code for that particular type of Action.
Is there any way in Struts2 to find what type of Action it is?
Thanks in advance.
There is nothing called as RedirectAction or ForwardAction, what you need it Redirect Result Type.
In your interceptor you have an instance of ActionInvocation passes to your intercept method, you can get the result from ActionInvocation object and then check as per your use case. Different Results are listed here
public String intercept(ActionInvocation actionInvocation) {
//After invoking the action you can get the result of from ActionInvocation.
Result result = actionInvocation.getResult();
//As per your use case you can check against different types.
}

How to know strong name of GWT serialization policy at the time of host page generation?

There is an excellent article describing a way to embed GWT RPC payload into the host page. A key element is missing there is how to know Strong Name of RPC serialization policy at run time.
Strong Name is computed at the compile time, put into the client and obfurscated. Strong name is sent to the server with RPC request as described here. What would you suggest to make this parameter available at the time of host page generation?
I have integrated GWT with spring with a custom SerializationPolicyProvider where I always had to rename <strong name>.gwt.rpc file and hard code the name in my custom SerializationPolicyProvider class. I got work around by looking at GWT docs. Strong Name is MD5 hash with length of 32. Each time RPC call is made to Spring based Controller's method: public String processCall(String payload), I parse the payload using following code to get strong name:
String strongName = null;
if(payload!=null){
StringTokenizer tokens = new StringTokenizer(payload,String.valueOf(AbstractSerializationStream.RPC_SEPARATOR_CHAR));
while(tokens.hasMoreTokens()){
String s = tokens.nextToken();
if(s.length() == 32){
strongName = s;
break;
}
}
}
Then in your SerializationPolicyProvider impl class use following:
to get SerializationPolicy:
return SerializationPolicyLoader.loadFromStream(servletContext.getResourceAsStream(moduleBaseURL+"/"+strongName+"gwt.rpc");
One solution seems to be using compiler -gen option. Get _Proxy.java from compiler output and extract SERIALIZATION_POLICY from it.