dap4/d4servlet/src/main/java/dap4/servlet/DapController.java
protected void
    doData(DapRequest drq, DapContext cxt)
            throws IOException
    {
        // Convert the url to an absolute path
        String realpath = getResourcePath(drq, drq.getDatasetPath());

        DSP dsp = DapCache.open(realpath, cxt);
        if(dsp == null)
            throw new DapException("No such file: " + drq.getResourceRoot());
        DapDataset dmr = dsp.getDMR();
        if(DUMPDMR) {
            printDMR(dmr);
            System.err.println(printDMR(dmr));
            System.err.flush();
        }

        /* Annotate with our endianness */
        ByteOrder order = (ByteOrder) cxt.get(Dap4Util.DAP4ENDIANTAG);
        setEndianness(dmr, order);

        // Process any constraint
        CEConstraint ce = null;
        String sce = drq.queryLookup(DapProtocol.CONSTRAINTTAG);
        ce = CEConstraint.compile(sce, dmr);
        setConstraint(dmr, ce);

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        // Get the DMR as a string
        DMRPrinter dapprinter = new DMRPrinter(dmr, ce, pw, drq.getFormat());
        dapprinter.print();
        pw.close();
        sw.close();

        String sdmr = sw.toString();
        if(DEBUG || DUMPDMR)
            System.err.println("Sending: Data DMR:\n" + sdmr);

        // Wrap the outputstream with a Chunk writer
        OutputStream out = drq.getOutputStream();
        ChunkWriter cw = new ChunkWriter(out, RequestMode.DAP, order);
        cw.setWriteLimit(getBinaryWriteLimit());
        cw.cacheDMR(sdmr);
        cw.flush();

        addCommonHeaders(drq);

        // Dump the databuffer part
        switch (drq.getFormat()) {
        case TEXT:
        case XML:
        case HTML:
            throw new IOException("Unsupported return format: " + drq.getFormat());
            /*
            sw = new StringWriter();
            DAPPrint dp = new DAPPrint(sw);
            dp.print(dsp.getDataset(), ce);
            break;
                */
        case NONE:
        default:
            DapSerializer writer = new DapSerializer(dsp, ce, cw, order, drq.getChecksumMode());
            writer.write(dsp.getDMR());
            cw.flush();
            cw.close();
            break;
        }
        // Should we dump data?
        if(DUMPDATA) {
            byte[] data = cw.getDump();
            if(data != null)
                DapDump.dumpbytestream(data, cw.getWriteOrder(), "ChunkWriter.write");
        }
    }
protected void
    doData(DapRequest drq, DapContext cxt)
            throws IOException
    {
        // Convert the url to an absolute path
        String realpath = getResourcePath(drq, drq.getDatasetPath());

        DSP dsp = DapCache.open(realpath, cxt);
        if(dsp == null)
            throw new DapException("No such file: " + drq.getResourceRoot());
        DapDataset dmr = dsp.getDMR();
        if(DUMPDMR) {
            printDMR(dmr);
            System.err.println(printDMR(dmr));
            System.err.flush();
        }

        /* Annotate with our endianness */
        ByteOrder order = (ByteOrder) cxt.get(Dap4Util.DAP4ENDIANTAG);
        setEndianness(dmr, order);

        // Process any constraint
        CEConstraint ce = null;
        String sce = drq.queryLookup(DapProtocol.CONSTRAINTTAG);
        ce = CEConstraint.compile(sce, dmr);
        setConstraint(dmr, ce);

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        // Get the DMR as a string
        DMRPrinter dapprinter = new DMRPrinter(dmr, ce, pw, drq.getFormat());
        dapprinter.print();
        pw.close();
        sw.close();

        String sdmr = sw.toString();
        if(DEBUG || DUMPDMR)
            System.err.println("Sending: Data DMR:\n" + sdmr);

        // Wrap the outputstream with a Chunk writer
        OutputStream out = drq.getOutputStream();
        ChunkWriter cw = new ChunkWriter(out, RequestMode.DAP, order);
        cw.setWriteLimit(getBinaryWriteLimit());
        cw.cacheDMR(sdmr);
        cw.flush();

        addCommonHeaders(drq);

        // Dump the databuffer part
        switch (drq.getFormat()) {
        case TEXT:
        case XML:
        case HTML:
            throw new IOException("Unsupported return format: " + drq.getFormat());
            /*
            sw = new StringWriter();
            DAPPrint dp = new DAPPrint(sw);
            dp.print(dsp.getDataset(), ce);
            break;
                */
        case NONE:
        default:
            DapSerializer writer = new DapSerializer(dsp, ce, cw, order, drq.getChecksumMode());
            writer.write(dsp.getDMR());
            cw.flush();
            cw.close();
            break;
        }
        // Should we dump data?
        if(DUMPDATA) {
            byte[] data = cw.getDump();
            if(data != null)
                DapDump.dumpbytestream(data, cw.getWriteOrder(), "ChunkWriter.write");
        }
    }
protected void doData ( DapRequest drq , DapContext cxt ) throws IOException { // Convert the url to an absolute path String realpath = getResourcePath ( drq , drq . getDatasetPath ( ) ) ; DSP dsp = DapCache . open ( realpath , cxt ) ; if ( dsp == null ) throw new DapException ( "No such file: " + drq . getResourceRoot ( ) ) ; DapDataset dmr = dsp . getDMR ( ) ; if ( DUMPDMR ) { printDMR ( dmr ) ; System . err . println ( printDMR ( dmr ) ) ; System . err . flush ( ) ; } /* Annotate with our endianness */ ByteOrder order = ( ByteOrder ) cxt . get ( Dap4Util . DAP4ENDIANTAG ) ; setEndianness ( dmr , order ) ; // Process any constraint CEConstraint ce = null ; String sce = drq . queryLookup ( DapProtocol . CONSTRAINTTAG ) ; ce = CEConstraint . compile ( sce , dmr ) ; setConstraint ( dmr , ce ) ; StringWriter sw = new StringWriter ( ) ; PrintWriter pw = new PrintWriter ( sw ) ; // Get the DMR as a string DMRPrinter dapprinter = new DMRPrinter ( dmr , ce , pw , drq . getFormat ( ) ) ; dapprinter . print ( ) ; pw . close ( ) ; sw . close ( ) ; String sdmr = sw . toString ( ) ; if ( DEBUG || DUMPDMR ) System . err . println ( "Sending: Data DMR:\n" + sdmr ) ; // Wrap the outputstream with a Chunk writer OutputStream out = drq . getOutputStream ( ) ; ChunkWriter cw = new ChunkWriter ( out , RequestMode . DAP , order ) ; cw . setWriteLimit ( getBinaryWriteLimit ( ) ) ; cw . cacheDMR ( sdmr ) ; cw . flush ( ) ; addCommonHeaders ( drq ) ; // Dump the databuffer part switch ( drq . getFormat ( ) ) { case TEXT : case XML : case HTML : throw new IOException ( "Unsupported return format: " + drq . getFormat ( ) ) ; /*
            sw = new StringWriter();
            DAPPrint dp = new DAPPrint(sw);
            dp.print(dsp.getDataset(), ce);
            break;
                */ case NONE : default : DapSerializer writer = new DapSerializer ( dsp , ce , cw , order , drq . getChecksumMode ( ) ) ; writer . write ( dsp . getDMR ( ) ) ; cw . flush ( ) ; cw . close ( ) ; break ; } // Should we dump data? if ( DUMPDATA ) { byte [ ] data = cw . getDump ( ) ; if ( data != null ) DapDump . dumpbytestream ( data , cw . getWriteOrder ( ) , "ChunkWriter.write" ) ; } }
Process a DataDMR request.
Note that if this throws an exception,
then it has not yet started to output
a response. It a response had been initiated,
then the exception would produce an error chunk.
<p>
* @param cxt     The dap context
Process a DataDMR request . Note that if this throws an exception then it has not yet started to output a response . It a response had been initiated then the exception would produce an error chunk . <p > *