web stats
HTTP Sender "application/x-www-form-urlencoded" - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #11  
Old 03-08-2017, 08:21 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

Not sure if this will help But you can create a javascript method in mirth that works like your C# method using java.net.url. There would be an example somewhere on the forums.
Reply With Quote
  #12  
Old 03-10-2017, 01:40 PM
ISpdxdc ISpdxdc is offline
OBX.1 Kenobi
 
Join Date: Mar 2011
Location: Dallas, Tx
Posts: 48
ISpdxdc is on a distinguished road
Default

I figured out what I was doing wrong. Instead of building the string and trying to send the whole thing, I individually setup the "parameter" strings in the parameter piece of the http sender. That fixed the encoding. Now I am receiving a cookie and a redirect and trying to send that back to a browser.... more fun!
Reply With Quote
  #13  
Old 03-10-2017, 02:10 PM
ISpdxdc ISpdxdc is offline
OBX.1 Kenobi
 
Join Date: Mar 2011
Location: Dallas, Tx
Posts: 48
ISpdxdc is on a distinguished road
Default

So my next question is how to send the back the the entire response with the cookies and headers and such to my http listener which is the source? It seems the http sender is intercepting that and then accepting the cookies and only returning a redirect url as a small snippet of HTML. My listener only receives the html portion so the browser I'm trying to send it back to does not receive the cookie to save locally nor redirect to the URL. Basically this is like a proxy. Local webpage hits a mirth http listener, sends to https with encrypted cert as token, receives back a cookie and a redirect. I don't know how to pass that back to the listener and then to the web browser. Any ideas?
Reply With Quote
  #14  
Old 03-13-2017, 03:05 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

Well that's what we've been telling you in earlier posts that you need to set params.

Now, in order to get cookies from the response you can do that in response transformer by using .getHeaderFields().get("Set-Cookie")

http://stackoverflow.com/questions/5...kies-with-java
Reply With Quote
  #15  
Old 03-13-2017, 07:39 AM
ISpdxdc ISpdxdc is offline
OBX.1 Kenobi
 
Join Date: Mar 2011
Location: Dallas, Tx
Posts: 48
ISpdxdc is on a distinguished road
Default

Sorry, I clearly wasn't understanding I needed to break my string up into individual parameters to put into the UI, instead of putting my built string into A parameter. Nonetheless I am getting there. Thanks for the pointers thus far. As for the cookies, did you mean use that in a postprocessor script, or actually the transformer? That example looks like they are writing the connection in Java. Do I have access to the connection and headers from a standard http sender, or were you suggesting I use the java.net.url from your previous post?

Last edited by ISpdxdc; 03-13-2017 at 08:02 AM.
Reply With Quote
  #16  
Old 03-13-2017, 08:48 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

On the standard HTTP Sender Destination, open a response transformer and Use below to capture your cookie.

Code:
chocolateCookies=$('responseHeaders').get('Set-Cookie')
Reply With Quote
  #17  
Old 03-13-2017, 09:01 AM
ISpdxdc ISpdxdc is offline
OBX.1 Kenobi
 
Join Date: Mar 2011
Location: Dallas, Tx
Posts: 48
ISpdxdc is on a distinguished road
Default

Awesome, that worked. One thing to mention though, I am getting this warning: "[2017-03-13 09:57:50,135] ERROR (com.mirth.connect.userutil.MessageHeaders:39): The get(key) method for retrieving Http headers is deprecated and will soon be removed. Please use getHeader(key) or getHeaderList(key) instead."

Is that a Mirth thing, or a Java thing?

update: nevermind, I just changed it to getHeader and it stopped complaining

Last edited by ISpdxdc; 03-13-2017 at 09:15 AM.
Reply With Quote
  #18  
Old 03-13-2017, 12:14 PM
ISpdxdc ISpdxdc is offline
OBX.1 Kenobi
 
Join Date: Mar 2011
Location: Dallas, Tx
Posts: 48
ISpdxdc is on a distinguished road
Default

So I'm not understanding where to go from here. Why isn't the response going back with the cookie from the http sender and firing a redirect? The html body of the 302 is going back to the browser but. I am pulling the cookie but not sure what next step is. Do I have to write a custom HTTP response to send back to the listener? Whats the magic incantation?

local browser > http listener > channel writer > channel reader > http sender > send response with cookies back to browser (through http listener)

Last edited by ISpdxdc; 03-13-2017 at 12:26 PM.
Reply With Quote
  #19  
Old 03-13-2017, 03:28 PM
ISpdxdc ISpdxdc is offline
OBX.1 Kenobi
 
Join Date: Mar 2011
Location: Dallas, Tx
Posts: 48
ISpdxdc is on a distinguished road
Default

So I have no clue if I'm doing this correct, but I wrote another http sender, and I am taking the response of the first sender 302, parsing the cookie and the redirect URL and I am sending a GET using the cookie string to the redirect URL, and hoping to send that back to the original HTTP listener. The new Get is getting another 401, so I don't know if I'm supposed to do that.

***UPDATE*** I changed the response to xml body and parse multipart to Yes with metadata. I am seeing that my 302 is actually replying with sometimes multiple cookies. In this scenario where only 1 cookie comes back and I send a GET back to the URL with the header "Cookie" using the cookie they sent, I am actually getting a 200 response. In the situations where they send back multiple Set-Cookies and I send only 1 back I get a 401. The questions is how do I pull >1 cookie from the responseheaders using the response transformer? I tried a javascript step with something like $('responseHeaders').getHeader('Set-Cookie').toArray(), but that didn't work. Here is the transformed response:


<HttpResponse>
<Status>HTTP/1.1 302 Found</Status>
<Header>
<Field>
<Name>Cache-Control</Name>
<Value>private, s-maxage=0</Value>
</Field>
<Field>
<Name>Server</Name>
<Value>Microsoft-IIS/10.0</Value>
</Field>
<Field>
<Name>X-AspNet-Version</Name>
<Value>4.0.30319</Value>
</Field>
<Field>
<Name>Set-Cookie</Name>
<Value>Auth=EAAAAOnEt8xVSNLOHDHPfC5vefYZgC/==; path=/; secure</Value>
</Field>
<Field>
<Name>Set-Cookie</Name>
<Value>Auth=EAAAABSTz3Wt9ql6hfQ/e6VtK1M5a73LV+==; path=/; secure</Value>
</Field>
<Field>
<Name>Content-Length</Name>
<Value>176</Value>
</Field>
<Field>
<Name>Date</Name>
<Value>Tue, 14 Mar 2017 04:22:29 GMT</Value>
</Field>
<Field>
<Name>Content-Type</Name>
<Value>text/html; charset=utf-8</Value>
</Field>
<Field>
<Name>Location</Name>
<Value>/test/Edit/7fc1380e-fe47-49c4-beca-a735016fda79</Value>
</Field>
<Field>
<Name>X-AspNetMvc-Version</Name>
<Value>4.0</Value>
</Field>
<Field>
<Name>X-Powered-By</Name>
<Value>ASP.NET</Value>
</Field>
</Header>
<Body multipart="no">&lt;html&gt;&lt;head&gt;&lt;title&g t;Object moved&lt;/title&gt;&lt;/head&gt;&lt;body&gt;
&lt;h2&gt;Object moved to &lt;a href="/test/Edit/7fc1380e-fe47-49c4-beca-a735016fda79"&gt;here&lt;/a&gt;.&lt;/h2&gt;
&lt;/body&gt;&lt;/html&gt;
</Body>
</HttpResponse>

Last edited by ISpdxdc; 03-13-2017 at 08:25 PM.
Reply With Quote
  #20  
Old 03-13-2017, 10:07 PM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

Quote:
The questions is how do I pull >1 cookie from the responseheaders using the response transformer?
var chocolateCookies = []; //array
or
var chocolateCookies=new java.util.ArrayList();


Maybe?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:00 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation