Camel Zip with multiple entries - apache-camel

I have a message that comes in via a queue. I want to send that message off to a signing service. This service returns a signature. I then want to put the original message and the signature message into a Zip file as two seperate Zip entries. I want to asked for the world on a stick and do this as a blueprint, and entirely via XML with no compiled java code (other than my signing microservice which is already built and running in our infrastructure).
Ideas?
Looking at the docs and playing around with it I think I can...maybe.
It seems the default aggregators might not do quite what I need for this usecase.

Just found the solution. Below is a PoC:
context.addRoutes(new RouteBuilder() {
#Override
public void configure() throws Exception {
from("timer://foo?fixedRate=true&period=1s").to("direct:start");
from("direct:start").setBody().simple("hello").multicast(new ZipAggregationStrategy(true, true)).to("direct:a", "direct:b").end().to("file://target?fileName=any.zip");
from("direct:a").setHeader("CamelFileName").simple("data.txt").to("log:mylog");
from("direct:b").setHeader("CamelFileName").simple("signature.txt").to("http://mysignatureservice");
}
});

Related

Dynamic sitemap generation for GWT based appengine website

We are aware of the appengine limitation relating to writing files to disk. So the idea of having a dynamic sitemap via i/o seems a bit difficult for AppEngine. So here are some ideas that we wish to validate:
Can we have a servlet that generates a google sitemap compatible xml dynamically?
If this is possible, can someone share an example?
Can such a sitemap, in turn, contain dynamic links that return raw textual data suitable for indexing?
If the above is true, the only problem we see is that, such dynamic URLs, that are only meant for indexing content, will become available in search results. Instead we wish that users land directly on the homepage of the website.
With respect to SEO, given that the website is pure GWT, is there a better way to index content?
For dynamic URLs your only solution since you are using Java on Google App Engine is to create a servlet that will create this response.
There are many libraries that you can use that will make sure that your XML is correct but the simplest example that can get you started will look like this:
public class SitemapsServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("application/xml");
resp.getWriter().println("<?xml version="1.0" encoding="UTF-8"?>");
resp.getWriter().println("<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">");
resp.getWriter().println(" <url>");
resp.getWriter().println(" <loc>http://www.example.com/?id=who</loc>");
resp.getWriter().println(" <lastmod>2009-09-22</lastmod>");
resp.getWriter().println(" <changefreq>monthly</changefreq>");
resp.getWriter().println(" <priority>0.8</priority>");
resp.getWriter().println(" </url>");
resp.getWriter().println("</urlset>");
}
}
For the rest of the questions make sure that you understand how the sitemaps are working and what's their purpose.

Eclipse doesn't generate google cloud endpoint client library

I'm trying to create my first GAE Endpoint app, and instead of generating an endpoint from a class, I'd like to create my own personalised Endpoint... is this possible?
I've written this class:
#Api(name="my_endpoint", path="my_endpoint")
public class MyFirstEndpoint {
#ApiMethod (name="my_method", path="my_method", httpMehod=HttpMethod.GET)
public Response myMethod(#Named("param1") String param1) {
...
}
}
But when I try to generate the Endpoint Client Library in Eclipse, it says that there was an error... and the worst thing is that it doesn't say what error it is!
Yes it's possible to create custom Endpoints.
I had the same error. I think you can't use "_" in the name of the Api nor the ApiMethod...
Try using "myEndpoint" and "myMethod" as the names and keep the "_" in the paths.
A bit unrelated to this particular case, but it's the first thing that popped up on Google when searching for the error: you can't have overloaded methods in your Endpoints classes. Found this by looking in the Error console as described above in a comment.

Datastore callbacks are not called in Google Application Engine

I have a simple GAE application using JPA and eclipse plugin for GAE (sdk version 1.7.2).
I only have one simple entity mapped wit 2 properties : 1 Key key ; and one String name.
I have created only one class (taken from the "Datastore Callbacks" documentation of gae)
public class PostPutCallbacks {
static Logger logger = Logger.getLogger(PostPutCallbacks.class.getName());
#PostPut
public void collectSample(PutContext context) {
logger.fine("Finished putting " + context.getCurrentElement().getKey());
}
}
The database callback is not called.
I tried with several other annotations (#PrePut #PreGet) but they still didn't work .
I've also tried with the Datastore low leve API and the callback is still not called.
I searched the web to see if there is a configuration besides the annotation processing jar manualy added for eclipse but I didn't find anything..
Can anyone give me a hint?
I want to provide more information in this thread. If you are unable to see the datastore callbacks being triggered. Try this procedure as documented. You need to do some simple project set up at Eclipse in order to make it work. Hope this helps.
I jumped a little fast to stackoverflow..I had to restart eclipse and it worked

How to dynamically map URLs to Java servlet handlers based on their names? (Google App Engine)

What I'm looking for is some sort of class or annotation I can add to Java classes that are dedicated to handling specific requests, and having URLs map to these based on their name. For example, have the URL ".../api/GetContactsRequest" map to a handler named GetContactsRequest (or 404 if no such handler exists). I know I could write servlets and map each URL to each servlet, but I figure the less boilerplate routing code/configuration, the better! These will mostly be application request handlers, communicating using JSON. I haven't figured out how I'll be handling static requests, but I'll most likely just be sending a big web application at the user that navigates itself or something.
For background, I'm using the Google App Engine so I have access to yaml configurations and their servlet APIs. So is there a standard way of doing this with either the Java servlet APIs or the Google App Engine-specific framework? I've only ever used specific Java servlet frameworks like Apache and stuff before, which were all already built by the time I started working on them, so I really don't know what there is to use with this environment. I'm also new to this all in general, and having trouble wading through what Servlets, Services, Filters, Listeners, and Handlers all are, and which is best for this simple routing behavior that I want/need. I'm worried I'll pick the wrong one, or don't even know of the one that would suit my needs.
This is what JAX-RS does - not exactly class name mapping, but mapping via annotations. See some of the features.
There are several implementations, personally I use RESTEasy - it works flawlessly on GAE. Additionally I use Jackson (comes with RESTEasy) to produce JSON.
If you need to produce html then look at htmleasy - it's a thin layer on top of RESTEasy enabling use of different html templating libraries. It'll help you separate logic from presentation.
EDIT:
If you really want to avoid using standard libs and writing something on your own, then write a servlet filter that inspects the request and forwards it to your servlet (or invoke custom code):
public class ForwardFilter implements Filter {
#Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
if(request.getRequestURI().equals("/some/path")){
request.getRequestDispatcher("/path/where/servlet/registered").forward(request, response);
return; // prevents normal request processing
}
// you need this for normal request path
filterChain.doFilter(request, response);
}
}

Silverlight Ria Authentication - Checking Authentication Before Using DomainContext

I have the beginnings of a standard Silverlight/ RIA/ EF application that is just working straight away as expected.
I wanted to restrict my entire DomainService to only authenticated users, as the application will eventually live on the public internet, and all data access needs to be user authenticated.
The problem I have, is that I cannot use the auto-generated DomainContext class in my Silverlight app unless I wrap all of its Load methods inside a custom class that verifies the authentication status of the user before attempting to retrieve data - which seems like a long and tedious coding task.
Surely there must be a simple solution that Ive missed ?
This stuff was easy in ASP.NET because the moment you lost (or never had) authentication you were redirected to a login page (as configured in web.config).
Im really suprised theres no similar mechanism in Silverlight, as it seems to be to be a standard business application requirement.
Requiring authentication in your DomainService is easy. Just add a [RequiresAuthentication] or [RequiresRole] attribute to either the class (applies to all operations) or operation you want to authorize. You might find these links helpful.
How to: Enable Authentication in RIA Services
RequiresAuthenticationAttribute
I am not 100% sire if this is the answer you want and if it's a good practice to do it like this but you could implement a message inspector that inspects whether the user is authenticated like this:
public class ClientCustomHeadersDispatchMessageInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
if (!HttpContext.Current.User.Identity.IsAuthenticated) {
throw new SecurityException("User not authenticated");
}
return null;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
}
}

Resources