listQS.add(new NameValuePair(translateEncoding(param.getName(), http.charset),translateEncoding(param.getValueAsString(), http.charset)));
}
// Form
else if(type.equals("formfield") || type.equals("form")) {
hasForm=true;
if(http.method==METHOD_GET) throw new ApplicationException("httpparam type formfield can't only be used, when method of the tag http equal post");
if(post!=null){
if(doMultiPart){
parts.add(new RailoStringPart(param.getName(),param.getValueAsString(),_charset));
}
else post.addParameter(new NameValuePair(param.getName(),param.getValueAsString()));
}
//else if(multi!=null)multi.addParameter(param.getName(),param.getValueAsString());
}
// CGI
else if(type.equals("cgi")) {
if(param.getEncoded())
httpMethod.addRequestHeader(
translateEncoding(param.getName(),http.charset),
translateEncoding(param.getValueAsString(),http.charset));
else
httpMethod.addRequestHeader(param.getName(),param.getValueAsString());
}
// Header
else if(type.startsWith("head")) {
if(param.getName().equalsIgnoreCase("content-type")) hasContentType=true;
if(param.getName().equalsIgnoreCase("Accept-Encoding")) {
acceptEncoding.append(headerValue(param.getValueAsString()));
acceptEncoding.append(", ");
}
else httpMethod.addRequestHeader(param.getName(),headerValue(param.getValueAsString()));
}
// Cookie
else if(type.equals("cookie")) {
Cookie c=toCookie(_url.getHost(),param.getName(),param.getValueAsString(),_charset);
c.setPath("/");
client.getState().addCookie(c);
}
// File
else if(type.equals("file")) {
hasForm=true;
if(http.method==METHOD_GET) throw new ApplicationException("httpparam type file can't only be used, when method of the tag http equal post");
if(doMultiPart) {
try {
parts.add(new ResourcePart(param.getName(),new ResourcePartSource(param.getFile()),getContentType(param),_charset));
}
catch (FileNotFoundException e) {
throw new ApplicationException("can't upload file, path is invalid",e.getMessage());
}
}
}
// XML
else if(type.equals("xml")) {
hasBody=true;
hasContentType=true;
httpMethod.addRequestHeader("Content-type", "text/xml; charset="+http.charset);
//post.setRequestBody(new NameValuePair [] {new NameValuePair(translateEncoding(param.getName(), charset),translateEncoding(param.getValue(), charset))});
if(eem==null)throw new ApplicationException("type xml is only supported for type post and put");
eem.setRequestBody(param.getValueAsString());
}
// Body
else if(type.equals("body")) {
hasBody=true;
if(eem==null)throw new ApplicationException("type body is only supported for type post and put");
Object value = param.getValue();
if(value instanceof InputStream) {
eem.setRequestEntity(new InputStreamRequestEntity((InputStream)value,"application/octet-stream"));
}
else if(Decision.isCastableToBinary(value,false)){
eem.setRequestEntity(new ByteArrayRequestEntity(Caster.toBinary(value)));
}
else {
eem.setRequestEntity(new StringRequestEntity(param.getValueAsString()));
}
}
else {
throw new ApplicationException("invalid type ["+type+"]");
}
}
httpMethod.setRequestHeader("Accept-Encoding",acceptEncoding.append("gzip").toString());
// multipart
if(doMultiPart && eem!=null) {
hasContentType=true;
boolean doIt=true;
if(!http.multiPart && parts.size()==1){
Part part = parts.get(0);
/* jira 1513
if(part instanceof ResourcePart){
ResourcePart rp = (ResourcePart) part;
eem.setRequestEntity(new ResourceRequestEntity(rp.getResource(),rp.getContentType()));
doIt=false;
}
else */
if(part instanceof RailoStringPart){
RailoStringPart sp = (RailoStringPart) part;
try {
eem.setRequestEntity(new StringRequestEntity(sp.getValue(),sp.getContentType(),sp.getCharSet()));
} catch (IOException e) {
throw Caster.toPageException(e);
}
doIt=false;
}
}
if(doIt)
eem.setRequestEntity(new MultipartRequestEntityFlex(parts.toArray(new Part[parts.size()]), eem.getParams(),http.multiPartType));
}
if(hasBody && hasForm)
throw new ApplicationException("mixing httpparam type file/formfield and body/XML is not allowed");
if(!hasContentType) {
if(isBinary) {
if(hasBody) httpMethod.addRequestHeader("Content-type", "application/octet-stream");
else httpMethod.addRequestHeader("Content-type", "application/x-www-form-urlencoded; charset="+http.charset);