Citrus Framework to validate byte array - citrus-framework

I would like to receive a byte array and do some basic validation (converting to String and splitting, etc).
Do I have to define a message validator, or a validation script? What is the best approach?
Are there any samples?
Thanks!

You could use the default binary message validator that automatically converts the binary data to base64 encoded string (http://www.citrusframework.org/reference/html/index.html#validation-binary) so you can do basic compare validation.
If this is not the way to go you could also implement your own special message validator that converts the payload and performs further validation steps. The easiest way to do this is to use a validation callback in Java DSL: http://www.citrusframework.org/reference/html/index.html#validation-callback

Related

Serving different media types in AWS Lambda with Java/Scala

When writing a function for AWS Lambda (in Java/Scala), the handler function can have one of different signatures:
// Raw input / output
def handleRequest(is: InputStream): OutputStream = ???
// Using the AWS dependency
def handleRequest(input: APIGatewayProxyRequestEvent, context: Context): APIGatewayProxyResponseEvent = ???
This is the two possible signatures I know of, at least. Maybe there is more.
The difference is that the first one is a raw response, that needs to be packed into a REST response by the API Gateway with manually configured properties like media type and response code.
The second response seems to utilize the Lambda Proxy Integration and will extract all configuration from the APIGatewayProxyResponse.
Now for my question:
The field body of APIGatewayProxyResponse is of type String.
To me it looks like this POJO is serialized to JSON before being sent to the API Gateway.
This would make it impossible to serve binary data like images or PDF files.
The raw OutputStream cannot carry the information about headers etc. (or can it?), which means I cannot serve multiple different media types.
Of course I could convert images, for example, to Base64. But that is far from optimal.
Is there a way I can serve different (binary and non-binary) media types (with correct headers etc.) in a single AWS Lambda handler? How do I have to configure the API Gateway for that?
Note: This answer is based on reading the docs. I haven't tried it in practice so it may not work.
If you open the "Output Format of a Lambda Function for Proxy Integration" section of the documentation you may see isBase64Encoded field and following text:
The output body is marshalled to the frontend as the method response payload. If body is a binary blob, you can encode it as a Base64-encoded string and set isBase64Encoded to true. Otherwise, you can set it to false or leave it unspecified.
And if you open APIGatewayProxyResponse in the .Net library you can see the IsBase64Encoded property there. It looks like it is just Java API that does not expose this field. But all the rest of the infrastructure should support it. You may also see that a similar field was added to APIGatewayProxyRequestEvent.java at some point but not to APIGatewayProxyResponse. So I think a following workaround should work: create your own APIGatewayProxyResponseEvent class with isBase64Encoded field and use it. Or just extend from the standard com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent and add this field in your subclass. I expect that if you match the naming convention, it should work. It should be marshalled to a JSON after all.

MessageBodyWriter most suitable Variant

The MessageBodyWriter.writeTo method includes MediaType mediaType and MultivaluedMap<String,Object> httpHeaders.
mediaType is supposed to be the most appropiate output format, but how is it being selected when multiple Accept header values are included (i.e. application/xml, q=0.5; application/json, q=0.9).
Besides, how is the best variant selected (language, etc.)? Using Request.selectVariant() is possible to do it automatically, but I haven't found how to do so within the MessageBodyWriter.
Thanks
Besides, how is the best variant selected (language, etc.)?
That really depends on the implementation.
but I haven't found how to do so within the MessageBodyWriter
Because MessageBodyWriter.writeTo doesn't really care about selecting the best variant. After checking a few implementations, like StringProvider, SerializableProvider or FormMultivaluedMapProvider it seems clear that they just take the input, and write it to the output stream in their respecitve formats: as a string, as a serialized object or as a form encoded string. They only use mediaType for such minor details as the character encoding they should use.
Therefore the decision about the most appropriate output format has to be decided before choosing the used MessageBodyWriter implementation as e.g. a StringProvider will always only output the string, and won't care if it's a JSON string or and XML string or something else.

Understanding GWT-RPC Concept

Can anybody explain me about this thing?
X-GWT-Permutation:1F79347D29BC07C95FC8B3A262D5DC8E
i have tried decoding some of the strings using Base 64.
i am using the following base to decode strings like bwR2, bwSo, bwSn, bwTU...
Base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$_
i got this string from this type of Request Payload Header:
7|0|10|https://www.bosscapital.com/app/Basic/|B8CC86B6E3BFEAF758DE5845F8EBEA08|com.optionfair.client.common.services.TradingService|prepare2OpenPosition|J|D|java.lang.String/2004016611|I|1.11427|0|1|2|3|4|11|5|5|5|5|6|6|7|7|8|7|8|BHLE|bwRF|E|Po|1.11427|1.11427|9|0|49|10|1|
The X-GWT-Permutation header references a GWT permutation's strong name (the strong name is an MD5 of the generated JavaScript code out of the JavaToJavaScriptCompiler, before it gets passed to the "linker").
The value isn't actually checked, only the presence of the header (as a partial countermeasure against XSRF).
The GWT-RPC wire protocol is described in https://drive.google.com/open?id=1eG0YocsYYbNAtivkLtcaiEE5IOF5u4LUol8-LL0TIKU

Converting a String to a Splittable in GWT

I'm maintaining a site written in GWT (2.5.0) that is used internally by our development team, and I've been experimenting with using AutoBeans for client side json parsing. I have a few objects with json that is not well defined — a developer can dump whatever json string he wants in there — so I'm using a Splittable property. In order to support editing this arbitrary json I'd like to convert a String into a Splittable, but I haven't found a straight-forward way of accomplishing this. Do I need to implement this interface myself or resort to something hacky like wrapping the json in another json object I can then decode into a throw-away AutoBean just to get a Splittable of the original json?
StringQuoter is the utility class which we do much of our manual Splittable work with.
Just user StringQuoter.create("some string"); to produce a Splittable whose payload is
"some string"
Once you have that splittable, you can assign it to a key in another splittable with the following method:
Splittable.assign(Splittable parent, String propertyName);
However, if you are trying to convert some arbitrary string which contains a JSON structure into a splittable, use StringQuoter.split(..) to create it. The resulting splittable can be queried as normal (i.e. what keys exist/don't exist, etc).

Strict date pattern for DateTextField in Wicket

I have a DateTextField component in my application and I want the input of date using a predefined pattern. The pattern that I need is "yyyy-MM-dd". I created the DateTextField using the following code.
DateTextField dtf_ExpiryDate = DateTextField.forDatePattern("ExpDate", "yyyy-MM-dd");
dtf_ExpiryDate.add(new DatePicker());
It helps to prevent date input in most of other formats. But it accepts input in dd-MM-yyyy format and converts it into some weird format. For example, 12-06-2013 is automatically converted to 0012-06-20.
Is there a way to throw an error when the date is given in dd-MM-yyyy ?
Javadocs of DateTextField says that the conversion is done internally using the Joda time parser. Is there a way to add more constraints ?
I really don't want the data to be captured as String and add a StringValidator to check if it confirms to the pattern using Regex.
Thank you
As far as I know, the answer is NO. DateTextField uses DatePattern or DateStyles internally and it is not possible to enforce stricter rules. If you don't want to use Javascript (custom) or JQuery, you have to use a REGEX to validate the input.
Have a look at here. Use the StrictPatternDateConverter class shown below to enforce a strict validation for the input.
Yep! StringRegExp is a good solution. But another solution could be the use of jqWicket. It provides a MaskedInputBehavior. Take a look at: http://code.google.com/p/jqwicket/wiki/MaskedInputExample