Example usage for javax.xml.stream XMLStreamWriter close

List of usage examples for javax.xml.stream XMLStreamWriter close

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter close.

Prototype

public void close() throws XMLStreamException;

Source Link

Document

Close this writer and free any resources associated with the writer.

Usage

From source file:org.deegree.services.wps.provider.jrxml.contentprovider.Utils.java

public static ProcessletInputs getInputs(String parameterId, String mimeType, String schema,
        InputStream complexInput) throws IOException, XMLStreamException, FactoryConfigurationError {
    List<ProcessletInput> inputs = new ArrayList<ProcessletInput>();
    ProcessletInputs in = new ProcessletInputs(inputs);

    ComplexInputDefinition definition = new ComplexInputDefinition();
    definition.setTitle(getAsLanguageStringType(parameterId));
    definition.setIdentifier(getAsCodeType(parameterId));
    ComplexFormatType format = new ComplexFormatType();

    format.setEncoding("UTF-8");
    format.setMimeType(mimeType);//  w w  w  . j av a 2s  .c  o  m
    format.setSchema(schema);
    definition.setDefaultFormat(format);
    definition.setMaxOccurs(BigInteger.valueOf(1));
    definition.setMinOccurs(BigInteger.valueOf(0));

    File f = File.createTempFile("tmpStore", "");
    StreamBufferStore store = new StreamBufferStore(1024, f);

    XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(complexInput);
    XMLStreamWriter xmlWriter = null;
    try {
        xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(store);
        if (xmlReader.getEventType() == START_DOCUMENT) {
            xmlReader.nextTag();
        }
        XMLAdapter.writeElement(xmlWriter, xmlReader);
    } finally {
        try {
            xmlReader.close();
        } catch (XMLStreamException e) {
            // nothing to do
        }
        try {
            xmlWriter.close();
        } catch (XMLStreamException e) {
            // nothing to do
        }
        IOUtils.closeQuietly(store);
    }

    ComplexInputImpl mapProcesslet = new EmbeddedComplexInput(definition, new LanguageString("title", "ger"),
            new LanguageString("summary", "ger"), format, store);

    inputs.add(mapProcesslet);
    return in;
}

From source file:org.deegree.tools.crs.XMLCoordinateTransform.java

private static void doTransform(CommandLine line) throws IllegalArgumentException, TransformationException,
        UnknownCRSException, IOException, XMLStreamException, FactoryConfigurationError {

    // TODO source srs should actually override all srsName attributes in document, not just be the default
    ICRS sourceCRS = null;/*from  w w w  . j  ava2  s .c  o  m*/
    String sourceCRSId = line.getOptionValue(OPT_S_SRS);
    if (sourceCRSId != null) {
        sourceCRS = CRSManager.lookup(sourceCRSId);
    }

    String targetCRSId = line.getOptionValue(OPT_T_SRS);
    ICRS targetCRS = CRSManager.lookup(targetCRSId);

    String transId = line.getOptionValue(OPT_TRANSFORMATION);
    List<Transformation> trans = null;
    if (transId != null) {
        Transformation t = CRSManager.getTransformation(null, transId);
        if (t != null) {
            trans = Collections.singletonList(CRSManager.getTransformation(null, transId));
        } else {
            throw new IllegalArgumentException(
                    "Specified transformation id '" + transId + "' does not exist in CRS database.");
        }
    }

    GMLVersion gmlVersion = GMLVersion.GML_31;
    String gmlVersionString = line.getOptionValue(OPT_GML_VERSION);
    if (gmlVersionString != null) {
        gmlVersion = GMLVersion.valueOf(gmlVersionString);
    }

    String i = line.getOptionValue(OPT_INPUT);
    File inputFile = new File(i);
    if (!inputFile.exists()) {
        throw new IllegalArgumentException("Input file '" + inputFile + "' does not exist.");
    }
    XMLStreamReader xmlReader = XMLInputFactory.newInstance()
            .createXMLStreamReader(new FileInputStream(inputFile));

    String o = line.getOptionValue(OPT_OUTPUT);
    XMLStreamWriter xmlWriter = null;
    if (o != null) {
        File outputFile = new File(o);
        xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(outputFile),
                "UTF-8");
    } else {
        xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out, "UTF-8");
    }

    xmlWriter = new IndentingXMLStreamWriter(xmlWriter, "    ");
    xmlWriter.writeStartDocument("UTF-8", "1.0");
    XMLTransformer transformer = new XMLTransformer(targetCRS);
    transformer.transform(xmlReader, xmlWriter, sourceCRS, gmlVersion, false, trans);
    xmlWriter.close();
}

From source file:org.deegree.tools.services.wms.FeatureTypesToLayerTree.java

/**
 * @param args// w w w  .j  a va 2 s .c  o m
 */
public static void main(String[] args) {
    Options options = initOptions();

    // for the moment, using the CLI API there is no way to respond to a help argument; see
    // https://issues.apache.org/jira/browse/CLI-179
    if (args.length == 0 || (args.length > 0 && (args[0].contains("help") || args[0].contains("?")))) {
        CommandUtils.printHelp(options, FeatureTypesToLayerTree.class.getSimpleName(), null, null);
    }

    XMLStreamWriter out = null;
    try {
        CommandLine line = new PosixParser().parse(options, args);

        String storeFile = line.getOptionValue("f");
        String nm = new File(storeFile).getName();
        String storeId = nm.substring(0, nm.length() - 4);

        FileOutputStream os = new FileOutputStream(line.getOptionValue("o"));
        XMLOutputFactory fac = XMLOutputFactory.newInstance();
        out = new IndentingXMLStreamWriter(fac.createXMLStreamWriter(os));
        out.setDefaultNamespace(ns);

        Workspace ws = new DefaultWorkspace(new File("nix"));
        ws.initAll();
        DefaultResourceIdentifier<FeatureStore> identifier = new DefaultResourceIdentifier<FeatureStore>(
                FeatureStoreProvider.class, "unknown");
        ws.add(new DefaultResourceLocation<FeatureStore>(new File(storeFile), identifier));
        ws.prepare(identifier);
        FeatureStore store = ws.init(identifier, null);

        AppSchema schema = store.getSchema();

        // prepare document
        out.writeStartDocument();
        out.writeStartElement(ns, "deegreeWMS");
        out.writeDefaultNamespace(ns);
        out.writeAttribute("configVersion", "0.5.0");
        out.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        out.writeAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation",
                "http://www.deegree.org/services/wms http://schemas.deegree.org/wms/0.5.0/wms_configuration.xsd");
        out.writeStartElement(ns, "ServiceConfiguration");

        HashSet<FeatureType> visited = new HashSet<FeatureType>();

        if (schema.getRootFeatureTypes().length == 1) {
            writeLayer(visited, out, schema.getRootFeatureTypes()[0], storeId);
        } else {
            out.writeCharacters("\n");
            out.writeStartElement(ns, "UnrequestableLayer");
            XMLAdapter.writeElement(out, ns, "Title", "Root Layer");
            for (FeatureType ft : schema.getRootFeatureTypes()) {
                writeLayer(visited, out, ft, storeId);
            }
            out.writeEndElement();
            out.writeCharacters("\n");
        }

        out.writeEndElement();
        out.writeEndElement();
        out.writeEndDocument();
    } catch (ParseException exp) {
        System.err.println(Messages.getMessage("TOOL_COMMANDLINE_ERROR", exp.getMessage()));
        CommandUtils.printHelp(options, FeatureTypesToLayerTree.class.getSimpleName(), null, null);
    } catch (ResourceInitException e) {
        LOG.info("The feature store could not be loaded: '{}'", e.getLocalizedMessage());
        LOG.trace("Stack trace:", e);
    } catch (FileNotFoundException e) {
        LOG.info("A file could not be found: '{}'", e.getLocalizedMessage());
        LOG.trace("Stack trace:", e);
    } catch (XMLStreamException e) {
        LOG.info("The XML output could not be written: '{}'", e.getLocalizedMessage());
        LOG.trace("Stack trace:", e);
    } catch (FactoryConfigurationError e) {
        LOG.info("The XML system could not be initialized: '{}'", e.getLocalizedMessage());
        LOG.trace("Stack trace:", e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (XMLStreamException e) {
                LOG.trace("Stack trace:", e);
            }
        }
    }

}

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

private void writeExportAnchors() throws DITAOTException {
    if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) {
        // Output plugin id
        final File pluginIdFile = new File(job.tempDir, FILE_NAME_PLUGIN_XML);
        final DelayConrefUtils delayConrefUtils = new DelayConrefUtils();
        delayConrefUtils.writeMapToXML(exportAnchorsFilter.getPluginMap(), pluginIdFile);

        XMLStreamWriter export = null;
        try (OutputStream exportStream = new FileOutputStream(new File(job.tempDir, FILE_NAME_EXPORT_XML))) {
            export = XMLOutputFactory.newInstance().createXMLStreamWriter(exportStream, "UTF-8");
            export.writeStartDocument();
            export.writeStartElement("stub");
            for (final ExportAnchor e : exportAnchorsFilter.getExportAnchors()) {
                export.writeStartElement("file");
                export.writeAttribute("name",
                        tempFileNameScheme.generateTempFileName(toFile(e.file).toURI()).toString());
                for (final String t : sort(e.topicids)) {
                    export.writeStartElement("topicid");
                    export.writeAttribute("name", t);
                    export.writeEndElement();
                }//from w w w. j  a  v a  2s .c  o m
                for (final String i : sort(e.ids)) {
                    export.writeStartElement("id");
                    export.writeAttribute("name", i);
                    export.writeEndElement();
                }
                for (final String k : sort(e.keys)) {
                    export.writeStartElement("keyref");
                    export.writeAttribute("name", k);
                    export.writeEndElement();
                }
                export.writeEndElement();
            }
            export.writeEndElement();
            export.writeEndDocument();
        } catch (final IOException e) {
            throw new DITAOTException("Failed to write export anchor file: " + e.getMessage(), e);
        } catch (final XMLStreamException e) {
            throw new DITAOTException("Failed to serialize export anchor file: " + e.getMessage(), e);
        } finally {
            if (export != null) {
                try {
                    export.close();
                } catch (final XMLStreamException e) {
                    logger.error("Failed to close export anchor file: " + e.getMessage(), e);
                }
            }
        }
    }
}

From source file:org.dita.dost.reader.ChunkMapReader.java

/**
 * Create the new topic stump.//from  ww  w  .j a  v  a 2 s  .  com
 */
private void createTopicStump(final File newFile) {
    OutputStream newFileWriter = null;
    try {
        newFileWriter = new FileOutputStream(newFile);
        final XMLStreamWriter o = XMLOutputFactory.newInstance().createXMLStreamWriter(newFileWriter, UTF8);
        o.writeStartDocument();
        o.writeProcessingInstruction(PI_WORKDIR_TARGET,
                UNIX_SEPARATOR + newFile.getParentFile().getAbsolutePath());
        o.writeProcessingInstruction(PI_WORKDIR_TARGET_URI, newFile.getParentFile().toURI().toString());
        o.writeStartElement(ELEMENT_NAME_DITA);
        o.writeEndElement();
        o.writeEndDocument();
        o.close();
        newFileWriter.flush();
    } catch (final RuntimeException e) {
        throw e;
    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        try {
            if (newFileWriter != null) {
                newFileWriter.close();
            }
        } catch (final Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:org.eclipse.gyrex.logback.config.internal.LogbackConfigGenerator.java

public File generateConfig() {
    // get state location
    if (!parentFolder.isDirectory() && !parentFolder.mkdirs()) {
        throw new IllegalStateException(
                String.format("Unable to create configs directory (%s).", parentFolder));
    }//from ww w.  j a va 2s .  c om

    // save file
    final File configFile = new File(parentFolder,
            String.format("logback.%s.xml", DateFormatUtils.format(lastModified, "yyyyMMdd-HHmmssSSS")));
    OutputStream outputStream = null;
    XMLStreamWriter xmlStreamWriter = null;
    try {
        outputStream = new BufferedOutputStream(FileUtils.openOutputStream(configFile));
        final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        xmlStreamWriter = outputFactory.createXMLStreamWriter(outputStream, CharEncoding.UTF_8);
        // try to format the output
        try {
            final Class<?> clazz = getClass().getClassLoader()
                    .loadClass("com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter");
            xmlStreamWriter = (XMLStreamWriter) clazz.getConstructor(XMLStreamWriter.class)
                    .newInstance(xmlStreamWriter);
        } catch (final Exception e) {
            // ignore
        }
        config.toXml(xmlStreamWriter);
        xmlStreamWriter.flush();
    } catch (final IOException e) {
        throw new IllegalStateException(
                String.format("Unable to create config file (%s).", ExceptionUtils.getRootCauseMessage(e)), e);
    } catch (final XMLStreamException e) {
        throw new IllegalStateException(
                String.format("Error writing config (%s).", ExceptionUtils.getRootCauseMessage(e)), e);
    } finally {
        if (null != xmlStreamWriter) {
            try {
                xmlStreamWriter.close();
            } catch (final Exception e) {
                // ignore
            }
        }
        IOUtils.closeQuietly(outputStream);
    }

    // cleanup directory
    removeOldFiles(parentFolder);

    return configFile;
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void writeMessage(final OutputStream out) throws XMLStreamException {
    final XMLStreamWriter writer = this.dmClient.createXMLStreamWriter(out, ENCODING);
    writer.writeStartDocument(ENCODING, "1.0"); //$NON-NLS-1$
    // CHECKSTYLE:OFF (imbricated blocks)
    {//from   w  ww .j  av  a  2s  .co  m
        writer.writeStartElement("SyncML"); //$NON-NLS-1$
        writer.writeAttribute("xmlns", "SYNCML:SYNCML1.2"); //$NON-NLS-1$//$NON-NLS-2$
        {
            writer.writeStartElement("SyncHdr"); //$NON-NLS-1$
            {
                writer.writeStartElement("VerDTD"); //$NON-NLS-1$
                writer.writeCharacters("1.2"); //$NON-NLS-1$
                writer.writeEndElement();
                writer.writeStartElement("VerProto"); //$NON-NLS-1$
                writer.writeCharacters("DM/1.2"); //$NON-NLS-1$
                writer.writeEndElement();
                writer.writeStartElement("SessionID"); //$NON-NLS-1$
                writer.writeCharacters(this.sessionId);
                writer.writeEndElement();
                writer.writeStartElement("MsgID"); //$NON-NLS-1$
                writer.writeCharacters(String.valueOf(this.idGenerator.nextMsgID()));
                writer.writeEndElement();
                writer.writeStartElement("Target"); //$NON-NLS-1$
                {
                    writer.writeStartElement("LocURI"); //$NON-NLS-1$
                    writer.writeCharacters(this.server.toString());
                    writer.writeEndElement();
                }
                writer.writeEndElement();
                writer.writeStartElement("Source"); //$NON-NLS-1$
                {
                    writer.writeStartElement("LocURI"); //$NON-NLS-1$
                    writer.writeCharacters(this.client.toString());
                    writer.writeEndElement();
                }
                writer.writeEndElement();

                /*
                 * Add basic authentication
                 */
                writer.writeStartElement("Cred"); //$NON-NLS-1$
                {
                    writer.writeStartElement("Meta"); //$NON-NLS-1$
                    {
                        writer.writeStartElement("Format"); //$NON-NLS-1$
                        writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$
                        writer.writeCharacters("b64"); //$NON-NLS-1$
                        writer.writeEndElement();

                        writer.writeStartElement("Type"); //$NON-NLS-1$
                        writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$
                        writer.writeCharacters("syncml:auth-basic"); //$NON-NLS-1$
                        writer.writeEndElement();
                    }
                    writer.writeEndElement();

                    writer.writeStartElement("Data"); //$NON-NLS-1$
                    writer.writeCharacters(userAuth);
                    writer.writeEndElement();

                }
                writer.writeEndElement();
                /*
                 * End authentication
                 */
            }
            writer.writeEndElement();
            writer.writeStartElement("SyncBody"); //$NON-NLS-1$
            {
                writeStatus(writer);
                if (!this.isClientAuthenticated) {
                    writeAlert(writer, "1201"); //$NON-NLS-1$
                    writeGenericAlert(writer, this.genericAlerts);
                    writeReplace(writer, this.devInfoNodes);
                }

                writer.writeStartElement("Final"); //$NON-NLS-1$
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    }
    // CHECKSTYLE:ON
    writer.writeEndDocument();
    writer.flush();
    writer.close();
}

From source file:org.eclipse.smila.datamodel.tools.DatamodelSerializationUtils.java

/**
 * Serialize2string.// w ww. ja v  a2 s  .  c  o  m
 * 
 * @param id
 *          the id
 * 
 * @return the string
 */
public static String serialize2string(final Id id) {
    if (id == null) {
        return null;
    }
    try {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLStreamWriter writer = null;
        try {
            writer = getStaxWriterFactory().createXMLStreamWriter(out, "utf-8");
            writer.writeStartDocument("utf-8", "1.1");
            getIdWriter().writeId(writer, id);
            writer.writeEndDocument();
            return out.toString("utf-8");
        } catch (final Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (final XMLStreamException e) {
                    ; // nothing to do
                }
            } // if
            if (out != null) {
                IOUtils.closeQuietly(out);
            }
        } // finally
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.smila.datamodel.tools.DatamodelSerializationUtils.java

/**
 * Serializes a Record into a ByteArrayOutputStream. It does NOT serialize Attachment values, only their names !
 * //from  ww w  . j  a  va  2s .  com
 * @param record
 *          the record
 * @return the ByteArrayOutputStream
 */
public static ByteArrayOutputStream serialize2stream(final Record record) {
    if (record == null) {
        return null;
    }

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLStreamWriter writer = null;
    try {
        writer = getStaxWriterFactory().createXMLStreamWriter(out, "utf-8");
        writer.writeStartDocument("utf-8", "1.1");
        getRecordWriter().writeRecord(writer, record);
        writer.writeEndDocument();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final XMLStreamException e) {
                ; // nothing to do
            }
        } // if
        if (out != null) {
            IOUtils.closeQuietly(out);
        }
    } // finally
    return out;
}

From source file:org.exist.webstart.JnlpWriter.java

/**
 * Write JNLP xml file to browser.//from w ww .j  av a 2 s.co  m
 *
 * @param response Object for writing to end user.
 * @throws java.io.IOException
 */
void writeJnlpXML(JnlpJarFiles jnlpFiles, HttpServletRequest request, HttpServletResponse response)
        throws IOException {

    logger.debug("Writing JNLP file");

    // Format URL: "http://host:8080/CONTEXT/webstart/exist.jnlp"
    final String currentUrl = request.getRequestURL().toString();

    // Find BaseUrl http://host:8080/CONTEXT
    final int webstartPos = currentUrl.indexOf("/webstart");
    final String existBaseUrl = currentUrl.substring(0, webstartPos);

    // Find codeBase for jarfiles http://host:8080/CONTEXT/webstart/
    final String codeBase = existBaseUrl + "/webstart/";

    // Perfom sanity checks
    int counter = 0;
    for (final File jar : jnlpFiles.getAllWebstartJars()) {
        counter++; // debugging
        if (jar == null || !jar.exists()) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "Missing Jar file! (" + counter + ")");
            return;
        }
    }

    // Find URL to connect to with client
    final String startUrl = existBaseUrl.replaceFirst("http:", "xmldb:exist:")
            .replaceFirst("https:", "xmldb:exist:").replaceAll("-", "%2D") + "/xmlrpc";

    //        response.setDateHeader("Last-Modified", mainJar.lastModified());
    response.setContentType("application/x-java-jnlp-file");
    try {
        final XMLStreamWriter writer = XMLOutputFactory.newInstance()
                .createXMLStreamWriter(response.getOutputStream());

        writer.writeStartDocument();
        writer.writeStartElement("jnlp");
        writer.writeAttribute("spec", "1.0+");
        writer.writeAttribute("codebase", codeBase);
        writer.writeAttribute("href", "exist.jnlp");

        writer.writeStartElement("information");

        writer.writeStartElement("title");
        writer.writeCharacters("eXist XML-DB client");
        writer.writeEndElement();

        writer.writeStartElement("vendor");
        writer.writeCharacters("exist-db.org");
        writer.writeEndElement();

        writer.writeStartElement("homepage");
        writer.writeAttribute("href", "http://exist-db.org");
        writer.writeEndElement();

        writer.writeStartElement("description");
        writer.writeCharacters("Integrated command-line and gui client, "
                + "entirely based on the XML:DB API and provides commands "
                + "for most database related tasks, like creating and "
                + "removing collections, user management, batch-loading " + "XML data or querying.");
        writer.writeEndElement();

        writer.writeStartElement("description");
        writer.writeAttribute("kind", "short");
        writer.writeCharacters("eXist XML-DB client");
        writer.writeEndElement();

        writer.writeStartElement("description");
        writer.writeAttribute("kind", "tooltip");
        writer.writeCharacters("eXist XML-DB client");
        writer.writeEndElement();

        writer.writeStartElement("icon");
        writer.writeAttribute("href", "jnlp_logo.jpg");
        writer.writeEndElement();

        writer.writeStartElement("icon");
        writer.writeAttribute("href", "jnlp_icon_128x128.gif");
        writer.writeAttribute("width", "128");
        writer.writeAttribute("height", "128");
        writer.writeEndElement();

        writer.writeStartElement("icon");
        writer.writeAttribute("href", "jnlp_icon_64x64.gif");
        writer.writeAttribute("width", "64");
        writer.writeAttribute("height", "64");
        writer.writeEndElement();

        writer.writeStartElement("icon");
        writer.writeAttribute("href", "jnlp_icon_32x32.gif");
        writer.writeAttribute("width", "32");
        writer.writeAttribute("height", "32");
        writer.writeEndElement();

        writer.writeEndElement(); // information

        writer.writeStartElement("security");
        writer.writeEmptyElement("all-permissions");
        writer.writeEndElement();

        // ----------

        writer.writeStartElement("resources");

        writer.writeStartElement("property");
        writer.writeAttribute("name", "jnlp.packEnabled");
        writer.writeAttribute("value", "true");
        writer.writeEndElement();

        writer.writeStartElement("j2se");
        writer.writeAttribute("version", "1.6+");
        writer.writeEndElement();

        for (final File jar : jnlpFiles.getAllWebstartJars()) {
            writer.writeStartElement("jar");
            writer.writeAttribute("href", jar.getName());
            writer.writeAttribute("size", "" + jar.length());
            writer.writeEndElement();
        }

        writer.writeEndElement(); // resources

        writer.writeStartElement("application-desc");
        writer.writeAttribute("main-class", "org.exist.client.InteractiveClient");

        writer.writeStartElement("argument");
        writer.writeCharacters("-ouri=" + startUrl);
        writer.writeEndElement();

        writer.writeStartElement("argument");
        writer.writeCharacters("--no-embedded-mode");
        writer.writeEndElement();

        if (request.isSecure()) {
            writer.writeStartElement("argument");
            writer.writeCharacters("--use-ssl");
            writer.writeEndElement();
        }

        writer.writeEndElement(); // application-desc

        writer.writeEndElement(); // jnlp

        writer.writeEndDocument();

        writer.flush();
        writer.close();

    } catch (final Throwable ex) {
        logger.error(ex);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    }

}