httpclient's (3.1) URIUtil.encodeQuery() is gone in org.apache.httpcomponents (4.4.1), any substitute? - httpclient

In my project code, there is a requirement to encode the URL. its currently using httpclient 3.1 jar and uses its method URIUtil.encodeQuery() to do the job. but we are upgrading the jar to the newer version, org.apache.httpcomponents 4.4.1.
where I couldn't find any exact substitute for encodeQuery method. it has been discussed in the post What happened to URIUtil.encodePath from commons-httpclient-3.1?.
But still I am looking for any good substitute for encodeQuery(), can anyone has suggestion.
Thanks

In our project we use the URIBuilder class.
https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/utils/URIBuilder.html
The builder returns the standard java URI.

If you have a new project I suggest to follow the other answer by using the Builder.
On my side, as my project is old and do not want to refactor too much, I just switched to another util class in the CXF project (as it's already a dependency I have).
I just replaced the code URIUtil.encodeQuery(strQuery) by URIParserUtil.escapeChars(strQuery)
The API documentation is here.

Related

How to retrieve the package-name of a resource using the SonarQube REST-API?

Can you think of an elegant way to determine the package of a JAVA-class in SonarQube using the REST-API?
This snippet
http://myhost:9000/sonar/api/resources?resource=my.project%3Asimple.analysis&depth=-1&scopes=FIL
delivers a result containing
<lname>my/project/src/com/tobi/my/heros/SchmidtsKatze.java</lname>
I could XSLT it to com/tobi/my/heros/, but I wonder if there is a propper way? What do you think?
From the question you ask, I reckon you are using SonarQube 4.2 or later.
Since SQ 4.2, resource WS is fully language agnostic and deals only with files and directories, not Java class and packages anymore.
Therefor, the information you are looking for is not available in plain in the WS response, you'll will have to do some XSLT or some other parsing and transformation.

Can I write Eclipse plugins using Groovy?

Groovy seems to fix a lot of the things I dislike about Java, and I was wondering if it would be possible to actually write an Eclipse plugin in Groovy instead of Java.
Does anyone know if this is possible, and if so how to go about it?
I've just found a blog entry which says it's not officially supported but is actually possible.
Not yet tested to see if it works, but it seems promising:
Writing Eclipse plugins with Groovy, by Jörn Dinkla
#Peter, I do not think that the blog post you linked to is complete or if it will really work. It is pointing to the old version of Groovy-Eclipse, which is no longer supported and is out of date.
Yes. It is possible to create your own plugins in Groovy.
First, install the Groovy-Eclipse plugin from here:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.7/
Then you can create a new plugin project and add the Groovy Nature.
Remove the Groovy Libraries classpath container
Instead, add the org.codehause.groovy as a required bundle
Create your Groovy code as normal
Now, the tricky part is exporting the plugin using PDE. See this blog post for how to do that: http://contraptionsforprogramming.blogspot.com/2010/08/groovy-pde-redux.html
One important thing to note is that you will need at least one Java file in your project for PDE to compile anything, It can be a dummy, empty file (this is a bug that has not yet been fixed).
Rejoice!
As an example, here is the codenarc Eclipse plugin that was written completely in Groovy:
http://sourceforge.net/projects/codenarceclipse/
You can also use JRuby, or Javascript ...
JAM Circle is a great example showing how to make great use of a scripting language in an Eclipse plugin, by allowing the end user to write his own actions and load them at runtime.
There's a proxy-like plugin that allows you to implement the plugin virtually in any language that supports JSR223 (javax.scripting)

Problems with GWT 2.4

I compiled the version in svn tagged as gwt2.4rc. Now there are a
couple of more libraries than I had the last time. Are the any
instructions on which library is needed for what? I tried it with only
the standard libraries (servlet, servlet-deps, user) but I get the
following error when a requestfactory call is made:
java.lang.NoSuchMethodError:
com.google.gwt.core.client.impl.WeakMapping.setWeak(Ljava/lang/
Object;Ljava/lang/String;Ljava/lang/Object;)
I tried declaring the requestfactory-client and requestfactory-server
jars as dependencies, but i doesn't help. I am using maven to manage
my dependencies.
I would go back to 2.4 beta, but I need the drag&drop features that
were introduced later.
Does anybody has an idea what could be wrong? or any hints how i can
dig deeper into this? I spend a lot of time trying to figure this out
but without any success :(
Do I need to provide more information?
Regards,
arne
Are you sure you deployed the 2.4-rc1 gwt-servlet.jar in your war/WEB-INF/lib ? Also, make sure you override the SDK for the gwt-maven-plugin: http://mojo.codehaus.org/gwt-maven-plugin/user-guide/using-different-gwt-sdk-version.html
That being said:
when using Maven, you shouldn't use gwt-servlet-deps but instead reference org.json:json and javax.validation:validation-api
requestfactory-server can be used instead of gwt-servlet if you only use RequestFactory on the server-side (no GWT-RPC, no SafeHtml, no RegExp, etc.); requestfactory-client is to be used for Java clients (such as Android), not the case here.

How to implement HashMap in GWT?

I have some amount of messages which are coming to my client from the server.
Every messages have an unique key which is possible to be duplicated in messages I have already received.
Which collection can I use in GWT to avoid duplication?
HashMap seems not to be a case for GWT. Is there any other way to organize it?
You can use the standard java.util.HashMap in GWT without problems. Be sure you haven't accidentally imported the com.google.gwt.dev.util.collect.HashMap. It happened to me several times while using Eclipse's Organize imports feature..
For questions like this, you should take a look at the GWT JRE Emulation Reference. It contains the java classes of the Java runtime library that can be automatically translated by GWT. The link points to the JRE ER for GWT 1.6. to show you that HashMap wasn't just included in the latest version. (The JRE ER for the latest version can be found here)
As xor_eq points you should check the GWT JRE Emulation Reference Check the link to the latest version (or the version that you're running). The support for for HashMap was added to GWT sometime ago (in 2.0 I think), so you should have no problem.

Using Netbeans RCP with Google Guice

I would like to use Google Guice (2.0 or 3.0, does not matter) for my Netbeans Platform Project. My Project has several Netbeans Modules. I managed to use Guice in a single Netbeans Module, but now I want to Inject a Dependency from one NBModule to another. Is this possible? I googled a lot and searched the mailing lists of netbeans and guice, but it seems like noone ever tried this.
I do not want to use the Lookup API for this, because I really need Dependency Injection for better testing.
Has anyone experiences with that?
Edit: To be more specific: Can i Use the same Injector for all NBModules or do I have to create an Injector for every Module?
I realize that this question is old, but since the subject is still relevant I decided to share my findings.
We successfully use Google Guice 3.0 in our Netbeans Platform project. This includes injecting dependencies across NBMs using one injector. The only issue we encountered was that Guice didn't recognize annotations in other NBMs, because they were loaded through other classloaders. See http://tkills.blogspot.com/2014/08/using-google-guice-in-netbeans-rcp.html for details.
I have not worked with Netbeans RCP, only with Eclipse RCP and with integration with Spring. We had to have separate Springs application context for every plugin, with one root context that was shared between all other plugins. So you would need similar thing, separate injectors for every modul. I am not sure but i thing Guice does not support concept of including one injector to another as parent injector.