Category Archives: webMethods

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:

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

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



TIP 1:
Start nc like this:

nc -l localhost 8000 &

Now run curl like this:

curl --proxy localhost:8000 --silent --max-time 1

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">


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):

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


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


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



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

webMethods 8.2 Unable to sync Document Type with correct broker Document Type

I stumbled across this problem after removing a Document Type in Designer without removing the corresponding Document Type on the Broker and then creating a new Document Type with the same name as the previous one. In this case the Broker will create a new Document Type with the extension “_1” and all changes will sync to this one instead.


  1. Delete a Publishable Document Type eg ‘myDocument’ using the Designer (without removing it from Broker)
  2. Now create a new Document Type called ‘myDocument’ and make it publishable
  3. If you now check the Broker Doc Type in the properties you will see that its name is wm::is::myDocument_1

To fix this we have to go through a number of steps:

  1. Open MWS->Messaging->Client Groups and click ‘IntegrationServer
  2. Open tab canPublish and use next to find ‘myDocument‘ and ‘myDocument_1
  3. Tick the box to the left of both Document Types and then click ‘Delete
  4. Open canSubscribe tab and use next to find ‘myDocument‘ and ‘myDocument_1
  5. Tick the box to the left of both Document Types and then click ‘Delete
  6. Now go to MWS->Messaging->Message Types
  7. Use ‘Next‘ to find both the ‘myDocument‘ and ‘myDocument_1
  8. Tick the box to the left of both Document Types and then click ‘Delete
  9. Now go into Designer and find the ‘myDocument‘ Document Type and lock it for edit
  10. In the properties section temporarily change ‘Publishable‘ to ‘false‘ and save
  11. Now change the ‘Publishable‘ property back to ‘true‘ and save

The doctype should now be called ‘myDocument‘ on the Broker and it should also be found in canPublish and canSubscribe on the ‘IntegrationServerClient Group. It is quite a lot of steps to fix this error. To never have to face this situation again be sure to ALWAYS delete the publishable document on the Broker if you remove it in Designer

NOTE! When this happens there is also a possibility that you have to reset the triggers that use this Document type – that has happened to me a few times. Just delete the Document Typer on the trigger and add it back (and set the appropriate filters again) and it should start working again

Tested on webMethods IS 8.2.2