ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » converting messages to URLEncoded format for HTTPRequest

Post new topic  Reply to topic
 converting messages to URLEncoded format for HTTPRequest « View previous topic :: View next topic » 
Author Message
cool_ziv
PostPosted: Thu Feb 18, 2010 7:27 am    Post subject: converting messages to URLEncoded format for HTTPRequest Reply with quote

Newbie

Joined: 24 Nov 2009
Posts: 8

HI,
I've a requirement where I need to make a web service call using HTTPRequest node. The message that I need to send is an XML message.
The header of HTTPRequest will have an additional header
"Content-Type=application/x-www-form-urlencoded" along with Authorization header. So this requires the XML messages to be URLEncoded(percent-encoding) in the HTTPRequest message.
(I'm getting the desired response only when I send the messages in the URLEncoded format otherwise it returns a Null exception response)
For eg:
The XML message
<dummy>
<text>This is for testing</text>
</dummy>"
should appear like
"%3Cdummy%3E%3Ctext%3EThis+is+for+testing%3C%2Ftext%3E%3C%2Fdummy%3E"

The one option that this can be done is using Java static method java.net.URLEncoder.encode(String,'UTF-8').
I'm trying to know if there is any in-built function within WMB to handle this conversion. I'm comfortable with handling JCN or calling java method from ESQL (in this case I cannot b'cas the method encode(String,'UTF-8') have a 'throws' clause).
I searched the forum for any URLEncoded topic and I didn't get any help. So I would like to have the opinion whether I missing something or I'm heading in the right direction? Even directing me to any other topic related to this would be really helpful.
Please let me know if you need any more details that may help you in providing me a better answer.
Back to top
View user's profile Send private message
cool_ziv
PostPosted: Mon Feb 22, 2010 8:24 am    Post subject: Reply with quote

Newbie

Joined: 24 Nov 2009
Posts: 8

Any help?
Back to top
View user's profile Send private message
mgk
PostPosted: Tue Feb 23, 2010 4:43 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Quote:
I need to make a web service call using HTTPRequest node ... Content-Type=application/x-www-form-urlencoded


It seems a very strange Web Service that requires the body to be x-www-form-urlencoded. All the Web Services I am familiar with want plain SOAP-XML and so I assume that is why this thread has had no responses so far. Perhaps you could post the WSDL for this service if you have one along with a sample input and response messages? Ones captured "on the wire" showing the HTTP headers would be ideal...
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
cool_ziv
PostPosted: Fri Feb 26, 2010 4:48 pm    Post subject: Reply with quote

Newbie

Joined: 24 Nov 2009
Posts: 8

Hi mgk, thank you for your reply.

WSDL file is not available for this webservice. I was provided with a sample Java code (which works fine) and I need to implement this webservice using WMB. Like I mentioned in my initial description, it works fine only when I encode the outgoing XML message in the URLEncoded format and setting the HTTP Header in the appropriate type.

I did happened to capture the message when it reaches the server (From the sample Java file I redirected the URL to a message flow which listens to an incoming HTTPrequest and captured the message that the given java file sends to the server.). Below you can find the piece of the java code which send out the message via HTTP.

Code:
public void processXmlInput(String xmlInput) {
            //The string xmlInput contains whole XML as a string format.
            inRootEl.removeContent(); // Clear Request JDOM document
            setXmlInput(xmlInput);
            String requestType = "BillRequest";
            success = false; outRootEl.removeContent(); // Clear Reponse JDOM document
            try {
               // Encode the input for a POST
               xmlInput = URLEncoder.encode(xmlInput,"UTF-8");
               }
            catch (UnsupportedEncodingException use) {
               // If error, add error element outRootEl.addContent(new Element("Error").setText(use.getMessage()));
               error = true;
               return;
               }
            HttpURLConnection Conn = getUrlConnection(postUrl);
            DataOutputStream myOutStream = null;
            try {
               myOutStream = new DataOutputStream(Conn.getOutputStream());
               myOutStream.writeBytes(requestType + "=" + xmlInput);
               myOutStream.flush();
               myOutStream.close();
               // Test the URL Connection for success
               if (! Conn.getResponseMessage().equals("OK")) {
                  outRootEl.addContent(new Element("Error") .setText("URL " + Conn.getURL().toExternalForm()
                        + ": " +Conn.getResponseMessage()));
                  error = true;
                        return;
                        }
               // Create the output JDOM document using the connection's InputStream
               outJdomDoc = saxb.build(Conn.getInputStream());
               outRootEl = outJdomDoc.getRootElement();
               if (outRootEl.getChild("Error")==null) success = true;
               error = false;
               }
            catch(IOException ioe) {
               outRootEl.addContent(new Element("Error").setText(ioe.getMessage()));
               error = true;
               }
            catch (JDOMException jde) {
               outRootEl.addContent(new Element("Error").setText(jde.getMessage()));
               error = true;
               }
            }


For eg.
If the value of the string 'xmlInput' has a value
Quote:
"<text>This is for testing</text>"
then the message that arrives on the server looks like
Quote:
BillRequest=%3Ctext%3EThis+is+for+testing%3C%2Ftext%3E
.

The HTTPrequest header appears on the server end is like
Quote:
Content-Type: application
Type: x-www-form-urlencoded
along with other request headers like authorization .


Also the response header from the server for response message is
Quote:
HTTP/1.1 200 OK
Date: Thu, 18 Feb 2010 00:54:26 GMT
Server: Sun-ONE-Web-Server/6.1
Set-Cookie: LtpaToken2=kR5FsCoRuFZGDJbCmJLJ+FV2IbnqEt2xOuNRU=; Path=/
Set-Cookie: LtpaToken=qEfVuwB6+rQgD81WuEkzlphWFEt/tw==; Path=/
Set-Cookie: user=XYZ(I removed it); Path=/
x-username:
Connection: close
Content-Type: text/xml
Content-Language: en-US
Set-Cookie: BIGipServerp-prod-www.XYZ.com=16849306.3685.000; path=/
Vary: Accept-Encoding, User-Agent

and it contains the response XML in a plain text XML format.

Quote:
<Response>Request received</response>

and if there is any Error a null:Exception message is included in the response content.

So, from mgk's response, I believe, this is something unusual and encoding the content by calling the Java static method java.net.URLEncoder.encode(String,'UTF-8') is one way to do it ?? and there is no built in function (in ESQL) available with message broker for Encoding it in this format?
Advance thank you for the response.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » converting messages to URLEncoded format for HTTPRequest
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.