JNI test connection with spring
This commit is contained in:
parent
213945b2e9
commit
b697e66b2c
8
JNI/build.sh
Executable file
8
JNI/build.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
gcc -fPIC -shared \
|
||||
-I"$JAVA_HOME/include" \
|
||||
-I"$JAVA_HOME/include/linux" \
|
||||
-o libbtcjni.so native_impl.c
|
||||
echo "Built libbtcjni.so"
|
||||
|
||||
BIN
JNI/libbtcjni.so
Executable file
BIN
JNI/libbtcjni.so
Executable file
Binary file not shown.
28
JNI/native_impl.c
Normal file
28
JNI/native_impl.c
Normal file
@ -0,0 +1,28 @@
|
||||
//native_impl.c
|
||||
|
||||
#include <jni.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// JNI functions for com.example.cezenBTC.service.NativeBridge
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_example_cezenBTC_service_NativeBridge_hello(JNIEnv *env, jclass clazz, jstring jname) {
|
||||
(void)clazz; // unused
|
||||
const char *name = jname ? (*env)->GetStringUTFChars(env, jname, NULL) : "World";
|
||||
|
||||
char buf[256];
|
||||
snprintf(buf, sizeof(buf), "Hello from JNI, %s!", (name && *name) ? name : "World");
|
||||
|
||||
if (jname) {
|
||||
(*env)->ReleaseStringUTFChars(env, jname, name);
|
||||
}
|
||||
return (*env)->NewStringUTF(env, buf);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_example_cezenBTC_service_NativeBridge_add(JNIEnv *env, jclass clazz, jint a, jint b) {
|
||||
(void)env; (void)clazz;
|
||||
return a + b;
|
||||
}
|
||||
|
||||
@ -109,6 +109,7 @@ public class CezenRoutsSecurityChain {
|
||||
"/btc/get_races_by_venue_id",
|
||||
"/btc/get_all_races_by_today",
|
||||
"/btc/get_race_card",
|
||||
"/btc/tester",
|
||||
"/cezen/set_aors",
|
||||
"/cezen/set_password",
|
||||
"/cezen/add_extension"
|
||||
|
||||
@ -47,4 +47,10 @@ public class BtcOperations {
|
||||
|
||||
return this.btcRaceService.getRaceCard(LocalDate.now());
|
||||
}
|
||||
|
||||
@GetMapping("/tester")
|
||||
public ResponseEntity<String> testData(){
|
||||
|
||||
return this.btcRaceService.testConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,4 +114,13 @@ public class BtcRaceService {
|
||||
|
||||
return ResponseEntity.status(200).body(raceCard);
|
||||
}
|
||||
|
||||
// this is a JNI test to spring
|
||||
public ResponseEntity<String> testConnection(){
|
||||
|
||||
//jni logic here
|
||||
String msg = NativeBridge.hello("Spring");
|
||||
int sum = NativeBridge.add(21, 21);
|
||||
return ResponseEntity.ok(msg + " | add(21,21)=" + sum);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.example.cezenBTC.service;
|
||||
|
||||
public final class NativeBridge {
|
||||
public static native String hello(String name);
|
||||
public static native int add(int a, int b);
|
||||
|
||||
static {
|
||||
// ABSOLUTE PATH to the generated library
|
||||
// Linux: libbtcjni.so, macOS: libbtcjni.dylib, Windows: btcjni.dll
|
||||
System.load("/home/mathew/Desktop/dev/horse/JNI_spring/btc_horse/JNI/libbtcjni.so"); // <-- change this to the real path
|
||||
}
|
||||
|
||||
private NativeBridge() {}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user