vendredi 11 mars 2011

Comment créer des EJBs WebService

1- Création de l'interface EJB

package org.test

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

@WebService
@SOAPBinding(style = Style.RPC)
public interface IUserManagerEJB
{
public void createNewUser(User user) throws SOAPSession
}



2- Création de la classe EJB



package org.test

import javax.annotation.Resource;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.HandlerChain;
import javax.jws.WebService;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;


@Stateless
@WebService(endpointInterface = "org.test.IUserManagerEJB")
@Remote(IUserManagerEJB.class)
@HandlerChain(file="aas_handler.xml")
public class UserManagerEJB implements IUserManagerEJB
{

@Resource
private WebServiceContext ctx;
public void createNewUser(User user) throws SOAPSession
{
// Implementatation de la méthode
}
}






Fichier aas_handler.xml

<handler-chains 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">
<handler-chain>
<handler>
<handler-name>AuthenticationHandler</handler-name>
<handler-class>com.test.AASHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>


package com.test;

public class AASHandler implements SOAPHandler
{
// Complete Implemented méthode here
}

Aucun commentaire: