Grails 2.3.2:
This new version of grails (2.3) gives me the possibility to create a REST endpoint by extending the RestfulController class. I extend that class but when I POST to that endpoint with special characters these characters change.
I have these lines in my config file:
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"
And all my pages and requests use the UTF-8 charset.
What am I doing wrong?
A REST endpoint use HTTP connections, the gsp encoding is applied only for GSP views and though the converters apply the encoding as JSON formaters configuration the problem is in the HTTP connection.
The web container layer is the first filter and it affects the URI requested. Then you can apply a few container parameters as a JAVA_OPTS:
-Dorg.apache.catalina.connector.URI_ENCODING=UTF-8
-DjavaEncoding=UTF-8
-Dfile.encoding=UTF-8
-Dfile.io.encoding=UTF-8
Posibly you already resolved, but I hope that this response will be util for another cases.
Related
I have a setup where I run Wiremock standalone (as a Docker container, if that matters), with mappings defined in JSON files.
Is there a way to specify certain headers that will be applied to all responses? Specifically, I want all responses to have Content-Type: application/json, without having to repeat it in each mapping.
Is there a way (e.g. from a WildFly management console) to list all REST endpoints deployed in WildFly? Or to list them in a log while a server is starting?
Using the RegistryStatsResource
With RESTEasy (that is shipped with WildFly), you could add the following to your web.xml:
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>org.jboss.resteasy.plugins.stats.RegistryStatsResource</param-value>
</context-param>
And then request the following URL:
http://[hostname]:[port]/[context]/[api-path]/resteasy/registry
Such endpoint can produce XML and JSON content. Just add the Accept header to the request with the desired media type:
application/xml
application/json
Checking the source code
If you are interested in the source code to create your own implementation, have a look at the RegistryStatsResource class on GitHub.
The most relevant part of the source code is shown below (it's RESTEasy specific):
ResourceMethodRegistry registry = (ResourceMethodRegistry)
ResteasyProviderFactory.getContextData(Registry.class);
for (String key : registry.getBounded().keySet()){
List<ResourceInvoker> invokers = registry.getBounded().get(key);
for (ResourceInvoker invoker : invokers) {
if (invoker instanceof ResourceMethodInvoker) {
ResourceMethodInvoker rm = (ResourceMethodInvoker) invoker;
// Extract metadata from the ResourceMethodInvoker
}
}
Swagger may be an alternative
Depending on your requirements, you can use Swagger to document your API. It comes with a set of annotations to describe your REST endpoints.
Then use Swagger UI to provide a live documentation for your API.
Note: As of February 2017, looks like the RegistryStatsResource class is completely undocumented. I occasionally discovered it when digging into the RESTEasy source code for debugging purposes. Also, I found this JBoss EAP issue that tracks the lack of documentation for that class.
From the Management Console, you can view the published endpoints.
When you login as an administrator, Click the Runtime option on the top navigation bar as shown below.
Click the JAX-RS option, then click the REST Resources option. This will display the endpoints to the far right.
I am trying to test web service for my project. The Web service accepts a SOAP request and gives appropriate response.
In JMeter I have chosen SOAP/ XML-RPC request. It works completely fine for me and gives me correct response. However, I have more than 100s of web services in my scope of testing and I have to test them in different environments. It is very cumbersome work to change the URL value from the SOAP/ XML-RPC sample to point it to different env. Do we have something like HTTP Request Default for SOAP/XML-RPC requests?
I have also tried a bean shell sampler where I am setting the value of a variable and then retrieve it in the SOAP sampler URL parameter. However it did not work for me. Below is the code.
Bean Shell sampler code:
vars.put("baseURL","http://localhost:9191/ws/soap");
SOAP/ XML-RPS Sampler URL value:
${__BeanShell(vars.get("baseURL"))}
Any suggestions? I read in JMeter docs that this can be done via http sampler, however, I want to avoid using the same if possible.
You should avoid using SOAP/XML-RPC in favor of pure Http Sampler.
Use the "Templates..." (menu) > Building a SOAP Webservice Test Plan:
This way you can use HTTP Request Default if you want.
But note from what you describe, using a CSV Data Set Config would allow you to variabilize the URL.
Use JMeter Properties to set base url like:
in user.properties file (under /bin folder of your JMeter installation) add one line per property:
baseURL=http://localhost:9191/ws/soap
alternatively you can pass the property via -J command line key as:
jmeter -JbaseURL=http://localhost:9191/ws/soap -n -t /path/to/your/testplan.jmx -l /path/to/results.jtl
Refer the defined property in your test plan using __P() function
${__P(baseURL,)}
You can even provide the default value, i.e. if the property is not set via user.properties file or command-line argument - default value will be used:
${__P(baseURL,http://localhost:9191/ws/soap)}
See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of setting, overriding and using them.
We use zuul as an gateway to dispatch incoming requests to services.
When we upgraded from 1.0.0, we noticed two issues, one of which we got a workaround to.
The second issue is that in some of the incoming have encoded uris to deal with special characters in the request, e.g. ....rovi//45846 which needs to be changed to rovi%2F%2F45846 in order to pass in.
So for a rest uri like the following POST http://localhost:8902/contentservice/content/subscriptionPackages/624460160/channels/rovi%252F%252F45846
If I make this request directly to the service, it works correctly.
But if I route it through zuul as POST http://localhost:8765/contentservice/content/subscriptionPackages/624460160/channels/rovi%252F%252F45846 then it disappears.
Now if I take the % out it is passed in and treated as an error in the contentservice when I step through the content service front end controller (off course).
What has changed between spring cloud 1.0.0 to 1.0.1 in the zuul functionality to stop this from working. As it definitely was working in 1.0.0.
So the spring cloud team has fixed this in the snapshot releases and you can fixed more detail here
https://github.com/spring-cloud/spring-cloud-netflix/issues/366#issuecomment-106363315
Our problem with ColdFusion 10 is that there is the /rest/ URL binded. In our application we have a rest service ourselves. Since ColdFusion 10 it will not work because the URL is already defined and our requests won't get through. Is there any way to disable /rest/ completely? Or do we have to rename our service?
I also tried to edit the axis2.xml file
<parameter name="disableREST" locked="true">true</parameter>
<parameter name="restPath">restdisabled</parameter>
But that won't effect anything on the server.
Thanks in advance!
Disclaimer: I have not tried this and do not have a ColdFusion 10 installation nearby to verify
There is a servlet mapping defined in the web.xml file that defines how to handle /rest/ requests for ColdFusion. So you should be able to rename that URI to something else for your implementation. The web.xml file is located under the wwwroot\WEB-INF directory on your ColdFusion server.
I found some reference to this here - Getting started with RESTful web services in ColdFusion (under the Accessing a REST Service through HTTP section)
That documentation also mentioned updating the uriworkermap.properties file. Here is an excerpt from that page:
rest in the URL specifies that the request is for a REST service. ColdFusion has a servlet mapping for the same and would direct the request to the servlet that handles REST service. If there is a directory in the server webroot with the same name, you must update the servlet mapping in web.xml file inside wwwroot\WEB-INF directory. Also, you must update the same mapping in the uriworkermap.properties file located under the config\wsconfig\1 of the server directory.
You will need to restart the ColdFusion service after making any changes to these files.
While this will not disable the functionality in ColdFusion it will allow your services to respond under the /rest/ URI because ColdFusion will be listening under a different one that you define.