Sunday, August 10, 2008

Exploring webmethods 2 (Sending xml file via http)

Today's exploration is about webmethods. To be more specific is sending a file to IS through http channel. I had done the following ways and only one success. I am not really sure what is the cause of it.

  • html post, This way I just create an html page and publish it using apache webserver. As usual, I create html element file. Using this element, I can choose whatever file that I want to send over. The form itself, I point to the flow service that I had just created. But unlucky me, this way fails and I dont know what is the cause.
  • Apache httpcommon , I was playing around with this useful stuff. The first try I failed. In the first try I was using a class that I am not familiar with. The following is a piece of code that I use:
Part[] parts = { part , new FilePart(f.getName(), f) };
filePost.setRequestEntity( new MultipartRequestEntity(parts, filePost.getParams()) );

The above method is actually encapsulate a file in the variable named parts. This way fails with the same output as the first way and again I dont know what is the cause of this problem. However, the second try is success. In this way, I was using the following code to send a file.

File f = new File("F:/SINAU/WM/xml/test.xml");
FileRequestEntity fileReq = new FileRequestEntity(f, "text/xml"); filePost.setRequestEntity(fileReq);

In the flow service side, I perform the following flow steps, to extract or parse the result that I want to:

What the above flow steps do are:
  • Fetch a content of file and put it in the variable test.
  • Convert the content of file to document type.
  • Perform query on the node.
The above sample may be not really efficient as it seems that I can directly query from node using flow step queryXMLNode.

The next exploration is... errmm... not sure !!!! :D

No comments: