Hi Martin,

Guice code came from maven central, but should be the same as your link, yes.

org.apache.axis2.ServiceObjectSupplier is in axis2-1.5.1.jar, so from
http://ws.apache.org/axis2/download/1_5/download.cgi

My implementation of ServiceObjectSupplier is
GuiceServiceObjectSupplier (attached).  We also need a web.xml and some
glue classes for the guice/servlet integration (attached).  This
approach is very similar to that at
http://ssagara.blogspot.com/2009/05/guice-axis2-integration.html .

Finally, we add <parameter name="ServiceClass"
locked="false">com.example.Api</parameter>
       <parameter name="ServiceObjectSupplier"
locked="false">com.example.guiceintegration.GuiceServiceObjectSupplier</parameter>
    to the services.xml (as per
http://ws.apache.org/axis2/1_5_1/axis2config.html#Service_Configuration)

Our service class com.example.Api can now use google injections.

So, my question is: In the case when I use jsr181 annotations, and
deploy my annotated pojo, as at
http://ws.apache.org/axis2/1_5_1/pojoguide.html#jsr181pojows I don't
have a services.xml.  How then can I tell axis2 to use my
GuiceServiceObjectSupplier?

Hope you can now track what I'm trying to do - let me know if I've
missed any details.

Cheers,

Bruce.



Quoting Martin Gainty <[email protected]>:


Hi Bruce

experiencing difficulty tracking your guice injection effort

did you get your Guice code here?
http://code.google.com/p/google-guice/downloads/list

can you provide the link for the jars or source which contain
ServiceObjectSupplier?

thanks!
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede
unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig.
Diese Nachricht dient lediglich dem Austausch von Informationen und
entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten
Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den
Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes
pas le destinataire prévu, nous te demandons avec bonté que pour
satisfaire informez l'expéditeur. N'importe quelle diffusion non
autorisée ou la copie de ceci est interdite. Ce message sert à
l'information seulement et n'aura pas n'importe quel effet légalement
obligatoire. Étant donné que les email peuvent facilement être sujets
à la manipulation, nous ne pouvons accepter aucune responsabilité
pour le contenu fourni.




Date: Sun, 25 Apr 2010 23:46:08 +0100
From: [email protected]
To: [email protected]
Subject: [Axis2] JSR181 and ServiceObjectSupplier

Hi,

I'm using axis2-1.5.1.  What is the JSR181 equivalent of the parameter
"ServiceObjectSupplier" in services.xml?  Is it sensible to write a
custom POJODeployer?

I'm trying to integrate Google Guice and Axis2 using JSR181 annotated
POJOs to define my web service.

a) I can make Guice inject dependencies into my services by adding the
parameter

  <parameter name="ServiceObjectSupplier" locked="false">
com.example.guiceintegration.GuiceServiceObjectSupplier
  </parameter>
       to my services.xml, where
com.example.guiceintegration.GuiceServiceObjectSupplier is an
implementation of org.apache.axis2.ServiceObjectSupplier which supplies
instances of the service object obtained from the Guice injector.

b) I can deploy JSR181 annotated POJOs by putting the .class in the
directory specified in <deployer extension=".class" directory="pojo"
class="org.apache.axis2.deployment.POJODeployer"/> in my axis2.xml


What is the best way to combine a) and b)?

Either

1) Is there an annotation which does the job of the
ServiceObjectSupplier parameter?  I would like something like
@WebService(name="foo",
serviceobjectsupplier=GuiceServiceObjectSupplier.class).

or

2) Can I achieve the effect I want by writing a custom POJODeployer?
I'm not very familiar with the axis2 codebase - is there a hook for
creating service objects?

might be good approaches.









---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


_________________________________________________________________
Hotmail is redefining busy with tools for the New Busy. Get more from
your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2


package com.example.guiceintegration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

import org.apache.axis2.AxisFault;
import org.apache.axis2.ServiceObjectSupplier;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.log4j.Logger;

import com.google.inject.Injector;

/**
 * Supplies service objects, created by Guice, to Axis.
 * 
 * @author bruce
 * 
 */
public class GuiceServiceObjectSupplier implements ServiceObjectSupplier {

    private static final String INJECTOR_NAME = Injector.class.getName();
    private static final String SERVICE_CLASS_PARAMETER_NAME = "ServiceClass";

    private static final Logger log = Logger.getLogger(GuiceServiceObjectSupplier.class);

    public Object getServiceObject(AxisService axisService) throws AxisFault {

        try {
            Class<?> serviceClass = serviceClass(axisService);
            Injector injector = injector(axisService);

            if (serviceClass != null && injector != null) {
                return injector.getInstance(serviceClass);
            }

        } catch (ServiceObjectException e) {
            log.error(e.getMessage());
        } catch (ClassNotFoundException e) {
            log.error(e.getMessage());
        }

        return null;
    }

    private Injector injector(AxisService axisService) throws ServiceObjectException {
        Parameter servletConfigParam = axisService.getAxisConfiguration().getParameter(HTTPConstants.HTTP_SERVLETCONFIG);

        if (servletConfigParam == null) {
            throw new ServiceObjectException("Axis2 Can't find ServletConfigParameter");
        }

        Object obj = servletConfigParam.getValue();
        ServletContext servletContext;
        if (obj instanceof ServletConfig) {
            ServletConfig servletConfig = (ServletConfig) obj;
            servletContext = servletConfig.getServletContext();
        } else {
            throw new ServiceObjectException("Axis2 Can't find ServletConfig");
        }

        return (Injector) servletContext.getAttribute(INJECTOR_NAME);
    }

    private Class<?> serviceClass(AxisService axisService) throws ClassNotFoundException, ServiceObjectException {
        Parameter serviceParam = axisService.getParameter(SERVICE_CLASS_PARAMETER_NAME);
        if (serviceParam == null) {
            throw new ServiceObjectException("Couldn't find parameter '" + SERVICE_CLASS_PARAMETER_NAME + "' in axis service config.");
        }
        String serviceName = (String) serviceParam.getValue();
        if (serviceName == null) {
            throw new ServiceObjectException("Parameter '" + SERVICE_CLASS_PARAMETER_NAME + "' in axis service config has no value.");
        }
        return Class.forName(serviceName.trim());
    }

    private static class ServiceObjectException extends Exception {

        public ServiceObjectException(String message) {
            super(message);
        }

    }

}

-----------------------------

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
    version="2.4">
   
    <filter>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>com.example.guiceintegration.GuiceServletConfig</listener-class>
    </listener>

</web-app>

--------------------------------


-----------------------------------------

package com.example.config;

import com.google.inject.AbstractModule;
import com.google.inject.servlet.ServletModule;
import com.example.GuiceAxisServlet;

public class WebappModule extends AbstractModule {

    @Override
    protected void configure() {
        install(new ServletModule() {
            @Override
            protected void configureServlets() {
                serve("/services/*").with(GuiceAxisServlet.class);
            }
        });
    }
}


-----------------------------------------

package com.example.guiceintegration;

import org.apache.axis2.transport.http.AxisServlet;

import com.google.inject.Singleton;

@Singleton
public class GuiceAxisServlet extends AxisServlet {

    private static final long serialVersionUID = 1L;

}

------------------------------------------

package com.example.guiceintegration;

import com.google.inject.Module;
import com.google.inject.servlet.GuiceServletContextListener;

import com.example.config.WebappModule;

/**
 * Integration point for guice/servlet integration. A listener in the webapp
 * context listens for context created and starts up Guice by creating the
 * injector. The injector is also stored in the servlet context so that service
 * objects created by Axis can also be guiced: this happens via
 * {...@link GuiceServiceObjectSupplier}.
 * 
 * @author bruce
 * 
 */
public class GuiceServletConfig extends GuiceServletContextListener {

    @Override
    protected Module getModule() {
        return new WebappModule();
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to