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; }
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; }
@Override public void patchDocument(RequestLogger reqlog, DocumentDescriptor desc, String transactionId, Set<Metadata> categories, boolean isOnContent, DocumentPatchHandle patchHandle) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { HandleImplementation patchBase = HandleAccessor.checkHandle( patchHandle, "patch"); putPostDocumentImpl(reqlog, "patch", desc, transactionId, categories, isOnContent, null, patchBase.getMimetype(), patchHandle); }
@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 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); } } }
@Override public void patchDocument(RequestLogger reqlog, DocumentDescriptor desc, Transaction transaction, Set<Metadata> categories, boolean isOnContent, RequestParameters extraParams, String sourceDocumentURI, DocumentPatchHandle patchHandle) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { HandleImplementation patchBase = HandleAccessor.checkHandle(patchHandle, "patch"); if(sourceDocumentURI != null) extraParams.add("source-document", sourceDocumentURI); putPostDocumentImpl(reqlog, "patch", desc, transaction, categories, isOnContent, extraParams, patchBase.getMimetype(), patchHandle); }
@Override public <T extends TriplesReadHandle> T read(String uri, T handle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.as(handle); String mimetype = baseHandle.getMimetype(); if ( mimetype == null ) baseHandle.setMimetype(defaultMimetype); services.readGraph(requestLogger, uri, handle, transaction); baseHandle.setMimetype(mimetype); return handle; }
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); }
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); }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public <T extends StructureReadHandle> T readStatus(T handle) throws ForbiddenUserException, FailedRequestException { if (handle == null) throw new IllegalArgumentException("reading transaction status with null handle"); HandleImplementation handleBase = HandleAccessor.checkHandle(handle, "structure"); handleBase.receiveContent( services.getValue( null, "transactions", getTransactionId(), false, handleBase.getMimetype(), handleBase.receiveAs() ) ); return handle; }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public <T extends StructureReadHandle> T readStatus(T handle) throws ForbiddenUserException, FailedRequestException { if (handle == null) throw new IllegalArgumentException("reading transaction status with null handle"); HandleImplementation handleBase = HandleAccessor.checkHandle(handle, "structure"); handleBase.receiveContent( services.getValue( null, "transactions", getTransactionId(), this, false, handleBase.getMimetype(), handleBase.receiveAs() ) ); return handle; }
if (metadataBase != null) { metadataFormat = metadataBase.getFormat().toString().toLowerCase(); metadataMimetype = metadataBase.getMimetype(); contentMimetype = contentBase.getMimetype();
if (metadataBase != null) { metadataFormat = metadataBase.getFormat().toString().toLowerCase(); metadataMimetype = metadataBase.getMimetype(); contentMimetype = contentBase.getMimetype();
@Test public void testExecuteDescribeWithJSONNotMime() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.JSON, Format.TEXT.getDefaultMimetype()); assertFalse(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFJSON)); assertTrue(triplesHandle.getMimetype().equals(Format.TEXT.getDefaultMimetype())); }
@Test public void testExecuteDescribeWithXMLNotMime() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.XML, Format.TEXT.getDefaultMimetype()); assertFalse(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFXML)); assertTrue(triplesHandle.getMimetype().equals(Format.TEXT.getDefaultMimetype())); }
/** * Test of executeDescribe method, of class SPARQLQueryManagerImpl. */ @Test public void testExecuteDescribeWithJSON() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.JSON, Format.JSON.getDefaultMimetype()); assertTrue(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFJSON)); }
@Test public void testExecuteDescribeWithUNKNOWNFormat() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.UNKNOWN, Format.JSON.getDefaultMimetype()); assertFalse(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFJSON)); }
@Test public void testExecuteDescribeWithXML() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.XML, Format.XML.getDefaultMimetype()); assertTrue(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFXML)); }
"read"); String mimetype = outputBase.getMimetype(); Class as = outputBase.receiveAs();