Examples of RestXqServiceException


Examples of org.exquery.restxq.RestXqServiceException

                is = new CachingFilterInputStream(cache, is);
            }
           
            is.mark(Integer.MAX_VALUE);
        } catch(final IOException ioe) {
            throw new RestXqServiceException(RestXqErrorCodes.RQDY0014, ioe);
        }

        Sequence result = null;
        try {

            //was there any POST content?
            if(is != null && is.available() > 0) {
                String contentType = request.getContentType();
                // 1) determine if exists mime database considers this binary data
                if(contentType != null) {
                    //strip off any charset encoding info
                    if(contentType.indexOf(";") > -1) {
                        contentType = contentType.substring(0, contentType.indexOf(";"));
                    }

                    MimeType mimeType = MimeTable.getInstance().getContentType(contentType);
                    if(mimeType != null && !mimeType.isXMLType()) {

                        //binary data
                        try {
                           
                            final BinaryValue binaryValue = BinaryValueFromInputStream.getInstance(binaryValueManager, new Base64BinaryValueType(), is);
                            if(binaryValue != null) {
                                result = new SequenceImpl<BinaryValue>(new BinaryTypedValue(binaryValue));
                            }
                        } catch(final XPathException xpe) {
                            throw new RestXqServiceException(RestXqErrorCodes.RQDY0014, xpe);
                        }
                    }
                }

                if(result == null) {
                    //2) not binary, try and parse as an XML documemnt
                    final DocumentImpl doc = parseAsXml(is);
                    if(doc != null) {
                        result = new SequenceImpl<Document>(new DocumentTypedValue(doc));
                    }
                }

                if(result == null) {

                    String encoding = request.getCharacterEncoding();
                    // 3) not a valid XML document, return a string representation of the document
                    if(encoding == null) {
                        encoding = "UTF-8";
                    }

                    try {
                        //reset the stream, as we need to reuse for string parsing
                        is.reset();

                        final StringValue str = parseAsString(is, encoding);
                        if(str != null) {
                            result = new SequenceImpl<StringValue>(new StringTypedValue(str));
                        }
                    } catch(final IOException ioe) {
                        throw new RestXqServiceException(RestXqErrorCodes.RQDY0014, ioe);
                    }
                }
            }
        } catch (IOException e) {
            throw new RestXqServiceException(e.getMessage());
        } finally {

            if(cache != null) {
                try {
                    cache.invalidate();
View Full Code Here

Examples of org.exquery.restxq.RestXqServiceException

                OutputStream os = null;
                try {
                    os = response.getOutputStream();
                    binaryValue.streamBinaryTo(os);
                } catch(final IOException ioe) {
                    throw new RestXqServiceException("Error while serializing binary: " + ioe.toString(), ioe);
                } finally {
                    if(os != null) {
                        try {
                            os.close();
                        } catch (final IOException ioe) {
                            LOG.warn(ioe);
                        }
                    }
                }
               
                return; //TODO support more than one binary result -- multipart?
            } else {
                throw new RestXqServiceException("Expected binary value, but found: " + typedValue.getType().name());
            }
        }
    }
View Full Code Here

Examples of org.exquery.restxq.RestXqServiceException

 
            writer.flush();
            writer.close();
         
        } catch(IOException ioe) {   
            throw new RestXqServiceException("Error while serializing xml: " + ioe.toString(), ioe);
        } catch(EXistException ee) {  
            throw new RestXqServiceException("Error while serializing xml: " + ee.toString(), ee);
        } catch(SAXException se) {   
            throw new RestXqServiceException("Error while serializing xml: " + se.toString(), se);
        } finally {
            if(sax != null) {
                SerializerPool.getInstance().returnObject(sax);
            }
            if(broker != null) {
View Full Code Here

Examples of org.exquery.restxq.RestXqServiceException

            fnRef.analyze(new AnalyzeContextInfo());
            final org.exist.xquery.value.Sequence result = fnRef.evalFunction(null, null, fnArgs);
           
            return new SequenceAdapter(result);
        } catch(final URISyntaxException use) {
            throw new RestXqServiceException(use.getMessage(), use);
        } catch(final PermissionDeniedException pde) {
            throw new RestXqServiceException(pde.getMessage(), pde);
        } catch(final XPathException xpe) {
            throw new RestXqServiceException(xpe.getMessage(), xpe);
        } catch(final EXistException ee) {
            throw new RestXqServiceException(ee.getMessage(), ee);
        } finally {
           
            //clear down monitoring
            if(processMonitor != null) {
                xquery.getContext().getProfiler().traceQueryEnd(xquery.getContext());
View Full Code Here

Examples of org.exquery.restxq.RestXqServiceException

                convertedValue = value;
            }
           
        } catch(final XPathException xpe) {
            //TODO define an ErrorCode
            throw new RestXqServiceException("TODO need to implement error code for problem with parameter conversion!: " +  xpe.getMessage(), xpe);
        }
           
        return new TypedValue<X>() {

            @Override
View Full Code Here

Examples of org.exquery.restxq.RestXqServiceException

            writer.endElement();
            writer.endElement();
            writer.endDocument();
           
        } catch(IOException ioe) {   
            throw new RestXqServiceException("Error while serializing XML for exception '" + e.getClass().getName() + ":" + e.getMessage() + "': " + ioe.toString(), ioe);
        }
    }
View Full Code Here

Examples of org.exquery.restxq.RestXqServiceException

        if(strStatus != null && !strStatus.isEmpty()) {
            final int status = Integer.parseInt(strStatus);
            try {
                httpStatus = HttpStatus.fromStatus(status);
            } catch(final IllegalArgumentException iae) {
                throw new RestXqServiceException("Invalid HTTP Status in rest:response/@status: " + strStatus, iae);
            }
        }
       
        //get the reason (if present)
        final String reason = httpResponse.getAttribute(REASON_ATTR_NAME);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.