Question No: 52

An enterprise developer needs to modify the order of interceptor method execution specified by the Bean Provider, but does NOT have access to the bean#39;s source code. No deployment descriptor was provided in the EJB jar delivered by the Bean Provider.

Which represents the solution to this problem?

No solution is possible under these conditions.

The Deployer can add metadata annotations to the ejb-jar.

The Application Assembler can add metadata annotations to the ejb-jar.

The System Administrator can add interceptor binding information at runtime, using vendor-specific tools.

The Application Assembler can add a deployment descriptor to the ejb-jar that includes interceptor binding information.

Answer: E

Question No: 53

A developer wants to package an enterprise bean FooBean within a .war file:

@Stateless

public xlass FooBean {

public void foo () {}

}

Which package approach is correct?

/ (Root)

I – META – INF /

I – acme

I – FooBean.class

/ (Root) I – acme

I – FooBean.class

/ (Root)

I – WEB – INF /

I – acme

I – FooBean.class

/ (Root)

I – WEB – INF /

I – Classes/ I – acme

I – FooBean.class

Answer: D

Explanation: To include enterprise bean class files in aWARmodule, the class files should be in the

WEB-INF/classes directory.

Note: Enterprise beans often provide the business logic of a web application. In these cases, packaging the enterprise bean within the web application’sWARmodule simplifies deployment and application organization. Enterprise beans may be packaged within aWARmodule as Java

programming language class files or within a JAR file that is bundled within theWARmodule.

Question No: 55

Assume you have been tasked with building an ejb-jar containing an EJB application. The EJB application contains local, remote, and web service and-point EJBs that provide reusable services within an enterprise. When the application is deployed clients will access the remote session beans using the global JNDI name java/: ServiceLayer / lt;bean_namegt;. All of the EJBs are located in the com.acme.servicelayer package and are deployed as class files. The application uses a maximum of deployment descriptor and annotation configuration?

Name the jar servicelayer.jar with the following structure:

/ (Root)

I – META – INF /

I – MANIFEST.MF

I – classes/ I – com/

I – acme/

I – servicelayer /

lt;list of classesgt;

Name the jar servicelayer.jar with the following structure:

/ (Root)

I – META – INF/

I – MANIFEST.MF

I – ejb – jar.xml I – classes/

I – com/

I – acme /

I – servicelayer/

lt;list of classesgt;

Name the jar servicelayer.jar with the following structure:

/(Root)

I – META – INF /

I – ejb – jar.xml I – com/

I – acme/

I – servicelayer/

lt;list of classesgt;

Name the jar servicelayer.jar with the following structure:

/ (Root)

I – META – INF/

I – MANIFEST.MF

I – ejb-jar.xml I – com/

I – servicelayer/

lt;list of classesgt;

Answer: A

Explanation: Structure of an Enterprise Bean JAR:

Assembly Root ejb-jar.xml

glassfish-ejb-jar.xml (optional, not used hereNot D, Not C, not B)) META-INF

Question No: 56

A developer writes a stateful session bean with local business interface Bar containing method test. Method test is implemented as:

@Remove

public void test () {}

A business method in a stateless session bean invokes a reference to bean Bar as follows:

11. @EJB Bar bar; 12.

public void foo () {

bar.test ();

bar.test();

16. }

Assuming execution reaches Line 15, what is the expected result?

Method foo returns without error.

A javax.ejb.NoSuchEJBException is thrown.

A java.rmi.NoSuchObjectException is thrown.

A javax.ejb.NoSuchEntityException is thrown.

Answer: B

Question No: 57

MyMsg is a JMS message-driven bean with container-managed transaction demarcation. FooBean is an EJB 3.x stateless session bean that sends message to the JMS destination with MyMsgBean is associated.

MyMsgBean’s message listener method has transaction attribute REQUIRED, and is defined as follows:

public class MyMsgBean implements javax.jms.messageListener {

public void onMessage(javax.jms.Message message) {

/ / do some work not shown here

thrown new RuntimeException(“unexpected error . . . “);

14. }

Which statement is true about the result of message processing?

FooBean receives javax.ejb.EJBException.

The container discards the MyMsgBean bean instance.

FooBean receives the original RuntimeException thrown from the message listener method.

The container does NOT roll back the transaction, and FooBean can continue the transaction.

Answer: C Explanation:

Note: public interface MessageListener

A MessageListener object is used to receive asynchronously delivered messages.

Each session must insure that it passes messages serially to the listener. This means that a listener assigned to one or more consumers of the same session can assume that the onMessage method is not called with the next message until the session has completed the last call.

Reference: Enum TransactionAttributeType

Question No: 58

Given an JMS message-driven bean, which statement is true about its exception handling?

Its message listener method can throw any checked exception that implements java.io.Serializable.

Answer: A

Question No: 59

Which is a correct way to define a runtime exception as an EJB 3.x application exception?

public class MyAppException extends javax.ejb.EJBException

@ApplicationException

public class MyAppException extends javax.ejb.EJBException

public class MyAppException extends javax.lang.EJBException

@ApplicationException

public class MyAppException extends javax.lang.EJBException

Answer: B

Explanation: Use the @javax.ejb.ApplicationException annotation to specify that an exception class is an application exception thrown by a business method of the EJB. The EJB container reports the exception directly to the client in the event of the application error.

Note: java.lang.Object java.lang.Throwable java.lang.Exception

java.lang.RuntimeException javax.ejb.EJBException javax.ejb

public class EJBException

extends java.lang.RuntimeException

The EJBException is thrown to report that the invoked business method or callback method could not be completed because of an unexpected error (e.g. the instance failed to open a database connection).

Example:

The following ProcessingException.java file shows how to use

the @ApplicationException annotation to specify that an exception class is an application exception thrown by one of the business methods of the EJB:

package examples;

import javax.ejb.ApplicationException;

/*** Application exception class thrown when there was a processing error* with a business method of the EJB. Annotated with the* @ApplicationException annotation.*/

Question No: 60

A developer writes a stateless session bean with one local business interface and with container-managed transactions. All business methods have transaction attribute REQUIRED. The bean has an injected field sessionCtx of the type SessionContext. Which two operations are allowed in a business method of the bean? (Choose two.)