From: <del...@us...> - 2012-05-29 20:43:02
|
Revision: 16501 http://exist.svn.sourceforge.net/exist/?rev=16501&view=rev Author: deliriumsky Date: 2012-05-29 20:42:54 +0000 (Tue, 29 May 2012) Log Message: ----------- [refactor] further abstaction into EXQuery. Build is fixed. Persistence is temporarily disabled. More to come soon. Almost there!!! Modified Paths: -------------- branches/adam/project-sleepy/lib/core/exquery-annotations-common-1.0-SNAPSHOT.jar branches/adam/project-sleepy/lib/core/exquery-annotations-common-api-1.0-SNAPSHOT.jar branches/adam/project-sleepy/lib/core/exquery-common-1.0-SNAPSHOT.jar branches/adam/project-sleepy/lib/core/exquery-restxq-1.0-SNAPSHOT.jar branches/adam/project-sleepy/lib/core/exquery-restxq-api-1.0-SNAPSHOT.jar branches/adam/project-sleepy/lib/core/exquery-serialization-annotations-1.0-SNAPSHOT.jar branches/adam/project-sleepy/lib/core/exquery-serialization-annotations-api-1.0-SNAPSHOT.jar branches/adam/project-sleepy/lib/core/exquery-xquery-1.0-SNAPSHOT.jar branches/adam/project-sleepy/lib/core/exquery-xquery3-1.0-SNAPSHOT.jar branches/adam/project-sleepy/src/org/exist/http/sleepy/RESTfulXQueryService.java branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/CompiledHTTPRESTfulXQueryCache.java branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryService.java branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryServiceRegistry.java branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryServlet.java branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/RESTResponse.java branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/URIOrderedHttpMethodList.java branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/XQueryCompilationTrigger.java Modified: branches/adam/project-sleepy/lib/core/exquery-annotations-common-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/lib/core/exquery-annotations-common-api-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/lib/core/exquery-common-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/lib/core/exquery-restxq-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/lib/core/exquery-restxq-api-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/lib/core/exquery-serialization-annotations-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/lib/core/exquery-serialization-annotations-api-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/lib/core/exquery-xquery-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/lib/core/exquery-xquery3-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Modified: branches/adam/project-sleepy/src/org/exist/http/sleepy/RESTfulXQueryService.java =================================================================== --- branches/adam/project-sleepy/src/org/exist/http/sleepy/RESTfulXQueryService.java 2012-05-29 17:07:57 UTC (rev 16500) +++ branches/adam/project-sleepy/src/org/exist/http/sleepy/RESTfulXQueryService.java 2012-05-29 20:42:54 UTC (rev 16501) @@ -55,5 +55,5 @@ public boolean canService(final HttpRequest httpRequest); //TODO how to remove DBBroker from here, inject in an interface for context? - public void service(final DBBroker broker, final HttpRequest httpRequest, final HttpResponse httpResponse); + public void service(final DBBroker broker, final HttpRequest httpRequest, final HttpResponse httpResponse) throws RESTfulXQueryServiceException; } \ No newline at end of file Modified: branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/CompiledHTTPRESTfulXQueryCache.java =================================================================== --- branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/CompiledHTTPRESTfulXQueryCache.java 2012-05-29 17:07:57 UTC (rev 16500) +++ branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/CompiledHTTPRESTfulXQueryCache.java 2012-05-29 20:42:54 UTC (rev 16501) @@ -68,7 +68,7 @@ } if(xquery == null) { - xquery = XQueryCompiler.compile(broker, service.getXQueryLocation()); + xquery = XQueryCompiler.compile(broker, service.getResourceFunction().getXQueryLocation()); } //reset the state of the query Modified: branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryService.java =================================================================== --- branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryService.java 2012-05-29 17:07:57 UTC (rev 16500) +++ branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryService.java 2012-05-29 20:42:54 UTC (rev 16501) @@ -26,12 +26,9 @@ */ package org.exist.http.sleepy.impl; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; +import java.io.*; +import java.util.*; import java.util.Map.Entry; -import java.util.*; import javax.xml.transform.OutputKeys; import org.apache.commons.io.input.CloseShieldInputStream; import org.exist.dom.NodeSet; @@ -39,11 +36,6 @@ import org.exist.http.BadRequestException; import org.exist.http.sleepy.RESTfulXQueryService; import org.exist.http.sleepy.RESTfulXQueryServiceException; -import org.exist.http.sleepy.annotations.BinaryTypedParameter; -import org.exist.http.sleepy.annotations.DefaultTypedParameter; -import org.exquery.xquery.TypedParameter; -import org.exquery.serialization.annotations.MethodAnnotation; -import org.exist.http.sleepy.annotations.output.SerializationAnnotation; import org.exist.http.sleepy.impl.adapters.TypeAdapter; import org.exist.memtree.DocumentImpl; import org.exist.memtree.ElementImpl; @@ -53,6 +45,7 @@ import org.exist.storage.serializers.EXistOutputKeys; import org.exist.storage.serializers.Serializer; import org.exist.util.MimeType; +import org.exist.util.serializer.AttrList; import org.exist.util.serializer.SAXSerializer; import org.exist.util.serializer.SerializerPool; import org.exist.xquery.*; @@ -61,11 +54,17 @@ import org.exquery.http.HttpMethod; import org.exquery.http.HttpRequest; import org.exquery.http.HttpResponse; +import org.exquery.restxq.Namespace; import org.exquery.restxq.ResourceFunction; import org.exquery.restxq.annotation.HttpMethodAnnotation; +import org.exquery.restxq.annotation.HttpMethodWithBodyAnnotation; import org.exquery.restxq.annotation.ParameterAnnotation; +import org.exquery.serialization.annotation.MethodAnnotation; +import org.exquery.serialization.annotation.SerializationAnnotation; import org.exquery.xquery.FunctionArgument; import org.exquery.xquery.FunctionSignature; +import org.exquery.xquery.TypedArgumentValue; +import org.exquery.xquery.TypedValue; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -132,9 +131,9 @@ return resourceFunction; } - private EnumSet<HttpMethod> getServicedMethods() { + public EnumSet<HttpMethod> getServicedMethods() { final EnumSet<HttpMethod> servicedMethods = EnumSet.noneOf(HttpMethod.class); - for(HttpMethodAnnotation httpMethodAnnotation : getResourceFunction().getHttpMethodAnnotations()) { + for(final HttpMethodAnnotation httpMethodAnnotation : getResourceFunction().getHttpMethodAnnotations()) { servicedMethods.add(httpMethodAnnotation.getHttpMethod()); } return servicedMethods; @@ -185,7 +184,7 @@ } @Override - public void service(final DBBroker broker, final HttpRequest request, HttpResponse response) { + public void service(final DBBroker broker, final HttpRequest request, HttpResponse response) throws RESTfulXQueryServiceException { final CompiledHTTPRESTfulXQueryCache cache = CompiledHTTPRESTfulXQueryCache.getInstance(); CompiledXQuery xquery = null; @@ -213,12 +212,10 @@ //serialize the results serialize(result, response, broker); - } catch(RESTfulXQueryServiceException se) { - serializeExceptionResponse(response, se); } catch(XPathException xpe) { - serializeExceptionResponse(response, xpe); + throw new RESTfulXQueryServiceException(xpe.getMessage(), xpe); } catch(BadRequestException bde) { - serializeExceptionResponse(response, bde); + throw new RESTfulXQueryServiceException(bde.getMessage(), bde); } finally { //clear down monitoring @@ -232,28 +229,39 @@ } } + private Set<HttpMethodWithBodyAnnotation> getBodyContentAnnotations() { + final Set<HttpMethodWithBodyAnnotation> bodyContentAnnotations = new HashSet<HttpMethodWithBodyAnnotation>(); + for(final HttpMethodAnnotation methodAnnotation : getResourceFunction().getHttpMethodAnnotations()) { + if(methodAnnotation instanceof HttpMethodWithBodyAnnotation) { + bodyContentAnnotations.add((HttpMethodWithBodyAnnotation)methodAnnotation); + } + } + return bodyContentAnnotations; + } + private FunctionCall createFunctionCall(final CompiledXQuery xquery, final UserDefinedFunction fn, final HttpRequest request) throws XPathException { final FunctionCall fnCall = new FunctionCall(xquery.getContext(), fn); + final Map<String, Item> paramNameValues = new HashMap<String, Item>(); - final Map<String, String> paramNameValues = new HashMap<String, String>(); - //extract the param mappings for the Path Annotation - paramNameValues.putAll(getResourceFunction().getPathAnnotation().extractPathParameters(request.getPath())); + for(Entry<String, String> pathParameter : getResourceFunction().getPathAnnotation().extractPathParameters(request.getPath()).entrySet()) { + paramNameValues.put(pathParameter.getKey(), new StringValue(pathParameter.getValue())); + } //extract the param mappings for the Body Content Annotations if(!getBodyContentAnnotations().isEmpty()) { final Item requestBody = parseRequestBody(xquery.getContext(), request); - for(AbstractBodyContentAnnotation bodyContentAnnotation : getBodyContentAnnotations()) { - paramNameValues.put(bodyContentAnnotation.getBodyFnParamName(), requestBody); + for(final HttpMethodWithBodyAnnotation bodyContentAnnotation : getBodyContentAnnotations()) { + paramNameValues.put(bodyContentAnnotation.getBodyParameterName(), requestBody); } } //extract the param mappings for Param Annotations - for(ParameterAnnotation parameterAnnotation : getResourceFunction().getParameterAnnotations()) { - final Entry<String, TypedParameter> paramNameValue = parameterAnnotation.extractParameter(request); - paramNameValues.put(paramNameValue.getKey(), typedParameterToItem(xquery.getContext(), paramNameValue.getValue())); + for(final ParameterAnnotation parameterAnnotation : getResourceFunction().getParameterAnnotations()) { + final TypedArgumentValue typedArgumentValue = parameterAnnotation.extractParameter(request); + paramNameValues.put(typedArgumentValue.getArgumentName(), typedValueToItem(xquery.getContext(), typedArgumentValue.getTypedValue())); } @@ -408,7 +416,7 @@ private void processSerializationAnnotations(final Properties outputProperties) { //get the serialzation annotations - for(SerializationAnnotation serializationAnnotation : getSerializationAnnotations()) { + for(SerializationAnnotation serializationAnnotation : getResourceFunction().getSerializationAnnotations()) { if(serializationAnnotation instanceof MethodAnnotation) { final String method = ((MethodAnnotation)serializationAnnotation).getMethod(); outputProperties.setProperty("method", method); @@ -470,7 +478,7 @@ try { sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class); - Writer writer = new OutputStreamWriter(response.getOutputStream(), outputProperties.getProperty(OutputKeys.ENCODING)); + final Writer writer = new OutputStreamWriter(response.getOutputStream(), outputProperties.getProperty(OutputKeys.ENCODING)); sax.setOutput(writer, outputProperties); serializer.setProperties(outputProperties); @@ -483,23 +491,84 @@ writer.close(); } catch(IOException ioe) { - throw new BadRequestException("Error while serializing xml: " + ioe.toString(), ioe); + throw new BadRequestException("Error while serializing XML: " + ioe.toString(), ioe); } catch(SAXException se) { - throw new BadRequestException("Error while serializing xml: " + se.toString(), se); + throw new BadRequestException("Error while serializing XML: " + se.toString(), se); } finally { if(sax != null) { SerializerPool.getInstance().returnObject(sax); } } } + + public void serializeExceptionResponse(final HttpResponse response, final Exception e, final DBBroker broker) throws BadRequestException { + //serialize the exception + final Serializer serializer = broker.getSerializer(); + serializer.reset(); + SAXSerializer sax = null; + try { + sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class); + + final Properties outputProperties = new Properties(); + outputProperties.putAll(DEFAULT_SERIALIZATION_PROPERTIES); + + final Writer writer = new OutputStreamWriter(response.getOutputStream(), outputProperties.getProperty(OutputKeys.ENCODING)); + sax.setOutput(writer, outputProperties); + + serializer.setProperties(outputProperties); + serializer.setSAXHandlers(sax, sax); + + final QName qnResponse = new QName("response", Namespace.ANNOTATION_NS); + final QName qnException = new QName("exception", Namespace.ANNOTATION_ERROR_NS); + final QName message = new QName("message", Namespace.ANNOTATION_ERROR_NS); + final QName qnStack = new QName("stack", Namespace.ANNOTATION_ERROR_NS); - private Item typedParameterToItem(final XQueryContext context, final TypedParameter typedParameter) throws XPathException { - if(typedParameter instanceof DefaultTypedParameter) { - return new StringValue(((DefaultTypedParameter)typedParameter).getValue()); - } else if(typedParameter instanceof BinaryTypedParameter) { - return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), ((BinaryTypedParameter)typedParameter).getValue()); + sax.startDocument(); + sax.startElement(qnResponse, null); + sax.startElement(qnException, null); + sax.startElement(message, null); + sax.characters(e.getClass().getName() + ": " + e.getLocalizedMessage()); + + final StackTraceElement[] trace = e.getStackTrace(); + for(final StackTraceElement element : trace) { + + final AttrList attrs = new AttrList(){{ + addAttribute(new QName("file"), element.getFileName()); + addAttribute(new QName("class"), element.getClassName()); + addAttribute(new QName("method"), element.getMethodName()); + addAttribute(new QName("line"), Integer.toString(element.getLineNumber())); + }}; + + sax.startElement(qnStack, attrs); + sax.endElement(qnStack); + } + + sax.endElement(message); + sax.endElement(qnException); + sax.endElement(qnResponse); + sax.endDocument(); + + writer.flush(); + writer.close(); + + } catch(IOException ioe) { + throw new BadRequestException("Error while serializing XML for exception '" + e.getClass().getName() + ":" + e.getMessage() + "': " + ioe.toString(), ioe); + } catch(SAXException se) { + throw new BadRequestException("Error while serializing XML for exception '" + e.getClass().getName() + ":" + e.getMessage() + "': " + se.toString(), se); + } finally { + if(sax != null) { + SerializerPool.getInstance().returnObject(sax); + } + } + } + + private Item typedValueToItem(final XQueryContext context, final TypedValue typedValue) throws XPathException { + if(typedValue.getType().equals(org.exquery.xquery.Type.STRING)) { + return new StringValue((String)typedValue.getValue()); + } else if(typedValue.getType().equals(org.exquery.xquery.Type.BASE64_BINARY)) { + return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), (InputStream)typedValue.getValue()); } else { - throw new XPathException("Could not convert TypedParameter: " + typedParameter.getClass().getName() + " to org.exist.xquery.value.Item"); + throw new XPathException("Could not convert TypedValue of type: " + typedValue.getType().name() + " for class " + typedValue.getValue().getClass().getName() + " to org.exist.xquery.value.Item"); } } Modified: branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryServiceRegistry.java =================================================================== --- branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryServiceRegistry.java 2012-05-29 17:07:57 UTC (rev 16500) +++ branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryServiceRegistry.java 2012-05-29 20:42:54 UTC (rev 16501) @@ -26,20 +26,15 @@ */ package org.exist.http.sleepy.impl; -import java.io.*; -import java.lang.reflect.Constructor; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; import java.net.URI; -import java.util.*; -import org.apache.commons.io.FileUtils; +import java.util.EnumSet; +import java.util.List; import org.exist.http.sleepy.RESTfulXQueryService; import org.exist.http.sleepy.RESTfulXQueryServiceRegistry; -import org.exist.http.sleepy.annotations.AnnotationWrapper; -import org.exist.http.sleepy.annotations.output.SerializationAnnotation; -import org.exist.http.sleepy.annotations.rest.AbstractBodyContentAnnotation; -import org.exquery.restxq.impl.annotation.AbstractParameterAnnotation; -import org.exist.http.sleepy.annotations.rest.PathAnnotation; -import org.exist.http.sleepy.impl.URIOrderedHttpMethodList.ListTask; -import org.exist.http.sleepy.impl.adapters.AnnotationAdapter; import org.exquery.http.HttpMethod; import org.exquery.http.HttpRequest; @@ -97,93 +92,93 @@ } public void loadState(final File dataDir) throws IOException { - getServices().executeExclusiveWrite(new ListTask<HttpMethod, HTTPRESTfulXQueryService>(){ - @Override - public void execute(Map<HttpMethod, List<HTTPRESTfulXQueryService>> uriOrderedMethodList) throws IOException { - - //clear the registry - empty(uriOrderedMethodList); - - final File fRegistry = new File(dataDir, REGISTRY_FILENAME); - DataInputStream is = null; - try { - is = new DataInputStream(new BufferedInputStream(new FileInputStream(fRegistry))); - final byte onDiskVersion = is.readByte(); - if(onDiskVersion != ON_DISK_VERSION) { - throw new IOException("Expected Registry file version: " + ON_DISK_VERSION + " but got version: " + onDiskVersion); - } - - final int serviceCount = is.readInt(); - for(int i = 0; i < serviceCount; i++) { - final HTTPRESTfulXQueryService service = new HTTPRESTfulXQueryService(); - loadServiceState(is, service); - register(service); - } - - } finally { - if(is != null) { - is.close(); - } - } - } - - private void empty(final Map<HttpMethod, List<HTTPRESTfulXQueryService>> uriOrderedMethodList) { - - final Set<RESTfulXQueryService> uniqueServices = new HashSet<RESTfulXQueryService>(); - for(List<HTTPRESTfulXQueryService> services : uriOrderedMethodList.values()) { - for(RESTfulXQueryService Service: services) { - uniqueServices.add(Service); - } - } - - //remove the compiled representations form the Cache - CompiledHTTPRESTfulXQueryCache.getInstance().removeServices(uniqueServices); - - //empty the list - uriOrderedMethodList.clear(); - } - }); +// getServices().executeExclusiveWrite(new ListTask<HttpMethod, HTTPRESTfulXQueryService>(){ +// @Override +// public void execute(Map<HttpMethod, List<HTTPRESTfulXQueryService>> uriOrderedMethodList) throws IOException { +// +// //clear the registry +// empty(uriOrderedMethodList); +// +// final File fRegistry = new File(dataDir, REGISTRY_FILENAME); +// DataInputStream is = null; +// try { +// is = new DataInputStream(new BufferedInputStream(new FileInputStream(fRegistry))); +// final byte onDiskVersion = is.readByte(); +// if(onDiskVersion != ON_DISK_VERSION) { +// throw new IOException("Expected Registry file version: " + ON_DISK_VERSION + " but got version: " + onDiskVersion); +// } +// +// final int serviceCount = is.readInt(); +// for(int i = 0; i < serviceCount; i++) { +// final HTTPRESTfulXQueryService service = new HTTPRESTfulXQueryService(); +// loadServiceState(is, service); +// register(service); +// } +// +// } finally { +// if(is != null) { +// is.close(); +// } +// } +// } +// +// private void empty(final Map<HttpMethod, List<HTTPRESTfulXQueryService>> uriOrderedMethodList) { +// +// final Set<RESTfulXQueryService> uniqueServices = new HashSet<RESTfulXQueryService>(); +// for(List<HTTPRESTfulXQueryService> services : uriOrderedMethodList.values()) { +// for(RESTfulXQueryService Service: services) { +// uniqueServices.add(Service); +// } +// } +// +// //remove the compiled representations form the Cache +// CompiledHTTPRESTfulXQueryCache.getInstance().removeServices(uniqueServices); +// +// //empty the list +// uriOrderedMethodList.clear(); +// } +// }); } public void saveState(final File dataDir) throws IOException { - getServices().executeExclusiveRead(new ListTask<HttpMethod, HTTPRESTfulXQueryService>(){ - @Override - public void execute(final Map<HttpMethod, List<HTTPRESTfulXQueryService>> uriOrderedMethodList) throws IOException { - - final File fNewRegistry = new File(dataDir, REGISTRY_FILENAME_TMP); - DataOutputStream os = null; - try { - os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fNewRegistry))); - os.write(ON_DISK_VERSION); - - final Set<HTTPRESTfulXQueryService> distinctServices = new HashSet<HTTPRESTfulXQueryService>(); - - //serialize each service - for(final List<HTTPRESTfulXQueryService> servicesList : uriOrderedMethodList.values()) { - for(final HTTPRESTfulXQueryService service : servicesList) { - if(!distinctServices.contains(service)) { - distinctServices.add(service); - } - } - } - - os.writeInt(distinctServices.size()); - for(HTTPRESTfulXQueryService service : distinctServices) { - saveServiceState(os, service); - } - } finally { - if(os != null) { - os.close(); - } - } - - //replace the old file with the new file - final File fRegistry = new File(dataDir, REGISTRY_FILENAME); - FileUtils.deleteQuietly(fRegistry); - FileUtils.moveFile(fNewRegistry, fRegistry); - } - }); +// getServices().executeExclusiveRead(new ListTask<HttpMethod, HTTPRESTfulXQueryService>(){ +// @Override +// public void execute(final Map<HttpMethod, List<HTTPRESTfulXQueryService>> uriOrderedMethodList) throws IOException { +// +// final File fNewRegistry = new File(dataDir, REGISTRY_FILENAME_TMP); +// DataOutputStream os = null; +// try { +// os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fNewRegistry))); +// os.write(ON_DISK_VERSION); +// +// final Set<HTTPRESTfulXQueryService> distinctServices = new HashSet<HTTPRESTfulXQueryService>(); +// +// //serialize each service +// for(final List<HTTPRESTfulXQueryService> servicesList : uriOrderedMethodList.values()) { +// for(final HTTPRESTfulXQueryService service : servicesList) { +// if(!distinctServices.contains(service)) { +// distinctServices.add(service); +// } +// } +// } +// +// os.writeInt(distinctServices.size()); +// for(HTTPRESTfulXQueryService service : distinctServices) { +// saveServiceState(os, service); +// } +// } finally { +// if(os != null) { +// os.close(); +// } +// } +// +// //replace the old file with the new file +// final File fRegistry = new File(dataDir, REGISTRY_FILENAME); +// FileUtils.deleteQuietly(fRegistry); +// FileUtils.moveFile(fNewRegistry, fRegistry); +// } +// }); } /** @@ -203,77 +198,79 @@ */ private void saveServiceState(final DataOutputStream os, final HTTPRESTfulXQueryService service) throws IOException { - os.writeUTF(service.getXQueryLocation().toString()); - - os.writeInt(service.getServicedMethods().size()); - for(final HttpMethod servicedMethod : service.getServicedMethods()) { - os.writeInt(servicedMethod.ordinal()); - } - - final List<AnnotationWrapper> allAnnotations = new ArrayList<AnnotationWrapper>(); - allAnnotations.add(service.getPathAnnotation()); - allAnnotations.addAll(service.getSerializationAnnotations()); - allAnnotations.addAll(service.getBodyContentAnnotations()); - allAnnotations.addAll(service.getParamAnnotations()); - allAnnotations.addAll(service.getOtherAnnotations()); - - os.writeInt(allAnnotations.size()); - - for(final AnnotationWrapper an : allAnnotations) { - an.serialize(os); - } +// os.writeUTF(service.getXQueryLocation().toString()); +// +// os.writeInt(service.getServicedMethods().size()); +// for(final HttpMethod servicedMethod : service.getServicedMethods()) { +// os.writeInt(servicedMethod.ordinal()); +// } +// +// final List<AnnotationWrapper> allAnnotations = new ArrayList<AnnotationWrapper>(); +// allAnnotations.add(service.getPathAnnotation()); +// allAnnotations.addAll(service.getSerializationAnnotations()); +// allAnnotations.addAll(service.getBodyContentAnnotations()); +// allAnnotations.addAll(service.getParamAnnotations()); +// allAnnotations.addAll(service.getOtherAnnotations()); +// +// os.writeInt(allAnnotations.size()); +// +// for(final AnnotationWrapper an : allAnnotations) { +// an.serialize(os); +// } } public void loadServiceState(final DataInputStream is, final HTTPRESTfulXQueryService service) throws IOException { - service.setXQueryLocation(URI.create(is.readUTF())); - final int servicedMethodsSize = is.readInt(); - service.getServicedMethods().clear(); - for(int i = 0; i < servicedMethodsSize; i++) { - final int servicedMethodOrdinal = is.readInt(); - service.getServicedMethods().add(HttpMethod.values()[servicedMethodOrdinal]); - } - /* following is AnnotationWrappers */ - //1) clear any annotations - service.setPathAnnotation(null); - service.getSerializationAnnotations().clear(); - service.getBodyContentAnnotations().clear(); - service.getParamAnnotations().clear(); - service.getOtherAnnotations().clear(); - - //2) load annotations - try { - final int annotationWrappers = is.readInt(); - for(int i = 0; i < annotationWrappers; i++) { - final String className = is.readUTF(); - - final Class clazz = Class.forName(className); - final Constructor cstrAnnotationWrapper = clazz.getConstructor(org.exquery.xquery3.Annotation.class); - - final AnnotationAdapter annotation = new AnnotationAdapter(); - annotation.deserialize(is); - - final AnnotationWrapper aw = (AnnotationWrapper)cstrAnnotationWrapper.newInstance(annotation); - aw.initialise(); - - if(aw instanceof PathAnnotation) { - service.setPathAnnotation((PathAnnotation)aw); - } else if(aw instanceof SerializationAnnotation) { - service.getSerializationAnnotations().add((SerializationAnnotation)aw); - } else if(aw instanceof AbstractBodyContentAnnotation) { - service.getBodyContentAnnotations().add((AbstractBodyContentAnnotation)aw); - } else if(aw instanceof AbstractParameterAnnotation) { - service.getParamAnnotations().add((AbstractParameterAnnotation)aw); - } else { - service.getOtherAnnotations().add(aw); - } - } - } catch(Exception e) { - throw new IOException(e.getMessage(), e); - //TODO perhaps should throw different exception, like RESTFulXQueryService exception - propbably best to externalise serialization - } +// service.setXQueryLocation(URI.create(is.readUTF())); +// +// final int servicedMethodsSize = is.readInt(); +// service.getServicedMethods().clear(); +// for(int i = 0; i < servicedMethodsSize; i++) { +// final int servicedMethodOrdinal = is.readInt(); +// service.getServicedMethods().add(HttpMethod.values()[servicedMethodOrdinal]); +// } +// +// /* following is AnnotationWrappers */ +// //1) clear any annotations +// service.setPathAnnotation(null); +// service.getSerializationAnnotations().clear(); +// service.getBodyContentAnnotations().clear(); +// service.getParamAnnotations().clear(); +// service.getOtherAnnotations().clear(); +// +// //2) load annotations +// try { +// final int annotationWrappers = is.readInt(); +// for(int i = 0; i < annotationWrappers; i++) { +// final String className = is.readUTF(); +// +// final Class clazz = Class.forName(className); +// final Constructor cstrAnnotationWrapper = clazz.getConstructor(org.exquery.xquery3.Annotation.class); +// +// final AnnotationAdapter annotation = new AnnotationAdapter(); +// annotation.deserialize(is); +// +// final AnnotationWrapper aw = (AnnotationWrapper)cstrAnnotationWrapper.newInstance(annotation); +// aw.initialise(); +// +// if(aw instanceof PathAnnotation) { +// service.setPathAnnotation((PathAnnotation)aw); +// } else if(aw instanceof SerializationAnnotation) { +// service.getSerializationAnnotations().add((SerializationAnnotation)aw); +// } else if(aw instanceof AbstractBodyContentAnnotation) { +// service.getBodyContentAnnotations().add((AbstractBodyContentAnnotation)aw); +// } else if(aw instanceof AbstractParameterAnnotation) { +// service.getParamAnnotations().add((AbstractParameterAnnotation)aw); +// } else { +// service.getOtherAnnotations().add(aw); +// } +// } +// } catch(Exception e) { +// throw new IOException(e.getMessage(), e); +// //TODO perhaps should throw different exception, like RESTFulXQueryService exception - propbably best to externalise serialization +// } } private URIOrderedHttpMethodList<HttpMethod, HTTPRESTfulXQueryService> getServices() { Modified: branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryServlet.java =================================================================== --- branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryServlet.java 2012-05-29 17:07:57 UTC (rev 16500) +++ branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/HTTPRESTfulXQueryServlet.java 2012-05-29 20:42:54 UTC (rev 16501) @@ -36,6 +36,7 @@ import org.exist.EXistException; import org.exist.http.servlets.AbstractExistHttpServlet; import org.exist.http.sleepy.RESTfulXQueryService; +import org.exist.http.sleepy.RESTfulXQueryServiceException; import org.exist.http.sleepy.impl.adapters.HttpServletRequestAdapter; import org.exist.http.sleepy.impl.adapters.HttpServletResponseAdapter; import org.exist.security.Subject; @@ -44,7 +45,6 @@ import org.exist.util.Configuration; import org.exist.util.io.FilterInputStreamCacheFactory.FilterInputStreamCacheConfiguration; import org.exquery.http.HttpMethod; -import org.exquery.http.HttpMethod; import org.exquery.http.HttpRequest; /** @@ -133,6 +133,9 @@ } catch(EXistException ee) { getLog().error(ee.getMessage(), ee); throw new ServletException(ee.getMessage(), ee); + } catch(RESTfulXQueryServiceException rqse) { + getLog().error(rqse.getMessage(), rqse); + throw new ServletException(rqse.getMessage(), rqse); } finally { if(broker != null) { getPool().release(broker); Modified: branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/RESTResponse.java =================================================================== --- branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/RESTResponse.java 2012-05-29 17:07:57 UTC (rev 16500) +++ branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/RESTResponse.java 2012-05-29 20:42:54 UTC (rev 16501) @@ -28,9 +28,9 @@ import java.util.Properties; import org.exist.dom.QName; -import org.exquery.restxq.Namespace; import static org.expath.httpclient.HttpConstants.HTTP_CLIENT_NS_URI; import org.exquery.http.HttpResponse; +import org.exquery.restxq.Namespace; import org.w3c.dom.Element; import org.w3c.dom.NodeList; Modified: branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/URIOrderedHttpMethodList.java =================================================================== --- branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/URIOrderedHttpMethodList.java 2012-05-29 17:07:57 UTC (rev 16500) +++ branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/URIOrderedHttpMethodList.java 2012-05-29 20:42:54 UTC (rev 16501) @@ -86,7 +86,7 @@ final List<V> serviceList = uriOrderedMethodList.get(key); for(V service : serviceList) { - if(service.getXQueryLocation().equals(uri)) { + if(service.getResourceFunction().getXQueryLocation().equals(uri)) { //remove the compiled representations form the Cache CompiledHTTPRESTfulXQueryCache.getInstance().removeService(service); Modified: branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/XQueryCompilationTrigger.java =================================================================== --- branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/XQueryCompilationTrigger.java 2012-05-29 17:07:57 UTC (rev 16500) +++ branches/adam/project-sleepy/src/org/exist/http/sleepy/impl/XQueryCompilationTrigger.java 2012-05-29 20:42:54 UTC (rev 16501) @@ -28,9 +28,7 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.util.*; import org.exist.collections.triggers.FilteringTrigger; import org.exist.collections.triggers.TriggerException; import org.exist.dom.DocumentImpl; @@ -42,8 +40,10 @@ import org.exist.xquery.Annotation; import org.exist.xquery.CompiledXQuery; import org.exist.xquery.UserDefinedFunction; -import org.exquery.annotation.AnnotationException; +import org.exquery.ExQueryException; import org.exquery.restxq.ResourceFunction; +import org.exquery.restxq.impl.ResourceFunctionFactory; +import org.exquery.restxq.impl.annotation.RestAnnotationFactory; /** * @@ -156,27 +156,21 @@ final UserDefinedFunction function = itFunctions.next(); final Annotation annotations[] = function.getSignature().getAnnotations(); - - - - - - - List<AnnotationWrapper> functionRestAnnotations = null; + Set<org.exquery.xquery3.Annotation> functionRestAnnotations = null; //process the function annotations for(final Annotation annotation : annotations) { if(RestAnnotationFactory.isRestXqAnnotation(annotation.getName().toJavaQName())) { - final AnnotationWrapper restAnnotation = RestAnnotationFactory.getAnnotation(new AnnotationAdapter(annotation)); + final org.exquery.xquery3.Annotation restAnnotation = RestAnnotationFactory.getAnnotation(new AnnotationAdapter(annotation)); if(functionRestAnnotations == null) { - functionRestAnnotations = new ArrayList<AnnotationWrapper>(); + functionRestAnnotations = new HashSet<org.exquery.xquery3.Annotation>(); } functionRestAnnotations.add(restAnnotation); } } if(functionRestAnnotations != null) { - final ResourceFunction resourceFunction = ResourceFunctionFactory.create(document.getURI(), functionRestAnnotations); + final ResourceFunction resourceFunction = ResourceFunctionFactory.create(document.getURI().getURI(), functionRestAnnotations); final HTTPRESTfulXQueryService service = new HTTPRESTfulXQueryService(resourceFunction); //add service and compiled query to the cache @@ -188,8 +182,8 @@ } } catch(RESTfulXQueryServiceCompilationException ce) { throw new TriggerException(ce.getMessage(), ce); - } catch(AnnotationException rae) { - throw new TriggerException(rae.getMessage(), rae); + } catch(ExQueryException exqe) { + throw new TriggerException(exqe.getMessage(), exqe); } return services; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |