あなたが学んだことを適用し、再版へようこそ、詳細についてはQQ:289325414にお問い合わせください
1つは、Maven-webプロジェクトを作成する
日食
(参照してください)https://blog.csdn.net/qq_37203082/article/details/100557128
考え
https://www.cnblogs.com/zhangchengzi/p/9865546.html
2つ目は、pom.xmlがJARパッケージを参照することです。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spdb</groupId>
<artifactId>axis</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>axis</name>
<!-- FIXME change it to the project's website -->
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
</dependencies>
<build>
<finalName>axis</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
3、簡単なビジネスロジックを書く
実装クラス
package com.spdb.axis.impl;
import java.sql.Date;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.spdb.axis.service.StudentService;
import com.spdb.axis.util.StudAppUtil;
/**
*
* 公共学生信息服务的实现类
*
* @author CJW
*
*/
public class StudentServiceImpl implements StudentService {
@Override
public String getStudentMarks(String strInfoDo) {
JSONObject map = JSON.parseObject(strInfoDo);
return StudAppUtil.invokeInnerService(map, "getStudentMarks");
}
@Override
public String getStudentList(String strInfoDo) {
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date=new Date(System.currentTimeMillis());
String time=format.format(date);
System.out.println(time);
JSONArray list = JSON.parseArray(strInfoDo);
System.out.println(list.get(0));
return String.valueOf(list.size());
}
}
インターフェイスクラス
package com.spdb.axis.service;
/**
*
* 公共的学生信息服务接口
*
* @author CJW
*
*/
public interface StudentService {
/**
* 根据学号和学科号获取成绩
*
* @param studentNo
* 学生学号
* @param subjectNo
* 学科号
* @return 成绩
*/
String getStudentMarks(String strInfoDo);
/**
* 获取大量LIST
*
* @param studentNo
* 学生学号
* @param subjectNo
* 学科号
* @return 成绩
*/
String getStudentList(String strInfoDo);
}
ツールクラス
package com.spdb.axis.util;
import java.util.Map;
/**
*
* 公共学生信息工具类
*
* @author CJW
*
*/
public class StudAppUtil {
/**
*
* 调用内部服务
*
* @param dataMap
* 请求数据集
* @param txnCode
* 交易码
* @return 返回交易的结果信息
*/
public static String invokeInnerService(Map<String,Object> dataMap, String txnCode) {
String responseInfo = "";
if("getStudentMarks".equals(txnCode)){
String studentNo = (String)dataMap.get("studentNo");
String subjectNo = (String)dataMap.get("subjectNo");
responseInfo = "学号=" + studentNo +",学科号="+subjectNo + ",成绩=98";
}
System.out.println(responseInfo);
return responseInfo;
}
}
第四に、WEB.xmlを構成します
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- WebService接入配置 BEGIN -->
<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接入配置 END -->
</web-app>
deploy.wsddファイルを作成します
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- WebService接入配置 BEGIN -->
<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接入配置 END -->
</web-app>
5、server-config.wsddを作成します
1. DOSコマンドウィンドウでアプリケーションのデプロイメントパスに切り替えます。ローカルデプロイメントパスは次のとおりです。D:\ MyDeveloper \ normal \ workspace.metadata.plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps \ axis \ WEB-INF
(Tomcatはコンテンツの印刷を開始します。デプロイメントパスを見つけることができます)
2.パスの下で次のコマンド行を実行します。
java -Djava.ext.dirs = lib org.apache.axis.client.AdminClient -l http://127.0.0.1:7777/axis/services deploy.wsdd
実行が成功した後、次の図は、server-config.wsddファイルが正常に生成されたことを示しています。
6、server-config.wsddをプロジェクトにコピーします
セブン、TOMCATを起動します
ブラウザ入力後
http:// localhost:7777 / axis / services / StudentService?wsdl
は、成功を示すために次のように表示されます
上記はサーバー側のコード構造全体です
簡単なクライアント認証メッセージ送信を作成しましょう
1つは、Mavenプロジェクトを作成する
2つ目は、Pom.xmlがjar参照を追加することです。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spdb</groupId>
<artifactId>axisCus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>axisCus Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
</dependencies>
<build>
<finalName>axisCus</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
プログラムテストファイルを作成する
package com;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class Test {
public static void main(String[] args) {
try {
String xmlStr="123";
String result2= invoke("http://localhost:7777/axis/services/StudentService","getStudentInfo",xmlStr);
System.out.println(result2);
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* 调用webservice路口
* @param endpoint 地址
* @param methodName 调用的方法
* @param xmlStr 传递的xml字符串参数
* @return
*/
public static String invoke(String endpoint, String methodName, String xmlStr) {
Service service = new Service();
Call call = null;
try {
call = (Call) service.createCall();
} catch (ServiceException e) {
e.printStackTrace();
}
QName qn = new QName(methodName);
call.setOperationName(qn);
call.setTargetEndpointAddress(endpoint);
call.setUseSOAPAction(true);
String result = "";
try {
// 给方法传递参数,并且调用方法
result = (String) call.invoke(new Object[]{xmlStr});
} catch (RemoteException e) {
e.printStackTrace();
}
return result;
}
}
起動して実行します。戻り値はサーバー側とクライアント側を示します。コミュニケーションは成功しました
ソースコード:
サーバー側:https://github.com/chenjunwei111/axis1.4
クライアント:https://github.com/chenjunwei111/axisCus
参照:
https://blog.csdn.net/jack_david/article/details/86532983#tomcat_228