From ec4f40f7aec24745ca3078178cc514377c533de8 Mon Sep 17 00:00:00 2001 From: "LORENZO\\pacio" Date: Wed, 23 Oct 2024 13:03:43 +0200 Subject: [PATCH] init --- .gitignore | 112 ++++--------- .idea/.gitignore | 3 + .idea/artifacts/TerreDelPapaApiClient_jar.xml | 8 + .idea/encodings.xml | 7 + .idea/misc.xml | 14 ++ .idea/uiDesigner.xml | 124 ++++++++++++++ .../TerreDelPapaApiClient.jar | Bin 0 -> 3173 bytes pom.xml | 17 ++ .../com/poloinformatico/TDPApiClient.java | 151 ++++++++++++++++++ src/main/resources/META-INF/MANIFEST.MF | 3 + src/test/java/test1.java | 18 +++ 11 files changed, 376 insertions(+), 81 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/artifacts/TerreDelPapaApiClient_jar.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 out/artifacts/TerreDelPapaApiClient_jar/TerreDelPapaApiClient.jar create mode 100644 pom.xml create mode 100644 src/main/java/com/poloinformatico/TDPApiClient.java create mode 100644 src/main/resources/META-INF/MANIFEST.MF create mode 100644 src/test/java/test1.java diff --git a/.gitignore b/.gitignore index 3df9a13..5ff6309 100644 --- a/.gitignore +++ b/.gitignore @@ -1,88 +1,38 @@ -# ---> Java -# Compiled class file -*.class +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ -# Log file -*.log +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* - -# ---> Eclipse -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# CDT- autotools -.autotools - -# Java annotation processor (APT) +### Eclipse ### +.apt_generated +.classpath .factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) +.project +.settings .springBeans +.sts4-cache -# Code Recommenders -.recommenders/ +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ -# Annotation Processing -.apt_generated/ -.apt_generated_test/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -# Uncomment this line if you wish to ignore the project description file. -# Typically, this file would be tracked if it contains build/dependency configurations: -#.project +### VS Code ### +.vscode/ +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/artifacts/TerreDelPapaApiClient_jar.xml b/.idea/artifacts/TerreDelPapaApiClient_jar.xml new file mode 100644 index 0000000..8b4a823 --- /dev/null +++ b/.idea/artifacts/TerreDelPapaApiClient_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/TerreDelPapaApiClient_jar + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..132404b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/artifacts/TerreDelPapaApiClient_jar/TerreDelPapaApiClient.jar b/out/artifacts/TerreDelPapaApiClient_jar/TerreDelPapaApiClient.jar new file mode 100644 index 0000000000000000000000000000000000000000..3d6811be3aaa32f6858782ab0f402750735c993e GIT binary patch literal 3173 zcmaKucT|(<62?QX0i_6`NiWhtLBzmla@7?P@?|ILe@4Pef%`<=fjNw$&8~}QHdO%N-r6u4m;s8(s z5ISaBvM@uaJVMJ52Gub&lS4p{NC3btVxZpuE-N<*gv*{A8W^rKQ5aWVSow$;7?LwyE=(u*rgE0h3ZI2}F1qZM1& z@sD+nukrCXi~s;V;BVtlAHOE4oiP8Z_|sz7|5z0N zMTHr}SPP53;)Qnc36OL0a`5-hvt$Ti@8LY6<8RL3qN1dtwBeJRnR?O1SEQud&W*(< zPpvB4Y!jAk_-&FAt>YV3jwmdJ>Ct;@kClso3xQ(za+OZBzC2mH3}G8K|MmVSjc4KL zcbd|D8HC)Ou7cpC;K7`)N2iRrEfb<}X0x^lB27kJNX~8Khif!naSAM~l^4bL>A+S=u^cT%hI8BPkjsKO zv7F(*bqekYUYe%?6G#{YdtQfjUcG*-g<83Gwn zhEz=O!x#tXV+QiGn?M&th*w>UbsL3+>dKu0*GVCz8a#@Q7W^)_PkII@$1X(s>+c$^ z;?+G*J;)CsqLb!sk7^{Ix_gFGsI)TYJaipnt9-ycB!`km=v$|_50W6-+dydQ7@h99 z)0~npf2SDpx*}PGn9z{=!vY<^RHfYn}YVT`ZkTIx>GKbwcZB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F5$-;ld(i0Z`Z~cmlPr5JyevPm{yCffne**2V zD^8I1r-;YlNyXm*_vhp%i2GObCy4t~%g5pW>+pBr{U;wMYx}9?W3&I+hB2Im_T-7? O_~=jo0E|p0Uw;7pdS}i6 literal 0 HcmV?d00001 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4c16a7a --- /dev/null +++ b/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + com.poloinformatico + TerreDelPapaApiClient + 1.0-SNAPSHOT + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/src/main/java/com/poloinformatico/TDPApiClient.java b/src/main/java/com/poloinformatico/TDPApiClient.java new file mode 100644 index 0000000..f71e433 --- /dev/null +++ b/src/main/java/com/poloinformatico/TDPApiClient.java @@ -0,0 +1,151 @@ +package com.poloinformatico; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class TDPApiClient { + public static void main(String[] args) { + + + } + + public static ArrayList doPost(String apiUrl,String params) { + + ArrayList res=new ArrayList(); + + System.out.println(params); + + // Request parameters (key-value pairs) + Map parameters = new HashMap<>(); + + String par1 = "",par2="",par3="",par4 = ""; + + try{ + par1=params.split("#")[0]; + }catch (Exception e){} + try{ + par2=params.split("#")[1]; + }catch(Exception e){} + try{ + par3=params.split("#")[2]; + }catch(Exception e){} + try{ + par3=params.split("#")[3]; + }catch(Exception e){} + + parameters.put("KEY_EXT", par1); + parameters.put("ToPLC1", par2); + parameters.put("ToPLC2", par3); + parameters.put("ToPLC3", par4); + + // Construct URL with parameters + StringBuilder urlBuilder = new StringBuilder(apiUrl); + urlBuilder.append("?"); + urlBuilder.append(buildUrlParameters(parameters)); + + StringBuilder response = null; + try { + URL url = new URL(urlBuilder.toString()); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + + // Set the request method to POST + connection.setRequestMethod("POST"); + + // Get the response code + int responseCode = connection.getResponseCode(); + System.out.println("Response Code: " + responseCode); + + // Read the response from the server + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + response = new StringBuilder(); + String line; + + while ((line = reader.readLine()) != null) { + response.append(line); + } + reader.close(); + + // Print the response + System.out.println("Response Body: " + response.toString()); + + res.add(String.valueOf(responseCode)); + res.add(String.valueOf(response)); + + // Disconnect the connection + connection.disconnect(); + + } catch (Exception e) { + e.printStackTrace(); + } + return res; + } + + public static ArrayList doGet(String apiUrl){ + + ArrayList res=new ArrayList(); + + try { + URL url = new URL(apiUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + + // Set request method to GET + connection.setRequestMethod("GET"); + + // Get the response code + int responseCode = connection.getResponseCode(); + System.out.println("Response Code: " + responseCode); + + // Read the response from the server + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + StringBuilder response = new StringBuilder(); + String line; + + while ((line = reader.readLine()) != null) { + response.append(line); + } + reader.close(); + + // Print the response + System.out.println("Response Body: " + response.toString()); + + res.add(String.valueOf(responseCode)); + res.add(String.valueOf(response)); + + // Disconnect the connection + connection.disconnect(); + + } catch (Exception e) { + e.printStackTrace(); + } + + + return res; + } + + private static String buildUrlParameters(Map params) { + StringBuilder urlParams = new StringBuilder(); + + for (Map.Entry entry : params.entrySet()) { + try { + if (urlParams.length() != 0) { + urlParams.append("&"); + } + urlParams.append(URLEncoder.encode(entry.getKey(), "UTF-8")) + .append("=") + .append(URLEncoder.encode(entry.getValue(), "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); // Handle the exception according to your needs + } + } + + return urlParams.toString(); + } + +} diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..58b75db --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.poloinformatico.TDPApiClient + diff --git a/src/test/java/test1.java b/src/test/java/test1.java new file mode 100644 index 0000000..447f80b --- /dev/null +++ b/src/test/java/test1.java @@ -0,0 +1,18 @@ +import com.poloinformatico.TDPApiClient; + +public class test1 { + + + + public static void main(String[] args) { + + System.out.println(TDPApiClient.doPost("https://jsonplaceholder.typicode.com/posts","2023_5# #0# ")); + + + System.out.println(TDPApiClient.doGet("https://jsonplaceholder.typicode.com/posts/1")); + + + } + + +}