Retrofit migration to 2.0 - java

While migrating to Retrofit it's a nightmare to remove all service calls containing callbacks. I made use of Structural Search and Replace, but i've to repeat templates due to varied number of arguments for a method call. My templates are as follows,
Search template
$MethodType$ $methodName$(
$paramtype1$ $param1$,
$paramtype2$ $param2$,
Callback<$type$> callback);
Replace template
Call<$type$> $methodName$(
$paramtype1$ $param1$,
$paramtype2$ $param2$);
I used number fo parameters to address all service call we have. Was wondering if there is any way to write a search template that would find all methods that has "Callback callback" as a parameter.

It's possible to use a search template like this
$MethodType$ $methodName$($paramtype$ $param$, Callback<$type$> $callback$);
Click Edit Variables... and give $param$ an Occurrences count of 0,∞. This will find all methods with a last parameter of type Callback and zero or more other parameters.
Use the following replacement template
Call<$type$> $methodName$($paramtype$ $param$);

Related

Ebay Finding API

I am making a call from a server that is located in US to FindItemsAdvanced of ebay finding api.
I define ListedIn as "EBAY-ENCA", however, when I make the call - I see that it doesn't return results. I believe that this is because that items are not available to US.
I see that there is a parameter called: AvailableTo - but how can I say "to all countries" ? Writing each iso code in the world could be exhausting..
My code:
ItemFilter marketFilter = new ItemFilter();
marketFilter.setName(ItemFilterType.LISTED_IN);
marketFilter.getValue().add("EBAY-ENCA");
request.getItemFilter().add(marketFilter);
ItemFilter conditionFilter = new ItemFilter();
conditionFilter.setName(ItemFilterType.AVAILABLE_TO);
conditionFilter.getValue().add("UK");
request.getItemFilter().add(conditionFilter);
In general this call should work - regardless from where you call the API. So I assume that you get an error message from the API that prevent items from being returned. Be aware that the FindItemsAdvanced call of the eBay Finding API requires either a given "categoryId" or a "keyword". Do you set any of these?
Here is the XML payload of a working call:
<findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/search/v1/services">
<keywords>iPhone6</keywords>
<itemFilter>
<name>ListedIn</name>
<value>EBAY-ENCA</value>
</itemFilter>
</findItemsAdvancedRequest>
I've created an example in our API playground. It uses the XML version of the Finding API. Just execute the call to see the valid response with items included. You can adapt and customize the request parameters to your needs and see how the API responses.
The "AvailableTo" filter can only be used once per request with exactly one value. So it won't be possible to add it multiple times or to add it once with multiple values. But I'm not sure if I get your use case right. Do you really want to get only those items that are available world wide? If yes, then I'm afraid this most probably isn't possible without filtering them locally (eg. by filtering for "Worldwide" in the "shipToLocations").

Servlet not retrieve parameters from AJAX call

I used AJAX to call an action and pass parameters, the AJAX call occurs from xsl page and its as follows:
xmlHttp.open("GET","examcont?action=AJAX_SectionsBySessionId&sessionId="+sessionId,true);
I decided to put the amp; after & as xsl raises this error when I removed it:
The reference to entity "sessionId" must end with the ';' delimiter
the problem is that the action is unable to read the parameter sessionId however I tried the same action URL but without the amp; and the action reads the parameter successfully
The problem seems to be that the & represents & in the style sheet but gets expanded/escaped to & again during output (because it is HTML/XML). You may try to use the following in XSL to avoid escaping:
xmlHttp.open("GET","examcont?action=AJAX_SectionsBySessionId<xsl:text disable-output-escaping="yes">&</xsl:text>sessionId="+sessionId,true);
However, note that - if you happen to let your XSL run in the browser - this does not work (although it is correct XSL and it should) on Firefox according to https://bugzilla.mozilla.org/show_bug.cgi?id=98168.
As portable alternative, you can use the following which avoids mentioning & by inserting it at runtime with what you might call "Javascript-escaping":
xmlHttp.open("GET","examcont?action=AJAX_SectionsBySessionId"+String.fromCharCode(38)+"sessionId="+sessionId,true);
Also have a look at similar question with deeper discussion and other options using a html entity in xslt (e.g. )

Redirect with anchor in play 2

I'm looking for possibility to add anchor to url returned in controller:
public static Result open(String id) {
// here I want to add acnhor like #foo to the produced url
return redirect(routes.MyPage.show(id));
}
I found that it was possible in play 1 using addRef method, but I couldn't find any replacement of the method in play 2.
Of course I can use concatenation like:
public static Result open(String id) {
// here I want to add acnhor like #foo to the produced url
return redirect(routes.MyPage.show(id).url + "#foo");
}
But it seems ugly.
Thank you for any help! Have a good day!
Before trying to answer that question.
I should recommend you change whatever behavior you're currently setting.
Because, an URL fragment's purpose is client side only. Such fragment is never sent to the server, so that it's cumbersome to do the opposite.
However, here is the embryo of a (quite?) elegant solution that you could follow.
What I'll try to do is to leave the browser deal with the fragment, in order to keep potential behaviors (f.i. go to ID or even deal with history...).
To do so, you could add an implicit parameter to your main template which will define the fragment that the URL should have:
#(title: String)(content: Html)(urlFragment:Option[UrlFragment] = None)
As you can see I wrapped the parameter in an Option and default'ed it to None (in order to avoid AMAP pollution).
Also, it simply wraps a String but you could use String alone -- using a dedicated type will enforce the semantic. Here is the definition:
case class UrlFragment(hash:String)
Very simple.
Now here is how to tell the browser to deal with it. Right before the end of the head element, and the start of body, just add the following:
#urlFragment.map { f =>
<script>
$(function() {
//after everything is ready, so that other mechanism will be able to use the change hash event...
document.location.hash = "#Html(#f.hash)";
});
</script>
}
As you can see, using map (that is when the urlFragment is not None) we add a script block that will set the hash available in urlFragment.
This might be a start, however... Think about another solution for the whole scenario.
As of Play 2.4, it's possible to use Call.withFragment().
routes.Application.index.withFragment("some-id").absoluteURL(request)
This was added by PR #4152.

Error creating queue with WebSphere MQ API

I trying to create queues using PCF command in the WebSphere API as detailed in $MQM_HOME/samp/pcf/samples/PCF_CreateQeue.java. The creation fails when i add a description
command.addParameter(PCFConstants.MQCA_Q_DESC, "Created using MQMonitor");
I get the error: com.ibm.mq.pcf.PCFException: MQJE001: Completion Code 2, Reason 3015 : MQRCCF_CFST_PARM_ID_ERROR
Is there another way of setting the description, i'm using version 6 of the API.
The Commands page in the PCF manual states that:
The required parameters and the
optional parameters are listed. On
platforms other than z/OS®, the
parameters must occur in the order:
All required parameters, in the order stated, followed by
Optional parameters as required, in any order, unless specifically
noted in the PCF definition.
The section Change, Copy and Create Queue lists the required parameters in the following order:
MQCA_Q_NAME
MQIA_Q_TYPE
Optional parameters, including QDesc
The same manual provides required parameters and their order for all PCF commands so no need to play hide-and-seek trying out parms and orders in the future.
It turns out the addParameter on the PCFMessage should in a certain sequence (stumbled on it). If i change the add parameters if works. This is not just for creating queues, but for channels as well.
command.addParameter(PCFConstants.MQCA_Q_NAME, qname);
command.addParameter(PCFConstants.MQIA_Q_TYPE, PCFConstants.MQQT_LOCAL);
command.addParameter(PCFConstants.MQCA_Q_DESC, qdesc);
command.addParameter(PCFConstants.MQIA_DEF_PERSISTENCE, PCFConstants.MQPER_PERSISTENT);
the above will execute without error.
command.addParameter(PCFConstants.MQCA_Q_NAME, qname);
command.addParameter(PCFConstants.MQCA_Q_DESC, qdesc);
command.addParameter(PCFConstants.MQIA_Q_TYPE, PCFConstants.MQQT_LOCAL);
command.addParameter(PCFConstants.MQIA_DEF_PERSISTENCE, PCFConstants.MQPER_PERSISTENT);
the above will fail after moving around the description.
I haven't seen it documented in the Java docs, and if thats the case i looks forward to some hide and seek.

#Path regex expression in RESTful server

I'm writing a RESTful Java server with CXF framework.
How do I can write a #Path Regular Expression in order to obtain any URI finished in "/action" value?
Not sure if its /action/*, /*/action, or /*/action/* you want?. Anyway here goes:
1) /action/* can be matched by
#Path("/action/{search:.*}")<br>
doStuff(#PathParam("search") List<PathSegment> list)
In this example, a request like GET /action/order/2/price will be served by the doStuff() method where list can be used to get to all the path segments in order/2/price captured by the regular expression.
2) /*/action can be matched by (WARNING untested)
#Path("/{search:.*}/action")
findStuff(#PathParam("search") List<PathSegment> list)
In this example, a request like GET /item/2/action will be served by the findStuff() method where list can be used to get to all the path segments in item/2 captured by the regular expression.
3) /*/action/* Here I believe you are out of luck (feel free to correct me if I am wrong), for further info check this blog post.

Categories