Total Pageviews

Showing posts with label WebSphere. Show all posts
Showing posts with label WebSphere. Show all posts

2016/08/06

[Websphere] WTRN0006W: Transaction has timed out after 120 seconds

Problem
I am deploying WAR in WAS 7. 
I got this error message as I do test:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[2016-05-16 15:28:23][INFO][Non-deferrable Alarm : 1][Line:1709][com.ibm.ws.tx.jta.TimeoutManager.logToJSR47Logger]WTRN0006W: Transaction 00000154B8756C5F00000003618D9380FB564FCFE7EE45F38E06607A9BFB0CE57778367B00000154B8756C5F00000003618D9380FB564FCFE7EE45F38E06607A9BFB0CE57778367B00000001 has timed out after 120 seconds.
[2016-05-16 15:28:23][INFO][Non-deferrable Alarm : 1][Line:1709][com.ibm.ws.tx.jta.TimeoutManager.logToJSR47Logger]WTRN0124I: When the timeout occurred the thread with which the transaction is, or was most recently, associated was Thread[SimpleAsyncTaskExecutor-1,5,main]. The stack trace of this thread when the timeout occurred was: 
 java.io.RandomAccessFile.readBytes(Native Method)
 java.io.RandomAccessFile.read(RandomAccessFile.java:368)
 org.apache.fontbox.ttf.BufferedRandomAccessFile.fillBuffer(BufferedRandomAccessFile.java:122)
 org.apache.fontbox.ttf.BufferedRandomAccessFile.read(BufferedRandomAccessFile.java:160)
 org.apache.fontbox.ttf.RAFDataStream.read(RAFDataStream.java:162)
 org.apache.fontbox.ttf.TTFDataStream.read(TTFDataStream.java:263)
 org.apache.fontbox.ttf.TTFDataStream.readString(TTFDataStream.java:91)
 org.apache.fontbox.ttf.TTFDataStream.readString(TTFDataStream.java:64)
 org.apache.fontbox.ttf.TTFParser.readTableDirectory(TTFParser.java:232)
 org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:139)
 org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:87)
 org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.addTrueTypeFont(FileSystemFontProvider.java:502)
 org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.scanFonts(FileSystemFontProvider.java:246)
 org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.<init>(FileSystemFontProvider.java:225)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl$DefaultFontProvider.<clinit>(FontMapperImpl.java:132)
 java.lang.J9VMInternals.initializeImpl(Native Method)
 java.lang.J9VMInternals.initialize(J9VMInternals.java:236)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl.getProvider(FontMapperImpl.java:151)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFont(FontMapperImpl.java:415)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFontBoxFont(FontMapperImpl.java:378)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl.getFontBoxFont(FontMapperImpl.java:352)
 org.apache.pdfbox.pdmodel.font.PDType1Font.<init>(PDType1Font.java:115)
 org.apache.pdfbox.pdmodel.font.PDType1Font.<clinit>(PDType1Font.java:76)
 java.lang.J9VMInternals.initializeImpl(Native Method)
 java.lang.J9VMInternals.initialize(J9VMInternals.java:236)
 org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:62)
 org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:123)
 org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:60)
 org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:815)
 org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:472)
 org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:446)
 org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149)
 org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:189)
 org.apache.pdfbox.rendering.PDFRenderer.renderPage(PDFRenderer.java:208)
 org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:139)
 org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:94)


How To
Here has a workaround approach, but you need to figure out the reason why your program had spent just a long time to execute. If your program really need more time to execute, you should log into WAS administration console to modify the value of Total transaction lifetime timeout and Maximum transaction timeout.

The configuration steps are as follows:

  • Step1. Log in to administration console
  • Step2. WebSphere Application Server 7.0: Click Servers > Server Types > WebSphere application servers > server_name > Container Services > Transaction Service.
  • Step3. Increase the Total transaction lifetime timeout. The default value is 120.
  • Step4. Increase the Maximum transaction timeout. The default value is 300 seconds.



  • Step5. Save your changes and restart WAS


Reference
[1] https://stackoverflow.com/questions/23004900/how-to-resolve-this-timeout-exception-in-was-7

2016/07/09

[PDFBox] No ImageWriter found for 'tif' format in WebSphere

Problem
As I try to convert PDF to TIF via PDFBox in WebSphere 8, I got the error message during the conversion process:
1
2
[Line:198][org.apache.pdfbox.tools.imageio.ImageIOUtil.writeImage]No ImageWriter found for 'tif' format
[Line:206][org.apache.pdfbox.tools.imageio.ImageIOUtil.writeImage]Supported formats: BMP bmp jpg JPG wbmp jpeg png PNG JPEG WBMP GIF gif 


Lacking of jai-imageio-core jar file in your classpath must get this error message.
But I have add jai-imageio-core dependency in pom.xml.
Snippet of pom.xml looks like:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!-- for generating tif file -->
<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>pdfbox-tools</artifactId>
    <version>2.0.0</version>
</dependency>

<dependency>
    <groupId>com.github.jai-imageio</groupId>
    <artifactId>jai-imageio-core</artifactId>
    <version>1.3.1</version>
</dependency>

Therefore, I try to print log to figure out the weird problem:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 try {
     Enumeration<URL> urls = Thread.currentThread().getContextClassLoader()
             .getResources("META-INF/services/javax.imageio.spi.ImageWriterSpi");
     while (urls.hasMoreElements()) {
         log.info("[convertToTiff] url = " + urls.nextElement().toString());
     }
 
 } catch (IOException e1) {
     e1.printStackTrace();
     throw new RuntimeException(e1);
 }

 The jar file exists in my ear file ! What happened?
1
 [convertToTiff] url = wsjar:file:/usr/IBM/WebSphere/AppServer/profiles/AppSrv03/installedApps/FDCSRA205Node03Cell/yuantalife-ecp-manage.ear/yuantalife-ecp-manage-war-0.1.0-SNAPSHOT.war/WEB-INF/lib/jai-imageio-core-1.3.1.jar!/META-INF/services/javax.imageio.spi.ImageWriterSpi

Here is my source code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package albert.practice.file;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;

import javax.imageio.ImageIO;

import lombok.extern.slf4j.Slf4j;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.tools.imageio.ImageIOUtil;

@Slf4j
public class PdfFileToTif {

    private final float dpi = 300f;

    public static void main(String[] args) {
        File pdfFile = new File("D:\\dropbox\\Getting Started.pdf");
        String destination = "D:\\dropbox\\";

        PdfFileToTif test = new PdfFileToTif();
        test.checkImageIoJarFile();
        test.convertPdfToTif(pdfFile, destination);
    }

    public void convertPdfToTif(File pdfFile, String destination) {
        if (!isFileExisted(pdfFile)) {
            throw new RuntimeException("File not found ! (" + pdfFile.getAbsolutePath() + ")");
        }

        String pdfFileName = pdfFile.getName();

        try {
            // load PDF document
            PDDocument document = PDDocument.load(pdfFile);

            // create PDF renderer
            PDFRenderer renderer = new PDFRenderer(document);

            // go through each page of PDF, and generate TIF for each PDF page.
            for (int i = 0; i < document.getNumberOfPages(); i++) {
                // Returns the given page as an RGB image with 300 DPI.
                BufferedImage image = renderer.renderImageWithDPI(i, dpi, ImageType.BINARY);

                // Assign the file name of TIF
                String fileName = pdfFileName + "_" + String.format("%02d", i + 1);
                log.debug("Generating  " + fileName + ".tif to " + destination);

                // Writes a buffered image to a file using the given image format.
                ImageIOUtil.writeImage(image, destination + fileName + ".tif", Math.round(dpi));
                image.flush();
            }
            log.debug("PDF to TIF conversion well done!");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 判斷檔案是否存在
     * 
     * @param file
     * @return true - 檔案存在; false - 檔案不存在
     */
    private Boolean isFileExisted(File file) {
        Boolean isExisted = Boolean.FALSE;
        isExisted = (file.exists() && (!file.isDirectory()));
        return isExisted;
    }

    private void checkImageIoJarFile() {
        try {
            Enumeration<URL> urls = Thread.currentThread().getContextClassLoader()
                    .getResources("META-INF/services/javax.imageio.spi.ImageWriterSpi");
            while (urls.hasMoreElements()) {
                log.info("[convertToTiff] urls = " + urls.nextElement().toString());
            }

        } catch (IOException e1) {
            e1.printStackTrace();
            throw new RuntimeException(e1);
        }
    }
}


How-to
The root cause is not so clear. It may results from WebSphere's classloading problem.
Hence, I find an API to scans for plug-ins on the application class path, loads their service provider classes, and registers a service provider instance for each one found with the IIORegistry. This strange problem had been resolved as I add ImageIO.scanForPlugins();

Here is my updated source code (Line46):
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package albert.practice.file;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;

import javax.imageio.ImageIO;

import lombok.extern.slf4j.Slf4j;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.tools.imageio.ImageIOUtil;

@Slf4j
public class PdfFileToTif {

    private final float dpi = 300f;

    public static void main(String[] args) {
        File pdfFile = new File("D:\\dropbox\\Getting Started.pdf");
        String destination = "D:\\dropbox\\";

        PdfFileToTif test = new PdfFileToTif();
        test.checkImageIoJarFile();
        test.convertPdfToTif(pdfFile, destination);
    }

    public void convertPdfToTif(File pdfFile, String destination) {
        if (!isFileExisted(pdfFile)) {
            throw new RuntimeException("File not found ! (" + pdfFile.getAbsolutePath() + ")");
        }

        String pdfFileName = pdfFile.getName();

        try {
            // load PDF document
            PDDocument document = PDDocument.load(pdfFile);

            // Scans for plug-ins on the application class path, loads their service provider
            // classes, and registers a service provider instance for each one found with the
            // IIORegistry.
            ImageIO.scanForPlugins();

            // create PDF renderer
            PDFRenderer renderer = new PDFRenderer(document);

            // go through each page of PDF, and generate TIF for each PDF page.
            for (int i = 0; i < document.getNumberOfPages(); i++) {
                // Returns the given page as an RGB image with 300 DPI.
                BufferedImage image = renderer.renderImageWithDPI(i, dpi, ImageType.BINARY);

                // Assign the file name of TIF
                String fileName = pdfFileName + "_" + String.format("%02d", i + 1);
                log.debug("Generating  " + fileName + ".tif to " + destination);

                // Writes a buffered image to a file using the given image format.
                ImageIOUtil.writeImage(image, destination + fileName + ".tif", Math.round(dpi));
                image.flush();
            }
            log.debug("PDF to TIF conversion well done!");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 判斷檔案是否存在
     * 
     * @param file
     * @return true - 檔案存在; false - 檔案不存在
     */
    private Boolean isFileExisted(File file) {
        Boolean isExisted = Boolean.FALSE;
        isExisted = (file.exists() && (!file.isDirectory()));
        return isExisted;
    }

    private void checkImageIoJarFile() {
        try {
            Enumeration<URL> urls = Thread.currentThread().getContextClassLoader()
                    .getResources("META-INF/services/javax.imageio.spi.ImageWriterSpi");
            while (urls.hasMoreElements()) {
                log.info("[convertToTiff] urls = " + urls.nextElement().toString());
            }

        } catch (IOException e1) {
            e1.printStackTrace();
            throw new RuntimeException(e1);
        }
    }
}




Reference 
[1] http://stackoverflow.com/questions/17178591/how-to-add-tiff-imagereader-to-those-registered-in-grails

2016/07/06

[WebSphere] How to Configure Shared Library in WAS?

Problem
How do I configure shared library in WAS?

Solution
Go to Environment -> Shared Libraries   
1.    Create your own Shared Library. Add the classpath pointing to your JAR files.


2.    Apply and save this configuration.


Go to Servers -> Application Servers -> Select the server-> Java and Process Management -> ClassLoader.
4.    Click on that class loader.


5.    Click on the Shared Library References


6.    Click on Add.


7.    Add your shared library.




8.    Save and restart Websphere Servers.


Reference
[1] http://www-01.ibm.com/support/docview.wss?uid=swg27023549&aid=1

2016/07/05

[WebSphere] How to Enable Classloading log in WAS?

Problem
How do I know the class loading list which load by WAS?

Solution

  • Step1. Log into WAS administration console
  • Step2. Go to application server > server_name > Java and Process Management > Process definition > Java Virtual Machine, check the verbose classloading option
  • Step3. Save your configuration and restart WAS
  • Step4. You will find the classloading informations in the native_stderr.log, which located in /profiles//logs/ directory. ex. /usr/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/server1

Reference

2016/06/09

[WAS] WSVR0605W - "Thread may be hung"

Problem
I'm running my web application on IBM WebSphere.
There is a warning message in System.out.log :
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[4/25/16 17:16:03:756 CST] 00000068 SystemOut     O [2016-04-25 17:16:03][WARN][Deferrable Alarm : 1][Line:1709][com.ibm.ws.runtime.component.ThreadMonitorImpl.logToJSR47Logger]WSVR0605W: Thread "WebContainer : 6" (000000d3) has been active for 667,910 milliseconds and may be hung.  There is/are 1 thread(s) in total in the server that may be hung.
    at java.io.RandomAccessFile.readBytes(Native Method)
    at java.io.RandomAccessFile.read(RandomAccessFile.java:368)
    at org.apache.fontbox.ttf.BufferedRandomAccessFile.fillBuffer(BufferedRandomAccessFile.java:122)
    at org.apache.fontbox.ttf.BufferedRandomAccessFile.read(BufferedRandomAccessFile.java:160)
    at org.apache.fontbox.ttf.RAFDataStream.read(RAFDataStream.java:162)
    at org.apache.fontbox.ttf.TTFDataStream.read(TTFDataStream.java:263)
    at org.apache.fontbox.ttf.TTFDataStream.readString(TTFDataStream.java:91)
    at org.apache.fontbox.ttf.TTFDataStream.readString(TTFDataStream.java:64)
    at org.apache.fontbox.ttf.TTFParser.readTableDirectory(TTFParser.java:232)
    at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:139)
    at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:87)
    at org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.addTrueTypeFont(FileSystemFontProvider.java:502)
    at org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.scanFonts(FileSystemFontProvider.java:246)
    at org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.<init>(FileSystemFontProvider.java:225)
    at org.apache.pdfbox.pdmodel.font.FontMapperImpl$DefaultFontProvider.<clinit>(FontMapperImpl.java:132)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:236)
    at org.apache.pdfbox.pdmodel.font.FontMapperImpl.getProvider(FontMapperImpl.java:151)
    at org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFont(FontMapperImpl.java:415)
    at org.apache.pdfbox.pdmodel.font.FontMapperImpl.getTrueTypeFont(FontMapperImpl.java:323)
    at org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.<init>(PDTrueTypeFont.java:198)
    at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:75)
    at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:123)
    at org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:60)
    at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:815)
    at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:472)
    at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:446)
    at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149)
    at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:189)
    at org.apache.pdfbox.rendering.PDFRenderer.renderPage(PDFRenderer.java:208)
    at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:139)
    at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:94)

And my function is hung after I click execute button.


How-to
You need to log into WAS administration console, then go to Servers > Application Servers > server_name. Click Administration > Custom Properties Under Server Infrastructure.

And add four arbitrates

  • com.ibm.websphere.threadmonitor.interval: 180
  • com.ibm.websphere.threadmonitor.threshold: 600
  • com.ibm.websphere.threadmonitor.false.alarm.threshold: 100
  • com.ibm.websphere.threadmonitor.dump.java: false



Remember to save attributes and restart WAS.

But this is just a workaround solution, it may means your programs may consume lots of memory for some reasons. You still need to figure out its root causes and fix them.


Reference
[1] http://websphere-solutions.blogspot.tw/2011/10/hung-threads.html