Spring Cloud Contract base64 image upload to long - spring-cloud

How can we create a contract for an image upload in base 64?
These base64 strings tend to get very long and we seem to get this exception:
String too long. The given string is 500000 Unicode code units long, but only a maximum of 65535 is allowed

Do you really need to upload such a gigantic image for a contract test? You want to use contract testing to just check whether your application can parse an image, not parse gigantic images. For the latter tests you can do integration testing. In my opinion you're misusing the tool.

Related

Most brief way to encode binary blob in Dart code?

I need to encode some binary blob (say, 100KB) in Dart code. Do not want to put it in a separate file, but hope can put it in .dart code (because, for example, I want the excellent flutter hot restart instead of rebuilding the Flutter app again and again if the file chages).
What is the most brief way to do so?
For example I can come up with final bytes = [100, 70, 220, 132, ...]; but it will make the .dart file huge.
I can also do final data = 'aGVsbG8...' and use it by base64.decode(data), but it takes up 33% extra space in generated binary.
Unfortunately those are your options as there's no way to export binary data from a file (i.e., like directly generating a .o file that exports a symbol in C/C++) without using either a Dart list or some other form of encoding.
However, if you're dealing with fixed binary data representations, I'd highly recommend looking at types provided in dart:typed_data to ensure you're storing this data in memory efficiently (e.g., using UInt8List vs List<int> will use 8-bits per element instead of the 64-bits that can be represented by int).

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.

Xtext Code Generation: Get raw String from XBlockExpression

Currently I am working on code generation based on an Xtext-DSL. Now I am facing the following problem:
I'm generating an .xtend file with my own implementation of the IGenerator interface. Everything works flawless but I can't access the raw String from an XBlockExpression in my DSL. I can only access the EMF-AST with all the attributes but re-generating the raw code from the model seems like a lot of overhead since I really just need all the code from withtin the XBlockExpression.
Does anybody have an idea?
you can always access the textual representation via the so called node model. the class NodeModelUtilsgives you access to it e.g. by calling findActualNodeFor. The resulting INode can be asked for its text

GWT Client Server Communication

I'm wondering whether it is at all possible to make the client ask the server for a given string, and incorporate it into another string ?
I don't see how to do that using the async approach.
As far as I know there is no really simple way to do this, because the i18n machanism of GWT replaces strings at compile-time and not at runtime.
You can try one of the following approaches:
Load the i18n in your entrypoint, store all messages in a local Map and create the Label etc, with the values from you cache. PRO: all GWT standard CONS: one request more, before you can show a translated page
Use JSP and no HTML at serverside. Wthin you jsp can create a JSON from your
message.properties and put it into your hostpage. PRO: You can synchronous read te values CONS: You will need to write a JSP which reads the properties for the correnct language, You will need to write a JSNI method to load the translated values.
Rethink, if you need a different way of translation. The built-in i18n will create tranlated versions of your app at compile-tim
I think I would use the second approach.

Matlab tiff setTag number not recognized

I am trying to change the value of a tag from a TIFF object in my matlab code. I keep getting this error:
Error using tifflib
Tag number (273) is unrecognized by the TIFF library.
Error in Tiff/setTag (line 1146)
tifflib('setField',obj.FileID, ...
The code I am using is included below:
fname='C:\FileLocation\pcd144_012.tif';
t=Tiff(fname,'r+');
t.getTag('StripOffsets')
t.setTag('StripOffsets',[8, 16392])
Why is it I can get the tag and see it, but cannot set the tag to a different value?
Here is a link to the tiff I am working with:
Tiff Data
I think that you're out of luck with this approach. The setTag methods are mostly used when building a TIFF from scratch. My guess is that the 'StripOffsets' field is not modifiable. Keep in mind that these tools are designed for the normal case of non-broken image files and that changing this field in such cases would either break the file or necessitate re-encoding of the data most of the time. The function should give better feedback (documentation for the TIFF could be better in general) so you might still contact The MathWorks to let them know about this.
As far as finding a way to edit these tags/fields, you might look for and try out some TIFF tag viewer/editor programs to see if they might do it. Otherwise it may come down to parsing the header yourself to find the relevant bytes.