点击上面 免费订阅本账号!
本公众号主要推送javaweb开发相关技术,基础知识点,同时会深入剖析复杂的问题,分享一些优秀的框架,大型项目经验,当今最流行的Javaweb技术,热点科技新闻,招聘信息,生活乐趣等等。点击上方的蓝字,这样您每天可以看到更多的java知识和资讯!完全是免费订阅,请放心关注。
第一步,添加jar包
axis1实现webservice所需jar包
axis-ant.jar
axis.jar
jaxrpc.jar (加粗的为核心包,简单的发布用这三个即可)
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
activation.jar
log4j-1.2.8.jar
mail.jar
saaj.jar
wsdl4j-1.5.1.jar
xalan.jar
xmlsec-1.2.1.jar
第二步,修改web.xml
[html] view plain copy
<!--axis 需要引入的 Servlet -->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
第三步,接口实现类及对外发布的调用方法
webservice.Java(这里getStr() 方法提供给外部调用)
[java] view plain copy
package com.business.apps;
import javax.xml.rpc.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.remoting.jaxrpc.ServletEndpointSupport;
import com.business.apps.manager.TestWebService;
@SuppressWarnings("deprecation")
public class WebService extends ServletEndpointSupport {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private TestWebService testWebService;
@Override
protected void onInit() throws ServiceException {
// 初始化Spirng 配置
applicationContext = super.getApplicationContext();
testWebService = (TestWebService) applicationContext.getBean("testWebService");
}
/**
*
* @Description: 接口
* @param
* @return
* @throws Exception
* @author
* @date
* @update:[日期YYYY-MM-DD] [更改人姓名][变更描述]
*/
public String getStr(String jsonString) throws Exception {
return String.valueOf(testWebService.getStr(jsonString));
}
}
上面接口涉及的两个处理类如下:
TestWebserviceImpl.java
[java] view plain copy
/**
*
*/
package com.business.apps.manager.impl;
/**
* @author
* @version 创建时间:2017年1月5日 下午4:21:25
*
*/
import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.business.apps.manager.TestWebService;
public class TestWebServiceImpl implements TestWebService{
@SuppressWarnings("null")
@Transactional
public String getStr(String jsonString)throws Exception {///接收参数为String,然后再返回一个字符串String,方法里面是Json处理
JSONObject jsonOb = JSONObject.fromObject(jsonString);
String serviceTicket = jsonOb.optString("serviceTicket");
Map<String, String> result = new HashMap<String, String>();
result.put("URL","http://www.baidu.com");
JSONObject json = JSONObject.fromObject(result);
return json.toString();
}
}
/*@Component //这里是注解的方式发布接口,配置文件需要配置注解机制,此处略
@WebService(serviceName = "/TestService", targetNamespace = "http://localhost:8080")
public class TestWebServiceImpl implements TestWebService{
@WebMethod
@WebResult(targetNamespace = "http://localhost:8080")
@Transactional
@Override
public String getWgceaUrl(String jsonString) {
JSONObject jsonOb = JSONObject.fromObject(jsonString);
String serviceTicket = jsonOb.optString("serviceTicket");
Map<String, String> result = new HashMap<String, String>();
result.put("URL","http://localhost:8080/*************");
JSONObject json = JSONObject.fromObject(result);
return json.toString();
}
}*/
TestWebservice.java(TestWebserviceImpl对应的接口)
[java] view plain copy
/**
*
*/
package com.business.apps.manager;
/**
* @author
* @version 创建时间:2017年1月5日 下午4:22:45
*
*/
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;
public interface TestWebService {
public String getWgceaUrl(String jsonString)throws Exception;
}
第四步,创建配置文件:在WEB-INF下新建文件“server-config.wsdd”
[html] view plain copy
<?xml version="1.0" encoding="UTF-8"?>
<deployment
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="adminPassword" value="admin" />
<parameter name="sendXsiTypes" value="true" />
<parameter name="sendMultiRefs" value="true" />
<parameter name="sendXMLDeclaration" value="true" />
<parameter name="axis.sendMinimizedElements" value="true" />
<requestFlow>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session" />
</handler>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request" />
<parameter name="extension" value=".jwr" />
</handler>
</requestFlow>
</globalConfiguration>
<handler name="Authenticate"
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
<handler name="LocalResponder"
type="java:org.apache.axis.transport.local.LocalResponder" />
<handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"
/>
<service name="AdminService" provider="java:MSG">
<parameter name="allowedMethods" value="AdminService" />
<parameter name="enableRemoteAdmin" value="false" />
<parameter name="className" value="org.apache.axis.utils.Admin" />
<namespace>http://xml.apache.org/axis/wsdd/</namespace>
</service>
<service name="Version" provider="java:RPC">
<parameter name="allowedMethods" value="getVersion" />
<parameter name="className" value="org.apache.axis.Version" />
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper" />
<handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
</transport>
<transport name="local">
<responseFlow>
<handler type="LocalResponder" />
</responseFlow>
</transport>
<!-- 自定义服务 -->
<service name="WebService" provider="java:RPC">
<parameter name="className" value="com.business.apps.WebService" />
</service>
</deployment>
点击阅读全文阅读"微信小程序开发文档”
有人用微信聊天,有人却在微信中学习,成长。下面是2016最HOT IT公众号,赶快试试新的关注方法吧!
关注方式
★长按二维码,选择“识别图中二维码”进行关注。