ejb@glassfish.java.net

Environment Entry Resource Injection

From: Daniel Cavalcanti <dhcavalcanti_at_gmail.com>
Date: Wed, 5 Jul 2006 16:26:08 -0400

Hello,

I have an EJB 3.0 project that I'm having a little trouble with.
I have a remote, stateless bean, and this bean has a property called address
of type String.
I annotate the property to have resource injected to it, but the container
(glassfish) is not injecting the resource.

here is the code:

/*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/

package com.localmatters.mobile.services.geocode;

import java.util.List;
import javax.ejb.Remote;

/**
 * The geocode service interface.
 */
@Remote()
public interface GeocodeService {

    /**
     * Geocodes a free-form location.
     *
     * @param location The free-form location.
     * @throws NullPointerException If location is null.
     * @throws GeocodeServiceException If geocode service fails.
     * @return The geocodes for the location.
     */
    public List<Geocode> geocode(String location)
    throws NullPointerException, GeocodeServiceException;

    /**
     * Geocodes a location defined by its distinct fields.
     *
     * @param address The address field.
     * @param city The city field.
     * @param state The state (or province) field.
     * @param postal The postal code field.
     * @throws GeocodeServiceException If geocode service fails.
     * @return The geocodes for the location.
     */
    public List<Geocode> geocode(String address, String city, String state,
String postal)
    throws GeocodeServiceException;

}

/*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/

package com.localmatters.mobile.services.geocode;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Stateless;

/**
 * The hermes based geocode service implementation.
 *
 * @author Daniel Cavalcanti
 */
@Stateless()
public class GeocodeServiceBean implements GeocodeService {

    //
**********************************************************************
    // Instance variables
    //
**********************************************************************

    /**
     * The hermes web service WSDL URL.
     */
    @Resource()
    private String address;

    //
**********************************************************************
    // Constructors
    //
**********************************************************************

    /**
     * Creates a new instance of GeocodeServiceBean.
     */
    public GeocodeServiceBean() {
    }

    //
**********************************************************************
    // EJB life-cycle (call-back) methods
    //
**********************************************************************

    /**
     * Establishes connection to hermes web service client port.
     */
    @PostConstruct()
    private void postConstruct() {
        // TODO establish hermes web service client port connection
    }

    //
**********************************************************************
    // Getter/Setter methods
    //
**********************************************************************

    //
**********************************************************************
    // Geocode service implementation
    //
**********************************************************************

    public List<Geocode> geocode(String location)
    throws NullPointerException, GeocodeServiceException {

        if (location == null)
            throw new NullPointerException("Location cannot be null.");

        // TODO implement method
        return new ArrayList<Geocode>();

    }

    public List<Geocode> geocode(String address, String city, String state,
String postal)
    throws GeocodeServiceException {

        // TODO implement method
        return new ArrayList<Geocode>();

    }

}

/*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/

sun-ejb-jar.xml file


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application
Server 9.0 EJB 3.0//EN" "
http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
    <enterprise-beans>

        <session>

            <!-- The resource injection target bean -->
            <ejb-name>GeocodeService</ejb-name>
            <ejb-class>
com.localmatters.mobile.services.geocode.GeocodeServiceBean</ejb-class>

            <!-- The resource definitions -->
            <env-entry>
                <description>The hermes web service WSDL URL.</description>
                <env-entry-name>wsdl</env-entry-name>
                <env-entry-type>java.lang.String</env-entry-type>
                <env-entry-value>
http://mapping-ws.localmatters.com/services5/mapping?wsdl</env-entry-value>
            </env-entry>

        </session>

    </enterprise-beans>
</sun-ejb-jar>

/*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/

Could someone tell me what I'm doing wrong?

thanks,
Daniel