当前位置: 代码迷 >> Web前端 >> WEBLOGIC EJB 兑现
  详细解决方案

WEBLOGIC EJB 兑现

热度:391   发布时间:2012-09-02 21:00:34.0
WEBLOGIC EJB 实现

?EJB 为远程提供JNDI 代码如下:

?

@Stateless(mappedName = "HelloWorldBean")
@Remote({HollowWorld.class})
public class HollowWordBean implements HollowWorld,Serializable{

?private static final long serialVersionUID = 1L;

?// @Override
?public void remotePrintln() {
??// TODO Auto-generated method stub
??System.out.println("remote is run!!");
?}

}

?

系统测试代码为:

?

?????? java.util.Properties prop = new java.util.Properties();??
????? prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,??
????????????? WLInitialContextFactory.class.getName());??
????? prop.setProperty(Context.PROVIDER_URL, "t3://localhost:7001"); //
????? prop.setProperty(Context.SECURITY_PRINCIPAL, "user");
????? prop.setProperty(Context.SECURITY_CREDENTIALS, "12345678");
????? InitialContext ic = new InitialContext(prop);?????
?????
????? UserOptionTestDao? userOptionDao = (UserOptionTestDao)ic.lookup?????????? ("userDao#com.yineng.jpa.UserOptionTestDao");//lookup的名称在weblogic 中可以查找到

?

?

EJB 提供webservice服务的代码:

?

? /**
?*@see 本地的webservice实现类
?*@author desert
?*@version 1.0
?*/
@Stateless
@WebService(name = "HelloWorldService",? serviceName = "HelloWorldService",targetNamespace=Contants.targetNamespace)
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class HelloWorldService implements HelloWorldServiceInteface{
?
?@WebMethod
?@WebResult(name="String")
?public String? sayHello(@WebParam(name = "name")String name){
??return name+ "说:这是我的第一个web 服务";
?}

}

?

系统的测试代码:

?????? 创建远程接口

????? @WebService(targetNamespace=Contants.targetNamespace) //必须要否则无法调取远程?????????????? (targetNamespace="http://127.0.0.1")
?????????? public interface HelloWorldServiceInteface{
????
????????????????????@WebMethod?? //必须要否则无法调取远程
??????????????????? @WebResult(name="String")?? //必须要否则无法调取远程
????????????????? public String? sayHello(@WebParam(name = "name")String name);
?
??????????? }

?

? 测试类(用的Apache 的 cxf 解析webservice):

? ApplicationContext ctx = new ClassPathXmlApplicationContext(??
???????????????? "applicationContext.xml");??
????????
???????? HelloWorldServiceInteface client = (HelloWorldServiceInteface) ctx.getBean("client");??

???????? String result = client.sayHello("HELLO");??

???????? System.out.println(result);??

?

?? cxf 在spring 中的配置文件如下:

??? <!--载入webservice properties-->
??? <bean id="propertyConfigurer"
????????????? class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
??????? <property name="location" value="classpath:webservice-config" />
??? </bean>?????????????????
????
????
??? <bean id="client" class="com.yineng.webservice.HelloWorldServiceInteface"
???????????????????????????? factory-bean="clientFactory" factory-method="create"/>

??? <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
??????????????????? <property name="serviceClass" value="com.yineng.webservice.HelloWorldServiceInteface"/>
??????????????????? <property name="address">
??????????????????????? <value>${ws-test}</value>
??????????????????? </property>?
?
??? </bean>

?

????webservice-config 文件内容如下:

????????????????? ws-test=http://127.0.0.1:7001/HelloWorldService/HelloWorldService

?

? 这个时SOA 最基本要了解的 如果有业务流程的话 可以用BPEL (自己探索)。下面有个详细的文档下载;如有误请谅解。

?

?

  相关解决方案