mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-12 02:05:50 +00:00
CHANGED: fixed ApiService
This commit is contained in:
parent
2fc74ac583
commit
9fb434cdd6
10
pom.xml
10
pom.xml
@ -47,5 +47,15 @@
|
||||
<artifactId>jersey-server</artifactId>
|
||||
<version>2.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet</artifactId>
|
||||
<version>2.27</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>9.4.11.v20180605</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
71
src/api/ApiService.java
Normal file
71
src/api/ApiService.java
Normal file
@ -0,0 +1,71 @@
|
||||
package api;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.InetAccessHandler;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.servlet.ServletContainer;
|
||||
|
||||
import settings.Settings;
|
||||
|
||||
public class ApiService {
|
||||
|
||||
public Server server;
|
||||
|
||||
public ApiService()
|
||||
{
|
||||
//CREATE CONFIG
|
||||
Set<Class<?>> s = new HashSet<Class<?>>();
|
||||
s.add(BlocksResource.class);
|
||||
|
||||
ResourceConfig config = new ResourceConfig(s);
|
||||
|
||||
//CREATE CONTAINER
|
||||
ServletContainer container = new ServletContainer(config);
|
||||
|
||||
//CREATE CONTEXT
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
context.setContextPath("/");
|
||||
context.addServlet(new ServletHolder(container),"/*");
|
||||
|
||||
//CREATE WHITELIST
|
||||
InetAccessHandler accessHandler = new InetAccessHandler();
|
||||
for(String pattern : Settings.getInstance().getRpcAllowed())
|
||||
accessHandler.include(pattern);
|
||||
accessHandler.setHandler(context);
|
||||
|
||||
//CREATE RPC SERVER
|
||||
this.server = new Server(Settings.getInstance().getRpcPort());
|
||||
this.server.setHandler(accessHandler);
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
try
|
||||
{
|
||||
//START RPC
|
||||
server.start();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//FAILED TO START RPC
|
||||
}
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
try
|
||||
{
|
||||
//STOP RPC
|
||||
server.stop();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//FAILED TO STOP RPC
|
||||
}
|
||||
}
|
||||
}
|
@ -2,8 +2,12 @@ package settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
@ -20,9 +24,15 @@ public class Settings {
|
||||
private int maxBytePerFee = 1024;
|
||||
private String userpath = "";
|
||||
|
||||
//RPC
|
||||
private int rpcPort = 9085;
|
||||
private List<String> rpcAllowed = new ArrayList<String>(Arrays.asList("127.0.0.1"));
|
||||
private boolean rpcEnabled = true;
|
||||
|
||||
// Constants
|
||||
private static final String SETTINGS_FILENAME = "settings.json";
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
private Settings() {
|
||||
@ -102,6 +112,23 @@ public class Settings {
|
||||
this.genesisTimestamp = ((Long) json.get("testnetstamp")).longValue();
|
||||
}
|
||||
}
|
||||
|
||||
// RPC
|
||||
if(json.containsKey("rpcport"))
|
||||
{
|
||||
this.rpcPort = ((Long) json.get("rpcport")).intValue();
|
||||
}
|
||||
|
||||
if(json.containsKey("rpcallowed"))
|
||||
{
|
||||
JSONArray allowedArray = (JSONArray) json.get("rpcallowed");
|
||||
this.rpcAllowed = new ArrayList<String>(allowedArray);
|
||||
}
|
||||
|
||||
if(json.containsKey("rpcenabled"))
|
||||
{
|
||||
this.rpcEnabled = ((Boolean) json.get("rpcenabled")).booleanValue();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTestNet() {
|
||||
@ -122,4 +149,18 @@ public class Settings {
|
||||
return this.userpath;
|
||||
}
|
||||
|
||||
public int getRpcPort()
|
||||
{
|
||||
return this.rpcPort;
|
||||
}
|
||||
|
||||
public List<String> getRpcAllowed()
|
||||
{
|
||||
return this.rpcAllowed;
|
||||
}
|
||||
|
||||
public boolean isRpcEnabled()
|
||||
{
|
||||
return this.rpcEnabled;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user