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 » content type application/json charset=utf-8 -HTTP Input node

Post new topic  Reply to topic
 content type application/json charset=utf-8 -HTTP Input node « View previous topic :: View next topic » 
Author Message
visasimbu
PostPosted: Tue Mar 17, 2015 8:03 am    Post subject: content type application/json charset=utf-8 -HTTP Input node Reply with quote

Disciple

Joined: 06 Nov 2009
Posts: 171

Hi All,
I have tried to handle the JSON message in my broker. My broker is 7.0.0.3.

My flow is look like below.

HTTP Input Node -> compute node -> RouteToLabel

POST(label)-> RCD(JSON) -> compute ->HTTP reply node


Here JSON message is constructed and sent to WMB flow by java application.
When the java application have content type ( application/json; charset=utf-8 ) like this. Then the flow is not triggered. If i remove this line from java application WMB flows is accepting the requesting and parsing the JSON messages with content type as - application/x-www-form-urlencoded; charset=UTF-8.

I have tried below options.

1) Givent the parser as JSON in HTTP Input node. - Didnt accept the input or flow is not triggered.
2) Have set the parser as BLOB in HTTP Input node. - Didnt worked.
3) Created a JSON message from SOAP UI with content type - application/json; charset=utf-8. Then my flow is picking and processing as i want. But it is not accepting responding for the requests coming from the Java application.

Could you please show some light where could be the issue.
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Tue Mar 17, 2015 11:19 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Not from the information you supplied. But the way you are building the JSON message is a good candidate. Find out what the difference is between a message built with SOAPUI (which apparently works) and one built by your Java application(not working). And remember to also check the URL the message was sent to...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
visasimbu
PostPosted: Tue Mar 17, 2015 11:42 am    Post subject: Reply with quote

Disciple

Joined: 06 Nov 2009
Posts: 171

fjb_saper wrote:
Not from the information you supplied. But the way you are building the JSON message is a good candidate. Find out what the difference is between a message built with SOAPUI (which apparently works) and one built by your Java application(not working). And remember to also check the URL the message was sent to...


Thanks fjb_saper for reply !

I have tried below more options.
1) Removed the below code setting content type in java client.
Code:
contentType: "application/json; charset=UTF-8",

Then WMB flow getting request from the client with proper post payload JSON messages.
If i un comment the content type line in client java code. Then WMB will not accept any request. I tried enabling traces. Looks WMB itself not reaching with any request from client. Is there anything HTTPInput node is doing with content type filtering ?
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Tue Mar 17, 2015 12:28 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

you need to setup an additional port and inspect the message "on the wire" before it hits the HTTP node. You can then see the differences between the java app message and the SOAP UI message. This should give you a clue on what you are potentially doing wrong in the java app... Could be a simple as spelling Json vs json and capitalization... but then what do I know about Json?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
stoney
PostPosted: Tue Mar 17, 2015 1:42 pm    Post subject: Reply with quote

Centurion

Joined: 03 Apr 2013
Posts: 140

visasimbu wrote:

1) Removed the below code setting content type in java client.
Code:
contentType: "application/json; charset=UTF-8",



Is this definitely Java code? It looks more like JavaScript code - if I'm right, is it JavaScript code that runs within a web browser?
Back to top
View user's profile Send private message
visasimbu
PostPosted: Tue Mar 17, 2015 2:29 pm    Post subject: Reply with quote

Disciple

Joined: 06 Nov 2009
Posts: 171

stoney wrote:
visasimbu wrote:

1) Removed the below code setting content type in java client.
Code:
contentType: "application/json; charset=UTF-8",



Is this definitely Java code? It looks more like JavaScript code - if I'm right, is it JavaScript code that runs within a web browser?


Apologies ! I am not expert in java. Yes it is java script.

Code:

 $.ajax({
                cache: false,
                type: "POST",
                async: false,
                url: GetURl,
             
              data: parameter1,
              contentType: "application/json; charset=UTF-8",
              dataType: "json",
              processData: true,
                success: function (emp) {
                   alert("Employee Function");
                   var div = document.createElement("div");
                    var span = document.createElement("span");
                     span.appendChild(document.createTextNode(emp.id));
                     span.appendChild(document.createTextNode(" - "));
                     span.appendChild(document.createTextNode(emp.name));
                     span.appendChild(document.createTextNode(" - "));
                     span.appendChild(document.createTextNode(emp.score));
                     span.appendChild(document.createTextNode(" - "));
                     span.appendChild(document.createTextNode(emp.state));
                     div.appendChild(span);
                     $("#divStudentDetails").html("").append(div);
                },
                error: function (errrroorr) {
                    alert('ErrorOccurred in post method');
                   $("#divStudentDetails").html("").append(errrroorr.responseText);
                    alert(errrroorr.responseText);
                }
            });
Back to top
View user's profile Send private message Send e-mail
stoney
PostPosted: Wed Mar 18, 2015 1:11 am    Post subject: Reply with quote

Centurion

Joined: 03 Apr 2013
Posts: 140

OK, so I can explain what is happening here.
Because you are making a request from JavaScript code running in a web browser directly to your broker, you have to make a cross-origin request.
You are hitting cross-origin resource sharing (CORS) problems.

When you make a POST request with the Content-Type set to "application/x-www-form-urlencoded; charset=UTF-8", a simple cross-origin request is made.
A simple cross-origin request sends the POST request directly to your broker, which is why you see the HTTPInput node in your message flow being invoked.
But - even though your message flow is invoked, your JavaScript code will never receive a response - your broker will not return the correct CORS headers in the response.
Because of this, the web browser will treat it as if the request was not permitted, and it will drop the response before passing the response to your JavaScript code.
You should see an error relating to CORS in the developer tools for your web browser when you make this request.

When you change the Content-Type to "application/json; charset=utf-8", this causes a preflight cross-origin request to be made instead (see "simple headers" in the CORS specification).
A preflight cross-origin request is first sent as a OPTIONS request to your broker.
OPTIONS requests aren't passed to HTTPInput nodes, so the broker just returns an HTTP 200 OK response, but it will not return the correct CORS headers in the response.
Again, because the response doesn't contain the correct CORS headers, your browser treats it as if the request was not permitted.
It will never send the actual POST request to the broker, and your HTTPInput node will never be invoked.

Unfortunately there is no built-in support for CORS in WMBv7.
What you could investigate is using the HTTP proxy servlet within an external web servlet container (such as WAS or Tomcat).
You can then host the JavaScript code and other web pages along side the HTTP proxy servlet in the web servlet container, in which case cross-origin requests aren't required.
Alternatively, if you don't want to move your JavaScript code and other web pages into the web servlet container, then you can enable CORS support on the web servlet container instead.
Your JavaScript code would then make the call to the web servlet container instead of broker, and the HTTP proxy servlet would pass the requests onto your HTTPInput nodes.
Here's a link to the WMBv7 documentation on the HTTP proxy servlet:
http://www-01.ibm.com/support/knowledgecenter/SSKM8N_7.0.0/com.ibm.etools.mft.doc/ac69300_.htm

FYI - the recently announced IIBv10 will include built-in support for CORS, but I appreciate that probably doesn't help you in this case.
Back to top
View user's profile Send private message
visasimbu
PostPosted: Wed Mar 18, 2015 2:14 pm    Post subject: Reply with quote

Disciple

Joined: 06 Nov 2009
Posts: 171

Stoney Thanks for your reply.

I have configured the servlet with the guidelines. But still i am not getting response in the web browser. I can find below error in the developer tool.

Code:
XMLHttpRequest cannot load http://XX.XX.XXX.XX:8181/proxyservlet/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.


I can find below trace in httpproxy-trace.txt (This is the trace from servlet end)

Quote:

20150318220751.475 20 WBIMBServlet processPost Found header accept: application/json, text/javascript, */*; q=0.01
20150318220751.475 20 WBIMBServlet processPost Found header origin: null
20150318220751.475 20 WBIMBServlet processPost Found header connection: Keep-Alive


Where can i mention about the orgin in the servlet. Looks WMB and web browser could not identify the origin.
Back to top
View user's profile Send private message Send e-mail
visasimbu
PostPosted: Thu Mar 19, 2015 1:35 pm    Post subject: Reply with quote

Disciple

Joined: 06 Nov 2009
Posts: 171

Hi Stoney,

After implementing the filter and filter mapping in my servlet. WMB can able to receive the message in the HTTP input node. But it is directly routing to the failure terminal of the input node saying
Code:
No protocol separator found

The reason is because the servlet is sending only URI like below.

Code:
X-Original-HTTP-Command:CHARACTER:POST /proxyservlet/ HTTP/1.1


how can we set the proper domain url in servlet. So that HTTP input node can accept the message.
Back to top
View user's profile Send private message Send e-mail
visasimbu
PostPosted: Thu Mar 19, 2015 10:30 pm    Post subject: Reply with quote

Disciple

Joined: 06 Nov 2009
Posts: 171

Now i can able to receive message. But http input header parser error occurs.

Code:
Text:CHARACTER:An error was found whilst parsing HTTP header data. The data is not a HTTP request or response. Invalid HTTP Header data.
         Insert
               Type:INTEGER:2
               Text:CHARACTER:0
         Insert
               Type:INTEGER:14
               Text:CHARACTER:null http://null:-1null null
X-Server-Name: abcde


Here abcde is the first 5 characters of my computer name. Any clue ?
Back to top
View user's profile Send private message Send e-mail
stoney
PostPosted: Mon Mar 23, 2015 5:47 am    Post subject: Reply with quote

Centurion

Joined: 03 Apr 2013
Posts: 140

Sorry for the delay in responding - I've been off on vacation the last couple of days.

It looks like you may be hitting a known problem in the proxy servlet:
http://www-01.ibm.com/support/docview.wss?uid=swg1IC96565

Unfortunately it doesn't look like this APAR has made it into a V7 fixpack at all.
Can you open a PMR for this problem and refer to this thread in the PMR?
Back to top
View user's profile Send private message
visasimbu
PostPosted: Mon Mar 23, 2015 7:45 pm    Post subject: Reply with quote

Disciple

Joined: 06 Nov 2009
Posts: 171

stoney wrote:
Sorry for the delay in responding - I've been off on vacation the last couple of days.

It looks like you may be hitting a known problem in the proxy servlet:
http://www-01.ibm.com/support/docview.wss?uid=swg1IC96565

Unfortunately it doesn't look like this APAR has made it into a V7 fixpack at all.
Can you open a PMR for this problem and refer to this thread in the PMR?


Hi Stoney,
Thanks for your guidance. Yes I too got this link when I tried to find the answer for the failure in web.

I have conclude that WMB 7.0.0.3 will not accept CORS request.
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Tue Mar 24, 2015 4:33 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

visasimbu wrote:
I have conclude that WMB 7.0.0.3 will not accept CORS request.


Or you could open a PMR and get the APAR.

Except you probably can't open a PMR for WMB v7...
Back to top
View user's profile Send private message
visasimbu
PostPosted: Mon Mar 30, 2015 12:36 pm    Post subject: Reply with quote

Disciple

Joined: 06 Nov 2009
Posts: 171

IBM released IIB V10.0 with CORS implementation.


http://www-01.ibm.com/support/knowledgecenter/api/content/nl/en-us/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ap04190_.htm
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » content type application/json charset=utf-8 -HTTP Input node
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.