Invoking a servlet

Hi Group,

I am a newbie. I need to invoke a servlet (located in a Application server) from webMethods. This servlet accepts 2 parameters and returns a xml based output which i need to map it webmethods document.

Can you pls help me how to do this. I would really appriciate if you can guide me step by step approach.

Thanks in Advance.

Usually, you can use pub.client:http to perform a post to the URL of the servlet. You can pass the two variables as parameters on the URL in the form ?variable1=value1&variable2=value2 or by mapping the two variables on the args parameter of the pub.client:http.

Other servlets require an XML document to be posted as the body of the post.

Please review the webMethods 6.x Built-In Services Guide for more information on the {pub.client:http} service.

Mark

Thanks for the reply Mark.

I will look into this.

Hi Mark,

The servlet will be expecting xml [approx 50 xml feilds] as the input from webMethods. The servlet will read this xml and return another xml as out put.

I did look into pub.client:http but could not figure out how to pass XML as input to the servlet

Can you pls let me know how to do this step by step

Thanks in advance

V,

Basically you have to wrap up whole XML in a string or bytes (use stringTobytes service) and map the string in the client:http data/string or bytes,set headers/content-type=“text/xml”.This will post the xmldata to your target Servlet.And the servlet should handle this xmldata string at the receiving end.

HTH,
RMG

I encountering some problems -Here is what i am doing

In the client.http I am passing - url value
- method Post
- loadAS bytes
- data/args/content= xml stirng
- data/args/soapAction = “some parameter”
- headers/content-type=text/xml

I am tring to connect to a webSphere application which hosts the service.

But when i run my service I am getting the follwing
lastError/pipeline/header/lines/Connection = Close
lastError/pipeline/header/status= 500
lastError/pipeline/header/statusMessage=InternalServerError

Thanks in Adv

V,

Check in google for InternalServerError,your service inputs looks good…
Also make sure your webSphere application is up and running and i believe you are sending the required params by the target application.

HTH,
RMG

Thanks for the reply.

I am passing the same parameters as required by the service on websphere. when i invoke the service[websphere] using a HTML GUI i am getting the result back but when i invoking the service through client.http i am getting errors.

I wonder if webMethods adds on or wraps the http requests?

Thanks

If thats the case there might be missing some info in http service or network transport layer from WM is not working as expected.Did you contacted your WM admin or sysadmin?

HTH,
RMG

this is what the network transport layer revealed for a request from a Browser

POST /hostintegration/webservice.srv
HTTP/1.1 SOAPAction: MatchAddressRequest
Content-Type: text/xml; charset=“utf-8”
Content-Length: 6488
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.4.2
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Connection: keep-alive

But when the same request is sent via webMethods i get the follwoing -

POST /hostintegration/webservice.srv HTTP/1.0
User-Agent: Mozilla/4.0 [en] (WinNT; I)
Accept: image/gif, /
Content-type: application/x-www-form-urlencoded
Connection: keep-alive
Content-Length: 4622

Inspite of setting Content-Type = text/html as a parameter in the header field - I am getting Content-type: application/x-www-form-urlencoded in the Network protocol level

Thanks

I am getting Error 500: JAXM POST failed Unable to internalize message

This is because of the reason indicates that the content-type that is
being used is application/x-www-form-urlencoded. According to the SOAP
1.1 specification Section 6 the content-type for any content needs to be text/xml

How can i change the content type to text/xml from application/x-www-form-urlencoded - which is defalut in client.http.

I have added a variable Content-type=text/xml in header.But at the runtime the content-type = application/x-www-form-urlencoded.

Any help on converting application/x-www-form-urlencoded to text/xml will be appricitate.

Thanks in adv

V,

If you are sending a soap message to your servlet, you will probably want to use pub.client:soapHTTP or pub.client:soapRPC to send the message instead of pub.client:http.

Is your servlet expecting a simple XML document or is it expecting a soap message?

Mark

BTW, both of the services I suggested set the content-type to text-xml by default.

Mark

Hi Mark,

Thanks for the reply.

The servelt is expecting a simple xml and returning a SOAP message.

I figured it out how to set the content-type= text/xml.

If one passes any information in the arguments webMethods by defaults the content-type to application/www.url…

But I have 2 variables which needs to be passed to the servlet and also set the content type =text/xml.

Currently i am passing one of the two variable in the string feild of client.http service, by doing so i can overwrite content type to text/xml. Is there a way by which i can pass pass 2 name value pairs to the service without using args feild

Thanks in Advance

What kind of convoluted servlet accepts plain ole XML but returns a soap message? I’ve never heard of that before. I guess asking for a WSDL that describes this service is out of the question, right?

So you need to send an xml file in the body of the post as well as two non-xml arguments? I don’t think a content-type of text/xml is correct for that arrangement since only one of the parms is XML.

This is a way weird implementation. I’m not sure how to advise you on this.

IMHO, if the servlet will return a soap message, it should accept one. If it is pretending to be a web service it should have a WSDL that describes it. If the service will accept XML doc only then you can use text/xml as the content-type. If the service needs to accept xml plus other args, text/xml is not correct.

If you are describing this correctly, it may be so screwed up that you’ll have to write a custom java service to do the post and force the content-type. Perhaps you could clarify with the developer / owner of the servlet, just how they intend for others to use their amazing service.

Mark

Hello,

Yemi Bedu