FIle transfer over a JMX method - file

I have a method exposed in a MBean in server. Now, i have to call this method from the client and transfer a file to the server. How do i do it?
Regards,
Al Niyas

I'm not clear on what this remote method looks like, but what I would recommend for this operation is to have the JMX Server expose a method like:
void transferFile(String fileName, byte[] content)
Your local client can read the local file, read in all the bytes into an array and then pass the file name and the byte array content as arguments to the JMX Server method.

Related

Flink - How to pass custom parameter when submitting Flink job through REST API

I need to provide a decrypted password in a Flink job to connect it to redis. But the redis password can only be decrypted on a local machine. So my plan is to decrypt it locally first and then try to pass it to Flink when submitting the job through REST API. (I'm not allowed to write the decrypted password to the properties file.)
Is this possible? I noticed that I can specify programArgs and programArgsList in the JSON POST request. However, I'm not finding any means to access these parameters inside my program.
I have checked StreamExecutionEnvironment.getExecutionEnvironment().getConfig(), but the parameters are not saved there.
Is there any way to access the parameters which I submitted with the job? Or are there better ways to achieve the same goal?
They are Java program arguments:
public static void main (String[] args) {
}
You'll have them in the args array. The documentation mentions it in here: https://nightlies.apache.org/flink/flink-docs-stable/docs/dev/datastream/application_parameters/#from-the-command-line-arguments

Apache camel multicast (ftps & file) producing empty file

I have created a camel (2.20.1) route using groovy DSL. I need to use multicast for 2 endpoints viz. ftps and file. If the order of routes is ftps and file then file is property written on ftp server but on file system empty file is written (with size 0 bytes). If i reverse the order i.e. file and then ftps then file is written on file system properly and empty file is written on ftp server.
It is working fine on Apache Mina FTP server, but with client ftp server it is working as mentioned above.
I have tried both multicast options:
.to("ftps:....").to("file:...")
as well as
.to("ftps:...").to("file:..."))
Also tried parallelProcessing(), but still the same result.
camelContext.addRoutes(new RouteBuilder() {
def void configure() {
from("file:///home/xyz/?fileName=file.txt&charset=utf-8&noop=true")
.multicast()
.to("ftps://localhost:21/files?username=anonymous&password=anonymous&binary=true&fileName=file.txt&passiveMode=true&fileExist=Fail")
.to("file://${directory}?fileName=\${file:name}-\${date:now:yyyyMMddHHmmssSSS}")
}
})
I am expecting that multicast should write the same content to both endpoints without data loss.
See Why is my message empty?. File consumer returns InputStream, which is consumed by first endpoint and thus is empty for the second endpoint. You need to enable Stream Caching, or convert body to some reusable object (e.g. String) before multicasting.
Enable stream caching:
from("file:///home/xyz/?fileName=file.txt&charset=utf-8&noop=true")
.streamCaching()
.multicast()
...
Convert body:
from("file:///home/xyz/?fileName=file.txt&charset=utf-8&noop=true")
.convertBodyTo(String.class)
.multicast()
...

Get filename from proxy response when write to file in OSB

I want to make a OSB service that asks for a file on another service (URI) and store the received file to a specific location. I managed to make the request and have the response from the external service, and now I want to store the file with a BS over a JCA Connector by writing the binary on the local disk (for instance).
I'm calling the BS from the Proxy with a Publish component. My problem is that I don't know how to pass the filename from the response in proxy to JCA through the Publish and BS.
Can anyone help me? Thank you.
What I understand is you have the file name in your proxy but not able pass it to jca. Here is what you have to do -
Inside you publish activity, place a 'Transport Header' activity.
Set direction to Outbound Request.
Set protocol to jca.
Set jca.file.FileName and jca.file.Directory to the values that you have in proxy.

Read an XML file uploaded with app

I am using Java, GWT and Eclipse. I have a static XML file I want to parse to get certain data that will fill in list boxes and other info. How can I read the static XML file in both the server and client side of the code? Where do I put the XML file? Also, where can I put it if I only want the server to have access to it (since it contains sensitive data)?
If you need it on a server side only, put it in the /war/WEB-INF directory, and you can read it directly in your server code.
You can use a DataResource if you need a file on the client side:
https://developers.google.com/web-toolkit/doc/latest/DevGuideClientBundle#DataResource
If you want this file accessible on the client side, put it in the /war directory.
I would suggest that you parse the file server-side using any good XML parser (for an example see this tutorial) and put the resulting data in POJOs. For the data that you need client-side, you can make an RPC call to the server to retrieve the POJOs previously populated. A good place to put the XML file to prevent it from being directly accessible is under the WEB-INF directory of your webapp.

Google AppEngine static file for server computations

I have a ~2MB file that my Google AppEngine server must use (not serve) as part of a computation for a service request.
That is, a client makes a particular request, my GAE server must first get the data from this ~2MB file, do some computations using this data, then serve a small response back to the client.
Where best do I store this data so that it can be quickly read and used by the server in the computation?
If the following assumptions hold true
the file is not going to require updates outside of appengine code updates
that the file is read only
Then deploy the file with your code and read the file into memory during startup (ideally using warmup requests) and just operate on it from memory. If you code has to have file based semantics to access the data (read,seek, etc) then read the file contents and wrap it in StringIO.
You will need to assign the value read from the file to a module level variable, that way whenever you get a new request you can just get the files contents by importing the module and referencing the name. ie. mymodule.filecontents

Resources