Primer commit de servicios

parent ed43ea6c
Pipeline #974 failed with stages
/target/
/nbproject/
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv4ee7</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<netbeans.hint.jdkPlatform>JDK_1.8</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
<?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>amx.ccie.etl</groupId>
<artifactId>etl-service-ccie-mvn</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>etl-service-ccie-mvn</name>
<url>http://www.example.com</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<!-- Java EE API for GlassFish -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<!-- Oracle JDBC Driver -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.8.0.0</version>
</dependency>
<!-- JAX-RS Client (Para consumir API externas) -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.34</version>
</dependency>
<!-- Quartz Scheduler (Para ejecutar el proceso cada día a la 1 AM) -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
package amx.ccie.etl.httpClient;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ResourceBundle;
import java.util.Scanner;
/**
*
* @author David Coronilla
*/
public class TestApisEmpleado {
private final String URL = "https://reqres.in/api/users";
public TestApisEmpleado(){}
public void getEmpleado() throws MalformedURLException, IOException, KeyManagementException, NoSuchAlgorithmException, Exception{
new TrustAllSSL().configureTrustAllSSL();
//COLOCAMOS LA URL PARA ENVIAR EL MENSAJE
URL url = new URL(this.URL);
//INICIALIZAMOS EL CONTENEDOR DEL ENVIO
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
//EL TIPO DE ENVIO DE DATOS VA A SER VIA POST
httpConn.setRequestMethod("POST");
//CODIGO DE AUTORIZACION DE JAVA
//httpConn.setRequestProperty("Authorization", "Bearer " + this.WA_TOKEN);
//DEFINIMOS QUE LOS DATOS SERAN TRATADOS COMO JSON
httpConn.setRequestProperty("Content-Type", "application/json");
//PREPARAMOS Y ENVIAMOS EL JSON
httpConn.setDoOutput(true);
try (OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream())) {
writer.write("{\"name\": \"Pedro\",\"job\": \"Developer\"}");
//LIMPIAMOS LOS DATOS
writer.flush();
}
//CERRAMOS LA CONEXION
httpConn.getOutputStream().close();
//RECIBIMOS EL RESULTADO DEL ENVIO
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
//OBTENEMOS LOS RESULTADOS
String respuesta = s.hasNext() ? s.next() : "";
System.out.print("Respuesta del servidor: " + respuesta);
}//end metod
}
package amx.ccie.etl.httpClient;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ResourceBundle;
import java.util.Scanner;
/**
*
* @author David Coronilla
*/
public class TestApisReporte {
private final String URL = "https://www.rsvamx.com:8081/amxmovil-servicefrontera-ventas/api/ventas/competidores/reporte/broadband-pdm-pais";
private final String TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VycGRtY29tIiwiaWF0IjoxNzIzMjM0Mjg2LCJleHAiOjE3NTQwMjQ0MDB9.3n9SQyksOk8EaUilIIRTA4cytmxI8aYVV_L12yk-EfA";
public TestApisReporte(){}
public void getReporte() throws MalformedURLException, IOException, KeyManagementException, NoSuchAlgorithmException, Exception{
new TrustAllSSL().configureTrustAllSSL();
//COLOCAMOS LA URL PARA ENVIAR EL MENSAJE
URL url = new URL(this.URL);
//INICIALIZAMOS EL CONTENEDOR DEL ENVIO
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
//EL TIPO DE ENVIO DE DATOS VA A SER VIA POST
httpConn.setRequestMethod("POST");
//CODIGO DE AUTORIZACION DE JAVA
httpConn.setRequestProperty("Authorization", "Bearer " + this.TOKEN);
//DEFINIMOS QUE LOS DATOS SERAN TRATADOS COMO JSON
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//PREPARAMOS Y ENVIAMOS EL JSON
httpConn.setDoOutput(true);
try (OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream())) {
writer.write("idPais=21&trimestre=3T2023");
//LIMPIAMOS LOS DATOS
writer.flush();
}
//CERRAMOS LA CONEXION
httpConn.getOutputStream().close();
//RECIBIMOS EL RESULTADO DEL ENVIO
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
//OBTENEMOS LOS RESULTADOS
String respuesta = s.hasNext() ? s.next() : "";
System.out.print("Respuesta del servidor: " + respuesta);
}//end metod
}
package amx.ccie.etl.httpClient;
import java.security.cert.X509Certificate;
import javax.net.ssl.*;
/**
*
* @author David Coronilla
*/
public class TrustAllSSL {
/**
* Configures SSL to trust all certificates and bypass hostname verification.
* This allows the application to connect to servers with untrusted or self-signed certificates.
* WARNING: This approach is insecure for production use.
*/
public void configureTrustAllSSL() throws Exception {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
// Do nothing - trust all clients
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
// Do nothing - trust all servers
}
}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
}//end method
}//end class
package amx.ccie.etl.scheduler;
import amx.ccie.etl.httpClient.TestApisEmpleado;
import amx.ccie.etl.httpClient.TestApisReporte;
import java.net.MalformedURLException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
/**
*
* @author montielj
*/
@Singleton
@Startup
public class CatalogoScheduler {
@Schedule(hour = "16", minute = "20", second = "0", persistent = false)
//@Schedule(dayOfMonth = "15", hour = "19", minute = "58", second = "0", persistent = false)
public void consultarCatalogoServicio() {
try {
new TestApisEmpleado().getEmpleado();
new TestApisReporte().getReporte();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (KeyManagementException | NoSuchAlgorithmException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
package amx.ccie.etl.service;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
public class ApiService {
private static final String API_URL = "https://api.example.com/data";
public String fetchData() {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(API_URL);
Response response = target.request(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == 200) {
return response.readEntity(String.class);
} else {
throw new RuntimeException("Error en la llamada al API: " + response.getStatus());
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<!--
Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<glassfish-web-app error-url="">
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment