Pages

Monday, July 2, 2012

Axis2 too many open file handle or low disc space

one of our project team using webservices using Axis2 in their project discovered that, Axis is creating lot of temp files in temp folder and that was casuing to too many file handles open and out of disc space problems.
This has caused because of Axis2 was creating modules jars files on every request initiated by the client code. this is an unavoidable situation because Axis2 classloader requires these files.
after investigate how this files are created we got a solution to cache its instance of context for all client request so that Axis2 will not crete module files for each request. here is the sample before and after
old--
insidemethod {

AxisConfigurator configurator = null;
        configurator = new URLBasedAxisConfigurator(new URL(resourceXml), new URL(resourceRepo));
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContext(configurator);
        ...
        ...
        }
new--

private static ConfigurationContext configurationContext = null;

insidemethod {

ConfigurationContext ctx = getAxis2ConfigurationContext();
....
....
}
private static synchronized ConfigurationContext getAxis2ConfigurationContext() throws Exception {
if (configurationContext == null) {
    AxisConfigurator configurator = null;
    configurator = new URLBasedAxisConfigurator(new URL(resourceXml), new URL(resourceRepo));
    configurationContext = ConfigurationContextFactory.createConfigurationContext(configurator);
}
return configurationContext;
}

7 comments:

  1. Thanks for such a wonderful explanation and solution

    ReplyDelete
  2. Hello,

    I need help, please?

    I created a Java class to call a web service (axis2).
    Every time I instantiate this class and I call the web service,
    I have as much calls as jars in tem directory.

    For your reply I do not see too much in what class I make this change, in addition to every call I create a new instance of my class, so I do not see too much done to share context??


    thanks

    ReplyDelete
    Replies
    1. Hi There,

      This should be at very beginning where you create a configuration context for your service to call, I hope if your java class that you are using must have it or its one of super class where this code implementation is made hidden.

      If still can't get it then please send me sample code of your client files on my gmail id available on my profile

      Regards,
      Raj

      Delete
  3. Hi, my english is bas so I try.

    Where in my code do change you mention.
    when I create my client axis2 generates two files:

    SampleWSCallbackHandler.java
    SampleWSStub.java

    my client is this:

    package cyber.hack;

    import java.rmi.RemoteException;

    import org.apache.axis2.AxisFault;

    import com.sun.corba.se.impl.javax.rmi.CORBA.StubDelegateImpl;

    import cyber.hack.SampleWSStub.Echo;
    import cyber.hack.SampleWSStub.EchoResponse;


    public class Cliente {

    public static void main(String[] args) throws RemoteException {
    SampleWSStub stub = new SampleWSStub();

    //creando la peticoin
    Echo request = new SampleWSStub.Echo();
    request.setVar("evan");

    //Invocando el servicio
    EchoResponse response = stub.echo(request);

    //Visualizando la respuesta en consola
    System.out.println(response.get_return());

    }

    }


    Where do I change?

    thank you very much .. I hope you can help me.

    ReplyDelete
  4. This is a very simple client normally i think you can also pass context to the stub object that you create.
    so if you create a context then you can pass it to your contructor
    for e.g.
    ConfigurationContext ctx = getAxis2ConfigurationContext(); // this will get context from static method as explained above
    SampleWSStub stub = new SampleWSStub(ctx);
    ...
    ...

    Please check more on axis tutorials if you want.

    ReplyDelete
  5. I am newbie in AXIS2

    Your article helped me a lot. Thank you for this article.

    Ritu Raj
    +91-9560087139

    ReplyDelete