use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class ExFuseki_01_NamedService method main.
public static void main(String... args) {
// Create a new operation: operations are really just names (symbols). The code to
// run is found by looking up the operation in a per-server table that gives the server-specific
// implementation as an ActionService.
Operation myOperation = Operation.alloc("http://example/special1", "special1", "Custom operation");
// Service endpoint name.
// This can be different for different datasets even in the same server.
// c.f. {@code fuseki:serviceQuery}
String endpointName = "special";
// The handled for the new operation.
ActionService customHandler = new DemoService();
FusekiServer server = FusekiServer.create().port(PORT).verbose(true).registerOperation(myOperation, customHandler).add(DATASET, DatasetGraphFactory.createTxnMem(), true).addEndpoint(DATASET, endpointName, myOperation).build();
// Start the server. This does not block this thread.
server.start();
// Try some operations on the server using the service URL.
String customOperationURL = SERVER_URL + DATASET + "/" + endpointName;
try {
// Service endpoint name : GET
String s1 = HttpOp.httpGetString(customOperationURL);
System.out.print(s1);
if (s1 == null)
System.out.println();
// Service endpoint name : POST
try (TypedInputStream stream = HttpOp.httpPostStream(customOperationURL, "text/plain")) {
String s2 = FileUtils.readWholeFileAsUTF8(stream);
System.out.print(s2);
if (s2 == null)
System.out.println();
} catch (IOException ex) {
IO.exception(ex);
}
// Service endpoint name. DELETE -> fails 405
try {
HttpOp.httpDelete(customOperationURL);
throw new IllegalStateException("DELETE succeeded");
} catch (HttpException ex) {
if (ex.getStatusCode() != HttpSC.METHOD_NOT_ALLOWED_405)
System.err.println("Unexpected HTTP Response Code: " + ex.getMessage());
else
System.out.println("DELETE rejected correctly: " + ex.getMessage());
}
} finally {
server.stop();
}
}
use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class ExFuseki_06_DataAccessCtl method fuseki.
/**
* Create a Fuseki server with:
* <ul>
* <li>port, dataset and name
* <li>user/password for Jetty basic authentication
* <li>Authorization service
* </ul>
*/
private static FusekiServer fuseki(int port, UserStore userStore, AuthorizationService authorizeSvc, String dsName, DatasetGraph dsgBase) {
// Associate access control information with the dataset.
DatasetGraph dsx = DataAccessCtl.controlledDataset(dsgBase, authorizeSvc);
// Build a Fuseki server with the access control operations replacing the normal (no control) operations.
FusekiServer.Builder builder = FusekiLib.fusekiBuilderAccessCtl(DataAccessCtl.requestUserServlet).port(port).add(dsName, dsx, false);
// Add service endpoint login for authentication.
ConstraintSecurityHandler sh = null;
if (userStore != null) {
sh = JettyLib.makeSecurityHandler("Dataset:" + dsName, userStore);
JettyLib.addPathConstraint(sh, dsName);
builder.securityHandler(sh);
}
return builder.build();
}
use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class ExFuseki_10_Https_Setup method codeHttps.
public static FusekiServer codeHttps() {
FusekiLogging.setLogging();
// Some empty dataset
DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
FusekiServer server = FusekiServer.create().https(3443, ExConst.KEYSTORE, ExConst.KEYSTOREPASSWORD).port(3030).add("/ds", dsg).build();
server.start();
// server.join();
return server;
}
use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class TestServiceDataAuthConfig method build.
public static FusekiServer build(int port, AuthPolicy policy) {
AuthPolicy policy12 = Auth.policyAllowSpecific("user1", "user2");
AuthPolicy policy13 = Auth.policyAllowSpecific("user1", "user3");
DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
DataService.Builder dSrvBuilder = DataService.newBuilder(dsg);
dSrvBuilder.addEndpoint(Endpoint.create(Operation.Query, null, policy12));
dSrvBuilder.addEndpoint(Endpoint.create(Operation.Update, null, policy13));
DataService dSrv = dSrvBuilder.build();
FusekiServer server = FusekiServer.create().verbose(true).port(port).passwordFile("testing/Access/passwd").add("/db", dSrv).build();
return server;
}
use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class ExFusekiMain_2_AddShiro method addShiroFilter.
// From Barry Nouwt : https://lists.apache.org/thread.html/r1e3fa952ff9f4a9108e16f07f1edf78c67e08c9b081497c627e3b833%40%3Cusers.jena.apache.org%3E
public static void addShiroFilter(FusekiServer fusekiServer) {
Server jettyServer = fusekiServer.getJettyServer();
ServletContextHandler servletContextHandler = (ServletContextHandler) jettyServer.getHandler();
ServletHandler servletHandler = servletContextHandler.getServletHandler();
// for shiro
EnvironmentLoaderListener ell = new EnvironmentLoaderListener();
servletContextHandler.addEventListener(ell);
// Copies
List<FilterMapping> mappings = new ArrayList<FilterMapping>(Arrays.asList(servletHandler.getFilterMappings()));
List<FilterHolder> holders = new ArrayList<FilterHolder>(Arrays.asList(servletHandler.getFilters()));
{
// add Shiro Filter and mapping
FilterHolder holder1 = new FilterHolder();
holder1.setFilter(new ShiroFilter());
FilterMapping mapping1 = new FilterMapping();
mapping1.setFilterName(holder1.getName());
mapping1.setPathSpec("/*");
mapping1.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
mappings.add(0, mapping1);
holders.add(0, holder1);
}
FilterMapping[] mappings3 = new FilterMapping[mappings.size()];
mappings3 = mappings.toArray(mappings3);
FilterHolder[] holders3 = new FilterHolder[holders.size()];
holders3 = holders.toArray(holders3);
servletHandler.setFilters(holders3);
servletHandler.setFilterMappings(mappings3);
// Specify the Session ID Manager
SessionIdManager idmanager = new DefaultSessionIdManager(jettyServer);
jettyServer.setSessionIdManager(idmanager);
// Specify the session handler
SessionHandler sessionsHandler = new SessionHandler();
sessionsHandler.setUsingCookies(false);
servletHandler.setHandler(sessionsHandler);
}
Aggregations