Annotation-Processing Using Custom ClassLoader Fails

Hi,
I have the following problem concerning annotations.
I am using Jaxb2 to marshal some classes and Jaxb relies heavily on processing annotation information contained in them.
If I put the Jaxb JAR's directly in the classpath everything works fine.
However, if I use a custom URLClassLoader to load all the Jaxb-related classes the annotation processing fails thus making Jaxb believe that the objects can't be marshaled.
Note that the classes to marshal containing the annotations to read are loaded with a different ClassLoader which is higher in the hierarchy.
I tracked down the problems to the class RuntimeInlineAnnotationReader of the Jaxb API which simply calls Class.getAnnotion(..).
When searching for this bug I also found the bug report 5015623 which relates to this problem. But it is rather outdated, so I hope that there are some better solutions than just ignoring it.
I wouldn't like having the Jaxb JARs on the global classpath 'cause they are used in only one class out of 100 and thats not worth the possible conflicts with other 3rd party libs.
Best regards,
beebop

No problem, I will give you some details about my architecture.
First of all I encapsulated the code which uses the Jaxb-API in one class, say Foo, which implements the interface FooInterface.
Secondly I load the Foo class in another class, Bar, using my derivation of URLClassLoader, called MyClassLoader. Then I use the interface to marshal an object gen of type GenClass where GenClass was generated using xjc:
class Bar {
  void method(URL[] urls, GenClass gen) {
    ClassLoader parent = Bar.class.getClassLoader();
    ClassLoader myCL = new MyClassLoader(urls,parent);
    Class clazz = myCL.loadClass("Foo");
    FooInterface foo = (FooInterface)clazz.newInstance();
    foo.marshal(gen);
}So my class loader will be a child of the current class loader. The delegation model of class loading is reversed in MyClassLoader so that first the urls will be checked and then, if the class was not found, the parent class loader.
Note that GenClass and its ObjectFactory which acutally contain the annotations Jaxb needs will be loaded by the current class loader, not my own. All classes of the Jaxb-API will be loaded by MyClassLoader. If I try to marshal gen, the annotations of the ObjectFactory corresponding to GenClass won't be readable causing the Class.getAnnotation(...) method called in the class RuntimeInlineAnnotationReader to return null.
If I don't use my own class loader, say
FooInterface foo = new Foo();everything works fine and the annotations of the ObjectFactory are loaded correctly.
I observed the different behaviour by stepping through the classes and methods around JaxbContext.newInstance(...).
MyClassLoader is not that different from URLClassLoader, only the loadClass method is overridden to change the delegation behaviour. Thats why I suspect an error in the annotations framework and not in my class loader but I may be mistaken.
Best regards,
beebop

Similar Messages

  • How to load an applet using custom classloader ?

    Hi All,
    How to load an applet using custom classloader rather than using default browsers classloader i.e AppletClassLoader usually ?
    Regards,
    Kumar.

    I would guess that that would require two applets.
    The first does nothing but create the custom class loader and then load the second applet.

  • Annotation processing using JDK 1.6 and Apache Ant

    Hello,
    I am trying to run my annotation processor using ant.
    I already built the processor, the javax.annotation.processor.Processor file is in the correct place with the correct content.
    The jar with the processor is in the classpath (i can see it in ant -v), but it does not process my classes. in fact, i get the warning:
    warning: Annotation processing without compilation requested but no processors were found.Do i have to specify -processor or -processorpath or can i just leave it to the default classpath scanning?
    I think everything is in the correct place, because when i compile with maven instead of ant, specifying the processor, it runs nicely. My pom contains:
                   <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                             <source>1.6</source>
                             <target>1.6</target>
                             <compilerArguments>
                                  <processor>br.com.sonner.infra.seguranca.SegurancaAnnotationProcessor</processor>
                             </compilerArguments>
                        </configuration>
                   </plugin>i am using jdk 1.0.6_02 and ant 1.7.0.
    Can anyone help me find out what am i doing wrong?

    Julio.Faerman wrote:
    Hello,
    I am trying to run my annotation processor using ant.
    I already built the processor, the javax.annotation.processor.Processor file is in the correct place with the correct content.
    The jar with the processor is in the classpath (i can see it in ant -v), but it does not process my classes. in fact, i get the warning:
    warning: Annotation processing without compilation requested but no processors were found.Do i have to specify -processor or -processorpath or can i just leave it to the default classpath scanning?When -processor is not given, a service loader is used to find the annotation processors (if any). In addition to the class files of the process, to allow your processor to be found as a service, make sure you've also provided the needed META-INF data in the jar file. The general service file format is described in
    http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html
    That said, I'd recommend setting an explicit processor path separate from your general classpath.

  • Complie time using custom classloader for decryption.

    I need to decrypt several class during compile time, but my custom classloader could load everything except my encrypted classes.
    Here is my sample code and how I test it.
    Test.java:
    public class Test {
         public Test(){
              System.out.println("test");
         public void hello(){
              System.out.println("hello");
    Test1.java
    public class Test1 extends java.lang.Test{
         public Test1(){
              System.out.println("test1");
         public static void main(String[] args){
              new Test1().hello();
    #EncryptedClassLoader will print out the class name it trying to load, for example: "load class: java.lang.System"
    1. Compile Test.java file and have it encrypted, make it into a jar file - test.jar.
    2. Compile Test1.java file and try to run Test1.class with encrypted Test.class file using :
    C:\lib>java -Djava.system.class.loader=EncryptedClassLoader -classpath c:\lib;c:\lib\tools.jar;c:\lib\test.jar Test1
    Gives the output:
    load class: java.lang.System
    load class: java.nio.charset.Charset
    load class: java.lang.String
    load class: Test1
    load class: Test
    load class: sun.security.provider.Sun
    load class: sun.security.rsa.SunRsaSign
    load class: com.sun.net.ssl.internal.ssl.Provider
    load class: com.sun.crypto.provider.SunJCE
    load class: java.lang.Object
    load class: java.io.PrintStream
    test
    test1
    hello
    So now I'm sure there's no problem with my EncryptedClassLoader
    3. Try to compile Test1.java with the encrypted Test.class in test.jar(These's no Test.java file in the same folder) by using:
    C:\lib>javac -J-Djava.system.class.loader=EncryptedClassLoader -J-classpath -J.;c:\lib;c:\lib\tools.jar;c:\lib\test.jar Test1.java
    Give the output:
    .............. (loading several system classes)
    load class: com.sun.tools.javac.util.Position
    Test1.java:4: cannot find symbol
    symbol: class Test
    public class Test1 extends Test{
    ^
    load class: java.lang.Long
    load class: java.io.DataInputStream
    load class: com.sun.tools.javac.jvm.ClassReader$AnnotationCompleter
    load class: com.sun.tools.javac.jvm.ClassReader$AnnotationDeproxy
    load class: com.sun.tools.javac.jvm.ClassReader$ProxyVisitor
    load class: com.sun.tools.javac.code.Types$SubstFcn
    load class: com.sun.tools.javac.code.BoundKind
    load class: java.lang.StringBuffer
    Test1.java:12: cannot find symbol
    symbol : method hello()
    location: class Test1
    new Test1().hello();
    ^
    2 errors
    ---> from the output I found that Test.class never visited/loaded by my EncryptedClassLoader
    Though I set EncryptedClassLoader as the default system classloader but it seems to load everything except my encrypted class.
    Does anyone know why it works like this??
    Thank you in advanced,
    Alex.
    null

    I don't know why he was specifying the javac classpath like that instead of using javac's -classpath option.
    But this whole business of decrypting class loades is pretty much a waste of time. It adds a layer of comfort but it's not really what I would call secure. At some point the unencrypted bytes have to appear in memory and from that point the classes are no longer secure.
    The best protection against software piracy is not anti-decompilation techniques but time-to-market and pricing your product so that buying it is cheaper than reverse-engineering it.

  • Using custom ClassLoader

    Is there a way to make my custom ClassLoader the default ClassLoader for my program?
    ie. Can I just set up my program to use my ClassLoader whenever it needs to access class files?
    Geoff.

    Hi,
    The main class is always loaded by the boot strap class loader(also called System ClassLoader). You can't change it. After that all the classes are loaded by the classloader of the loading class. i.e.
    If class A is loading class B, then class B's classloader will be the classloader of class A.
    So, basically you need to write a classloader, and a wrapper class for your main class like:
    public class WrapperClass
        public void main(String[] args) throws Exception
           MyClassLoader myClassLoader = new MyClassLoader();
           Class mainClass = myClassLoader.loadClass("MainClass");
           Method mainMethod = mainClass.getMethod("main", new Class[] {args.getClass()});
           mainMethod.invoke(null, args);
    }then rest of the classes including MainClass are loaded by the MyClassLoader. If you need help you writing ClassLoader please reply back.
    Hope this helps.

  • Custom classloader fails when using Java Web Start

    Hope you can help me with a problem that is driving me nuts. I have implemented my own classloader to support plugins. This classloader works as follows:
    1. The classloader is configured to access a plugin components jar file downloaded by jws.
    2. The plugin components jar file contains other jar files which contains the actual plugin code to be loaded using my own classloader.
    3. Upon initialization - my classloader extracts all jar files contained in the plugin components jar file into temporary files.
    4. These temporary files are used by my classloader when defining plugin classes.
    The classloader works fine when not using java web start. Then I launch the application using java web start with security policy in .jnlp file set to:
    <security>
    <all-permissions/>
    </security>
    After a while (it was able to load some of the classes) it fails with the following stack-trace:
    Regards,
    Terje
    java.security.AccessControlException: access denied (java.io.FilePermission C:\DOCUME~1\TEOES\LOCALS~1\Temp\activity61102.jar read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at java.util.zip.ZipFile.<init>(Unknown Source)
         at java.util.jar.JarFile.<init>(Unknown Source)
         at java.util.jar.JarFile.<init>(Unknown Source)
         at my.plugin.ActivityClassLoader.getJarFileEntry(ActivityClassLoader.java:258)
         at my.plugin.ActivityClassLoader.search(ActivityClassLoader.java:244)
         at my.plugin.ActivityClassLoader.loadClass(ActivityClassLoader.java:99)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Does anyone have source code for implementing a simple class loader that can be used with Java Web Start (preferrably with all jar files to be used by the classloader wrapped into a jar file)

    If you implement your own classloader, and then still run with a SecurityManager installed, then your ClossLoader is responsible for asigning the permissions to the code it loads.
    You need your ClassLoader to extend SecureClassLoader, and implement the method :
    SecureClassLoader.getPermissions(CodeSource cs) to return the PermissionCollection you want.
    /Andy

  • Can't use custom ClassLoader with ObjectInputStream

    Hi all,
    I want to transmit an object whose class is unknown to the receiver and whose class may not be loaded. Of course when the inputstream's readObject method tries to receive this class, it fails with a ClassNotFoundException. I have a custom FileClassLoader to dynamically load classes, this is tested and works.
    I can dynamically load this class and prove that the class was loaded by calling class.newInstance() from the loader.loadClass method. But then when I try to read that same class from the input stream, it says ClassNotFoundException!
    The code snippet looks like this:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    FileClassLoader loader = new FileClassLoader(classFolder);
    Class L = loader.loadClass(className); // no .class at end
    System.out.println("New Instance "+L.newInstance().toString()); // works
    ObjectInputStream eventStream = ... // stream from a socket
    eventStream.readObject(); // throws class not found exception!
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The only thing I can think is that the input stream only looks for classes loaded by the system classloader, could that be true? What other possibilities are there?
    If this is more appropriate for another forum just let me know and I'll post it there.
    Thanks in advance for any helpful hints anybody has!

    I was thinking of something along the lines of
    ObjectInputStream eventStream = (ObjectInputStream)Class.forName("java.io.ObjectInputStream", true, loader).newInstance();Of course, you would really have to get the proper Constructor for the class - and that just gets too long and stupid. Besides, I actually tried my suggestion, and it didn't work. I also tried setting the ContextClassLoader for the current thread (and creating a new thread with the ContextClassLoader set to "loader"). None of that works. Just setting the ContextClassLoader does not make the thread use it implicitly, it's apparently just a way to pass another ClassLoader to a thread, but it still needs to be used explicitly in a Class.forName call.
    I did, however, try David's suggestions of overriding resolveClass in ObjectInputStream. That worked fine! Here's what I created:
    import java.net.URLClassLoader;
    import java.io.InputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectStreamClass;
    import java.io.StreamCorruptedException;
    public class MyObjectInputStream extends java.io.ObjectInputStream
        URLClassLoader myLoader = null;
        public MyObjectInputStream(URLClassLoader newLoader, InputStream theStream) throws IOException, StreamCorruptedException
            super(theStream);
            myLoader = newLoader;
        protected Class resolveClass(ObjectStreamClass osc) throws IOException, ClassNotFoundException
            System.out.println("Hey, I'm in my resolveClass");
            Class theClass = null;
            try
                theClass = Class.forName(osc.getName(), true, myLoader);
            catch (Exception e)
                System.err.println("An Error in my ResolveClass:");
                e.printStackTrace();
            return theClass;
    }You then just create your ObjectInputStream with
    ObjectInputStream eventStream = new MyObjectInputStream(loader, theSocket.getInputStream());

  • Custom ClassLoader - fails to load java/lang/Object

    I have created a custom class loader based substantially on Jim Farley's code in "Java Distributed Computing" pp 39-44.
    The code does get a URL connection, download the class file, but fails when it tries to load (re-load) java/lang/Object. My understanding is that the same (custom) class loader is also used to load dependent classes (needed by the class your are originally loading). I had assumed that this would be handled by the call to findSystemClass() I had assumed.
    Any help or direction is appreciated,
    Jeff.
    Here is the output:
    File=/tasks/Person.class
    Host=n01
    Trying to load:/tasks/Person
    Check system :/tasks/Person
    Not found in System:/tasks/Person
    Check stream:/tasks/Person
    Class file is 815 bytes.
    Available = 815
    RemoteClassLoader: Reading class from stream...
    RemoteClassLoader: Defining class...
    java.lang.ClassNotFoundException: Cannot find class definition:
    java.lang.NoClassDefFoundError: java/lang/Object
         at java.lang.ClassLoader.defineClass0(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:426)
         at RemoteClassLoader.readClass(RemoteClassLoader.java:83)
         at RemoteClassLoader.loadClass(RemoteClassLoader.java:139)
         at TestRemoteClassLoader.main(TestRemoteClassLoader.java:18)
    Class was not loaded.Here is the code:
    import java.lang.*;
    import java.net.*;
    import java.io.*;
    import java.util.Hashtable;
    public class RemoteClassLoader extends ClassLoader {
       URL classURL = null;
       InputStream classStream = null;
       java.lang.Object o = null;
       Hashtable classCache = new Hashtable();
       InputStream source = null;
       // Constructor
       public RemoteClassLoader()
       // Parse a class name from a class locator (URL, filename, etc.)
       protected String parseClassName(String classLoc)
          throws ClassNotFoundException
             String className = null;
             try { classURL = new URL(classLoc); }
             catch (MalformedURLException malex) {
                throw new ClassNotFoundException("Bad URL \"" + classLoc + "\"given: " + malex);
             System.out.println("File=" + classURL.getFile());
             System.out.println("Host=" + classURL.getHost());
             String filename = classURL.getFile();
             // Make sure this is a class file
             if (!filename.endsWith(".class"))
                throw new ClassNotFoundException("Non-class URL given.");
             else
                className = filename.substring(0,filename.lastIndexOf(".class"));
             return className;
       // Initialize the input stream from a class locator
       protected void initStream(String classLoc)
          throws IOException
             classStream = classURL.openStream();
       // Read a class from the input stream
       protected Class readClass(String classLoc, String className)
          throws IOException, ClassNotFoundException
             //See how large the class file is.
             URLConnection conn = classURL.openConnection();
             int classSize = conn.getContentLength();
             System.out.println("Class file is " + classSize + " bytes.");
             // Read the class bytecodes from the stream
             DataInputStream dataIn = new DataInputStream(classStream);
             int avail = dataIn.available();
             System.out.println("Available = " + avail);
             System.out.println("RemoteClassLoader: Reading class from stream...");
             byte[] classData = new byte[classSize];
             dataIn.readFully(classData);
             // Parse the class definition from the bytecodes
             Class c = null;
             System.out.println("RemoteClassLoader: Defining class...");
             try{ c = defineClass(null, classData, 0, classData.length); }
             catch (ClassFormatError cfex) {
                throw new ClassNotFoundException("Format error found in class data.");
             catch (NoClassDefFoundError clsdeferr) {
                clsdeferr.printStackTrace();           
                throw new ClassNotFoundException("Cannot find class definition:\n" + clsdeferr);
             return c;
       // load the class
       public Class loadClass(String classLoc, boolean resolve)
          throws ClassNotFoundException
             String className = parseClassName(classLoc);
             Class c;
             System.out.println("Trying to load:" + className);
             //maybe already loaded
             c = findLoadedClass(className);
             if (c!=null) {
                System.out.println("Already loaded.");
                return c;
             c = (Class) classCache.get(className);
             if (c!=null) {
                System.out.println("Class was loaded from cache...");
                return c;
             System.out.println("Check system :" + className);
             // Not in cache, try the system class...
             try {
                c = findSystemClass(className);
                if (c!=null) {
                   System.out.println("System class found...");
                   classCache.put(className, c);
                   return c;
             catch (ClassNotFoundException cnfex) {
                System.out.println("Not found in System:" + className);
                ; // keep looking
             System.out.println("Check stream:" + className);
             // Not in system either, so try to get from tthe stream
             try {initStream(classLoc); }
             catch (IOException ioe) {
                throw new ClassNotFoundException("Failed opening stream to URL.");
             // Read the class from the input stream
             try {c = readClass(classLoc, className); }
             catch (IOException ioe) {
                   throw new ClassNotFoundException("Failed reading class from stream: " + ioe);
             // Add the new class to the cache for the next reference.
             classCache.put(className, c);
             // Resovle the class, if requested
             if (resolve)
                resolveClass(c);
             return c;

    Never mind - I've figure it out.
    The problem is that the ClassLoader calls RemoteClassLoader.loadClass() to load in java.lang.Object, which is fine. But, my code tries to first create a URL from this, which fails, eventually throwing a NoClassDefFoundError.
    I have fixed it by delaying the call to parseName() until after checking loaded classes and system classes.

  • JAXB 1.0 Final: jaxb.properties not found when using custom classloader

    JDK 1.3.1 is being used.
    The scenario:
    1) jaxb jar files, jaxb generated files and application files loaded in default class loader works, however
    2) jaxb jar files, jaxb generated files and application files loaded in a custom class loader generate the following exception:
    javax.xml.bind.JAXBException: Unable to locate jaxb.properties for package XXX
    To demonstrate here are two sample applications: a Launcher app whose job it is to start apps and a sample App1 application who needs JAXB.
    If launch is placed into a jar file named launch.jar and App1 is placed into a jar file named app1.jar (with a JAXB generated package), and both jar files are placed in a directory containing all the JAXB 1.0 jar files (dom, sax, namespace, etc) and the system is started with the following:
    jre\bin\java -cp launch.jar; testLaunch.launch
    the exception occurs.
    By way of comparison, if App1 is started directly with the following:
    jre\bin\java -cp app1.jar;jax-qname.jar;jaxb-xjc.jar;jaxb-ri.jar;jaxb-libs.jar;jaxb-api.jar;dom.jar;sax.jar;jaxp-api.jar;xercesImpl.jar;namespace.jar;ant.jar;xalan.jar testApp.app1
    the exception does not occur.
    Any help would be greatly appreciated.
    package testLaunch;
    import java.net.*;
    import java.io.*;
    public class launch extends javax.swing.JFrame
        private static URLClassLoader app1ClassLoader_; 
        private static Class  app1EntryClass_ = null;
        private static final String app1MainClassName_ = "testApp.app1";
        private Object appObj_ = null;
         static public void main(String args[])
              try {
                System.out.println("Launch Main");               
                new launch();          
                  System.exit(0);
              catch (Throwable t) {
                   t.printStackTrace();
                   System.exit(1);
         public launch()
            if (app1ClassLoader_== null)
                loadAppClassLoader();
            try{
                if (app1EntryClass_ == null)
                    app1EntryClass_ = app1ClassLoader_.loadClass(app1MainClassName_);
                if (app1EntryClass_ == null)
                    System.out.println(app1MainClassName_ + " was not found");
                else
                    appObj_ = app1EntryClass_.newInstance();
            catch(ClassNotFoundException x){
                x.printStackTrace();
            catch(Exception x){
                x.printStackTrace();
        private static void loadAppClassLoader()
            String jarPath = jarPath = System.getProperty("user.dir");
            System.out.println("jar path is: " + jarPath);
            try{
                File jarfile1 = new File(jarPath+File.separator+"app1.jar");
                File jarfile2 = new File(jarPath+File.separator+"dom.jar");
                File jarfile3 = new File(jarPath+File.separator+"jaxp-api.jar");
                File jarfile4 = new File(jarPath+File.separator+"jaxb-api.jar");
                File jarfile5 = new File(jarPath+File.separator+"jaxb-xjc.jar");
                File jarfile6 = new File(jarPath+File.separator+"jaxb-ri.jar");
                File jarfile7 = new File(jarPath+File.separator+"jaxb-libs.jar");
                File jarfile8 = new File(jarPath+File.separator+"jax-qname.jar");
                File jarfile9 = new File(jarPath+File.separator+"sax.jar");
                File jarfile10 = new File(jarPath+File.separator+"xercesImpl.jar");
                File jarfile11 = new File(jarPath+File.separator+"namespace.jar");
                File jarfile12 = new File(jarPath+File.separator+"xalan.jar");
                File jarfile13 = new File(jarPath+File.separator+"ant.jar");
                if (!jarfile1.exists())
                    System.out.println("**ERROR " + jarfile1 + " does not exist!");
                app1ClassLoader_ = new URLClassLoader( new URL[]{jarfile1.toURL(),
                                                                jarfile2.toURL(),
                                                                jarfile3.toURL(),
                                                                jarfile4.toURL(),
                                                                jarfile5.toURL(),
                                                                jarfile6.toURL(),
                                                                jarfile7.toURL(),
                                                                jarfile8.toURL(),
                                                                jarfile9.toURL(),
                                                                jarfile10.toURL(),
                                                                jarfile11.toURL(),
                                                                jarfile12.toURL(),
                                                                jarfile13.toURL()} );
            catch(Exception x){
                x.printStackTrace();
                return;
    package testApp;
    import javax.xml.bind.*; // JAXB classes
    import myGeneratedJAXBFiles;
    public class app1 extends javax.swing.JFrame
         static public void main(String args[])
              try {
                System.out.println("App1 Main");               
                new app1();           
                  System.exit(0);
              catch (Throwable t) {
                   t.printStackTrace();
                   System.exit(1);
         public app1()
            try
                JAXBContext jc_ = JAXBContext.newInstance( "myGeneratedJAXBFiles" );
                System.out.println("Successfully loaded JAXB Context");          
            catch (JAXBException jbe)
                jbe.printStackTrace();

    I'm doing something very similar. In fact my launcher is also stored in launcher.jar. It will start any application on the classpath and load dependencies jars located in the specified directory.
    The first thing you must do is specify the classloader when constructing the jaxb context:
    JAXBContext jc = JAXBContext.newInstance(xmlPackage, getClass().getClassLoader());
    After this I was still raning into the "jaxb.properties not found" exception in some situations. Basically if the class using the jaxb files is located in the same jar as jaxb.properties everything worked fine. However if the class using the jaxb objects was located in a different jar it did not work.
    I had to add the following early in the execution of the application that load the plugins to get things working correctly:
    Thread.currentThread().setContextClassLoader(jarDirClassLoader);
    As far as I can tell JAXB using the Context class loader to find the jaxb.properties file.
    I'm using JAXB 1.1
    I hope this helps!

  • Inbound idoc processing using custom FM to cancel sales orders

    hello all,
             I have a scenario where i need to create a customized function module which is assigned to custom message type. and this function module is triggered when inbound idoc comes, which will process idoc data for cancellation of sales orders. If an errror occurs than the error during cancellation has to be reflected back in the idoc status.
          can anyone tell me how exactly i can log the status and reflect it back, how exactly can i do this
         And what are all the objects i need to create to succusfully execute  this scenario, i have created message type, function module, i am using orders05 do i need to create process code also.
    Thanks,
    krishnam raju.

    Hi Krishna,
       Hope you are done with the Inbound function module creation. But, just creation of function module would not be enough, what u said that is like creation of Process code should also be done.
    WE42 is the transaction code for inbound process code.
    And while creation of the process code, we need to do few things like:
    We need to create an entry of the inbound function module in BD51 transaction or so. And coming to updating of the status, open any of the inbound function module, you will observe that there is a standard subroutine which will update the IDOC_STATUS record. You can implement the same logic whenever you want to update an error message.
    Thanks,
    Adithya K

  • Loading jar at runtime using custom classloader

    Hi,
    I'm trying to load a jar file to an application running inside weblogic at runtime.
    I followed the example that was posted at
    http://dev2dev.bea.com/cs/user/blog?file=/blog/jcscoobyrs/archive/2005/05/realworld_use_f.html
    and did the following:
    URLClassLoader loader = null;
    URL[] urls = {new URL("file:///" + "C:/Program Files/aaa/WEB-INF/lib/ImportTest3.jar")};
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    ClassLoader loader = new URLClassLoader(urls, classLoader);
    Thread.currentThread().setContextClassLoader(loader);
    Class customClass = Class.forName(className, true, loader);
    customCode = customClass.newInstance();
    Thread.currentThread().setContextClassLoader(classLoader);
    everything works fine when I access my application once.
    But when I'm trying to do the same again, everything fails.
    Any ideas?
    Thanks!

    When you say everything fails - can you clarify the failure? Can you paste the stacktrace? Is it a ClassNotFoundException?

  • Using custom classloader with javac

    There is an interesting thread going on at http://forums.java.net/jive/thread.jspa?threadID=13417&tstart=0.
    Since this forum seems to be more active than that forum, I wonder if anyone has an answer to my last post on that thread (post number 4 by garyh)?
    Thanks for any help.

    Please ignore this post.
    It was submitted before I finished writing it.
    Sorry,
    zganon

  • Code Generation Using Annotation Processing

    I'm trying to figure out how to do something like thus:
    Given this source file with the following custom annotation:
    @Composite(interfaces=Mammal.class)
    public class Dog implements IComposite
    };I want to create an annotation processor that inserts a data member, implementation into the constructor, and a public method into this class:
    @Composite(interfaces=Mammal.class)
    public class Dog implements IComposite
        IComponent[] m_inner_objects;
        public Dog()
            m_inner_objects = new IComponent[1];
            m_inner_objects[0] = Mammal.compose(this);
        public IComponent getComponent(Class<?> inInterface)
            if(inInterface == Mammal.class)
               return m_inner_objects[0];
            return null;
    };Are all three tasks possible? Are any of the three tasks possible? If yes to any of my questions how would I go about this. I've gotten just past the 'hello world' state in writing a custom annotation processor so I just need the more advanced knowledge of how to actually affect the code once I'm actively processing it.
    cheers,

    brucechapman wrote:
    sednivo wrote:
    I can get the CompilationUnitTree. Yes
    Then I can modify it with Compiler Tree API.Really?
    Where is a pitfall in my train of thought?The Tree API is an immutable API, you can look, but not modify.Here is example of modifying compiler tree.
    http://svntrac.hanhuy.com/repo/browser/hanhuy/trunk/panno/src/com/hanhuy/panno/processing/PropertyProcessor.java
    Also, the javax.annotation.processing.Filer will not allow you to overwrite an existing compilation unit, and you must use the Filer if you wish a generated class to be compiled in the next round.I don't use Filer class. Method writeCompilationUnit that I've wrote works well for existed files.
    There is a fundamental principle of java that the same program always has the same meaning. See the 3rd paragraph of the Preface to the first edition of the Java Language Spec . >This is the reason why you can't modify existing source code.We can mark generated methods in a class with @Generated annotation.

  • Custom Sql fails when using Date Parameter

    I need to do following using DB adapter
    select count(*) from some_table where creation_date >= #from_date and creation_date <= #to_date
    I used Custom sql options, but It did not asked for add params. so I added manually above params in the query. I am getting following query. I don't know how to get this working. i am on 10.1.3.
    Here I am getting from and to dates from a AQ message. AQ has from and to_date as date type elements. I am doing copy assign of these to SQL input params
    below is the error.
    <messages><input>
    <RecordCount_service_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    name="XI_RecordCount_serviceInput_msg"><XI_RecordCount_serviceInput xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/XI_RecordCount_service">
    <ns0:v_fromdate1 xmlns="" xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/XI_RecordCount_service">2008-01-01T00:00:00.000-06:00</ns0:v_fromdate1>
    <ns0:v_todate1 xmlns="" xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/XI_RecordCount_service">2008-01-31T00:00:00.000-06:00</ns0:v_todate1>
    <ns0:v_fromdate2 xmlns="" xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/XI_RecordCount_service">2008-01-01T00:00:00.000-06:00</ns0:v_fromdate2>
    <ns0:v_todate2 xmlns="" xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/XI_RecordCount_service">2008-01-31T00:00:00.000-06:00</ns0:v_todate2>
    </XI_RecordCount_serviceInput>
    </part></RecordCount_service_InputVariable></input><fault><bindingFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="code"><code>1861</code>
    </part><part name="summary"><summary>file:/u01/app/oracle/product/10.1.3/bpm/bpel/domains/arun/tmp/.bpel_XI_P2EU_Allegro_Service_1.0_79d8666bc8efe5a375691e0a5f06e2e4.tmp/XI_RecordCount_service.wsdl [ XI_RecordCount_service_ptt::XI_RecordCount_service(XI_RecordCount_serviceInput_msg,XI_RecordCount_serviceOutput) ] - WSIF JCA Execute of operation 'XI_RecordCount_service' failed due to: Pure SQL Exception.
    Pure SQL Execute of select count(*) record_count FROM XI_TABLE WHERE ( (trunc(CREATION_DATE) >= ? AND TRUNC(CREATION_DATE) &lt;= ?) OR (trunc(last_update_date) >= ? AND TRUNC(last_update_date) &lt;= ?) ) failed. Caused by java.sql.SQLException: ORA-01861: literal does not match format string
    ; nested exception is:
         ORABPEL-11633
    Pure SQL Exception.
    Pure SQL Execute of select count(*) record_count FROM XI_TABLE WHERE ( (trunc(CREATION_DATE) >= ? AND TRUNC(CREATION_DATE) &lt;= ?) OR (trunc(last_update_date) >= ? AND TRUNC(last_update_date) &lt;= ?) ) failed. Caused by java.sql.SQLException: ORA-01861: literal does not match format string
    The Pure SQL option is for border use cases only and provides simple yet minimal functionality. Possibly try the "Perform an operation on a table" option instead.
    </summary>
    </part><part name="detail"><detail>ORA-01861: literal does not match format string
    </detail>
    </part></bindingFault></fault></messages>

    I think the database accepts only your database format' dd-mm-yyyy'.
    Try to define #from_date & #to_date as string and use to_date() in your custim sql statement.
    Marc

  • Cancel Work process using SM50 fails

    When I ran a custom program while developing and system was hung. So I did CNTR ALT DEL. After that
    tried to cancel a work process using SM50 cancel without core, cancel with core, end session, end session using SM04 etc.
    I am getting a message "&An error occured when exiting the process".
    It seems work process released the program I was executing, but still shows in SM50 as running with no program details.
    SM04 Shows this extra session as SE38.
    Is there any function module to kill the Process by PID? or Any other means to kill the session from presentation server?
    Thanks in advance for your help.

    Hi,
    The options are... to try to kill it from SM04 / try to kill it from Sm50 / relogin and try to kill...
    If these does not work another option could be to do the following..
    The report program RSBDCOS0 can be used to execute an OS command on the application server....and on a windows server the command "taskkill" can be used to kill a process...
    SO run report RSBCOS0 and execute the OS command "taskkill /PID <nnn>"
    Thanks,
    Renjith

Maybe you are looking for

  • The error is " The Mapping to Node has not been completed

    Hi All, I am getting a strange type of error and need help immediately. The error is " The Mapping to Node COMPONENTCONTROLLER.1.PLANNING_ENTITY Has Not Been Completed" for the node that exists in the Parent component and is being used in all the chi

  • Compile jsp page

    Hi, I hope someone could help me there is a point i haven't undeerstood! I want to print data from a base to a jsp. So i have created my driver and a bean to access my base. I compile my bean and the driver without any pbm(they belong to a package).

  • Currency display problem in Report using WBS Element

    Hi Experts, PCS report displying different values aginest same WBS elements, in different currency. Report painter tool has been used. Requirement is  to display entered currency in the report. i.e the currency which is entered in selection screen. R

  • MR51 - Accounting & Material Doc

    Dear All I want to enhancement of Mr51 for MIIGO & MIRO doc no correspondance with Accounting doc. Please advise. WBR Avijit

  • HT2486 Smart Group not working for Multiple 'Not a Member of' Options

    I am trying to go through my contacts and assign everyone to a group.  I want to create a smart group whose criteria is "not in Group 1" AND 'Not in Group 2'. This does not work.  It simply gives me all the contacts. Also, is there anyone to see a co