We are using Apache Camel with CXF endpoints to process our web service requests. What I'd like to be able to do is have my application be able to accept messages on any URL like:
http://localhost:9000/[anything]/MyService
http://localhost:9000/foo/MyService
http://localhost:9000/bar/MyService
I think I could make this a configurable setting, but I would much rather have it be completely dynamic and accept any path component before my service name. I've read about the Camel URL Rewrite Component and it seems like that may work, but it didn't feel like the right answer.
If it helps here is my endpoint configuration (with some details removed for brevity):
<cxf:cxfEndpoint id="MessageEndpoint"
serviceClass="MyClass"
serviceName="RespondingGateway_PortType"
address="{{web-service-url}}:{{port}}/subpath/MyService">
</cxf:cxfEndpoint>
What I'd like to be able to do is put something like /*/subpath/MyService in the address property to match on anything, but this doesn't work.
Related
I am trying to do a POC where I am not able to change where the soap client gets their WSDL definition. This soap client has a ".wsdl" hardcoded in their code when they instantiate the service I am POCing. To start I have a pretty simple service, basically, a hello world which can be found here: https://github.com/apache/cxf/tree/master/distribution/src/main/release/samples/jaxws_spring_boot/src/main/java/sample/ws
The issue I am having is that I can't figure out how to configure jaxws or apache CXF to switch the WSDL URL response from http://localhost:8080/Service/Hello?wsdl to http://localhost:8080/Service/Hello.wsdl
I removed the metrics part from the example above and my WebServiceConfig looks like this:
#Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, new HelloPortImpl());
endpoint.publish("/Hello");
return endpoint;
}
Is there any way to get apache CXF to respond with the WSDL document from localhost/<myservice>.wsdl instead of localhost/<myservice>?wsdl
I feel like I am missing something really obvious.
The easiest thing is probably to issue a redirect or if the client doesn't honor that configure a rewrite rule.
You can also switch from a code first approach to a contract (WSDL) first approach and save the WSDL document somewhere else.
?wsdl is hard-coded in several places inside CXF and therefore not just a configuration to change.
I have a class that extends JAX-RS' Application. Its ApplicationPath is currently "/", however this overrides all requests from the root, which sucks because I have a lot of other servlets listed in web.xml that I don't want to handle with REST. I'd like to gradually move these existing endpoints over to JAX-RS, but all examples I've seen would imply that I can't selectively handle endpoints like this without URL rewrite rules on the server.
I would like to move these endpoints as such without having to rename them, i.e. without having to change /stuff/list to /rest/stuff/list.
Is there any other way? I'm using RESTeasy as my provider. It has a resteasy.resources web.xml parameter option with which I can specify my resources manually, but an Application with an ApplicationPath is still needed.
I'm running an instance of Apache Camel in order to proxy requests to another server (depending on the URI). The server Camel is running responds through a lot of a different domains (e.g. app1.server.com, app2.server.com).
By using jetty and http4, I was able to proxy requests by doing this:
from("jetty://http://app.server.com:8080/app1?matchOnUriPrefix=true").to("http4://app1host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");
from("jetty://http://app.server.com:8080/app2?matchOnUriPrefix=true").to("http4://app2host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");
Is there any way which is possible to create routes according to the domain name? Something like this:
from("jetty://http://app1.server.com:8080?matchOnUriPrefix=true").to("http4://app1host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");
from("jetty://http://app2.server.com:8080?matchOnUriPrefix=true").to("http4://app2host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");
Thank you very much.
You could create Content Based Router (http://camel.apache.org/content-based-router.html) like this
from("jetty://http://0.0.0.0:8080")
.choice()
.when(header("host").contains("app1.server.com"))
.log("app1.server.com").to(...)
.when(header("host").contains("app2.server.com"))
.log("app2.server.com").to(...);
We use Java DSL to configure our routes. All configurations for routes are in a db table and can be configured via a GUI.
How is it possible to ensure that the camelContext starts up even if a route is misconfigured (e.g. .to(invalidurl or typo) in a route or simply a bug in a route)?
Is there a possibilty to validate the routes before starting or maybe better some parameters/options which can be set on the context itself?
You can configure the routes with .autoStartup(false), and then start the routes manually when CamelContext has been started up.
To validate its really depending on what kind of component it is. If its some database component you can write some code that does a SQL query to see if the is valid user login or something.
To validate that an endpoint uri is misconfigured, then that is harder as they have a ton of options. But this is getting improved from Camel 2.16 onwards where we have during build time some tooling that generates a json schema file with the options, then we could potentially leverage that during parsing the routes to check for invalid configuration before attempting to create the endpoints which could detect errors sooner, and even also with IDE plugins or other 3rd party tooling.
Can you just before adding every route to the context, add it to a separate "test" context individually, and see if it spins up or fails; then based on that add it to your real context?
I've got a Spring Web MVC application (and also a BlazeDS application, though not as relevant) where files are dynamically generated based on certain client actions.
I'd like to just map a certain directory on the file system to Spring MVC (or the app server) url and let it serve the files in that directory (with streaming and standard last-modified header support). Ideally, the mapped directory would be configured via the spring config, since I already have support per-machine for setting that up.
So, how can I do this? The best I can find so far is to write a controller that reads the file manually and streams it byte-by-byte. However, that seems far less than ideal. Is support for something like this already baked into Spring MVC or the standard application server spec?
Thanks!
If your processing model supports it, why not cut the middleman of the filesystem out of the picture completely and just stream the files back through the response stream as they are generated? Take a look at the AbstractExcelView and AbstractPDFView classes of Spring MVC to see some examples of how this is done.
or the standard application server spec?
Yes, there is. As you didn't mention which one you're using, I'll give a Tomcat-targeted answer. All you basically need to do is to add a Context element for /path/to/your/resources in /conf/server.xml:
<Context docBase="/path/to/your/resources" path="/resources" />
This way they'll be accessible through http://example.com/resources/...
Ideal for this is using an lightweight proxying server in front of your appserver, like a nginx or lighthttpd. You can configure it for serving static content, without calling your app.
If directory and files so dynamic, you can prepare real path to file at your controller and give this filepath to the frontend server, using headers. For example for nginx it's a X-Accel-Redirect header. Read more about this (and follow links for other http servers) there