Documentos de Académico
Documentos de Profesional
Documentos de Cultura
COMPUTACIÓN
29/05/2023
Introducción
Un Servicio Web es un componente al que podemos acceder
mediante protocolos Web estándar, utilizando XML para el
intercambio de información.
Normalmente nos referimos con Servicio Web a una colección de
procedimientos (métodos) a los que podemos llamar desde
cualquier lugar de Internet o de nuestra intranet, siendo este
mecanismo de invocación totalmente independiente de la
plataforma que utilicemos y del lenguaje de programación en el
que se haya implementado internamente el servicio.
Los servicios Web son componentes de aplicaciones distribuidas
que están disponibles de forma externa. Se pueden utilizar para
integrar aplicaciones escritas en diferentes lenguajes y que se
ejecutan en plataformas diferentes. Los servicios Web son
independientes de lenguaje y de la plataforma gracias a que los
vendedores han admitido estándares comunes de Servicios Web.
Los servicios Web proporcionan una forma estándar de
interoperar entre aplicaciones software que se ejecutan en
diferentes plataformas. A los servicios web se le entiende por un
conjunto de aplicaciones o de tecnologías incluyendo XML, SOAP,
WSDL, UDDI con capacidad para interoperar en la Web.
OBJETIVO
SUSTENTO TEÓRICO.
DESARROLLO
@WebMethod(operationName = "countVowelsInFile")
public int countVowelsInFile(@WebParam(name = "file") DataHandler
file) {
try {
InputStream inputStream = file.getInputStream();
int vowelCount;
try (BufferedReader reader = new BufferedReader(new
InputStreamReader(inputStream))) {
String line;
vowelCount = 0;
while ((line = reader.readLine()) != null) {
vowelCount += countVowelsInString(line);
}
}
return vowelCount;
} catch (IOException e) {
return -1; // Valor de retorno para indicar un error
}
}
@WebMethod(operationName = "copyFile")
public boolean copyFile(@WebParam(name = "file") DataHandler file,
@WebParam(name = "destinationPath") String
destinationPath) {
try {
// Obtener el nombre del archivo original
String originalFileName = getOriginalFileName(file);
// Copiar el archivo
try (FileOutputStream outputStream = new
FileOutputStream(destinationFile)) {
file.writeTo(outputStream);
}
@WebMethod(operationName = "renameFile")
public boolean renameFile(@WebParam(name = "currentPath") String
currentPath,
@WebParam(name = "newName") String newName) {
try {
Path currentFilePath = Paths.get(currentPath);
Path newFilePath = currentFilePath.resolveSibling(newName);
Files.move(currentFilePath, newFilePath,
StandardCopyOption.REPLACE_EXISTING);
@WebMethod(operationName = "deleteFile")
public boolean deleteFile(@WebParam(name = "filePath") String
filePath) {
try {
File file = new File(filePath);
return file.delete();
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@WebMethod(operationName = "countLinesInFile")
public int countLinesInFile(@WebParam(name = "filePath") String
filePath) {
try {
File file = new File(filePath);
int lineCount = 0;
try (BufferedReader reader = new BufferedReader(new
FileReader(file))) {
while (reader.readLine() != null) {
lineCount++;
}
}
return lineCount;
} catch (IOException e) {
e.printStackTrace();
return -1; // Valor de retorno para indicar un error
}
}
@WebMethod(operationName = "getFileContent")
public String getFileContent(@WebParam(name = "filePath") String
filePath) {
try {
File file = new File(filePath);
StringBuilder content = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new
FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
}
}
return content.toString();
} catch (IOException e) {
e.printStackTrace();
return "Error al leer el archivo.";
}
}
@WebMethod(operationName = "backupFile")
public boolean backupFile(@WebParam(name = "filePath") String filePath,
@WebParam(name = "backupPath") String
backupPath) {
try {
File file = new File(filePath);
File backupFile = new File(backupPath);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
RESULTADOS
Ejecución:
Ejecución de contador de vocales, copia y renombrar: