Package org.exist.http.servlets

Examples of org.exist.http.servlets.ResponseWrapper


        final JavaObjectValue respValue = (JavaObjectValue)respVar.getValue().itemAt( 0 );

        if( !"org.exist.http.servlets.HttpResponseWrapper".equals( respValue.getObject().getClass().getName() ) ) {
            throw( new XPathException( this, signature.toString() + " can only be used within the EXistServlet or XQueryServlet" ) );
        }
        final ResponseWrapper response = (ResponseWrapper)respValue.getObject();

        response.setContentType( "application/zip" );
        response.setHeader("Content-Length", String.valueOf(backupFile.length()));
        try {
            final InputStream  is  = new FileInputStream( backupFile );
            final OutputStream os  = response.getOutputStream();
            final byte[]       buf = new byte[4096];
            int          c;

            while( ( c = is.read( buf ) ) > -1 ) {
                os.write( buf, 0, c );
            }
            is.close();
            os.close();
            response.flushBuffer();
        }
        catch( final IOException e ) {
            throw( new XPathException( this, "An IO error occurred while reading the backup archive" ) );
        }
        return( Sequence.EMPTY_SEQUENCE );
View Full Code Here


          context.declareVariable(SessionModule.PREFIX + ":session", reqw.getSession( false ));
      }
       
      if(response != null)
      {
        final ResponseWrapper respw = new HttpResponseWrapper(response);
        context.declareVariable(ResponseModule.PREFIX + ":response", respw);
      }
       
    }
View Full Code Here

            final JavaObjectValue respValue = (JavaObjectValue)
                respVar.getValue().itemAt(0);
            if (!"org.exist.http.servlets.HttpResponseWrapper".equals(respValue.getObject().getClass().getName()))
                {throw new XPathException(this, signatures[1].toString() +
                        " can only be used within the EXistServlet or XQueryServlet");}
            final ResponseWrapper response = (ResponseWrapper) respValue.getObject();
           
            //setup the response correctly
            final String mediaType = handler.getTransformer().getOutputProperty("media-type");
            final String encoding = handler.getTransformer().getOutputProperty("encoding");
            if(mediaType != null)
            {
              if(encoding == null)
              {
                response.setContentType(mediaType);
              }
              else
              {
                response.setContentType(mediaType + "; charset=" + encoding);
              }
            }
           
            //do the transformation
            try {
                final OutputStream os = new BufferedOutputStream(response.getOutputStream());
                final StreamResult result = new StreamResult(os);
                handler.setResult(result);
                final Serializer serializer = context.getBroker().getSerializer();
                serializer.reset();
                Receiver receiver = new ReceiverToSAX(handler);
                try {
                    serializer.setProperties(serializationProps);
                    if (expandXIncludes) {
                        XIncludeFilter xinclude = new XIncludeFilter(serializer, receiver);
                        String xipath = serializationProps.getProperty(EXistOutputKeys.XINCLUDE_PATH);
                        if (xipath != null) {
                            final File f = new File(xipath);
                            if (!f.isAbsolute())
                                {xipath = new File(context.getModuleLoadPath(), xipath).getAbsolutePath();}
                        } else
                            {xipath = context.getModuleLoadPath();}
                        xinclude.setModuleLoadPath(xipath);
                        receiver = xinclude;
                    }
                    serializer.setReceiver(receiver);
                    serializer.toSAX(inputNode, 1, inputNode.getItemCount(), false, false);
                } catch (final Exception e) {
                    throw new XPathException(this, "Exception while transforming node: " + e.getMessage(), e);
                }
                errorListener.checkForErrors();
                os.close();
               
                //commit the response
                response.flushBuffer();
            } catch (final IOException e) {
                throw new XPathException(this, "IO exception while transforming node: " + e.getMessage(), e);
            }
            return Sequence.EMPTY_SEQUENCE;
        }
View Full Code Here

    private HttpRequestWrapper declareVariables(final XQueryContext context,
        final ElementImpl variables, final HttpServletRequest request,
        final HttpServletResponse response) throws XPathException {

        final HttpRequestWrapper reqw = new HttpRequestWrapper(request, formEncoding, containerEncoding);
        final ResponseWrapper respw = new HttpResponseWrapper(response);

        // context.declareNamespace(RequestModule.PREFIX,
        // RequestModule.NAMESPACE_URI);
        context.declareVariable(RequestModule.PREFIX + ":request", reqw);
        context.declareVariable(ResponseModule.PREFIX + ":response", respw);
View Full Code Here

        if(!"org.exist.http.servlets.HttpResponseWrapper".equals(respValue.getObject().getClass().getName())) {
            throw (new XPathException(this, signature.toString() + " can only be used within the EXistServlet or XQueryServlet"));
        }

        final ResponseWrapper response = (ResponseWrapper) respValue.getObject();
        response.setHeader("Content-Type", contentType);

        if(filename != null) {
            response.setHeader("Content-Disposition", "inline; filename=\"" + filename + "\"");
        }

        try {
            final OutputStream os = response.getOutputStream();
            binary.streamBinaryTo(response.getOutputStream());
            os.close();

            //commit the response
            response.flushBuffer();
        } catch (final IOException e) {
            throw (new XPathException(this, "IO exception while streaming data: " + e.getMessage(), e));
        }

        return (Sequence.EMPTY_SEQUENCE);
View Full Code Here

        final JavaObjectValue respValue = (JavaObjectValue) respVar.getValue().itemAt(0);
       
        if (!"org.exist.http.servlets.HttpResponseWrapper".equals(respValue.getObject().getClass().getName()))
            {throw new XPathException(this, signature.toString() + " can only be used within the EXistServlet or XQueryServlet");}
       
        final ResponseWrapper response = (ResponseWrapper) respValue.getObject();
       
        final String mediaType = serializeOptions.getProperty("media-type", "application/xml");
        final String encoding = serializeOptions.getProperty("encoding", "UTF-8");
        if(mediaType != null) {
            response.setContentType(mediaType + "; charset=" + encoding);
        }
       
        Serializer serializer = null;
       
        BrokerPool db = null;
        DBBroker broker = null;
        try {
          db = BrokerPool.getInstance();
          broker = db.get(null);
         
            serializer = broker.getSerializer();
            serializer.reset();
           
            final OutputStream sout = response.getOutputStream();
            final PrintWriter output = new PrintWriter(new OutputStreamWriter(sout, encoding));

          final SerializerPool serializerPool = SerializerPool.getInstance();

          final SAXSerializer sax = (SAXSerializer) serializerPool.borrowObject(SAXSerializer.class);
          try {
            sax.setOutput(output, serializeOptions);

            serializer.setProperties(serializeOptions);
            serializer.setSAXHandlers(sax, sax);
              serializer.toSAX(inputNode, 1, inputNode.getItemCount(), false, false);
             
          } catch (final SAXException e) {
            e.printStackTrace();
            throw new IOException(e);
          } finally {
            serializerPool.returnObject(sax);
          }
          output.flush();
          output.close();
           
            //commit the response
            response.flushBuffer();
        } catch (final IOException e) {
            throw new XPathException(this, "IO exception while streaming node: " + e.getMessage(), e);
        } catch (final EXistException e) {
            throw new XPathException(this, "Exception while streaming node: " + e.getMessage(), e);
    } finally {
View Full Code Here

   
    final RequestWrapper reqw = new HttpRequestWrapper(
        request,
        request.getCharacterEncoding(), request.getCharacterEncoding());
   
    final ResponseWrapper respw = new HttpResponseWrapper(response);
    // context.declareNamespace(RequestModule.PREFIX,
    // RequestModule.NAMESPACE_URI);
    context.declareVariable(RequestModule.PREFIX + ":request", reqw);
    context.declareVariable(ResponseModule.PREFIX + ":response", respw);
    context.declareVariable(SessionModule.PREFIX + ":session", reqw.getSession(false));
View Full Code Here

              .itemAt(0);
          if (value != null
              && value.getObject() instanceof ResponseWrapper) {
            // have to take in account that if the header has allready been explicitely set
            // by the XQuery script, we should not modify it .
            final ResponseWrapper responseWrapper = ((ResponseWrapper) value.getObject());
            if ( responseWrapper.getDateHeader("Last-Modified") == 0 )
              {responseWrapper.setDateHeader(
                "Last-Modified", mostRecentDocumentTime);}
          }
        }
      }
    } catch (final Exception e) {
View Full Code Here

TOP

Related Classes of org.exist.http.servlets.ResponseWrapper

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.