How to replicate a composite POST in SOAP-UI - rest

I'm trying to test an endpoint that will accept a certain request. It takes 5 minutes to go through the process of firing off the request, so I'd like to replicate it in SOAP-UI. I'm not sure how to get the request to look like the following.
Host: somedomain.net
User-Agent: Jakarta; Commons-HttpClient/3.0.1
--7ZRj4zj5nzTkWtBlwkO5Y4Il-En_uTGP2enCIMn
Content-Disposition: form-data; name="companyId"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
985
--7ZRj4zj5nzTkWtBlwkO5Y4Il-En_uTGP2enCIMn
Content-Disposition: form-data; name="inputFormData"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><response>Response XML Data</response>
--7ZRj4zj5nzTkWtBlwkO5Y4Il-En_uTGP2enCIMn
Content-Disposition: form-data; name="completedAgreement"; filename="48ce7fa4079790440a964815a744d232.zip"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary
PK
Any help would be appreciated.

I could not recreate in SOAP-UI but I was able to create a simple html form to get the job done.
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="/api/receiver" method="post" enctype="multipart/form-data">
<p>
Company Id:<br />
<input type="text" value="725" name="companyId" />
</p>
<p>
Input Form Data:<br />
<textarea name="inputFormData" rows="10" cols="50">
</textarea>
</p>
<p>
Completed Agreement:<br />
<input type="file" name="completedAgreement" />
</p>
<p>
<input type="submit" value="submit" />
</p>
</form>
</body>
</html>
The most important part was setting the enctype in the form tag to enctype="multipart/form-data"

Related

JavaScript try/catch doesn't work when <meta charset="utf-8" /> is defined

I have a very simple JavaScript function that uses try/catch, though when the meta tag <meta charset="utf-8" /> is defined on the page, it doesn't work:
<!doctype html>
<meta charset="utf-8" />
<script type="text/javascript">
function demo(){
try{
undefinedfunction()
alert("I guess you do exist")
} catch(e){
alert("An error has occured: "+e.message)
}
}
</script>
<form method="post">
<b>Demo:</b> <input type="button" value="Click Me" onClick="demo()" />
</form>
In the above case instead of catching the undefinedfunction(), the console logs "Syntax Error: illegal character". If I remove the meta tag, the function behaves as expected, alerting a message.
Does anyone know why this is the case?
Ah nevermind, it seems the problem was with the spaces inside the function, instead of tabs. I guess "utf-8" is picky about those kinds of things.

JSP: Encoding of input parameter in form: Difference between IE and Firefox

i have a JSP with
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
in the head section, with following code i try to set the content to UTF-8:
<%#page contentType="text/html;charset=utf-8" %>
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
Within a form is an input field:
<input type="text" value="LastName*" class="input required" name="lastName" id="lastName" />
I have now problems with german special characters.
When i use request.getParameter("lastName"), this works fine in FireFox, but not in IE.
String encodedLastName = new String(request.getParameter("lastName").getBytes("iso-8859-1"), "UTF-8");
works on IE, but not in Firefox.
I tried to change everything to iso-8859-1, added accept-charset="UTF-8" to the form, ...
Now it is more guessing than working.
Can this only configured within the server (Tomcat) but why there is a difference between the behaviour of the browsers?
Thank, Markus
There were two problems which interfere with each other:
1) When using a normal post, i have to encode correct via
<%#page contentType="text/html;charset=utf-8" %>
and decode correct via
String encodedLastName = new String(request.getParameter("lastName").getBytes("iso-8859-1"), "UTF-8");
2) When using jquery, adding
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
in the $.ajax call.

Why <h:outputScript> does not work inside <h:form>

I am using JSF 2.1. I'm trying to use TinyEditor on a <h:inputTextarea>. Here is my code,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h:outputStylesheet library="css" name="editor_style.css" />
<h:outputStylesheet library="css" name="css/main.css" />
<h:outputStylesheet library="css" name="css/dropdown.css" />
<h:outputScript name="js/tinyeditor.js"></h:outputScript>
</h:head>
<h:body>
<div class="content">
<ui:include src="/template/layout/commonLayout.xhtml" />
<ui:include src="/template/layout/menu.xhtml" />
<h:form>
<div class="quick_links">
<div class="q_title">
</div>
<div class="q_window">
<div class="q_top"></div>
<div class="q_main">
<h:inputTextarea value="#{EditorBean.value}" id="input"
style="width:100%; height:300px;">Sample FAQ</h:inputTextarea>
<h:outputScript>
new TINY.editor.edit('editor',{
id:'input',
width:945,
height:175,
cssclass:'te',
controlclass:'tecontrol',
rowclass:'teheader',
dividerclass:'tedivider',
controls:['bold','italic','underline','strikethrough','|','subscript','superscript','|',
'orderedlist','unorderedlist','|','outdent','indent','|','leftalign',
'centeralign','rightalign','blockjustify','|','unformat','|','undo','redo','n',
'font','size','style','|','hr','link','unlink'],
footer:true,
fonts:['Verdana','Arial','Georgia','Trebuchet MS'],
xhtml:true,
cssfile:'style.css',
bodyid:'editor',
footerclass:'tefooter',
toggle:{text:'Source',activetext:'HTML',cssclass:'toggle'},
resize:{cssclass:'resize'}
});
</h:outputScript>
</div>
<div class="q_bottom"></div>
</div>
<h:commandButton value="Savebutton" action="#{EditorBean.test}"></h:commandButton>
</div>
<div class="push"></div>
</h:form>
</div>
</h:body>
</html>
If I remove the <h:form> tag, then only editor gets displayed, but the <h:commandButton> doesn't work.
If I keep the <h:form> tag, then the <h:commandButton> works, but the TinyEditor editor does not get initialized.
How is this caused and how can I solve it?
The <h:outputScript> works perfectly fine. The concrete problem is just in your own JavaScript code. You specified an ID of "input" in the TinyEditor configuration script:
id:'input',
However there is no such HTML element with that ID in the JSF-generated HTML output. Yes, you should be looking at the JSF-generated HTML output, because that's basically all what the browser is retrieving. JavaScript does not run in webserver, but in the webbrowser and sees the JSF-generated HTML output only. Rightclick page in browser and do View Source to see it yourself as well.
The generated ID of the <h:inputTextarea> has in this particular construct the ID of the <h:form> prepended. In your particular case, you didn't specify any ID for the <h:form>, so JSF will autogenerate one like so j_id123 so that the HTML element ID of the <textarea> as generated by <h:inputTextarea> will become j_id123:input. You need to specify exactly that ID in the TinyEditor configuration script.
However, better is to specify a fixed ID on the <h:form>, as the autogenerated ID may change whenever you add/remove components to the view.
<h:form id="form">
<h:inputTextarea id="input" />
...
This way the generated <textarea> will get an ID of form:input. Then you can just use it in the TinyEditor configuration script:
id:'form:input',

Can JSTL transform XML encoded in UTF-8?

I am making a simple JSP application to transform XML data into HTML.
I use JSTL and my XML data is encoded in UTF-8. It works, but the danish characters look strange in the browser.
Like this:
Danish characters written directly in jsp: ÆØÅ æøå
Same danish characters transformed with jstl:
character: Æ character: æ
character: Ø character: ø
character: Å character: å
However, if I manually change the xml definition like so:
<?xml version="1.0" encoding="ISO-8859-1" ?>
The output is transformed properly.
Should I set up JSTL in some way to handle UTF-8, or is it,that my file is actually latin1 encoded by mistake? I do not know how to check this...
Here is my test xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<rows>
<row>
<name>character: Æ</name>
<surname>character: æ</surname>
</row>
<row>
<name>character: Ø</name>
<surname>character: ø</surname>
</row>
<row>
<name>character: Å</name>
<surname>character: å</surname>
</row>
</rows>
Here is my xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="0">
<xsl:for-each select="rows/row">
<tr>
<td>
<xsl:value-of select="name" />
</td>
<td>
<xsl:value-of select="surname" />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
My index.jsp:
<?xml version="1.0" encoding="UTF-8" ?>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
Written directly in jsp: ÆØÅ æøå
<h3>xml transformed with jstl:</h3>
<c:import url="/Test.xsl" var="xsltdoc" />
<c:import url="/Test.xml" var="xmldoc" />
<x:transform xml="${xmldoc}" xslt="${xsltdoc}" />
</body>
</html>
I am using JSTL libraries (Implementation-Version: 1.2) on JBOSS AP 4.2.3.
Ok, I checked the encoding of my xml data here, and it is correct, that it is UTF-8 encoded.
Apparently, in index.jsp JSTL must be set to use UTF-8 like so
<c:import url="/Metadata1.xsl" var="xsltdoc" charEncoding="UTF-8" />
<c:import url="/Metadata1.xml" var="xmldoc" charEncoding="UTF-8" />
This solves my problem.

Uploading a file with cfhttp appends a newline (even on binary files)

Update: I've found a workaround. If I submit a dummy form field along with the file, it works. Is this a ColdFusion bug, or is there something in the HTTP spec that says forms must contain at least one non-file form field?
Update 2: I'm convinced this is a ColdFusion cfhttp bug. This is based on Leigh's answer and the fact that I used the code below to submit a form with only the file element using javascript, and it works fine:
<form enctype="multipart/form-data" action="<cfoutput>#CGI.PATH_INFO#</cfoutput>" method="POST" name="theForm">
<input name="theFile" type="file" /><br/>
</form>
submit
I'm running into a problem uploading files from a ColdFusion server to another webserver. It seems that cfhttpparam type="file" is indiscriminately appending a newline (carriage return and line feed) to the end of the file. This is breaking binary files. This does not happen when I manually upload the file via form field. I have tried with and without mimetype parameter, and I've tried lying about mimetype with various binary formats (exe, zip, jpg), but nothing has worked. Is there some parameter I'm missing, or is this a bug in ColdFusion? (I'm running on CF 8.0.1.195765 on WinXP.)
Below is test code I'm using, it just uploads the file to the same directory. The manual upload works, but the server-based upload ends up appending a CRLF to the file.
<cfset MyDir = "C:\test" />
<cfset MyFile = "test.zip" />
<cfif IsDefined("Form.TheFile")>
<cffile action="upload" fileField="theFile" destination="#MyDir#" nameConflict="MakeUnique" />
<cfelse>
<cfhttp url="http://#CGI.SERVER_NAME##CGI.SCRIPT_NAME#" method="POST" throwOnError="Yes">
<cfhttpparam type="file" name="theFile" file="#MyDir#\#MyFile#" />
</cfhttp>
</cfif>
<html><body>
<h2>Manual upload</h2>
<form enctype="multipart/form-data" action="<cfoutput>#CGI.PATH_INFO#</cfoutput>" method="POST">
<input name="theFile" type="file" /><br/>
<input type="submit" value="Submit" />
</form>
</body></html>
or is there something in the HTTP spec
that says forms must contain at least
one non-file form field?
I do not know for certain. But according to these definitions it seems like a POST containing only a file input should be valid. So I suspect the problem may be CFHTTP in ACF.
According to Fiddler the raw content from the cfhttp call in ACF contains an extra new line just before the end boundary (0D 0A in hex view). But under Railo it does not. So I think ACF's cfhttp might be the culprit.
Sample Code:
<cfhttp url="http://127.0.0.1:8888/cfusion/receive.cfm" method="post">
<cfhttpparam name="myFile" type="file" file="c:/test/testFile.zip" mimetype="application/octet-stream" />
</cfhttp>
Results Railo 3.1.2
POST /railo/receive.cfm HTTP/1.1
User-Agent: Railo (CFML Engine)
Host: 127.0.0.1:8888
Content-Length: 382
Content-Type: multipart/form-data; boundary=m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn
--m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn
Content-Disposition: form-data; name="myFile"; filename="testFile.zip"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary
PK
&�1=�cN'testFile.txtTestingPK
&�1=�cN' testFile.txtPK:1
--m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn--
Results ACF (versions 8 and 9)
POST /cfusion/receive.cfm HTTP/1.1
Host: 127.0.0.1:8888
... other headers removed for brevity ....
Content-type: multipart/form-data; boundary=-----------------------------7d0d117230764
Content-length: 350
-------------------------------7d0d117230764
Content-Disposition: form-data; name="JobFile"; filename="c:\test\testFile.zip"
Content-Type: application/octet-stream
PK
&�1=�cN'testFile.txtTestingPK
&�1=�cN' testFile.txtPK:1
-------------------------------7d0d117230764--
Maybe Railo 3.1.2 and ColdFusion 9 handle this a bit differently, but your code looks a bit incorrect for me.
Your CGI.PATH_INFO is not applicable here.
While browser is smart enough to use path without hostname, CFHTTP feels better with full hostname + script path + script name. Note: cgi.SCRIPT_NAME worked in CF9, Railo required cgi.SERVER_NAME to be prepended, though I feel this more correct in general.
That's why a bit modified version of the code works fine for me. Zip file is uploaded and posted without being corrupted.
Form:
<form enctype="multipart/form-data" action="<cfoutput>#cgi.SCRIPT_NAME#</cfoutput>" method="POST">
<input name="theFile" type="file" /><br/>
<input type="submit" value="Submit" />
</form>
CFHTTP:
<cfhttp url="#cgi.SERVER_NAME##cgi.SCRIPT_NAME#" method="POST" throwOnError="Yes">
<cfhttpparam type="file" name="theFile" file="#MyDir#/#MyFile#" />
</cfhttp>
Hope this helps.
I get the extra line feed and carriage return on file appends too. The problem for me is/was the combination of cfhttp and the cfloop. Once I broke the file creation into 3 parts: Create, cfloop endrow-1, then appending last record.
Seems like a kludgy way to do it, but no extra line feed.