Debu Panda

Subscribe to Debu Panda feed
Rumblings from a Technologist and Book author
Updated: 5 hours 42 min ago

Using EJBContext from an EJB 3 Interceptor

Wed, 2008-07-30 03:44

I got a question from a customer that he wants to use EJBContext from an EJB 3 Interceptor.

Yes, it’s very simple. Just inject the EJBContext into the interceptor using @Resource injection.

See the example code that uses methods of SessionContext as follows:


package actionbazaar.buslogic;

import javax.annotation.Resource;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

public class CheckPermissionInterceptor {
@Resource
private javax.ejb.SessionContext ctx;


@AroundInvoke
public Object checkUserRole(InvocationContext ic) throws Exception {
System.out.println("*** CheckPermission Interceptor invoked for "
+ ic.getTarget() + " ***");
if (!ctx.isCallerInRole("admin")) {
throw new SecurityException("User: '"
+ ctx.getCallerPrincipal().getName()
+ "' does not have permissions for method "
+ ic.getMethod());
}
return ic.proceed();
}
}

If you want the run-able version of the example code, you can download from http://manning.com/panda and look at Chapter 5 example.

My Sessions at Oracle Open World 2008

Tue, 2008-07-29 01:31

I’ve two sessions at Oracle Open World 2008, San Francisco. Here are my session details:

S298520 : Best Practices for Managing Your Oracle WebLogic Environment with Oracle Enterprise Manager
Track: Application Server and Transaction Processing
Room: Rm 2006
Date: 2008-09-22
Start Time: 11:30

S298522 : Top Five Things DBAs Must Know About Managing Middleware
Track: Application Server and Transaction Processing
Room: Rm 2003
Date: 2008-09-25
Start Time: 15:00

See you at San Francisco!



EJB 3 In Action available at Safari Online

Fri, 2008-07-18 03:37
If you enjoy reading online then it's a good news for readers of EJB 3 in Action. It is now available online at Safari

Introduction to EclipseLink

Mon, 2008-07-07 04:24
Doug Clarke has written a nice article that introduces EclipseLink.

EJB 3 Stateless bean Web service in WebLogic Server

Thu, 2008-06-26 05:39
I recently got some questions from customers about the procedure for deploying EJB 3 Session Bean Web service in WebLogic 10. In this blog, I will outline the steps.

First develop your EJB3 session bean web service as follows:

@WebService(name="PlaceBid",
serviceName="PlaceBidService", portName = "PlaceBidPort",
targetNamespace = "http://actionbazaar.com/xml")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
@PersistenceContext(unitName="actionBazaar",name="actionBazaar")
@Stateless
public class PlaceBidBean {

@WebMethod

public Long addBid(String userId, Long itemId, Double bidPrice) throws BidException {

….

}

}


Deployment

Unlike OC4J, WebLogic do not support parsing of JAX-WS annotations at deployment time and if you try to deploy the compiled EJB 3 Web service, you will get deployment time exception. You have to run the EJB 3 WS thru annotation parsing tool (jwsc –java web services compile) supplied with WebLogic to generate the artifacts and package in your ejb-jar module.

Here is an example ant task to create the web service:

<target
name="build-ws-server" description="Target that builds the
target Web Service"&gt
<jwsc
srcdir="${src.ejb.dir}&quot
destdir="${bld.service.dir}&quot
classpath="${common.j2ee.class.path}&quot
fork="true&quot
keepGenerated="true&quot
deprecation="${deprecation}&quot
keepTempFiles="true&quot
listfiles="true&quot
debug="${debug}"&gt
<jws
file="actionbazaar/buslogic/PlaceBidBean.java" type="JAXWS"
explode="true"/&gt
</jwsc&gt
</target&gt

<target name="package-ejb"
depends="compile-ejb-classes,build-ws-server">;

<mkdir dir="${bld.ejb.dir}/actionbazaar/buslogic/jaxws" />

<copy todir="${bld.ejb.dir}/actionbazaar/buslogic/jaxws">

<fileset dir="${bld.service.dir}/actionbazaar/buslogic/PlaceBidBean/actionbazaar/buslogic/jaxws" includes="*"/> </copy>
<echo message="-----> Create EJB jar file"/>
<jar jarfile="${bld.ear.dir}/${ejb.name}.jar">
<fileset dir="${bld.ejb.dir}" includes="**" />
</jar>
</target >

Make sure to package the generated artifacts in the EJB JAR and then deploy the EJB-JAR or EAR to the WebLogic Server. Note that if your web service depends upon custom Java objects - the generated artifacts contain duplicate Java classes that you already may have. These duplicated classes are on a separate package structure and cause ClassCastException for me. So I avoid packaging these classes.

Accessing EJB 3 Web service

After successful deployment you can access the web service as follows:

http://hostname:port/ejb-name/web-service-name?wsdl

http://localhost:7001/PlaceBidBean/PlaceBidBeanService?wsdl



Hope this helps.

You can download the working examples from here. Chapter 15 contains web services example.

Pages