Package org.exquery.xquery

Examples of org.exquery.xquery.Sequence


            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();
                } catch(final IOException ioe) {
                    LOG.error(ioe.getMessage(), ioe);
                }
            }

            if(is != null) {
                /*
                 * Do NOT close the stream if its a binary value,
                 * because we will need it later for serialization
                 */
                boolean isBinaryType = false;
                if(result != null) {
                    try {
                        final Type type = result.head().getType();
                        isBinaryType = (type == Type.BASE64_BINARY || type == Type.HEX_BINARY);
                    } catch(final IndexOutOfBoundsException ioe) {
                        LOG.warn("Called head on an empty HTTP Request body sequence", ioe);
                    }
                }
View Full Code Here


    @Override
    public void service(final HttpRequest request, final HttpResponse response, final ResourceFunctionExecuter resourceFunctionExecuter, final RestXqServiceSerializer restXqServiceSerializer) throws RestXqServiceException {
       
        final Set<TypedArgumentValue> typedArgumentValues = extractParameters(request);
       
        final Sequence result = resourceFunctionExecuter.execute(getResourceFunction(), typedArgumentValues, request);
       
        restXqServiceSerializer.serialize(result, getResourceFunction().getSerializationAnnotations(), response);
    }
View Full Code Here

            }
        }
       
        //extract the param mappings for the Body Content Annotations
        if(!getBodyContentAnnotations().isEmpty()) {
            final Sequence requestBody = extractRequestBody(request);
            for(final HttpMethodWithBodyAnnotation bodyContentAnnotation : getBodyContentAnnotations()) {
                paramNameValues.add(new TypedArgumentValue(){
                    @Override
                    public String getArgumentName() {
                        return bodyContentAnnotation.getBodyParameterName();
View Full Code Here

               
                processSerializationAnnotations(serializationAnnotations, serializationProperties);
                new RestResponseHandler().process(elem, serializationProperties, response);
                if(itResult.hasNext()) {
                   
                    final Sequence seqBody = result.tail();
                    serializeBody(seqBody, response, serializationProperties);
                }
            } else {
                //serialize just the body
                processSerializationAnnotations(serializationAnnotations, serializationProperties);
View Full Code Here

TOP

Related Classes of org.exquery.xquery.Sequence

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.