Hi Jarek,

your advice didn't work, unfortunately. The server logs still show the
additional "DEFAULT"-bean. I've attached the files you requested plus my
openejb-jar.xml just for completeness.

Janko

Jarek Gawor wrote:
> I think you end up with deploying two ejbs because the name of bean
> specified in the DD does not match the bean name of the annotated
> class. And so, the container thinks you are deploying two separate
> beans. To fix it, you could try adding "name=MyWebService" attribute
> to the @Stateless annotation.
> 
> If that still does not work right, send me your ejb-xml.jar file and
> the bean class.
> 
> Jarek
> 
> On Thu, Nov 13, 2008 at 2:33 AM, Janko Heilgeist
> <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I've got a problem when deploying web services under Geronimo
>> Tomcat/Axis. Not every instance of the stateless bean seems to receive
>> the @Resource that I would like to have injected into the bean. I create
>> a simple web service with an injected string that is accessed inside a
>> @PostConstruct method and inside an exposed web method.
>>
>> // relevant excerpts ........
>> @Resource
>> private String someString = "DEFAULT";
>>
>> @PostConstruct
>> public void init() {
>>    logger.info(String.format("init: EJB = '%08x', someString = '%s'",
>> hashCode(), this.someString));
>> }
>>
>> public void doSomething(int counter) {
>>    logger.info(String.format("doSomething: EJB = '%08x', someString =
>> '%s'", hashCode(), this.someString));
>> }
>>
>> Excerpts from ejb-jar.xml:
>>
>> <session>
>>    <ejb-name>MyWebService</ejb-name>
>>    <ejb-class>
>>    com.heilgeist.tests.tst_ws_with_resource.ws_ejb.MyServiceEJBImpl
>>    </ejb-class>
>>
>>    <env-entry>
>>        <env-entry-name>
>> com.heilgeist.tests.tst_ws_with_resource.ws_ejb.MyServiceEJBImpl/someString
>>        </env-entry-name>
>>        <env-entry-type>java.lang.String</env-entry-type>
>>        <env-entry-value>Hello, world!</env-entry-value>
>>    </env-entry>
>> </session>
>>
>> When I access this web service I get the following lines in the server log:
>>
>> 08:12:41,381 INFO  [MyServiceEJBImpl] init: EJB = '00b6d31c', someString
>> = 'Hello, world!'
>> 08:12:41,477 INFO  [MyServiceEJBImpl] init: EJB = '01c50523', someString
>> = 'DEFAULT'
>> 08:12:41,745 INFO  [MyServiceEJBImpl] doSomething: EJB = '00b6d31c',
>> someString = 'Hello, world!'
>>
>> The second line indicates, that there is an additional instance of the
>> stateless bean, that doesn't receive the injected string. It is only
>> created once directly following the deployment of the web service. Even
>> if further MYServiceEJBImpl instances are created later on to handle
>> concurrent requests there is only a single instance of the bean with the
>> default string. It's web service method is never called. Using the
>> Jetty/CXF package this additional stateless bean is not created:
>>
>> 08:09:54,557 INFO  [MyServiceEJBImpl] init: EJB = '015db507', someString
>> = 'Hello, world!'
>> 08:09:54,558 INFO  [MyServiceEJBImpl] doSomething: EJB = '015db507',
>> someString = 'Hello, world!'
>>
>> Can someone please shed some light on this funny behavior of Axis?
>>
>> Regards, Janko
>>

package com.heilgeist.tests.tst_ws_with_resource.ws_ejb;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jws.WebService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@Stateless(
		name="MyWebService")
@WebService(
		serviceName="MyService",
		portName="MyServicePort",
		endpointInterface="com.heilgeist.tests.tst_ws_with_resource.ws_ejb.MyServiceInterface",
		targetNamespace="http://heilgeist.com/tests/tst-ws-with-resource/service";)
public class MyServiceEJBImpl implements MyServiceInterface {
	private Log logger = LogFactory.getLog(MyServiceEJBImpl.class);

	@Resource
	private String someString = "DEFAULT";

	@PostConstruct
	public void init() {
		logger.info(String.format("init: EJB = '%08x', someString = '%s'",
				hashCode(), someString));
	}

	public void doSomething(int counter) {
		logger.info(String.format("doSomething: EJB = '%08x', someString = '%s'",
				hashCode(), someString));
		// waste some time...
		logger.info(String.format("EJB %08x is no longer busy", hashCode()));
	}

}
package com.heilgeist.tests.tst_ws_with_resource.ws_ejb;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService(
		name="MyServicePortType",
		targetNamespace="http://heilgeist.com/tests/tst-ws-with-resource/porttype";)
@SOAPBinding(style=Style.DOCUMENT)
public interface MyServiceInterface {

	void doSomething(int counter);

}
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0"
	xmlns="http://java.sun.com/xml/ns/javaee";
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd";>

	<display-name>Test: WS with injected @Resource</display-name>

	<enterprise-beans>
		<session>
			<ejb-name>MyWebService</ejb-name>
			<ejb-class>com.heilgeist.tests.tst_ws_with_resource.ws_ejb.MyServiceEJBImpl</ejb-class>

			<env-entry>
				<env-entry-name>
					com.heilgeist.tests.tst_ws_with_resource.ws_ejb.MyServiceEJBImpl/someString
				</env-entry-name>
				<env-entry-type>java.lang.String</env-entry-type>
				<env-entry-value>Hello, world!</env-entry-value>
			</env-entry>
		</session>
	</enterprise-beans>

</ejb-jar>
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1";
	xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2";
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
	xsi:schemaLocation="
		http://www.openejb.org/xml/ns/openejb-jar-2.1 http://geronimo.apache.org/xml/ns/j2ee/openejb/openejb-jar-2.1.xsd
		http://geronimo.apache.org/xml/ns/deployment-1.2 http://geronimo.apache.org/xml/ns/geronimo-module-1.2.xsd";>

	<sys:environment>
		<sys:moduleId>
			<sys:groupId>${pom.groupId}</sys:groupId>
			<sys:artifactId>${pom.artifactId}</sys:artifactId>
			<sys:version>${pom.version}</sys:version>
			<sys:type>ejb</sys:type>
		</sys:moduleId>
	</sys:environment>

	<enterprise-beans>
		<session>
			<ejb-name>MyWebService</ejb-name>
			<web-service-address>/MyWebService</web-service-address>
		</session>
	</enterprise-beans>

</openejb-jar>

Reply via email to