Package railo.commons.net.http.httpclient3

Examples of railo.commons.net.http.httpclient3.RailoStringPart


      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;
        }
View Full Code Here


      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());
          }
        }
View Full Code Here

      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());
          }
        }
View Full Code Here

  public static Header header(String name, String value) {
    return new HeaderImpl(name, value);
  }

  public static Entity getEmptyEntity(String contentType) {
    return new EmptyRequestEntity(contentType);
  }
View Full Code Here

  public static Entity getTemporaryStreamEntity(TemporaryStream ts, String contentType) {
    return new TemporaryStreamRequestEntity(ts,contentType);
  }
 
  public static Entity getResourceEntity(Resource res, String contentType) {
    return new ResourceRequestEntity(res,contentType);
  }
View Full Code Here

  public static Entity getByteArrayEntity(byte[] barr, String contentType) {
    return new _ByteArrayRequestEntity(barr, contentType);
  }
 
  public static Entity getTemporaryStreamEntity(TemporaryStream ts, String contentType) {
    return new TemporaryStreamRequestEntity(ts,contentType);
  }
View Full Code Here

  public static Entity getEmptyEntity(String contentType) {
    return new EmptyRequestEntity(contentType);
  }
   
  public static Entity getByteArrayEntity(byte[] barr, String contentType) {
    return new _ByteArrayRequestEntity(barr, contentType);
  }
View Full Code Here

TOP

Related Classes of railo.commons.net.http.httpclient3.RailoStringPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.