Mediaflux Plugin Development: Create dataset from HTTP URL (with Basic Auth)








The example shows how to create a dataset asset from a password protected URL (Basic HTTP Auth).




Java: HTTP GET data from URL (with basic HTTP Auth)








The example shows how to do HTTP GET to download a file from URL. It also include an example to call Mediaflux client api to create a dataset from the url by piping the streams.




encode Base64 string in command line








  • Encode base64 string:
    echo -n Secret | base64
    
  • Decode base64 string:
    echo -n U2VjcmV0 | base64 -D
    

Note:

When encoding, -n must be specified. otherwise, a newline character will always be appended, which will cause unexpected result.

See http://askubuntu.com/questions/694216/base64-encode-is-giving-ambigious-results


Maven: skip unit tests








<properties>
    <maven.test.skip>true</maven.test.skip>
</properties>



make Java HttpURLConnection support MKCOL PROFIND and other non-standard HTTP methods








    private static void setRequestMethod(HttpURLConnection conn, String method) throws Throwable {
        try {
            conn.setRequestMethod(method);
        } catch (ProtocolException e) {
            Class<?> c = conn.getClass();
            Field methodField = null;
            Field delegateField = null;
            try {
                delegateField = c.getDeclaredField("delegate");
            } catch (NoSuchFieldException nsfe) {

            }
            while (c != null && methodField == null) {
                try {
                    methodField = c.getDeclaredField("method");
                } catch (NoSuchFieldException nsfe) {

                }
                if (methodField == null) {
                    c = c.getSuperclass();
                }
            }
            if (methodField != null) {
                methodField.setAccessible(true);
                methodField.set(conn, method);
            }

            if (delegateField != null) {
                delegateField.setAccessible(true);
                HttpURLConnection delegate = (HttpURLConnection) delegateField.get(conn);
                setRequestMethod(delegate, method);
            }
        }
    }



Multi-threading in Mediaflux Plugin Service








package wxyz.mf.plugin.services;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import arc.mf.plugin.PluginLog;
import arc.mf.plugin.ServiceExecutor;
import arc.xml.XmlDoc.Element;
import arc.xml.XmlWriter;
import wxyz.mf.plugin.util.MultiThreadPluginService;

public class SvcTest extends MultiThreadPluginService<Integer> {

    private Interface _defn;

    public SvcTest() {
        _defn = new Interface();
    }

    @Override
    public Access access() {
        return ACCESS_ACCESS;
    }

    @Override
    public Interface definition() {
        return _defn;
    }

    @Override
    public String description() {

        return "Test multithreading.";
    }

    @Override
    public String name() {
        return "omics.test";
    }

    @Override
    protected void consume(ServiceExecutor executor, Integer input, PluginLog log) throws Throwable {
        Thread.sleep(1000);
        String uuid = executor.execute("server.uuid").value("uuid");
        if (input == 15) {
            log.add(PluginLog.WARNING, "#8: Mock Exception for value 15.");
            throw new Exception("Mock Exception for value 15.");
        }
        System.out.println(Thread.currentThread().getName() + " consumed: " + input);
        System.out.println(Thread.currentThread().getName() + " uuid: " + uuid);
    }

    @Override
    protected Collection<Integer> produce(Element args, Inputs in, Outputs out, XmlWriter w,
            Map<String, Object> intermediateResults) throws Throwable {
        List<Integer> inputs = new ArrayList<Integer>(100);
        for (int i = 0; i < 20; i++) {
            inputs.add(i);
        }
        return inputs;
    }

}



Mac OS X: generate a random string as password








openssl rand -base64  6
openssl rand -base64  8



HTML table fill up the whole page








<table style="width:100%; height:100%; position:absolute; top:0; bottom:0; left 0; right:0;" border="0" cellspacing="1" cellpadding="3">
    <tr id="content" style="height: 100%;">
        <td align="center">Content</td>
    </tr>
    <tr id="footer" style="height:28px;">
        <td align="center">footer</td>
    </tr>
</table>



DICOM Modalities








ModalityDescription
ARAutorefraction
ASMTContent Assessment Results
AUAudio
BDUSBone Densitometry (ultrasound)
BIBiomagnetic imaging
BMDBone Densitometry (X-Ray)
CRComputed Radiography
CTComputed Tomography
CTPROTOCOLCT Protocol (Performed)
DGDiaphanography
DOCDocument
DXDigital Radiography
ECGElectrocardiography
EPSCardiac Electrophysiology
ESEndoscopy
FIDFiducials
GMGeneral Microscopy
HCHard Copy
HDHemodynamic Waveform
IOIntra-Oral Radiography
IOLIntraocular Lens Data
IVOCTIntravascular Optical Coherence Tomography
IVUSIntravascular Ultrasound
KERKeratometry
KOKey Object Selection
LENLensometry
LSLaser surface scan
MGMammography
MRMagnetic Resonance
NMNuclear Medicine
OAMOphthalmic Axial Measurements
OCTOptical Coherence Tomography (non-Ophthalmic)
OPOphthalmic Photography
OPMOphthalmic Mapping
OPTOphthalmic Tomography
OPVOphthalmic Visual Field
OSSOptical Surface Scan
OTOther
PLANPlan
PRPresentation State
PTPositron emission tomography (PET)
PXPanoramic X-Ray
REGRegistration
RESPRespiratory Waveform
RFRadio Fluoroscopy
RGRadiographic imaging (conventional film/screen)
RTDOSERadiotherapy Dose
RTIMAGERadiotherapy Image
RTPLANRadiotherapy Plan
RTRECORDRT Treatment Record
RTSTRUCTRadiotherapy Structure Set
RWVReal World Value Map
SEGSegmentation
SMSlide Microscopy
SMRStereometric Relationship
SRSR Document
SRFSubjective Refraction
STAINAutomated Slide Stainer
TGThermography
USUltrasound
VAVisual Acuity
XAX-Ray Angiography
XCExternal-camera Photography



Modify Mediaflux mflux package to install it into non-default schema








  1. copy the mflux.zip from /opt/mediaflux/ext/packages/ to /tmp
    cp /opt/mediaflux/ext/packages/mflux.zip /tmp/
    mkdir /tmp/mfpkg; cd /tmp/mfpkg; unzip /tmp/mflux.zip
  2. edit __install.tcl file
    vi /tmp/mfpkg/__install.tcl
    # HTTP processors:
    
    if { [info exists host] } {
        
        if { [xvalue exists [http.processor.exists :host $host :url /mflux]] == "false" } { 
          http.processor.create :host $host :app mflux :url /mflux :type asset :translate /www :authentication < :domain $domain :user $user > :view mflux-www
        }
    
        # Set the servlet entry points for the HTTP processors.
        http.servlets.set :host $host :url /mflux \
           :servlet -path portal.mfjp -default true arc.mflux.main \
           :servlet -path icon.mfjp arc.mflux.icon \
           :servlet -path iptile.mfjp arc.mflux.image.pyramid.tile \
           :servlet -path meta.mfjp arc.mflux.meta \
           :servlet -path content.mfjp arc.mflux.content \
           :servlet -path share.mfjp arc.mflux.share \
           :servlet -path output.mfjp arc.mflux.session.output \
           :servlet -path execute.mfjp arc.mflux.execute \
           :servlet -path transcode.mfjp arc.mflux.transcode \
           :servlet -path aterm.jar arc.mflux.aterm \
           :servlet -path aar.jar arc.mflux.aar
           
    } else {
    
        if { [xvalue exists [http.processor.exists :url /mflux]] == "false" } { 
          http.processor.create :app mflux :url /mflux :type asset :translate /www :authentication < :domain $domain :user $user > :view mflux-www
        }
    
        # Set the servlet entry points for the HTTP processors.
        http.servlets.set :url /mflux \
           :servlet -path portal.mfjp -default true arc.mflux.main \
           :servlet -path icon.mfjp arc.mflux.icon \
           :servlet -path iptile.mfjp arc.mflux.image.pyramid.tile \
           :servlet -path meta.mfjp arc.mflux.meta \
           :servlet -path content.mfjp arc.mflux.content \
           :servlet -path share.mfjp arc.mflux.share \
           :servlet -path output.mfjp arc.mflux.session.output \
           :servlet -path execute.mfjp arc.mflux.execute \
           :servlet -path transcode.mfjp arc.mflux.transcode \
           :servlet -path aterm.jar arc.mflux.aterm \
           :servlet -path aar.jar arc.mflux.aar
    
    }
    
  3. Re-package:
    cd /tmp/mfpkg; zip -r ../mflux-1.zip ./*
  4. Install the modified package in Aterm:
    package.install :in file:/tmp/mflux-1.zip :arg -name host daris.vicnode.org.au



PPSR search from Australian govenment








The PPSR is used to find out if there's any money owing on a car, or if it's previously been written off.


https://transact.ppsr.gov.au/ppsr/QuickVINSearch