Skip to content

Commit 55d0117

Browse files
committed
Adding a response in JSON format
1 parent c42045b commit 55d0117

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

pom.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>pl.nip24</groupId>
77
<artifactId>nip24-client</artifactId>
8-
<version>1.3.9</version>
8+
<version>1.4.0</version>
99

1010
<name>nip24-java-client</name>
1111
<description>NIP24 Service Client for Java</description>
@@ -47,25 +47,28 @@
4747
<java.version>11</java.version>
4848
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4949

50-
<swagger.version>2.2.8</swagger.version>
51-
<jackson.version>2.14.2</jackson.version>
50+
<swagger.version>2.2.16</swagger.version>
51+
<jackson.version>2.15.2</jackson.version>
5252
</properties>
5353

5454
<build>
5555
<plugins>
56+
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
5657
<plugin>
5758
<groupId>org.apache.maven.plugins</groupId>
5859
<artifactId>maven-compiler-plugin</artifactId>
59-
<version>3.10.1</version>
60+
<version>3.11.0</version>
6061
<configuration>
6162
<source>${java.version}</source>
6263
<target>${java.version}</target>
6364
</configuration>
6465
</plugin>
66+
67+
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-source-plugin -->
6568
<plugin>
6669
<groupId>org.apache.maven.plugins</groupId>
6770
<artifactId>maven-source-plugin</artifactId>
68-
<version>3.2.1</version>
71+
<version>3.3.0</version>
6972
<executions>
7073
<execution>
7174
<id>attach-sources</id>
@@ -75,10 +78,12 @@
7578
</execution>
7679
</executions>
7780
</plugin>
81+
82+
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-javadoc-plugin -->
7883
<plugin>
7984
<groupId>org.apache.maven.plugins</groupId>
8085
<artifactId>maven-javadoc-plugin</artifactId>
81-
<version>3.4.1</version>
86+
<version>3.6.0</version>
8287
<executions>
8388
<execution>
8489
<id>attach-javadocs</id>

src/main/java/pl/nip24/client/NIP24Client.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
*/
5353
public class NIP24Client {
5454

55-
public final static String VERSION = "1.3.9";
55+
public final static String VERSION = "1.4.0";
5656

5757
public final static String PRODUCTION_URL = "https://www.nip24.pl/api";
5858
public final static String TEST_URL = "https://www.nip24.pl/api-test";
@@ -1068,7 +1068,7 @@ public KRSData getKRSSection(Number type, String number, int section)
10681068
String url = (this.url.toString() + "/get/krs/current/" + suffix + "/" + section);
10691069

10701070
// prepare request
1071-
byte[] b = get(url);
1071+
byte[] b = get(url, "application/json");
10721072

10731073
if (b == null) {
10741074
set(Error.CLI_CONNECT);
@@ -1268,11 +1268,12 @@ private ObjectMapper getObjectMapper()
12681268

12691269
/**
12701270
* Przygotowanie nagłówka z danymi do autoryzacji zapytania
1271+
* @param headers obiekt z nagłówkami HTTP
12711272
* @param method metoda HTTP
12721273
* @param url docelowy adres URL
12731274
* @return nagłówki HTTP lub null
12741275
*/
1275-
private Properties auth(String method, URL url)
1276+
private boolean auth(Properties headers, String method, URL url)
12761277
{
12771278
try {
12781279
// prepare auth header
@@ -1291,21 +1292,19 @@ private Properties auth(String method, URL url)
12911292
String mac = getMac(str);
12921293

12931294
if (mac == null) {
1294-
return null;
1295+
return false;
12951296
}
12961297

12971298
// prepare request
1298-
Properties p = new Properties();
1299-
1300-
p.setProperty("Authorization", "MAC id=\"" + id + "\", ts=\"" + ts + "\", nonce=\""
1299+
headers.setProperty("Authorization", "MAC id=\"" + id + "\", ts=\"" + ts + "\", nonce=\""
13011300
+ nonce + "\", mac=\"" + mac + "\"");
13021301

1303-
return p;
1302+
return true;
13041303
}
13051304
catch (Exception ignored) {
13061305
}
13071306

1308-
return null;
1307+
return false;
13091308
}
13101309

13111310
/**
@@ -1320,9 +1319,10 @@ private void userAgent(Properties headers)
13201319
/**
13211320
* Metoda HTTP GET
13221321
* @param url adres URL
1322+
* @param mimetype typ MIME odpowiedzi (application/xml lub application/json)
13231323
* @return pobrana odpowiedź lub null
13241324
*/
1325-
private byte[] get(String url)
1325+
private byte[] get(String url, String mimetype)
13261326
{
13271327
boolean set = false;
13281328

@@ -1343,10 +1343,12 @@ private byte[] get(String url)
13431343
set = true;
13441344
}
13451345

1346-
// auth
1347-
Properties headers = auth("GET", u);
1348-
1349-
if (headers == null) {
1346+
// headers
1347+
Properties headers = new Properties();
1348+
1349+
headers.setProperty("Accept", mimetype);
1350+
1351+
if (!auth(headers, "GET", u)) {
13501352
return null;
13511353
}
13521354

@@ -1420,6 +1422,16 @@ else if (url.toLowerCase().startsWith("http://")) {
14201422
return null;
14211423
}
14221424

1425+
/**
1426+
* Metoda HTTP GET
1427+
* @param url adres URL
1428+
* @return pobrana odpowiedź lub null
1429+
*/
1430+
private byte[] get(String url)
1431+
{
1432+
return get(url, "application/xml");
1433+
}
1434+
14231435
/**
14241436
* Odczyt zawartosci calego strumienia do tablicy
14251437
* @param stream strumien wejsciowy

0 commit comments

Comments
 (0)