Package com.volantis.mps.message.store

Examples of com.volantis.mps.message.store.MessageStoreException


                    // Parse the XML to check for correct tags etc.
                    reader.parse(new InputSource(new StringReader(xml)));
                } catch (SAXException se) {
                    // Invalid XML
                    logger.error("xml-validation-failure", se);
                    throw new MessageStoreException(
                            localizer.format("xml-validation-failure"),
                            MessageStoreMessageEnumeration.NOT_ACCEPTABLE);
                }
            }

            // Store the xml to disk
            File file = null;
            do {
                // Generate or regenerate the ID.  It is possible that in the
                // intervening time another thread has used the id and written
                // a file!
                newID = generateValidID();
                file = createEntryFile(newID);
            } while (!file.createNewFile());

            // get the xml as a byte array using specified encoding in prolog
            // if available - we assume that the XML prolog provides the
            // definitive answer w.r.t. the XML encoding
            byte[] xmlBuffer = null;

            if (encoding != null) {
                xmlBuffer = xml.getBytes(encoding);
            } else {
                xmlBuffer = xml.getBytes();
            }

            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(file);
                fos.write(xmlBuffer, 0, xmlBuffer.length);
                fos.flush();
            } catch (IOException ioe) {
                if (file != null) {
                    // Tidy up in case writing failed
                    file.delete();
                }
                logger.error("xml-write-error", ioe);
                throw new MessageStoreException(
                        localizer.format("xml-write-error"),
                        MessageStoreMessageEnumeration.BAD_REQUEST);
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch(IOException ioe) {
                        // ignore
                    }
                }
            }

            synchronized (messageStoreIDs) {
                // Store the id/timestamp in the memory cache
                messageStoreIDs.put(newID, generateTimeStamp(file));
            }

        } catch (IOException ioe) {
            logger.error("xml-write-error", ioe);
            throw new MessageStoreException(
                    localizer.format("xml-write-error"),
                    MessageStoreMessageEnumeration.BAD_REQUEST);
        } catch (MessageStoreException mse) {
            logger.error("id-generation-error", mse);
            throw new MessageStoreException(
                    localizer.format("id-generation-error"),
                    MessageStoreMessageEnumeration.BAD_REQUEST);
        }

        return newID;
View Full Code Here


        }

        // If the count has reached the limit there are no more IDs available
        if (count.compareTo(limit) == 0) {
            logger.error("id-limit-reached", new Object[] {limit});
            throw new MessageStoreException(
                    localizer.format("id-limit-reached", new Object[]{limit}),
                    MessageStoreMessageEnumeration.INTERNAL_SERVER_ERROR);
        }

        return newID;
View Full Code Here

        File file = createEntryFile(id);

        // File not found
        if (!file.exists()) {
            logger.error("file-non-existant-for-id", id);
            throw new MessageStoreException(
                    localizer.format("file-non-existant-for-id"),
                    MessageStoreMessageEnumeration.NOT_FOUND);
        }

        try {
            FileInputStream fis = new FileInputStream(file);

            // Restore old timestamp
            if (oldTimestamp != null) {
                synchronized (messageStoreIDs) {
                    messageStoreIDs.put(id, oldTimestamp);
                }
            }

            processXML(request, response, fis);

        } catch (IOException ioe) {
            logger.error("xml-read-error", ioe);
            throw new MessageStoreException(
                    localizer.format("xml-read-error"),
                    MessageStoreMessageEnumeration.NOT_FOUND);
        } catch (MarinerContextException mce) {
            logger.error("device-processing-error", mce);
            throw new MessageStoreException(
                    localizer.format("device-processing-error"),
                    MessageStoreMessageEnumeration.NOT_FOUND);
        } catch (ServletException se) {
            logger.error("mcs-comms-error", se);
            throw new MessageStoreException(
                    localizer.format("mcs-comms-error"),
                    MessageStoreMessageEnumeration.NOT_FOUND);
        } catch (SAXException se) {
            logger.error("xml-parse-error", se);
            throw new MessageStoreException(
                    localizer.format("xml-parse-error"),
                    MessageStoreMessageEnumeration.NOT_FOUND);
        }
    }
View Full Code Here

TOP

Related Classes of com.volantis.mps.message.store.MessageStoreException

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.