Change WS endpoint on Axis2 with no servicePath - redirect

I've developed an WS using Axis2 1.4 and glassfish 2.1.1, which is properly running using the endpoint url like
`http://server:port/appname/services/FooService`
but I need to get it working through an endpoint like
`http://server:port/FooService`
since the WS clients can't be changed to use a different endpoint.
Getting rid of the "appname" part was easy, setting the appname to root under the application server (changing the application.xml configuration file for the application). This leads to an endpoint like http://server:port/services/FooService which works fine but still has the "services" part on it.
To get rid of the "services" part, i tried:
Changed the "servicePath" property on the axis2.xml configuration file. If I set this property to blank, null, "" or "/" does not work. On the first two cases a "servicePath can't be null or empty" exception is thrown while deploying the application.
Added a new entry on the web.xml file to map the AxisServlet to the url pattern "/", but again it does not work.
So, my question is: Is there any way to get rid of the servicePath parameter?
Supposing there is no way for doing so, another idea is to "redirect" requests from the endpoint url i'm trying to use to the one that axis2 uses (with the servicePath). I'm not sure how to do this, maybe with a servlet? some configuration on the application server?

If you deployed an application as ROOT just put servlet mapping in web.xml :
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/FooService/*</url-pattern>
</servlet-mapping>

Related

Apache Camel REST - not connecting

I'm trying to get Apache Camel's REST DSL working but it's not connecting for me.
I've got a RouteBuilder that's being called:
#Override
public void configure() {
restConfiguration().component("servlet")
.contextPath("/")
.enableCORS(true)
.dataFormatProperty("prettyPrint", "true")
.apiContextPath("/api-doc")
.apiProperty("api.version", buildVersion)
.apiProperty("cors", "true")
.bindingMode(RestBindingMode.json);
rest("/say/hello")
.get().route().transform().constant("Hello World");
}
but then the routes don't actually work.
This is inside a Spring Boot app that has other REST endpoints defined via JAX-RS but this is an integration package that I want to be able to keep separate. The weird thing is that this WAS working a few months ago before I had to work on other things, but now, coming back to it, I can't even get this simple endpoint working.
I've got Camel in my Maven pom.xml and everything seems to be starting correctly, but nothing happens when I hit http:://localhost:9071/say/hello, I just get the standard Tomcat 404 page.
Any thoughts on what I'm missing?
According to this: http://www.baeldung.com/apache-camel-spring-boot
As of Camel’s version 2.19, this configuration has been dropped as the
CamelServlet is by default set to “/camel”.
so /camel/say/hello is the correct URL and it works for me. Still looking at how to customize this.
EDIT:
Here's how to customize this under Spring Boot. You add a property to application.properties like this:
camel.component.servlet.mapping.contextPath=/*

WildFly management - list/detect REST endpoints deployed in WildFly

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.

SOAP/HTTP using different folder mappings in ColdFusion

I'm experiencing some strange behaviour with a ColdFusion 11 server, which (among other things) publishes some web services accessed via both SOAP and HTTP. The server itself is Windows 2012, running IIS. Actual folder config is as follows:
IIS has two websites configured, 'BOB' and 'BOB_Services'. Both have been configured with the CF Server Config tool so that CF handles .cfc, .cfm files. They share a common CFIDE config.
BOB's root is I:/inetpub/BOB
BOB_Services's root is I:/inetpub/BOB_Services
There is a folder mapping configured in CF Admin from '/' to 'I:/inetpub/BOB'. Don't ask me why, no one seems to know.
Normally there is a services.cfc file in BOB_Services ONLY. Yesterday we accidentally copied that same file into the BOB root folder, and all of our SOAP services using BOB_Services\services.cfc started throwing errors. Yet I can query the same webservice via HTTP (eg. using http://bob/services.cfc?method=function1&param1=0 ....etc) and get a valid result.
This is a reference answer in case anyone else comes across this strange behaviour.
It appears that when BOB_Services/services.cfc is called using HTTP GET, the folder mapping
'/' -> 'I:/inetpub/BOB'
is ignored and the actual file used to process the request is I:/inetpub/BOB_Services/services.cfc.
When a function in BOB_Services/services.cfc is called using a SOAP client, the folder mapping is invoked and the file used to process the request is I:/inetpub/BOB/services.cfc, IF IT EXISTS. If it does not exist, the file I:/inetpub/BOB_Services/services.cfc is used as expected.
This behaviour appears to be entirely repeatable - I can make a SOAP request, get one result, change the mapping, make another request and get the other result.

Bluemix SAML and timeout session issue

I've created Web Application running on Java Liberty Runtime on Bluemix. Login is done by using SSO service with SAML enterprise provider. After login user redirected to my app and on every JAX-RS request I get user's credentials by following code:
Subject s = WSSubject.getCallerSubject();
Object credential = s.getPrivateCredentials().iterator().next();
String loginToken = credential.toString();
Everything works fine, but if the user has been idle for more then 10 minutes and then perform any ajax request WSSubject.getCallerSubject() returns null, and I required to refresh application.
I've tried to increase timeout by adding following attribute to web.xml:
<session-config>
<session-timeout>60</session-timeout>
</session-config>
But it didn't help. So I'm looking how can I increase timeout or possible I can retrieve user credentials in a different way?
You need to add the optional element <authCache> to the server.xml file to change the default values for the authentication cache.
As you mentioned in your question, the default value is 10 minutes. To change it to 60 minutes you need to include the following in the server.xml file:
<authCache initialSize="50" maxSize="25000" timeout="60m"/>
The documentation here provides more details and also explains initialSize and maxSize options, I left the default value for these two above and just updated timeout.
If you are deploying your application using the default method of pushing the war file, you will need to use a different approach to deploy the application with a custom server.xml file. Please check the documentation here for options on pushing Liberty profile applications (more specific check sections Server Directory and Packaged Server).
In this case, you may also want to check the server.xml file that is currently deployed and modify that version to add the <authCache> element.
You can get a copy of the file by running the following command:
$ cf files <your_app_name> app/wlp/usr/servers/defaultServer/server.xml

Disable /rest URL in ColdFusion10

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.