当前位置 : 主页 > 网页制作 > Nodejs >

webservice-xfire 示例

来源:互联网 收集:自由互联 发布时间:2021-06-24
用的是 xfire 自己做了一个简单的示例 所有的jar activation-1.1.jar bcprov-jdk15-133.jar commons-attributes-api-2.1.jar commons-beanutils-1.7.0.jar commons-codec-1.3.jar commons-discovery-0.2.jar commons-httpclient-3.0.jar com
用的是 xfire 自己做了一个简单的示例


所有的jar
activation-1.1.jar
bcprov-jdk15-133.jar
commons-attributes-api-2.1.jar
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-discovery-0.2.jar
commons-httpclient-3.0.jar
commons-logging-1.0.4.jar
jackson-annotations-2.3.0.jar
jackson-core-2.3.0.jar
jackson-databind-2.3.0.jar
jaxb-api-2.0.jar
jaxb-impl-2.0.1.jar
jaxb-xjc-2.0.1.jar
jaxen-1.1-beta-9.jar
jaxws-api-2.0.jar
jdom-1.0.jar
jsf-api.jar
jsf-impl.jar
jsr173_api-1.0.jar
jstl-1.2.jar
mail-1.4.jar
opensaml-1.0.1.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
spring-1.2.6.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wss4j-1.5.1.jar
wstx-asl-3.2.0.jar
xbean-2.2.0.jar
xbean-spring-2.8.jar
xfire-aegis-1.2.6.jar
xfire-annotations-1.2.6.jar
xfire-core-1.2.6.jar
xfire-generator-1.2.6.jar
xfire-java5-1.2.6.jar
xfire-jaxb2-1.2.6.jar
xfire-jaxws-1.2.6.jar
xfire-jsr181-api-1.0-M1.jar
xfire-spring-1.2.6.jar
xfire-ws-security-1.2.6.jar
xfire-xmlbeans-1.2.6.jar
XmlSchema-1.1.jar
xmlsec-1.3.0.jar
配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 配置service -->
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


创建一个和webRoot 同级的文件夹services/service.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>CurrentService</name>
<namespace>www.julongtech.com.cn/CurrentService</namespace>
<serviceClass>com.julongtech.webservice.CurrentService</serviceClass>
<implementationClass>
com.julongtech.webservice.impl.CurrentServiceImpl
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service>
<service>
<name>UserService</name>
<namespace>www.julongtech.com.cn/UserService</namespace>
<serviceClass>com.julongtech.webservice.UserService</serviceClass>
<implementationClass>
com.julongtech.webservice.impl.UserServiceImpl
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service>
</beans>

自己配置了两个 测试的时候可以选择一个

userinfo实体类
package com.julongtech.entity;

import java.io.Serializable;

public class UserInfo implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;
private String userId;
private String userName;
private String userPassword;
private String userAge;
private String userSex;
private String userAddress;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public String getUserAge() {
return userAge;
}
public void setUserAge(String userAge) {
this.userAge = userAge;
}
public String getUserSex() {
return userSex;
}
public void setUserSex(String userSex) {
this.userSex = userSex;
}
public String getUserAddress() {
return userAddress;
}
public void setUserAddress(String userAddress) {
this.userAddress = userAddress;
}
public UserInfo() {
super();
}



}

services 入口接口
package com.julongtech.webservice;

import java.util.List;

import com.julongtech.entity.UserInfo;

/**
* webservice的总入口
* @author julong
* @date 2016-6-23 下午10:39:03
*/
public interface CurrentService {
/**
* 获取用户信息
* @param userId
* @return
* @author julong
* @date 2016-6-23 下午10:48:06
*/
public abstract String getUser(String userId);

/**
* 删除用户信息
* @param userId
* @return
* @author julong
* @date 2016-6-23 下午10:48:19
*/
public abstract String deleteUser(String userId);

/**
* 测试程序接口
* @param userName
* @return
* @author julong
* @date 2016-6-23 下午10:49:36
*/
public abstract List<UserInfo> sayHello(String userName);

public abstract String byteTest(String userId);
}



package com.julongtech.webservice;

public interface UserService {
public String test();
}


实现类

package com.julongtech.webservice.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.julongtech.entity.UserInfo;
import com.julongtech.webservice.CurrentService;

public class CurrentServiceImpl implements CurrentService {

public String deleteUser(String userId) {
// TODO Auto-generated method stub
List<UserInfo> user = new ArrayList<UserInfo>();
for (int i = 0; i < 5; i++) {
UserInfo u = new UserInfo();
u.setUserId(""+i);
u.setUserName("中国人"+i);
u.setUserAddress("西安"+i);
u.setUserPassword("0000000");
u.setUserAge("20");
user.add(u);
}
ObjectMapper objectMapper = new ObjectMapper();
String result = "";
try {
result = objectMapper.writeValueAsString(user);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}

public String getUser(String userId) {
// TODO Auto-generated method stub
List<String> list = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
list.add("中国人"+i);
}
Map<String,Object> maps = new HashMap<String,Object>();
maps.put("key", list);
return maps.toString();
}

public List<UserInfo> sayHello(String userName) {
// TODO Auto-generated method stub
List<UserInfo> user = new ArrayList<UserInfo>();
for (int i = 0; i < 5; i++) {
UserInfo u = new UserInfo();
u.setUserId(""+i);
u.setUserName("中国人"+i);
user.add(u);
}
return user;
}

public String byteTest(String userId) {
// TODO Auto-generated method stub
List<UserInfo> user = new ArrayList<UserInfo>();
for (int i = 0; i < 5; i++) {
UserInfo u = new UserInfo();
u.setUserId(""+i);
u.setUserName("中国人"+i);
u.setUserAddress("西安"+i);
u.setUserPassword("0000000");
u.setUserAge("20");
user.add(u);
}
ObjectMapper objectMapper = new ObjectMapper();
byte[] result = null;
try {
result = objectMapper.writeValueAsBytes(user);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result.toString();
}



}


package com.julongtech.webservice.impl;

import com.julongtech.webservice.UserService;

public class UserServiceImpl implements UserService {

public String test() {
// TODO Auto-generated method stub
return "你上当啦!!";
}

}


如果想返回对象javabean 配置文件 CurrentService.aegis.xml

<?xml version="1.0" encoding="UTF-8"?>
<mappings>
<mapping>
<method name="sayHello">
<return-type componentType="com.julongtech.entity.UserInfo" />
</method>
</mapping>
</mappings>


只要配置好运行起来是没问题的 通过 http://localhost:8080/XfireService/services 访问 至此完成

网友评论