Compilación de cliente y servidor Axis1.4

Aplique lo que ha aprendido, bienvenido a reimprimir, comuníquese con QQ: 289325414 para obtener más información.

Uno, crea un proyecto web de Maven

eclipse

(Consulte) https://blog.csdn.net/qq_37203082/article/details/100557128

idea

https://www.cnblogs.com/zhangchengzi/p/9865546.html

 

Dos, pom.xml hace referencia al paquete 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>

Tres, escribe una lógica empresarial simple

Clase de implementación

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());
	}

}

Clase de interfaz

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);


}

Una clase de herramienta

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;
	}
}

Cuarto, configure 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>

Cree el archivo 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>

Cinco, cree server-config.wsdd

1. Cambie a la ruta de implementación de nuestra aplicación en la ventana de comandos de DOS. Mi ruta de implementación local es: D: \ MyDeveloper \ normal \ workspace.metadata.plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps \ axis \ WEB-INF

(Tomcat comienza a imprimir el contenido, puede encontrar la ruta de implementación)

2. Ejecute la siguiente línea de comandos debajo de la ruta:

java -Djava.ext.dirs = lib org.apache.axis.client.AdminClient -l http://127.0.0.1:7777/axis/services deploy.wsdd

Una vez que la ejecución es exitosa, la siguiente figura muestra que el archivo server-config.wsdd se generó exitosamente

å¨è¿éæå ¥ å¾çæè¿ °

Seis, copie server-config.wsdd al proyecto

Siete, comienza TOMCAT

Después de la entrada del navegador

http: // localhost: 7777 / axis / services / StudentService? wsdl
muestra lo siguiente para indicar el éxito

Lo anterior es la estructura completa del código en el lado del servidor.

Creemos un envío de mensaje de autenticación de cliente simple

Uno, crea un proyecto maven

Dos, Pom.xml agrega referencia de 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>

Crear un archivo de prueba de programa

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;
    }
}

Inicie y ejecute, y un valor de retorno indica el lado del servidor y el lado del cliente. La comunicación tuvo éxito

Código fuente:

Lado del servidor: https://github.com/chenjunwei111/axis1.4

Cliente: https://github.com/chenjunwei111/axisCus

referencia:

https://blog.csdn.net/jack_david/article/details/86532983#tomcat_228

Supongo que te gusta

Origin blog.csdn.net/qq_37203082/article/details/100557453
Recomendado
Clasificación