Java + PHP in wso2
wso2提供了两个框架:WSFSpring, WSFPHP, 分别可以用于java和php.可以通过webservice,提供跨语言的交流。充分发挥各语言自己的优势。以下将描述,如何搭建这样的沟通渠道。
1. 服务端(Java)
需要安装JDK1.6+, Tomcat 6.0+ , axis, 开发工具Eclipse
步骤:
1) 创建新项目:
File -> new -> Dynamic Web Project
项目名称 WSFSpringHelloWorld
2) 整理项目
a. Copy lib下载wsf spring 的 bin 包,解压缩后,
复制 wsf-spring-1.5-bin\wsf-spring-1.5-bin\samples\webapp\wsf-spring-sample-1.5\WEB-INF\lib 目录到 WSFSpringHelloWorld 项目中的 WebContent\WEB-INF 下(如上图)
这个lib下已经包含的spring和 wsfspring了
b. 复制 axis2Config.xml
复制 wsf-spring-1.5-bin\wsf-spring-1.5-bin\samples\webapp\wsf-spring-sample-1.5\WEB-INF\ axis2Config.xml 到目录到 WSFSpringHelloWorld 项目中的 WebContent\WEB-INF 下(如上图)
c. 创建HelloWorld 类
代码如下:
package com.hello;
public class HelloWorld {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String sayHello(String name) {
return name + " says Hello World!";
}
}
d. 配置 applicationContext.xml
在 WSFSpringHelloWorld 项目中的 WebContent\WEB-INF 新建一个文件applicationContext.xml。内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<import resource="axis2Config.xml"/>
<bean id="helloworld" class="com.hello.HelloWorld">
<property name="name" value="Tharindu Mathew"></property>
</bean>
<bean id="services" class="org.wso2.spring.ws.WebServices">
<property name="services">
<list>
<bean id="helloService" class="org.wso2.spring.ws.SpringWebService">
<property name="serviceBean" ref="helloworld"></property>
<property name="serviceName" value="helloWorldService"></property>
</bean>
</list>
</property>
</bean>
</beans>
e. 在WebContent\WEB-INF\web.xml中引用
主要是这两句
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
web.xml全文看起来就变成了:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>WSFSpringHelloWorld</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>axis2</servlet-name>
<servlet-class>
org.wso2.spring.ws.servlet.SpringAxis2Servlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>axis2</servlet-name>
<url-pattern>/axis2/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>axis2</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<!--
<welcome-file>index.jsp</welcome-file>
-->
<welcome-file>/axis2-web/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
f. 以上步骤就可以发布标准的axis服务了,为了更加方面了解,可以考虑将目录axis2-1.5.1-bin\axis2-1.5.1\webapp\axis2-web(请先下载axis2的bin包),复制到WSFSpringHelloWorld 项目中的 WebContent目录下。
3) 发布 项目
可以在eclipse中发布war包(右键单击项目,选择export->war即可), 发布的war包,可以部署到tomcat服务器上。当然也可以直接在eclipse上运行(右键单击项目,选择run as -> run on server即可)
当发现可以访问 http://localhost:8080/WSFSpringHelloWorld/services/helloWorldService?wsdl
则表示成功
(这里假定Tomcat发布的端口是8080)
2. 客户端(PHP)
需要安装 PHP 5.2.6+ , WSF PHP
有关安装WSF PHP 的步骤,请google相关文档。下载的包里面就有一个说明(README.INSTALL)。安装完毕后, 就可以使用WSClient这个类了。
新建一个php文件,内容如下:
<?php
$wsdl = "http://192.168.5.158:8080/WSFSpringHelloWorld/services/helloWorldService?wsdl";
$client = new WSClient(array("wsdl"=>$wsdl));
$proxy = $client->getProxy();
$input = array("name" => "hello");
print_r($input);
$re = $proxy->sayHello($input);
echo $re["return"];
echo "\n";
?>
其中,假定发布服务的WSDL的路径是: http://192.168.5.158:8080/WSFSpringHelloWorld/services/helloWorldService?wsdl
由此,你就可以看到从远程的java端发送过来的信息了。
结束语,
这个只是一个引子。要想理解其中为什么这样,请google相关文档。当然 wso2上也有很多相关文档(例如:http://wso2.org/library/3208)。
如果您真的想用它到你的项目中,那么建议好好理解其中的代码和配置,这样才能更加变通的利用到你的项目中。
- 大小: 168.4 KB
分享到:
相关推荐
WSO2-JAVA开发集成,采用该技术的伙伴可以参考下, 查找网上官方文档也可以,https://docs.wso2.com/display/ESB500
WSO2 ESB 使用手册,项目中使用到了WSO2的ESB功能作为ESB使用
最新WSO2 Enterprise Integrator6.6.0 使用手册,WSO2 ESB++ 企业集成。 包括rest代理和路由转发、rest转webservie服务,webservice服务转rest,tcp转webservice服务 WSO2三款产品介绍等
From beginning to the end, Beginning WSO2 ESB effectively guides you in gradually building expertise in enterprise integration with WSO2 ESB for your SOA infrastructure. Nowadays successful ...
WSO2ESB 5.0.0 汉化后的jar.zip 评分: 内含 WSO2ESB 5.0.0 界面汉化的jar包 下载后将zip格式文件解压后 将jar copy 到 wso2esb-5.0.0/repository/components/plugins 中 将对应的jar替换便可完成汉化
官网下载,Eclipse插件:WSO2 ESB tooling,适配WSO2 ESB 5.0.0。 仅 Eclipse Mars.2 Release (4.5.2) 版本可使用(我用的是Eclipse JEE Mare.2)。 如果需要Eclipse汉化,必须先安装 WSO2 ESB tooling,再安装...
wso2 esb installation part 5
WSO2安装手册,项目中对于WSO2工具的使用,关于安装手册的。
wso2 esb协议转换示例,包含基本的配置,博客参考http://blog.csdn.net/szh1124/article/details/43834487
wso2
WSO2ESB汉化版本,文档中提供了git地址供下载以及有汉化说明。
WSO2 Carbon is the award-winning, WSO2 Carbon light-weight, service-oriented platform that includes all WSO2 products. It is 100% open source and is delivered under Apache License 2.0. Consisting of ...
wso2as-4.1.0.zip wso2as-4.1.0.zip
wso2工程导入的java包
wso2esb-4.0.0.zip wso2esb-4.0.0.zip
wso2 新增OpenSSL生成並使用CA根證書籤名Keytool生成的證書請求 相關流程心智圖展開
WSO2 ESB 企业服务总线总结文档WSO2 ESB 企业服务总线总结文档WSO2 ESB 企业服务总线总结文档WSO2 ESB 企业服务总线总结文档
利用wso2 esb、wso2 bps进行服务编排的几个示例,包含基本的配置及图片步骤,写起来比较麻烦,2分吧。博客参考http://blog.csdn.net/szh1124/article/details/43835525
WSO2ESB的详细介绍指南 安装使用设置 官方文档