Package de.iritgo.aktera.clients

Examples of de.iritgo.aktera.clients.ClientException


          }
          catch (IOException e)
          {
            e.printStackTrace();
            log.error("Exception during file read/write:", e);
            throw new ClientException("Exception during file read/write", e);
          }
          finally
          {
            // Flush all streams, and close input streams
            try
            {
              data.close();
            }
            catch (IOException e1)
            {
              e1.printStackTrace();
            }

            try
            {
              buffOut.flush();
            }
            catch (IOException e2)
            {
              e2.printStackTrace();
            }

            // Do NOT close the Output stream here, as the
            // underlying output stream is/should be closed later.
          }
        }
        else
        {
          outputs.add(reAsBean);
        }
      }
      else if (re instanceof Command)
      {
        commands.add(reAsBean);
      }
    }

    wreq.setAttribute("inputs", inputs);
    wreq.setAttribute("outputs", outputs);
    wreq.setAttribute("commands", commands);

    int inputCount = 0;
    DynaProperty[] dps = new DynaProperty[inputs.size()];
    ResponseElementDynaBean oneInput = null;

    for (Iterator ii = inputs.iterator(); ii.hasNext();)
    {
      oneInput = (ResponseElementDynaBean) ii.next();

      Object defValue = oneInput.get("defaultValue");
      DynaProperty dp = null;

      if (defValue != null)
      {
        dp = new DynaProperty((String) oneInput.get("name"), oneInput.get("defaultValue").getClass());
      }
      else
      {
        try
        {
          dp = new DynaProperty((String) oneInput.get("name"), Class.forName("java.lang.String"));
        }
        catch (ClassNotFoundException e)
        {
          throw new ClientException("Cannot create String dynaproperty", e);
        }
      }

      dps[inputCount++] = dp;
    }

    BasicDynaClass bd;

    try
    {
      bd = new BasicDynaClass(modelName, Class.forName("org.apache.commons.beanutils.BasicDynaBean"), dps);

      BasicDynaBean newForm = (BasicDynaBean) bd.newInstance();

      // Now populate the newForm's properties
      for (Iterator i2 = inputs.iterator(); i2.hasNext();)
      {
        oneInput = (ResponseElementDynaBean) i2.next();
        newForm.set((String) oneInput.get("name"), oneInput.get("defaultValue"));
      }

      wreq.setAttribute("default", newForm);
    }
    catch (ClassNotFoundException e)
    {
      throw new ClientException(e);
    }
    catch (IllegalAccessException e)
    {
      throw new ClientException(e);
    }
    catch (InstantiationException e)
    {
      throw new ClientException(e);
    }
  }
View Full Code Here


          DynaActionForm df = (DynaActionForm) form;
          DynaClass dc = df.getDynaClass();

          if (dc == null)
          {
            throw new ClientException("Null dynaclass from the DynaActionForm - can't read properties");
          }

          DynaProperty[] props = dc.getDynaProperties();
          DynaProperty oneProp = null;

          if (log.isDebugEnabled())
          {
            // They are not available in Struts Dynaform objects.
            for (final Enumeration enumeration = this.hreq.getParameterNames(); enumeration
                    .hasMoreElements();)
            {
              // get parameter name
              // Get paramater values...
              // See if present in form.
              final String name = (String) enumeration.nextElement();

              try
              {
                for (int idx = 0;; idx++)
                {
                  final Object value = df.get(name, idx);

                  log.debug("Array Access Parameter/Value/Index: " + name + '/' + value + '/' + idx);
                }
              }
              catch (Exception e)
              {
                log.debug("Exception: " + e);
                log.debug("No more values for: " + name);
              }
            }

            for (final Enumeration enumeration = hreq.getParameterNames(); enumeration.hasMoreElements();)
            {
              final String name = (String) enumeration.nextElement();
              final String[] values = hreq.getParameterValues(name);

              log.debug("Servlet Parameter name: " + name);
              log.debug("Number of values: " + values.length);

              for (int idx = 0; idx < values.length; idx++)
              {
                log.debug("Idx/Value: " + idx + '/' + values[idx]);
              }
            }

            log.debug("# of properties: " + props.length);
          }

          for (int i = 0; i < props.length; i++)
          {
            oneProp = props[i];

            String oneName = oneProp.getName();
            final Object value = df.get(oneName);

            log.debug("Getting parameter/value/type:" + oneName + '/' + value + '/'
                    + (value == null ? "null" : value.getClass().getName()));

            // TODO: Handle mapped and indexed properties here
            // getName(), getType, isIndexed(), isMapped()
            if (df.get(oneName) != null && df.get(oneName) instanceof FormFile)
            {
              log.debug("Formfile");

              FormFile fileInfo = (FormFile) df.get(oneName);

              if (fileInfo != null && fileInfo.getFileSize() > 0)
              {
                BufferedInputStream inStream = null;

                try
                {
                  inStream = new BufferedInputStream(fileInfo.getInputStream(), BUFFER_SIZE);
                }
                catch (IOException e)
                {
                  throw new ClientException(e.getMessage(), e);
                }

                // Problem - DefaultFileItem is not comprised
                // completely of serializable components.
                // final FileItem fileItem =
                // DFIF.createItem(oneName,
                // fileInfo.getContentType(), false,
                // fileInfo.getFileName());
                // So we use BinaryWrapper instead, which is
                // completely serializable
                // TODO: Reset First parameter with Context Name
                // so that this will work over distributed
                // environments(I could not find the call to get
                // it - SPD)
                final BinaryWrapper fileWrapper = new BinaryWrapper(null, hreq.getContentType(),
                        fileInfo.getFileName(), BUFFER_SIZE, null);

                try
                {
                  final long written = fileWrapper.writeFrom(inStream);

                  if (this.log.isDebugEnabled())
                  {
                    log.debug("Read/Wrote " + written + "bytes.");
                  }
                }
                catch (IOException e)
                {
                  throw new ClientException(e.getMessage(), e);
                }
                finally
                {
                  if (inStream != null)
                  {
                    try
                    {
                      inStream.close();
                    }

                    // Done Anyways, so just print for log
                    // (hopefully) and carry on.
                    catch (IOException e)
                    {
                      e.printStackTrace();
                    }
                  } // end if(inStream

                  try
                  {
                    fileWrapper.close();
                  }

                  // Done Anyways, so just print for log
                  // (hopefully) and carry on.
                  catch (IOException e)
                  {
                    e.printStackTrace();
                  }
                } // end finally

                if (log.isDebugEnabled())
                {
                  log.debug("Setting FormFile parameter/value:" + oneName + '/'
                          + fileWrapper.getName());
                }

                kreq.setParameter(oneName, fileWrapper);
              } // end if (fileInfo!= null..
            } // end if(df.get(oneName)!=null
            else if (df.get(oneName) != null && df.get(oneName) instanceof java.io.Serializable)
            {
              if (log.isDebugEnabled())
              {
                log.debug("Setting FormField parameter/value:" + oneName + '/' + df.get(oneName));
              }

              // TODO: Fix this.
              // BUG # 880906 Need to get value(s) directly from
              // request.
              final String[] values = hreq.getParameterValues(oneName);

              if (values.length < 1)
              {
                log.debug("No values, so setting value=null");
                kreq.setParameter(oneName, null);
              }
              else if (values.length == 1)
              {
                log.debug("One value, saving as string");
                kreq.setParameter(oneName, values[1]);
              }
              else
              {
                // More than one value in this list, so send the
                // entire array
                log.debug("Many values, saving as array");
                kreq.setParameter(oneName, values);
              }
            } // end else if(df.get(oneName)!=null...instanceof
            // Serializable

            log.debug("Name/Value written to request: " + oneName);
          } // end for
        }
        else
        {
          // isMultipart == false - Just a regular dynaform
          log.debug("Standard Dyna Form...");

          // Populate the model parameters from the form
          DynaActionForm df = (DynaActionForm) form;
          DynaClass dc = df.getDynaClass();

          if (dc == null)
          {
            throw new ClientException("Null dynaclass from the DynaActionForm - can't read properties");
          }

          DynaProperty[] props = dc.getDynaProperties();
          DynaProperty oneProp = null;

          for (int i = 0; i < props.length; i++)
          {
            oneProp = props[i];

            String oneName = oneProp.getName();
            final Object value = df.get(oneName);

            if (log.isDebugEnabled())
            {
              log.debug("Getting parameter/value/type:" + oneName + '/' + value + '/'
                      + (value == null ? "null" : value.getClass().getName()));
            }

            // TODO: Handle mapped and indexed properties here
            // getName(), getType, isIndexed(), isMapped()
            // if(df.get(oneName)!=null && df.get(oneName) instanceof FormFile){
            //
            // FormFile fileInfo = (FormFile)df.get(oneName);
            // if(fileInfo!=null && fileInfo.getFileSize()>0){
            // //BUG #819550: Large file uploads mishandled
            // //Bad things will happen here if somebody tries to upload
            // //a GB+ file. This is normal in industries like Media
            // //Broadcast. - SPD Oct 7/2003
            // //TODO: Where does new FileSerializable object live?
            // //TODO: A new Serializable object needs to be created as
            // //specified in the bug report. As this object will NOT
            // //be struts specific, where it lives will need to be
            // //determined. - SPD Oct 7/2003
            // //TODO: Investigate using Struts FileUpload here.
            // ByteArrayOutputStream baos = new ByteArrayOutputStream(0);
            // InputStream stream = null;
            // try{
            // stream = fileInfo.getInputStream();
            // } catch(IOException ioe){
            // throw new ClientException(ioe.getMessage());
            // }
            // byte[] data = null;
            // //only write files out that are allowed by max_file_size param
            // double allowed_file_size = 0;
            // try{
            // allowed_file_size = (new Integer(max_file_size).intValue()) * 1024000;
            // } catch(NumberFormatException nfe){
            // throw new ClientException(nfe.getMessage());
            // }
            // if (fileInfo.getFileSize() < allowed_file_size) {
            //
            // byte[] buffer = new byte[8192];
            // int bytesRead = 0;
            // try{
            // while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
            // baos.write(buffer, 0, bytesRead);
            // }
            // } catch(IOException ioe){
            // throw new ClientException(ioe.getMessage());
            // }
            // data = baos.toByteArray();
            //
            // //HACK: Temporary fix until bug #819550 gets fixed.
            // //Then file object can be queried on file name, and will
            // //not need to embed in attribute key.
            // kreq.setParameter(oneName + "_file_data_"+ fileInfo.getFileName(),data);
            // kreq.setParameter("mimetype_"+
            // fileInfo.getFileName(),fileInfo.getContentType());
            // if(wreq.getParameter("file_desc_"+ oneName) != null){
            // kreq.setParameter(oneName + "_file_desc_"+
            // fileInfo.getFileName(),wreq.getParameter("file_desc_"+ oneName));
            // }
            // }
            // else {
            // String dataStr = new String("The file \""+fileInfo.getFileName()+"\" is
            // greater than "+max_file_size+"MB in size, " +
            // " and has not been written to stream." +
            // " File Size: " + fileInfo.getFileSize() + " bytes. ");
            //
            // kreq.setParameter("file_data_error",dataStr);
            // }//end else
            // } //end if (fileInfo!=null...
            // }//end if(dg.get(oneName)!=null...instanceof FormFile

            /* else */if (df.get(oneName) != null && df.get(oneName) instanceof java.io.Serializable)
            {
              if (log.isDebugEnabled())
              {
                log.debug("Setting parameter/value:" + oneName + '/' + df.get(oneName));
              }

              kreq.setParameter(oneName, df.get(oneName));
            } // end else if(df.get(oneName)!=null...instanceof
            // Serializable
          } // end for
        } // end else just a regular DynaForm
      }
      else
      {
        log.debug("Standard Form...");

        /*
         * Use introspection to get the parameters from a normal form
         * bean
         */
        PropertyDescriptor[] pd = PropertyUtils.getPropertyDescriptors(form);
        PropertyDescriptor oneDescriptor = null;
        String onePropertyName = null;

        for (int i = 0; i < pd.length; i++)
        {
          oneDescriptor = pd[i];
          onePropertyName = oneDescriptor.getName();

          try
          {
            kreq.setParameter(onePropertyName, PropertyUtils.getProperty(form, onePropertyName));
          }
          catch (IllegalAccessException e)
          {
            throw new ClientException(e);
          }
          catch (InvocationTargetException e)
          {
            throw new ClientException(e);
          }
          catch (NoSuchMethodException e)
          {
            throw new ClientException(e);
          }
        }
      }
    }
  }
View Full Code Here

          }
          catch (IOException e)
          {
            e.printStackTrace();
            log.error("Exception during file read/write:", e);
            throw new ClientException("Exception during file read/write", e);
          }
          finally
          {
            try
            {
              data.close();
            }
            catch (IOException e1)
            {
              e1.printStackTrace();
            }

            try
            {
              buffOut.flush();
            }
            catch (IOException e2)
            {
              e2.printStackTrace();
            }
          }
        }
        else
        {
          outputs.add(reAsBean);
        }
      }
      else if (re instanceof Command)
      {
        commands.add(reAsBean);
      }
    }

    request.setAttribute("inputs", inputs);
    request.setAttribute("outputs", outputs);
    request.setAttribute("commands", commands);

    int inputCount = 0;
    DynaProperty[] dps = new DynaProperty[inputs.size()];
    ResponseElementDynaBean oneInput = null;

    for (Iterator ii = inputs.iterator(); ii.hasNext();)
    {
      oneInput = (ResponseElementDynaBean) ii.next();

      Object defValue = oneInput.get("defaultValue");
      DynaProperty dp = null;

      if (defValue != null)
      {
        dp = new DynaProperty((String) oneInput.get("name"), oneInput.get("defaultValue").getClass());
      }
      else
      {
        try
        {
          dp = new DynaProperty((String) oneInput.get("name"), Class.forName("java.lang.String"));
        }
        catch (ClassNotFoundException e)
        {
          throw new ClientException("Cannot create String dynaproperty", e);
        }
      }

      dps[inputCount++] = dp;
    }

    BasicDynaClass bd;

    try
    {
      bd = new BasicDynaClass(beanName, Class.forName("org.apache.commons.beanutils.BasicDynaBean"), dps);

      BasicDynaBean newForm = (BasicDynaBean) bd.newInstance();

      for (Iterator i2 = inputs.iterator(); i2.hasNext();)
      {
        oneInput = (ResponseElementDynaBean) i2.next();
        newForm.set((String) oneInput.get("name"), oneInput.get("defaultValue"));
      }

      request.setAttribute("default", newForm);
    }
    catch (ClassNotFoundException e)
    {
      throw new ClientException(e);
    }
    catch (IllegalAccessException e)
    {
      throw new ClientException(e);
    }
    catch (InstantiationException e)
    {
      throw new ClientException(e);
    }
  }
View Full Code Here

    String associatedParams = request.getParameter(PARAMETER_PARAM + commandName);

    if (associatedParams == null)
    {
      throw new ClientException("Command '" + commandName + "' was found, but no parameters under name '"
              + PARAMETER_PARAM + commandName + "' was found");
    }

    StringTokenizer stk1 = new StringTokenizer(associatedParams, "&");
    String onePair = null;
View Full Code Here

    {
      beanName = (String) uiRequest.getParameter(BEAN_PARAM);

      if (StringTools.isTrimEmpty(beanName))
      {
        throw new ClientException("No bean specified in request: '" + request.getRequestURL() + "?"
                + request.getQueryString() + "'");
      }
    }

    uiRequest.setBean(beanName);
View Full Code Here

    KeelResponse kres = super.execute(kreq);

    if (kres == null)
    {
      throw new ClientException("Model response was null");
    }

    String modelName = kreq.getModel();

    kres.setAttribute("model", modelName);
View Full Code Here

            cmap.put(c.getName(), decoded);
            log.debug("Cookie '" + c.getName() + "', value '" + decoded + "'");
          }
          catch (UnsupportedEncodingException e)
          {
            throw new ClientException(e);
          }
        }

        kreq.setAttribute("cookies", cmap);
      }
View Full Code Here

      kreq.setBean(beanName);

      return;
    }

    throw new ClientException("No model/bean specified in request: '" + wreq.getRequestURL() + "?"
            + wreq.getQueryString() + "'");
  }
View Full Code Here

          {
            oneValueString = URLEncoder.encode(oneValue.toString(), "UTF-8");
          }
          catch (UnsupportedEncodingException e)
          {
            throw new ClientException("Error setting cookies", e);
          }

          Cookie c = new Cookie(oneName, oneValueString);

          c.setMaxAge(2592000);
View Full Code Here

    String associatedParams = wreq.getParameter(PARAMETER_PARAM + commandName);

    if (associatedParams == null)
    {
      throw new ClientException("Command '" + commandName + "' was found, but no parameters under name '"
              + PARAMETER_PARAM + commandName + "' was found");
    }

    StringTokenizer stk1 = new StringTokenizer(associatedParams, "&");
    String onePair = null;
View Full Code Here

TOP

Related Classes of de.iritgo.aktera.clients.ClientException

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.