Package com.dbxml.labrador.exceptions

Examples of com.dbxml.labrador.exceptions.RequestException


      if ( methodName == null || methodName.length() == 0 ) {
         Object val = instance.getProperty(DEFAULT_METHOD);
         if ( val instanceof String )
            methodName = (String)val;
         else
            throw new RequestException("No method name was set");
      }
      instance.setMethodName(methodName);

      BrokerContext context = Broker.getInstance().getBrokerContext();
      Discovery disc = context.getDiscovery();
      String[] paramNames = disc.listParams(methodName);
      boolean postUsed = false;

      for ( int i = 0; paramNames != null && i < paramNames.length; i++ ) {
         boolean array = disc.isParamArray(methodName, i);
         String[] vals = request.getValues(paramNames[i]);

         if ( vals != null ) {
            if ( array )
               instance.setParameter(i, vals);
            else
               instance.setParameter(i, vals[0]);
         }
         else if ( !postUsed && request.hasContent() ) {
            // If there is POST data, and this parameter is a String, Document,
            // or byte array, then let us assume that the POST data is intended
            // for this one.
            try {
               InputStream is = request.getInputStream();
               ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE);

               byte[] buffer = new byte[BUFFER_SIZE];
               int size;
               do {
                  size = is.read(buffer);
                  if ( size > 0 )
                     bos.write(buffer, 0, size);
               }
               while ( size != -1 );

               instance.setParameter(i, bos.toByteArray());
               postUsed = true;
            }
            catch ( IOException e ) {
               /** @todo Hmmm */
            }
         }
         else
            instance.setParameter(i, null);
      }

      // Initially set the MIME type in case we get an HTTP 403 Exception
      ID id = context.getId();

      String contentType = getMimeType(id);
      if ( contentType != null )
         response.setHeader(HTTP.HEADER_CONTENT_TYPE, contentType);

      Object o = instance.invoke();

      Object type = context.getProperty(CONTENT_TYPE);
      if ( type == null )
         type = instance.getProperty(CONTENT_TYPE+'_'+methodName);

      if ( type instanceof String ) {
         contentType = (String)type;
         response.setHeader(HTTP.HEADER_CONTENT_TYPE, contentType);
      }

      if ( contentType == null ) {
         if ( o instanceof Node || o instanceof Element )
            contentType = Headers.TYPE_TEXT_XML;
         else
            contentType = Headers.TYPE_TEXT_PLAIN;
         response.setHeader(HTTP.HEADER_CONTENT_TYPE, contentType);
      }

      try {
         OutputStream os = response.getOutputStream();
         writeValue(os, o);
         os.flush(); // Is this needed?
         os.close(); // Is this needed?
         response.close();
      }
      catch ( IOException e ) {
         throw new RequestException(e.getMessage());
      }
   }
View Full Code Here


      }
      catch ( RequestException e ) {
         throw e;
      }
      catch ( Throwable t ) {
         throw new RequestException(t.getMessage());
      }
   }
View Full Code Here

            args = newArgs;
         }
         args[idx] = value;
      }
      catch ( Exception e ) {
         throw new RequestException("Can't set parameter");
      }
   }
View Full Code Here

   public Object invoke() throws RequestException {
      try {
         return disc.invoke(getMethodName(), getParameters());
      }
      catch ( Throwable t ) {
         throw new RequestException(t.getMessage());
      }
   }
View Full Code Here

TOP

Related Classes of com.dbxml.labrador.exceptions.RequestException

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.