Category Archives: webMethods

Add custom solution to IS Admin page

Since I do not do this often I will put the description of how here

1. Create a flow service called “callback” in your package (or actually anywhere the IS can run it)
This flow service should contain at least one MAP with the following values:

name - description of menu item. Example: MYKPI
text - name of menu item. Example MYKPI 
url - URL to dsp page. Example: ../MYPackage
target - name of start page. Example: index.dsp

2. Create a flow service called “addSolution”
This service should contain one service from the WmRoot package: wm.server.ui:addSolution with the input: path to your “callback” service

3. Create a flow service called “removeSolution”
This service should also contain one service from the WmRoot package: wm.server.ui:removeSolution with the input: path to your “callback” service

4. Lastly we need to make sure that the solution is added to the IS Admin page every time the package gets reloaded
In your manifest.v3 file at the root of your package (example: MYPACKAGE/manifest.v3) there is a line like this:

<null name="startup_services"/>

This needs to be changed to:


    <null name="MYPACKAGE.processing:addSolution"/>
 

5. Run the “addSolution” service once
The link to your solution should now be visible in the IS Admin (after a refresh)

6. Done

Tested on webMethods 9.9 on Red Hat Linux 7.5

Using netcat to catch request data from cUrl

I recently needed to compare post data from cUrl and webMethods 9.9. The cUrl request worked like a charm but the same request from the pub.client.http service failed to be recognized by the consumer. I then got a tip from a colleague to use the netcat program to catch the output from both programs and compare the results. Here is how I did:

Start a listener on an non-privileged port eg. 8000

nc -l 8000

With this running in one console window we switch to another and run a curl command eg.

curl -F attachment=@file.csv http://localhost:8000

The file.csv in this example is a MIME message

The message is now captured and written to the console like this:

POST / HTTP/1.1
Host: localhost:8000
User-Agent: curl/7.54.0
Accept: */*
Content-Length: 382
Expect: 100-continue
Content-Type: multipart/form-data; boundary=--10e698fa110003d5

----10e698fa110003d5
Content-Disposition: form-data; name="attachment"; filename="file.csv"
Content-Type: application/octet-stream

HELLO WORLD

----10e698fa110003d5--

TIP 1:
Start nc like this:

 
nc -l localhost 8000 &

Now run curl like this:

 
curl --proxy localhost:8000 --silent --max-time 1 http://blog.niklasottosson.com

And you will catch one and one only request

TIP 2:
Start nc like this:

nc -l loclahost 8000 > request.txt 

And you will catch the request in a file called request.txt

Tested on OSX 10.13.6 and cUrl 7.54.0

webMethods 8.2 How to POST a file to a HTML form

This was a lot harder than I first thought and the only way I was able to do it was by making the MIME document by hand. I first tried using the pub.mime:createMimeData function together with pub.mime:addBodyPart and finally creating the document using pub.mime:getEnvelopeStream and sending it with pub.client:http, but my HTML test form never recognized the data it received. After a lot of searching Google and the WmUsers forum I found a solution and I’m going to share that solution here.

My test HTML form:

<form method="post" enctype="multipart/form-data" action="index.php">

File:<input name="File" id="File" type="file" /><br />

User:<input name="UserID" id="UserID" type="text" value=""/><br />

Password:<input name="Password" id="Password" type="password" value="" /><br />

<input type="submit" value="Send">

</form>

The function of the form is that it will accept a file for upload if the user credentials are correct

The index.php file looks like this:

file_put_contents("recievefile.log", date(DATE_RFC2822) . "\n" . print_r($_FILES, true), FILE_APPEND);
file_put_contents("recievefile.log", date(DATE_RFC2822) . "\n" . print_r($_POST, true), FILE_APPEND);

This is just for debugging. The php file writes the contents of the global FILE and POST variables to a logfile where I can see the result. In a production environment you would point the form data to a regular input script (php, .NET ASP, JAVA and whatnot)

So how do we POST to this form from webMethods? The solution is to manually creating the MIME document. So here is what I did to fill the form variables from webMethods:
My MIME document (a simple string in webMethods):

----=Part--123456789
Content-Disposition: form-data; name="File"; filename="filename.xml"; 
Content-Type: text/xml 

%variableWithTheXMLString% 

----=Part--123456789
Content-Disposition: form-data; name="UserID";
Content-Type: text/plain

%variableWithTheUserID%

----=Part--123456789
Content-Disposition: form-data; name="Password";
Content-Type: text/plain

%variableWithThePassword%

----=Part--123456789--

Lets go through the different lines. The “—-=Part–123456789” line is a part separator. It can be almost anything as long as it starts with “- -“. A part is simply one variable definition to send to the form. We have three form variables to fill so we have three part sections.
The “Content-Disposition” maps the section to the form variable. First we say that it is form-data we are sending (same as form is declaring in enctype). The name key value pair maps agains the forms key value pairs (File to the first input, UserID to the second and so on..)
The “Content-Type” simply says what type of data we are sending. For a simple UserID variable text/plain is sufficient. For the xml file I’m using the text/xml content type.
In the “variableWithThe?” section we simply paste the content for the form variables (File, UserID and Password). This is pasted as plaintext string in my case since I do not use any binary data (images, zip files and so on).

Now, to get the pub.client:http service to correctly send this to the form we need to do one more thing. The default header for pub.client:http needs to be corrected so we set one header row to the following:
Key: content-type
Value: multipart/form-data;boundary=”–=Part–123456789″
The “method” variable is set to “POST” and the “url” to the url of the form

After this you should be ready to send xml files to the HTML form and it should recognize the data as a file (called “File”) and two post variables (“UserID” and “Password”)

Tested on webMethods 8.2.2, Apache 2.2.24 (Unix), PHP 5.3.26