3 replies Latest Post - ‏2013-07-30T15:25:53Z by c.high
2 Posts

Pinned topic Check the JAXB context factory initialization class

‏2012-01-18T07:31:29Z |
I run the latest application migration tool on our java source code in eclipse and the tool give the result below that I do not quite understand.

The result is:
V6.1 to V7.0 migration --> Behavior changes --> Check JAXB context factory initialization class

The java source code is below. the line in bold is the place where the tool highlight with the result. Can someone tell me what this result mean? Is there anything we need to modify in the source code? The JAXBContext is from javax.xml.bind.JAXBContext.
public void init(String context) throws Exception {
JAXBContext jaxbCtx = (JAXBContext) contextMap.get(context);
if (jaxbCtx == null) {
jaxbCtx = JAXBContext.newInstance(context);
contextMap.put(context, jaxbCtx);
Updated on 2012-01-18T15:07:37Z at 2012-01-18T15:07:37Z by SystemAdmin
  • SystemAdmin
    102 Posts

    Re: Check the JAXB context factory initialization class

    ‏2012-01-18T15:07:37Z  in response to Yabing
    Please see the help associated with the rule. To access the help select the rule and press F1, or shift-F1 on linux.

    The help for the rule in question states:
    "This rule flags the JAXBContext newInstance() method because the context factory method had changed since earlier versions of JAXB. Scan properties files to see if an old context factory is being used."

    Furthermore, the detailed help states:

    The WebSphere 6.1 Feature pack for Web services shipped JAXB 2.0 which used a different initialization class than is used in JAXB 2.1 or 2.2.
    The initialization class can be defined using the javax.xml.bind.context.factory property. The old initialization class was com.sun.xml.bind.ContextFactory. If the old class name is set on the javax.xml.bind.context.factory property, you will get a java.lang.ClassNotFoundException when using the JAXB libraries available with Java 6.
    This rule scans for the javax.xml.bind.JAXBContext.newInstance method which is used to obtain a JAXBContext. If you are using JAXB, you should check your application for use of the old context factory. The rule will also detect the string literals "com.sun.xml.bind.ContextFactory" or "com.sun.xml.bind.DefaultJAXBContextImpl" in Java code, but it does not scan property files where these values are often set.
    JAXB properties are commonly loaded from a file. Manually scan your application property files to determine if the old context factory is defined.
    To scan the the properties files in Eclipse, select Search > File.... In the Containing text field, type com.sun.xml.bind.ContextFactory. In the File name patterns field, type *.properties. Repeat the search for the string com.sun.xml.bind.DefaultJAXBContextImpl.
    When using JAXB in WebSphere V7 or V8, the default initialization class is if no javax.xml.bind.context.factory property is set. You can also use the Java provided context factory com.sun.xml.internal.bind.v2.ContextFactory.
    • sp30
      1 Post

      Re: Check the JAXB context factory initialization class

      ‏2013-07-30T07:08:15Z  in response to SystemAdmin

      That was useful, in the application I am upgrading

      Currently the application code on (java 1.5 run on WAS6.1) references external jaxb 2.x jars. (api and impl jars).

      There is no properties file as mentioned above, instead the javax.xml.bind.context.factory = com.sun.xml.bind.ContextFactory is mentioned in the

      external JAXBContext class mentioned in the external jaxb-api  jar.

      On researching , what I understood is WAS8.0 comes bundled with its on version of JAXB.(rt.jar)
      What is the right thing to do? Remove the reference to the external jars and use the jaxb jar that comes bundled with
      WAS8.0 or leave the code as it is and compile and checkin the code.

      • c.high
        30 Posts

        Re: Check the JAXB context factory initialization class

        ‏2013-07-30T15:25:53Z  in response to sp30

        It is best practices to use the WebSphere supported version of JAXB, and you will want to use the default initialization class for best performance. 

        If your application is dependent on the behavior of the particular JAXB implementation you are currently shipping, you can continue to use it, but make sure your classloader is set to parentlast so that your implementation gets loaded before the WebSphere version.