mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-2128 refactor servlet binding services (#930)
This commit is contained in:
@@ -14,8 +14,7 @@ Require-Bundle: org.jkiss.dbeaver.model;visibility:=reexport,
|
||||
org.jkiss.bundle.graphql.java;visibility:=reexport,
|
||||
org.jkiss.bundle.apache.dbcp,
|
||||
com.google.gson;visibility:=reexport,
|
||||
jakarta.servlet-api;bundle-version="4.0.0";visibility:=reexport,
|
||||
org.eclipse.jetty.servlet
|
||||
jakarta.servlet-api;bundle-version="4.0.0";visibility:=reexport
|
||||
Export-Package: io.cloudbeaver,
|
||||
io.cloudbeaver.auth,
|
||||
io.cloudbeaver.auth.provider,
|
||||
|
||||
@@ -3,4 +3,5 @@ output.. = target/classes/
|
||||
bin.includes = .,\
|
||||
META-INF/,\
|
||||
plugin.xml,\
|
||||
schema/,\
|
||||
OSGI-INF/
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
<?eclipse version="3.2"?>
|
||||
|
||||
<plugin>
|
||||
<extension-point id="io.cloudbeaver.service" name="Web services" schema="schema/io.cloudbeaver.service.exsd"/>
|
||||
</plugin>
|
||||
|
||||
+1
-2
@@ -17,7 +17,6 @@
|
||||
package io.cloudbeaver.service;
|
||||
|
||||
import io.cloudbeaver.model.app.WebApplication;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
|
||||
/**
|
||||
@@ -25,5 +24,5 @@ import org.jkiss.dbeaver.DBException;
|
||||
*/
|
||||
public interface DBWServiceBindingServlet<APPLICATION extends WebApplication> extends DBWServiceBinding {
|
||||
|
||||
void addServlets(APPLICATION application, ServletContextHandler servletContextHandler) throws DBException;
|
||||
void addServlets(APPLICATION application, DBWServletContext servletContext) throws DBException;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* DBeaver - Universal Database Manager
|
||||
* Copyright (C) 2010-2022 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.cloudbeaver.service;
|
||||
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
public interface DBWServletContext {
|
||||
void addServlet(String servletId, HttpServlet servlet, String mapping) throws DBException;
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
<plugin>
|
||||
|
||||
<extension-point id="io.cloudbeaver.feature" name="Web features" schema="schema/io.cloudbeaver.feature.exsd"/>
|
||||
<extension-point id="io.cloudbeaver.service" name="Web services" schema="schema/io.cloudbeaver.service.exsd"/>
|
||||
<extension-point id="io.cloudbeaver.driver" name="Web drivers" schema="schema/io.cloudbeaver.driver.exsd"/>
|
||||
<extension-point id="io.cloudbeaver.valueSerializer" name="Web value serializers" schema="schema/io.cloudbeaver.valueSerializer.exsd"/>
|
||||
<extension-point id="io.cloudbeaver.handler" name="Web handlers" schema="schema/io.cloudbeaver.handler.exsd"/>
|
||||
|
||||
+3
-1
@@ -75,9 +75,11 @@ public class CBJettyServer {
|
||||
servletContextHandler.addEventListener(new CBServerContextListener());
|
||||
|
||||
// Add extensions from services
|
||||
|
||||
CBJettyServletContext servletContext = new CBJettyServletContext(servletContextHandler);
|
||||
for (DBWServiceBindingServlet wsd : WebServiceRegistry.getInstance().getWebServices(DBWServiceBindingServlet.class)) {
|
||||
try {
|
||||
wsd.addServlets(application, servletContextHandler);
|
||||
wsd.addServlets(application, servletContext);
|
||||
} catch (DBException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* DBeaver - Universal Database Manager
|
||||
* Copyright (C) 2010-2022 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.cloudbeaver.server.jetty;
|
||||
|
||||
import io.cloudbeaver.service.DBWServletContext;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
public class CBJettyServletContext implements DBWServletContext {
|
||||
private final ServletContextHandler contextHandler;
|
||||
|
||||
public CBJettyServletContext(ServletContextHandler contextHandler) {
|
||||
this.contextHandler = contextHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addServlet(String servletId, HttpServlet servlet, String mapping) throws DBException {
|
||||
contextHandler.addServlet(new ServletHolder(servletId, servlet), mapping);
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -23,10 +23,9 @@ import io.cloudbeaver.model.session.WebSession;
|
||||
import io.cloudbeaver.server.CBApplication;
|
||||
import io.cloudbeaver.service.DBWBindingContext;
|
||||
import io.cloudbeaver.service.DBWServiceBindingServlet;
|
||||
import io.cloudbeaver.service.DBWServletContext;
|
||||
import io.cloudbeaver.service.WebServiceBindingBase;
|
||||
import io.cloudbeaver.service.sql.impl.WebServiceSQL;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.jkiss.code.NotNull;
|
||||
import org.jkiss.code.Nullable;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
@@ -239,10 +238,12 @@ public class WebServiceBindingSQL extends WebServiceBindingBase<DBWServiceSQL> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addServlets(CBApplication application, ServletContextHandler servletContextHandler) {
|
||||
servletContextHandler.addServlet(
|
||||
new ServletHolder("sqlResultValueViewer", new WebSQLResultServlet(application, getServiceImpl())),
|
||||
application.getServicesURI() + "sql-result-value/*");
|
||||
public void addServlets(CBApplication application, DBWServletContext servletContext) throws DBException {
|
||||
servletContext.addServlet(
|
||||
"sqlResultValueViewer",
|
||||
new WebSQLResultServlet(application, getServiceImpl()),
|
||||
application.getServicesURI() + "sql-result-value/*"
|
||||
);
|
||||
}
|
||||
|
||||
private static class WebSQLConfiguration {
|
||||
|
||||
+4
-6
@@ -22,11 +22,11 @@ import io.cloudbeaver.model.WebConnectionConfig;
|
||||
import io.cloudbeaver.server.CBApplication;
|
||||
import io.cloudbeaver.service.DBWBindingContext;
|
||||
import io.cloudbeaver.service.DBWServiceBindingServlet;
|
||||
import io.cloudbeaver.service.DBWServletContext;
|
||||
import io.cloudbeaver.service.WebServiceBindingBase;
|
||||
import io.cloudbeaver.service.admin.impl.WebAdminLogsServlet;
|
||||
import io.cloudbeaver.service.admin.impl.WebServiceAdmin;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
import org.jkiss.utils.CommonUtils;
|
||||
|
||||
/**
|
||||
@@ -147,10 +147,8 @@ public class WebServiceBindingAdmin extends WebServiceBindingBase<DBWServiceAdmi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addServlets(CBApplication application, ServletContextHandler servletContextHandler) {
|
||||
servletContextHandler.addServlet(
|
||||
new ServletHolder("adminLogs", new WebAdminLogsServlet(application)),
|
||||
application.getServicesURI() + "logs/*");
|
||||
public void addServlets(CBApplication application, DBWServletContext servletContext) throws DBException {
|
||||
servletContext.addServlet("adminLogs", new WebAdminLogsServlet(application), application.getServicesURI() + "logs/*");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-6
@@ -19,13 +19,13 @@ package io.cloudbeaver.service.data.transfer;
|
||||
import io.cloudbeaver.server.CBApplication;
|
||||
import io.cloudbeaver.service.DBWBindingContext;
|
||||
import io.cloudbeaver.service.DBWServiceBindingServlet;
|
||||
import io.cloudbeaver.service.DBWServletContext;
|
||||
import io.cloudbeaver.service.WebServiceBindingBase;
|
||||
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferParameters;
|
||||
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferServlet;
|
||||
import io.cloudbeaver.service.data.transfer.impl.WebServiceDataTransfer;
|
||||
import io.cloudbeaver.service.sql.WebServiceBindingSQL;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
|
||||
/**
|
||||
* Web service implementation
|
||||
@@ -61,9 +61,11 @@ public class WebServiceBindingDataTransfer extends WebServiceBindingBase<DBWServ
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addServlets(CBApplication application, ServletContextHandler servletContextHandler) {
|
||||
servletContextHandler.addServlet(
|
||||
new ServletHolder("dataTransfer", new WebDataTransferServlet(application, getServiceImpl())),
|
||||
application.getServicesURI() + "data/*");
|
||||
public void addServlets(CBApplication application, DBWServletContext servletContext) throws DBException {
|
||||
servletContext.addServlet(
|
||||
"dataTransfer",
|
||||
new WebDataTransferServlet(application, getServiceImpl()),
|
||||
application.getServicesURI() + "data/*"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user