我在部署Web服务时尝试执行startUp方法,但不起作用。
我正在使用:
windows 7
tomcat 8.0.30
axis2 1.7.0
我尝试将我的服务部署为pojo服务,同时尝试生成* .aar并将其放入:
Apache的Tomcat的8.0.30 \ web应用\的axis2 \ WEB-INF \服务 但是当我运行tomcat并部署这个和其他服务时,startUp方法不会启动。 这是我的代码:
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
}
}
答案 0 :(得分:0)
您是否创建了描述服务的服务定义(services.xml)文件?
我指的是类似于以下链接{axis(1)}中的示例的文件(axis2快速启动):
https://axis.apache.org/axis2/java/core/docs/quickstartguide.html#services