gpt4 book ai didi

java - 在部署 Web 服务时运行启动方法

转载 作者:行者123 更新时间:2023-11-28 23:26:09 26 4
gpt4 key购买 nike

我尝试在部署我的 Web 服务时执行 startUp 方法,但不起作用。

我正在使用:

windows 7

tomcat 8.0.30

axis2 1.7.0

我尝试将我的服务部署为 pojo 服务,我也尝试生成 *.aar 并将其放入:

apache-tomcat-8.0.30\webapps\axis2\WEB-INF\services but when i run the tomcat, and deploy this and other services, the startUp method dont launch. this is my code:

import java.io.*;
import java.util.*;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.engine.ServiceLifeCycle;

public class Login implements ServiceLifeCycle{

static String IPprop = "";
static String rutaDB = "C:/resources/users_DB.txt";
static String rutaUddiXml = "C:/resources/uddi.xml";
static String rutaIP = "C:/resources/ip.txt";
static boolean registrado=false;
static String comp ="";

public static void main(String[] args) {

IP();
String nombreServicio = "Login";
String rutaServicio = "http://"+ IPprop +":8080/axis2/services/Login";
SimplePublishPortable spp = new SimplePublishPortable(rutaUddiXml);
spp.publish(nombreServicio, rutaServicio);
System.out.println("te registraste");
}

public static void createUser(String user, String pass) {
interacFich("crea", user, pass);
}

public static String loginAccess(String user, String pass) {
return interacFich("login", user, pass);
}

public static String runComprobation(){
return "deployed service" + comp;
}

public static String regComprobation(){
if(registrado==true){
return "registered";
}
else{
return "failed";
}
}

private static String getToken() {
String cadenaAleatoria = "";

int i = 0;
while (i < 10) {
char c = (char) ((int) (Math.random() * 255 + 1));
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')) {
cadenaAleatoria += c;
i++;
}
}
return cadenaAleatoria;
}

private static String interacFich(String accion, String user, String pass) {
String usuario = "";
LinkedHashMap<String, String> usuarios = new LinkedHashMap<String, String>();

File archivo = new File(rutaDB);

// leer fichero y meterlo en el mapa
if (archivo.exists() == false) {
try {
archivo.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
} else {
try (BufferedReader br = new BufferedReader(new FileReader(archivo))) {
while (br.ready()) {
usuario = br.readLine();
String[] param = usuario.split("\\*");
usuarios.put(param[0], param[1]);

}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
switch (accion) {
case "crea":
usuarios.put(user + "-" + pass, getToken());

try (BufferedWriter bw = new BufferedWriter(new FileWriter(archivo))) {
Set<String> keysUsuarios = usuarios.keySet();
for (String k : keysUsuarios) {
bw.write(k + "*" + usuarios.get(k).toString());
bw.write("\n");

}
System.out.println("todo escrito");
bw.close();

return "el fichero se crea";
} catch (IOException e) {
e.printStackTrace();
}
break;
case "login":
if (usuarios.containsKey(user + "-" + pass)) {
return usuarios.get(user + "-" + pass);
}
return "User o pass erroneos";
default:
break;

}

return null;
}

private static void IP() {
File archivo = new File(rutaIP);
try (BufferedReader br = new BufferedReader(new FileReader(archivo))) {
br.readLine();
IPprop = br.readLine();


br.close();
} catch (IOException e) {
e.printStackTrace();
}

return;

}
@Override
public void startUp(ConfigurationContext arg0, AxisService arg1) {
///////////////
//registrarse//
///////////////
comp="entramos";
IP();
String nombreServicio = "Login";
String rutaServicio = "http://"+ IPprop +":8080/axis2/services/Login";
SimplePublishPortable spp = new SimplePublishPortable(rutaUddiXml);
spp.publish(nombreServicio, rutaServicio);
registrado=true;
}

@Override
public void shutDown(ConfigurationContext arg0, AxisService arg1) {
// TODO Auto-generated method stub

}

}

最佳答案

您是否创建了描述服务的服务定义 (services.xml) 文件?

我指的是与以下链接(axis2 快速入门)中的代码 list 3:服务定义文件 中的示例类似的文件:

https://axis.apache.org/axis2/java/core/docs/quickstartguide.html#services

关于java - 在部署 Web 服务时运行启动方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36727579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com