We have a weblogic application that reads a file as a byte array. This byte array needs to be passed on to a service on webMethods, that will need to send out an email with an attachment that will contain a file created from the contents of the byte array.
I understand that a service on webMethods may be called from another application using http invoke, and parameters may be passed, but I don’t know if the entire contents of the file could be passed as byte array just like string variables. Once I receive the byte array into a webMethods service… I would be on my way. Guys… any help on this is appreciated.
Hello,
I think that when you receive over http, you will infact get a stream. So your invoked service would need to the wmPublic streamToBytes service. From there you have the rest.
Yemi - thanks for the response… but I think I didn’t make myself clear. Let me simplify things. All I need to know is how to invoke a webMethods service from a (say) servlet and pass a byte array.
If I were to pass a string variable say ‘message’, to a webMethods service named ‘writeMessage’ in a folder ‘service’, I would invoke this service as follows:
Do an HTTP post using normal Java HTTP constructs. Simplified example below:
[highlight=java]
// Open an http connection
URL url = new URL(“http://:/invoke/folder/service”);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
// Set the appropriate HTTP parameters. Change to whatever you need.
httpConn.setRequestProperty(“Content-Type”,“text/plain; charset=utf-8”);
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestMethod( “POST” );
// Post the bytes from the file.
OutputStream out = httpConn.getOutputStream() ;
out.write(yourBytesHere_OrReadFromYourFileInputStream);
out.close() ;
// Read the response.
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
// Read isr and do whatever you need with it
[/highlight] Your service will be invoked with a stream or a node or a string or something in the pipeline, depending on the content-type you set.
I dont know if this will be a better alternative in your case.
But there is one more way to call wm service. You can create a java client to call wm service from a standalone java application.
I’ve find a message where you describe how to send data in a stream to a webMethods service.
I’ve a problem because when i used this method to invoke wm.tn:receive there is no problem I can find my document in the database but when i want to invoke a personnal service my pipeline is empty even if my first service is streamToByte.
Could you help me?
To see what data is being passed into your service comment out all other Flow steps and insert a pub.flow:tracePipeline invoke. The output will be written to your IS server log or console. Remember that the variable placed into the pipeline will vary depending on the content-type that you specify in your post.
The node object that you see is actually an xml node. You should start by defining the input to your service - an object named ‘node’. Map this node object to the input[node] of the pub.xml:xmlNodeToDocument to get an IS document… and you can proceed from there.
When you pass an XML document to an IS service over HTTP and the content type is text/xml, IS will automatically parse the XML and create an XML node. This is the equivalent of the receiving service performing these steps, if it received the bytes directly:
bytesToString - given the byte array, converts to a string
xmlStringToXMLNode - given an XML string, parses to an XML node
Thus, IS does this work automatically for you. The resulting node is what you want to work with.
The node can be passed to any number of services, usually xmlNodeToDocument, to perform further processing.