@Override public <T extends TextReadHandle> T readServices(String resourceName, T sourceHandle) { if (resourceName == null) throw new IllegalArgumentException("Reading resource services source with null name"); if (logger.isInfoEnabled()) logger.info("Reading resource services source for {}", resourceName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "resource"); sourceBase.receiveContent( services.getValue(requestLogger, "config/resources", resourceName, true, sourceBase.getMimetype(), sourceBase.receiveAs()) ); return sourceHandle; }
private void writeTransform( String transformName, String sourceMimetype, AbstractWriteHandle sourceHandle, ExtensionMetadata metadata) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { if (transformName == null) throw new IllegalArgumentException("Writing transform with null name"); if (sourceHandle == null) throw new IllegalArgumentException("Writing transform source with null handle"); if (logger.isInfoEnabled()) logger.info("Writing transform source for {}", transformName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "transform"); Format sourceFormat = sourceBase.getFormat(); if ("application/xquery".equals(sourceMimetype)) { if (Format.TEXT != sourceFormat) sourceBase.setFormat(Format.TEXT); } else if ("application/xslt+xml".equals(sourceMimetype)) { if (Format.XML != sourceFormat) sourceBase.setFormat(Format.XML); } else if ("application/javascript".equals(sourceMimetype)) { if (Format.JSON != sourceFormat) sourceBase.setFormat(Format.JSON); } else { throw new MarkLogicInternalException( "Unsupported mimetype for source: "+sourceMimetype); } if (!sourceMimetype.equals(sourceBase.getMimetype())) sourceBase.setMimetype(sourceMimetype); RequestParameters extraParams = (metadata != null) ? metadata.asParameters() : null; services.putValue(requestLogger, "config/transforms", transformName, extraParams, sourceMimetype, sourceBase); }
static public <W extends AbstractWriteHandle> boolean isResendable(W handle) { if (handle == null) return false; return ((HandleImplementation) handle).isResendable(); } static public HandleImplementation as(Object handle) {
public Response apply(Request.Builder funcBuilder) { return doPost(null, funcBuilder.header(HEADER_CONTENT_TYPE, tempBaseHandle.getMimetype()), tempBaseHandle.sendContent()); } };
@SuppressWarnings("rawtypes") private String validateGraphsMimetype(HandleImplementation baseHandle) { String mimetype = baseHandle.getMimetype(); if ( mimetype == null ) { if ( defaultMimetype != null ) { baseHandle.setMimetype(defaultMimetype); } else { throw new IllegalArgumentException("You must either call setMimetype on your " + "handle or setDefaultMimetype on your GraphManager instance with a mimetype " + "from RDFMimeTypes"); } } return mimetype; }
@SuppressWarnings("rawtypes") private void checkContentFormat(HandleImplementation contentBase) { if (contentBase == null) return; if (contentFormat != null && contentFormat != Format.UNKNOWN) { Format currFormat = contentBase.getFormat(); if (currFormat != contentFormat) { contentBase.setFormat(contentFormat); if (currFormat != Format.UNKNOWN) contentBase.setMimetype(contentFormat.getDefaultMimetype()); } } }
inputMimetype = inputBase.getMimetype(); if ( inputMimetype == null && ( Format.JSON == inputBase.getFormat() || Format.XML == inputBase.getFormat() ) ) inputMimetype = inputBase.getFormat().getDefaultMimetype(); String outputMimetype = outputBase == null ? null : outputBase.getMimetype(); boolean isResendable = inputBase == null ? true : inputBase.isResendable(); Class as = outputBase == null ? null : outputBase.receiveAs(); final Object value = inputBase == null ? null :inputBase.sendContent(); Function<Request.Builder, Response> doPostFunction = new Function<Request.Builder, Response>() { public Response apply(Request.Builder funcBuilder) { outputBase.receiveContent(makeResult(reqlog, operation, "resource", response, as)); } else {
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public <T extends QueryOptionsListReadHandle> T optionsList(T optionsHandle) throws ForbiddenUserException, FailedRequestException { HandleImplementation optionsBase = HandleAccessor.checkHandle(optionsHandle, "optionslist"); Format optionsFormat = optionsBase.getFormat(); switch(optionsFormat) { case UNKNOWN: optionsFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON options list results are possible."); } String mimetype = optionsFormat.getDefaultMimetype(); optionsBase.receiveContent(services.optionsList(optionsBase.receiveAs(), mimetype, null)); return optionsHandle; } }
HandleImplementation handleBase = HandleAccessor.checkHandle( handle, "write"); Object value = handleBase.sendContent(); String inputMimetype = (mimetypes != null) ? mimetypes[i] : handleBase.getMimetype(); hasStreamingPart = !handleBase.isResendable();
@Override public <T extends TextReadHandle> T readServices(String resourceName, T sourceHandle) { if (resourceName == null) throw new IllegalArgumentException("Reading resource services source with null name"); if (logger.isInfoEnabled()) logger.info("Reading resource services source for {}", resourceName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "resource"); sourceBase.receiveContent( services.getValue(requestLogger, "config/resources", resourceName, true, "application/xquery", sourceBase.receiveAs()) ); return sourceHandle; }
@SuppressWarnings("rawtypes") public DocumentDescriptor create(DocumentUriTemplate template, DocumentMetadataWriteHandle metadataHandle, W contentHandle, ServerTransform transform, Transaction transaction, RequestParameters extraParams) throws ForbiddenUserException, FailedRequestException { if (logger.isInfoEnabled()) logger.info("Creating content"); if (metadataHandle != null) { HandleImplementation metadataBase = HandleAccessor.checkHandle(metadataHandle, "metadata"); Format metadataFormat = metadataBase.getFormat(); if (metadataFormat == null || (metadataFormat != Format.JSON && metadataFormat != Format.XML)) { if (logger.isWarnEnabled()) logger.warn("Unsupported metadata format {}, using XML",metadataFormat.name()); metadataBase.setFormat(Format.XML); } } checkContentFormat(contentHandle); return services.postDocument( requestLogger, template, (transaction == null) ? null : transaction.getTransactionId(), (metadataHandle != null) ? processedMetadata : null, mergeTransformParameters( (transform != null) ? transform : getWriteTransform(), extraParams ), metadataHandle, contentHandle ); }
private void copyDescriptor(DocumentDescriptor desc, HandleImplementation handleBase) { if (handleBase == null) return; handleBase.setFormat(desc.getFormat()); handleBase.setMimetype(desc.getMimetype()); handleBase.setByteLength(desc.getByteLength()); }
private void setRdfXmlOrJsonMimetype(TriplesReadHandle handle) { HandleImplementation baseHandle = HandleAccessor.as(handle); if ( baseHandle.getFormat() == Format.JSON ) { if ( Format.JSON.getDefaultMimetype().equals(baseHandle.getMimetype()) ) { baseHandle.setMimetype(RDFMimeTypes.RDFJSON); } } else if ( baseHandle.getFormat() == Format.XML ) { if ( Format.XML.getDefaultMimetype().equals(baseHandle.getMimetype())) { baseHandle.setMimetype(RDFMimeTypes.RDFXML); } } }
private RequestBody makeRequestBody(AbstractWriteHandle document) { if (document == null) { return new EmptyRequestBody(); } HandleImplementation handleBase = HandleAccessor.as(document); Format format = handleBase.getFormat(); String mimetype = (format == Format.BINARY) ? "application/x-unknown-content-type" : handleBase.getMimetype(); MediaType mediaType = MediaType.parse(mimetype); return (document instanceof OutputStreamSender) ? new StreamingOutputImpl((OutputStreamSender) document, null, mediaType) : new ObjectRequestBody(HandleAccessor.sendContent(document), mediaType); }
private String getMimetypeWithDefaultXML(Format payloadFormat, HandleImplementation baseHandle) { String payloadMimetype = baseHandle.getMimetype(); if (payloadFormat != null) { if (payloadMimetype == null) { payloadMimetype = payloadFormat.getDefaultMimetype(); } } else if (payloadMimetype == null) { payloadMimetype = MIMETYPE_APPLICATION_XML; } return payloadMimetype; }
Object nextValue = (handle != null) ? handle.sendContent() : value; boolean isResendable = (handle == null) ? !isStreaming : handle.isResendable();
static public <W extends AbstractWriteHandle> Object sendContent(W handle) { if (handle == null) return null; return ((HandleImplementation) handle).sendContent(); } static public <W extends AbstractWriteHandle> boolean isResendable(W handle) {
private HandleImplementation executeSetRdfXmlOrJsonMimetype(Format format, String mimeType) { HandleImplementation triplesHandle = new HandleImplementationTester(); triplesHandle.setFormat(format); triplesHandle.setMimetype(mimeType); RESTServices services = mock(RESTServices.class); SPARQLQueryManagerImpl sparqlQueryManager = new SPARQLQueryManagerImpl(services); SPARQLQueryDefinition qdef = new SPARQLQueryDefinitionImpl(); sparqlQueryManager.executeDescribe(qdef, (TriplesReadHandle) triplesHandle); return triplesHandle; }
@Override public void write(String uri, TriplesWriteHandle handle, GraphPermissions permissions, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.as(handle); String mimetype = validateGraphsMimetype(baseHandle); services.writeGraph(requestLogger, uri, handle, permissions, transaction); baseHandle.setMimetype(mimetype); }
"write"); String inputMimetype = inputBase.getMimetype(); boolean isResendable = inputBase.isResendable();