Package railo.runtime.exp

Examples of railo.runtime.exp.ApplicationException


  public static long getTotalBytes() throws ApplicationException {
    return physical().getTotalBytes();
  }
 
  public static double getCpuUsage(long time) throws ApplicationException {
    if(time<1) throw new ApplicationException("time has to be bigger than 0");
    if(jsm==null) jsm=new JavaSysMon();
    CpuTimes cput = jsm.cpuTimes();
    if(cput==null) throw new ApplicationException("CPU information are not available for this OS");
    CpuTimes previous = new CpuTimes(cput.getUserMillis(),cput.getSystemMillis(),cput.getIdleMillis());
        sleep(time);
       
        return jsm.cpuTimes().getCpuUsage(previous)*100D;
    }
View Full Code Here


 

  private synchronized static MemoryStats physical() throws ApplicationException {
    if(jsm==null) jsm=new JavaSysMon();
    MemoryStats p = jsm.physical();
    if(p==null) throw new ApplicationException("Memory information are not available for this OS");
    return p;
  }
View Full Code Here

  public static HttpEntityEnclosingRequestBase getHTTPPatch(String url) throws PageException  {
    // try to load the class, perhaps class does not exists with older jars
    Class clazz = ClassUtil.loadClass(
        HttpEntityEnclosingRequestBase.class.getClassLoader(),
        "org.apache.http.client.methods.HttpPatch",null);
    if(clazz==null) throw new ApplicationException("cannot load class [org.apache.http.client.methods.HttpPatch], you have to update your apache-commons-http*** jars");
    try {
      return (HttpEntityEnclosingRequestBase) ClassUtil.loadInstance(clazz,new Object[]{url});
    }
    catch (Throwable t) {
      throw Caster.toPageException(t);
View Full Code Here

    try{
      pc.getHttpServletRequest().setAttribute("railo.forward.request_uri", realPath);
     
          RequestDispatcher disp = context.getRequestDispatcher(realPath);
          if(disp==null)
          throw new PageServletException(new ApplicationException("Page "+realPath+" not found"));
           
          //populateRequestAttributes();
          disp.forward(removeWrap(pc.getHttpServletRequest()),pc.getHttpServletResponse());
    }
        finally{
View Full Code Here

        }
  }

  private static RequestDispatcher getRequestDispatcher(PageContext pc,String realPath) throws PageServletException {
    RequestDispatcher disp = pc.getServletContext().getRequestDispatcher(realPath);
      if(disp==null) throw new PageServletException(new ApplicationException("Page "+realPath+" not found"));
      return disp;
  }
View Full Code Here

      else if(method.equals("head")) this.method=METHOD_HEAD;
      else if(method.equals("delete")) this.method=METHOD_DELETE;
      else if(method.equals("put")) this.method=METHOD_PUT;
      else if(method.equals("trace")) this.method=METHOD_TRACE;
      else if(method.equals("options")) this.method=METHOD_OPTIONS;
      else throw new ApplicationException("invalid method type ["+(method.toUpperCase())+"], valid types are POST,GET,HEAD,DELETE,PUT,TRACE,OPTIONS");
  }
View Full Code Here

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

      multiPartType=multiPartType.trim().toLowerCase();
     
      if("form-data".equals(multiPartType))   this.multiPartType=MultipartRequestEntityFlex.MULTIPART_FORM_DATA;
      //else if("related".equals(multiPartType))     this.multiPartType=MultipartRequestEntityFlex.MULTIPART_RELATED;
      else
      throw new ApplicationException("invalid value for attribute multiPartType ["+multiPartType+"]",
          "attribute must have one of the folloing values [form-data]");
     
    }
View Full Code Here

    Tag parent=getParent();
    while(parent!=null && !(parent instanceof Mail)) {
      parent=parent.getParent();
    }
    if(parent instanceof Mail)return (Mail) parent;
    throw new ApplicationException("Wrong Context, tag MailPart must be inside a Mail tag")
  }
View Full Code Here

      if( "plaintext".equals(lcDataformatas) ||
        "html".equals(lcDataformatas)) {
        attributes.setEL("dataformatas",dataformatas);
      }
      else
        throw new ApplicationException("attribute dataformatas for tag input has an invalid value ["+dataformatas+"], valid values are [plaintext, html");
    }
View Full Code Here

TOP

Related Classes of railo.runtime.exp.ApplicationException

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.