Thursday, February 25, 2016

Winzip holds the zip file open

I often find that, when I select files and use the Explorer menu "WinZip/Add to somefile.zip", the somefile.zip remains opened by "some" process (Windows doesn't bother to tell you which one). Using ProcessExplorer doesn't help identifying the process.
The only workaround I found so far is restarting the Explorer.exe process.
Windows is a pathetic piece of piecemeal spaghetti disaster and WinZip is not better. I normally use 7Zip.


Monday, February 22, 2016

Notepad++ : all the accessories you need for it

Notepad++ is a really great tool, but you need a couple of plugins to make it a truly joyful war machine:
TextFX https://sourceforge.net/projects/npp-plugins/files/TextFX/
Xml Tools https://sourceforge.net/projects/npp-plugins/files/XML%20Tools/
They are both priceless!
For installation instructions, I leave you to google


Friday, February 19, 2016

weblogic.security.subject.SubjectManager.getSubjectManager hangs when using wrong JDK

Trying to connect from Eclipse to a WLS, Java client for EJB, using 2 way SSL and t3s, we get a stuck thread on this:

"main" #1 prio=5 os_prio=0 tid=0x000000000263f000 nid=0x12900 in Object.wait() [0x0000000002a6d000]
   java.lang.Thread.State: WAITING (on object monitor)
 at java.lang.Object.wait(Native Method)
 - waiting on <0x00000000d8d00d00> (a java.lang.Object)
 at java.lang.Object.wait(Object.java:502)
 at weblogic.security.subject.SubjectManager.getSubjectManager(SubjectManager.java:277)
 - locked <0x00000000d8d00d00> (a java.lang.Object)
 at weblogic.security.subject.SubjectManager$GetKernelIdentityAction.run(SubjectManager.java:440)
 at weblogic.security.service.SecurityManager.getKernelIdentity(SecurityManager.java:164)
 at weblogic.security.service.GetKernelIdentityAction.run(GetKernelIdentityAction.java:25)
 at java.security.AccessController.doPrivileged(Native Method)
 at weblogic.jndi.WLSJNDIEnvironmentImpl.(WLSJNDIEnvironmentImpl.java:57)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:264)
 at weblogic.jndi.internal.JNDIEnvironment.getJNDIEnvironment(JNDIEnvironment.java:37)
 at weblogic.jndi.Environment.(Environment.java:92)

...


The issue was solved changing JDK


Thursday, February 18, 2016

Funny error message using t3s and 2 way SSL

javax.naming.CommunicationException: t3s://localhost:25001: Destination 0:0:0:0:0:0:0:1, 25001 unreachable; nested exception is:
        javax.net.ssl.SSLException: Received fatal alert: bad_certificate; No available router to destination 

but there was absolutely no issue with the localhost or the port or anything else... WebLogic was listening on all IPv4 and IPv6 addresses on 25001...
googling around I find:
http://middlewaremagic.com/weblogic/

If the Client keystore/truststore PATH is not valid, so check the path specified in “-Djavax.net.ssl.trustStore” (OR) if the client keystore does not include the WebLogic certificate imported in it then we may see the following kind of error: Destination 0:0:0:0:0:0:0:1, 7443 unreachable.; nested exception is: 
    javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure; [RJVM:000576]No available router to destination.; nested exception is: 
    java.rmi.ConnectException: [RJVM:000576]No available router to destination.


check that what you are using as trust store and identity store are valid, and that valid password and alias is provided....


Tuesday, February 16, 2016

BEA-2162501 Class bytes found, but couldnt define class


<Feb 15, 2016 5:51:24 PM CET> <Error> <Class Loaders> <BEA-2162501> <Class bytes found, but couldnt define class, com.sun.faces.spi.InjectionProviderException due to the following error: {1}
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file com/sun/faces/spi/InjectionProviderException
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
 at weblogic.utils.classloaders.GenericClassLoader.defineClass(GenericClassLoader.java:412)
 at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:366)
 Truncated. see log file for complete stacktrace
> 




This error stems probably by the use of wrong JAR compiled with some JVM different from the one being used. Please check MANIFEST.MF file of the JAR and eventually recompile code.

Check also that the JAR from which you pick up the class (-verbose:class) contains the actual implementation of the class, and not only some abstract interface. You might have to review the way you package your code and define classpaths.

This discussion on JSF and Maven is interesting (scope=provided) http://stackoverflow.com/questions/8081234/how-to-properly-install-and-configure-jsf-libraries-via-maven



Friday, February 12, 2016

Quick script to create a domain for WLS 12.2.1


# https://docs.oracle.com/middleware/1221/wls/WLSTC/reference.htm#WLSTC3772
# Use selectTemplate followed by loadTemplates in place of readTemplate.

HOSTNAME='myhost.mydomain.com'
LISTENPORT=7012
SSLLISTENPORT=7022
JAVAHOME='/usr/java/jdk1.8.0_65'
DOMAINHOME='/opt/oracle/fmw1221/user_projects/domains/mydomain'

selectTemplate('Basic WebLogic Server Domain','12.2.1.0')
loadTemplates()

#readTemplate is deprecated
#readTemplate('/opt/oracle/fmw1221/wlserver/common/templates/wls/wls.jar') 

# Admin Server SSL and Non-SSL
print('Creating Server - Admin Server')
cd('Servers/AdminServer')
set('ListenAddress', HOSTNAME)
set('ListenPort', LISTENPORT)

create('AdminServer','SSL')
cd('SSL/AdminServer')
set('Enabled', 'True')
set('ListenPort', SSLLISTENPORT)

# Security
print('Creating Password')
cd('/')
cd('Security/base_domain/User/weblogic')
set('Password', 'Welcome1')
#cmo.setPassword('Welcome1')

# Start Up
print('Setting StartUp Options')
# Setting the JDK home. Change the path to your installed JDK for weblogic
setOption('JavaHome', JAVAHOME)
setOption('OverwriteDomain', 'true')

# Create Domain to File System
print('Writing Domain To File System')
# Change the path to your domain accordingly
writeDomain(DOMAINHOME)
closeTemplate()

# Read the Created Domain
print('Reading the Domain from In Offline Mode')
readDomain(DOMAINHOME)

# updating the changes
print('Finalizing the changes')
updateDomain()
closeDomain()

# Exiting
print('Exiting...')
exit()




WebLogic: validating config.xml

config.xml requires several XSDs to be validated:
 xsi:schemaLocation="http://xmlns.oracle.com/weblogic/security/xacml http://xmlns.oracle.com/weblogic/security/xacml/1.0/xacml.xsd
                            http://xmlns.oracle.com/weblogic/domain http://xmlns.oracle.com/weblogic/1.0/domain.xsd
                            http://xmlns.oracle.com/weblogic/security http://xmlns.oracle.com/weblogic/1.0/security.xsd
                            http://xmlns.oracle.com/weblogic/security/wls http://xmlns.oracle.com/weblogic/security/wls/1.0/wls.xsd
                            http://xmlns.oracle.com/weblogic/security/providers/passwordvalidator                             http://xmlns.oracle.com/weblogic/security/providers/passwordvalidator/1.0/passwordvalidator.xsd"


For the exact location of these files check here:
http://docs.oracle.com/cd/E28280_01/web.1111/e13716/config_files.htm#DOMCF128 for 10.3.6
namely: WL_HOME/server/lib/schema/weblogic-domain-binding.jar and diagnostics-binding.jar and the names are schema-0.xsd and schema-1.xsd (not a great idea IMHO to rename those files...)



Wednesday, February 3, 2016

HPROF is your friend (if you REALLY have nothing else at hand)

Official Java 7 doc https://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html
http://www.oracle.com/technetwork/java/javase/tooldescr-136044.html#gblvj Excellent also this article http://www.brendangregg.com/blog/2014-06-09/java-cpu-sampling-using-hprof.html

I am using this stupid class to test:
import java.util.HashMap;

public class CUT {
  public static void main(String[] args) {
    try {
      for (int i = 0; i < 10000; i++) {
         Thread.sleep(1);
         HashMap<String, Object> m = new HashMap<String, Object>();
         m.put("1", new Object());
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}


then I run
javac -g CUT.java

java -agentlib:hprof=cpu=samples CUT

less java.hprof.txt 



this is what I get:

THREAD START (obj=50000193, id = 200001, name="main", group="main")
THREAD END (id = 200001)
THREAD START (obj=50000193, id = 200004, name="DestroyJavaVM", group="main")
THREAD END (id = 200004)
THREAD END (id = 200002)
TRACE 300050:
        java.lang.Thread.sleep(Thread.java:Unknown line)
        CUT.main(CUT.java:7)
TRACE 300014:
        sun.usagetracker.UsageTrackerClient.getPropertyPrivileged(UsageTrackerClient.java:136)
        sun.usagetracker.UsageTrackerClient.getPropertyPrivileged(UsageTrackerClient.java:132)
        sun.usagetracker.UsageTrackerClient.(UsageTrackerClient.java:109)
        sun.misc.PostVMInitHook.trackJavaUsage(PostVMInitHook.java:28)
TRACE 300026:
        java.lang.System.arraycopy(System.java:Unknown line)
        java.lang.String.getChars(String.java:826)
        java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:422)
        java.lang.StringBuffer.append(StringBuffer.java:272)
TRACE 300042:
        java.io.FilePermissionCollection.(FilePermission.java:711)
        java.io.FilePermission.newPermissionCollection(FilePermission.java:642)
        java.security.Permissions.getPermissionCollection(Permissions.java:254)
        java.security.Permissions.add(Permissions.java:132)
TRACE 300051:
        java.util.HashMap.putVal(HashMap.java:628)
        java.util.HashMap.put(HashMap.java:611)
        CUT.main(CUT.java:9)
TRACE 300052:
        java.util.HashMap.put(HashMap.java:611)
        CUT.main(CUT.java:9)
CPU SAMPLES BEGIN (total = 12) Wed Feb  3 06:07:50 2016
rank   self  accum   count trace method
   1 58.33% 58.33%       7 300050 java.lang.Thread.sleep
   2  8.33% 66.67%       1 300014 sun.usagetracker.UsageTrackerClient.getPropertyPrivileged
   3  8.33% 75.00%       1 300026 java.lang.System.arraycopy
   4  8.33% 83.33%       1 300042 java.io.FilePermissionCollection.
   5  8.33% 91.67%       1 300051 java.util.HashMap.putVal
   6  8.33% 100.00%       1 300052 java.util.HashMap.put
CPU SAMPLES END



Using the other option
java -agentlib:hprof=cpu=times CUT

gives me

THREAD START (obj=5000017d, id = 200002, name="HPROF gc_finish watcher", group="system")
THREAD START (obj=5000017d, id = 200001, name="main", group="main")
THREAD END (id = 200001)
THREAD START (obj=5000017d, id = 200003, name="DestroyJavaVM", group="main")
THREAD END (id = 200003)
THREAD END (id = 200002)
TRACE 301665:
        CUT.main(CUT.java:Unknown line)
TRACE 301663:
        java.util.HashMap.putVal(HashMap.java:Unknown line)
        java.util.HashMap.put(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 301664:
        java.util.HashMap.put(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 301657:
        java.util.HashMap.(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 301659:
        java.util.HashMap.hash(HashMap.java:Unknown line)
        java.util.HashMap.put(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 301661:
        java.util.HashMap.newNode(HashMap.java:Unknown line)
        java.util.HashMap.putVal(HashMap.java:Unknown line)
        java.util.HashMap.put(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 301660:
        java.util.HashMap.resize(HashMap.java:Unknown line)
        java.util.HashMap.putVal(HashMap.java:Unknown line)
        java.util.HashMap.put(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 301662:
        java.util.HashMap.afterNodeInsertion(HashMap.java:Unknown line)
        java.util.HashMap.putVal(HashMap.java:Unknown line)
        java.util.HashMap.put(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 300952:
        java.util.HashMap$Node.(HashMap.java:Unknown line)
        java.util.HashMap.newNode(HashMap.java:Unknown line)
        java.util.HashMap.putVal(HashMap.java:Unknown line)
        java.util.HashMap.put(HashMap.java:Unknown line)
TRACE 301656:
        java.util.AbstractMap.(AbstractMap.java:Unknown line)
        java.util.HashMap.(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 301658:
        java.lang.String.hashCode(String.java:Unknown line)
        java.util.HashMap.hash(HashMap.java:Unknown line)
        java.util.HashMap.put(HashMap.java:Unknown line)
        CUT.main(CUT.java:Unknown line)
TRACE 300163:
        java.lang.invoke.MethodHandle.(MethodHandle.java:Unknown line)
TRACE 300094:
        java.lang.invoke.MethodHandleImpl.(MethodHandleImpl.java:Unknown line)
        java.lang.invoke.MethodHandle.(MethodHandle.java:Unknown line)
TRACE 300252:
        java.lang.CharacterDataLatin1.getProperties(CharacterDataLatin1.java:Unknown line)
        java.lang.CharacterDataLatin1.toLowerCase(CharacterDataLatin1.java:Unknown line)
        java.lang.Character.toLowerCase(Character.java:Unknown line)
        java.lang.Character.toLowerCase(Character.java:Unknown line)
TRACE 301251:
        sun.misc.PerfCounter.(PerfCounter.java:Unknown line)
        sun.misc.PerfCounter.newPerfCounter(PerfCounter.java:Unknown line)
        sun.misc.PerfCounter$CoreCounters.(PerfCounter.java:Unknown line)
        sun.misc.PerfCounter.getReadClassBytesTime(PerfCounter.java:Unknown line)
CPU TIME (ms) BEGIN (total = 11886) Wed Feb  3 06:21:21 2016
rank   self  accum   count trace method
   1 94.75% 94.75%       1 301665 CUT.main
   2  1.10% 95.85%   10000 301663 java.util.HashMap.putVal
   3  0.83% 96.69%   10000 301664 java.util.HashMap.put
   4  0.75% 97.43%   10000 301657 java.util.HashMap.
   5  0.58% 98.01%   10000 301659 java.util.HashMap.hash
   6  0.41% 98.43%   10000 301661 java.util.HashMap.newNode
   7  0.27% 98.70%   10000 301660 java.util.HashMap.resize
   8  0.24% 98.93%   10000 301662 java.util.HashMap.afterNodeInsertion
   9  0.22% 99.15%   10016 300952 java.util.HashMap$Node.
  10  0.21% 99.36%   10000 301656 java.util.AbstractMap.
  11  0.15% 99.51%   10000 301658 java.lang.String.hashCode
  12  0.04% 99.55%       1 300163 java.lang.invoke.MethodHandle.
  13  0.02% 99.57%       1 300094 java.lang.invoke.MethodHandleImpl.
  14  0.02% 99.59%      80 300252 java.lang.CharacterDataLatin1.getProperties
  15  0.02% 99.60%       6 301251 sun.misc.PerfCounter.
CPU TIME (ms) END


which SEEMS much more accurate.
Heap Profiling uses this:
java -agentlib:hprof=heap=sites CUT
which gives (shortened form)
TRACE 300318:
        java.util.HashMap.resize(HashMap.java:703)
        java.util.HashMap.putVal(HashMap.java:628)
        java.util.HashMap.put(HashMap.java:611)
        CUT.main(CUT.java:9)

TRACE 300316:
        java.util.AbstractMap.(AbstractMap.java:73)
        java.util.HashMap.(HashMap.java:474)
        CUT.main(CUT.java:8)

TRACE 300186:
        java.util.HashMap$Node.(HashMap.java:284)
        java.util.HashMap.newNode(HashMap.java:1734)
        java.util.HashMap.putVal(HashMap.java:630)
        java.util.HashMap.put(HashMap.java:611)


(etc etc)

SITES BEGIN (ordered by live bytes) Wed Feb  3 06:28:22 2016
          percent          live          alloc'ed  stack class
 rank   self  accum     bytes objs     bytes  objs trace name
    1 39.18% 39.18%    800000 10000    800000 10000 300318 java.util.HashMap$Node[]
    2 23.51% 62.69%    480000 10000    480000 10000 300316 java.util.HashMap
    3 15.69% 78.38%    320384 10012    320384 10012 300186 java.util.HashMap$Node
    4  7.84% 86.22%    160000 10000    160000 10000 300317 java.lang.Object
    5  0.34% 86.56%      7000   53      7000    53 300011 char[]
    6  0.07% 86.63%      1504    4      1504     4 300001 java.lang.Thread
    7  0.06% 86.70%      1304   11      1304    11 300154 char[]
    8  0.06% 86.76%      1296    3      1296     3 300000 java.lang.Thread
    9  0.06% 86.82%      1248   11      1248    11 300172 char[]
   10  0.06% 86.88%      1248   11      1248    11 300173 char[]
   11  0.06% 86.94%      1240   10      1240    10 300176 char[]
   12  0.05% 86.99%      1040    1      1040     1 300021 java.lang.invoke.MethodHandle[]




To get help do:
java -agentlib:hprof=help

     HPROF: Heap and CPU Profiling Agent (JVMTI Demonstration Code)

hprof usage: java -agentlib:hprof=[help]|[