0

Dicom イメージを読み取ろうとする次のコードがあります。

public  BufferedImage readDicomFile(File dicomFile) {

    ImageReader reader = (ImageReader) ImageIO.getImageReadersByFormatName("DICOM").next();
    BufferedImage tempImage = null;
    try {
        if (!dicomFile.exists()) {          
            return null;
        }
        ImageIO.scanForPlugins();
        tempImage = ImageIO.read(dicomFile);            
        DicomObject obj = new DicomInputStream(dicomFile).readDicomObject();
        String overlayData = obj.getString(1610625024);
        if ((overlayData != null) && (overlayData.length() > 0)) {
            tempImage = combineImages(tempImage,
                    OverlayUtils.extractOverlay(obj, 1610625024, reader,
                            "FFFFFF"));
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return tempImage;
}

しかし、これは私が得ているものです:

SEVERE: java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [org.dcm4che.data.DcmParserFactory], because it has not yet been started, or was already stopped
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1401)
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
at org.dcm4cheri.imageio.plugins.DcmImageReaderSpi.canDecodeInput(DcmImageReaderSpi.java:113)
at javax.imageio.ImageIO$CanDecodeInputFilter.filter(ImageIO.java:567)
at javax.imageio.spi.FilterIterator.advance(ServiceRegistry.java:810)
at javax.imageio.spi.FilterIterator.<init>(ServiceRegistry.java:804)
at javax.imageio.spi.ServiceRegistry.getServiceProviders(ServiceRegistry.java:508)
at javax.imageio.ImageIO.getImageReaders(ImageIO.java:646)
at javax.imageio.ImageIO.read(ImageIO.java:1438)
at javax.imageio.ImageIO.read(ImageIO.java:1308)
at edu.kfshrc.dm.services.DicomViewerService.readDicomFile(DicomViewerService.java:565)
at edu.kfshrc.dm.services.DicomViewerService.extractImageFromDicom(DicomViewerService.java:414)
at edu.kfshrc.dm.servlet.DicomViewerServlet.doGet(DicomViewerServlet.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)

SEVERE:     at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1401)
SEVERE:     at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
SEVERE:     at org.dcm4cheri.imageio.plugins.DcmImageReaderSpi.canDecodeInput(DcmImageReaderSpi.java:113)
SEVERE:     at javax.imageio.ImageIO$CanDecodeInputFilter.filter(ImageIO.java:567)
SEVERE:     at javax.imageio.spi.FilterIterator.advance(ServiceRegistry.java:810)
SEVERE:     at javax.imageio.spi.FilterIterator.<init>(ServiceRegistry.java:804)
SEVERE:     at javax.imageio.spi.ServiceRegistry.getServiceProviders(ServiceRegistry.java:508)
SEVERE:     at javax.imageio.ImageIO.getImageReaders(ImageIO.java:646)
SEVERE:     at javax.imageio.ImageIO.read(ImageIO.java:1438)
SEVERE:     at javax.imageio.ImageIO.read(ImageIO.java:1308)
SEVERE:     at edu.kfshrc.dm.services.DicomViewerService.readDicomFile(DicomViewerService.java:565)
SEVERE:     at edu.kfshrc.dm.services.DicomViewerService.extractImageFromDicom(DicomViewerService.java:414)
SEVERE:     at edu.kfshrc.dm.servlet.DicomViewerServlet.doGet(DicomViewerServlet.java:131)
SEVERE:     at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
SEVERE:     at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
SEVERE:     at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
SEVERE:     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
SEVERE:     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
SEVERE:     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
SEVERE:     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
SEVERE:     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
SEVERE:     at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
SEVERE:     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
SEVERE:     at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
SEVERE:     at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
SEVERE:     at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
SEVERE:     at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
SEVERE:     at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
SEVERE:     at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
SEVERE:     at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
SEVERE:     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
SEVERE:     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
SEVERE:     at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
SEVERE:     at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
SEVERE:     at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
SEVERE:     at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
SEVERE:     at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
SEVERE:     at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
SEVERE:     at java.lang.Thread.run(Thread.java:722)

特定のパス「c:\temp2\testing.dcm」を指すファイル オブジェクトを渡しています。Dicom ファイルを読み取ろうとする行になると、上記のエラーが発生します。

助けていただけますか?

4

1 に答える 1

0

サラム・ワエル

この問題の根本的な原因は、サーブレット コンテナー (Tomcat、..) がネイティブ ライブラリの登録/登録解除を自動的に処理できないことです。

これは、dcm4che がプラグインを所有する内部のネイティブ ライブラリを使用する ImageIO DICOM プラグインを読み込むときに、別の webApp (サーブレット) からそれを使用する場合、dcm4che DICOM リーダー/ライター コードの実行ごとにプラグインを再度スキャンする必要があることを意味します。

将来のメモリ リークの可能性を防ぐために、各実行後にネイティブの ImageIO プラグインを自分で登録解除することをお勧めします。

     try{
ImageIO.scanForPlugins()
    //Dicom code
        }
    catch {
    //exceptions
    }
    finally {
                try {
                    // De-register any locally registered IIO plugins. Relies on
                    // each web app having its own context class loader.
                    final IIORegistry registry = IIORegistry.getDefaultInstance();
                    final LocalFilter localFilter = new LocalFilter(Thread.currentThread().getContextClassLoader()); 

                    // scanForPlugins uses context  class loader
                    Iterator<Class<?>> categories = registry.getCategories();

                    while (categories.hasNext()) {
                        Class<?> category = categories.next();
                        Iterator<?> providers = registry.getServiceProviders(category, localFilter, false);

                        // Copy the providers, as de-registering while iterating
                        // over providers will lead to
                        // ConcurrentModificationExceptions.
                        List<Object> providersCopy = new ArrayList<Object>();
                        while (providers.hasNext()) {
                            providersCopy.add(providers.next());
                        }

                        for (Object provider : providersCopy) {
                            registry.deregisterServiceProvider(provider);
                            log.debug(String.format("Unregistered locally installed provider class: %s",provider.getClass()));
                        }
                    }
                } catch (Exception ex) {
                    _logger.error("Exception occured while de-registering locally registered IIO plugins", ex);
                }
于 2016-11-23T09:59:46.520 に答える