Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
58a78780
by Tony Chemit at 2023-11-23T13:58:02+01:00
-
5171ad36
by Tony Chemit at 2023-11-25T13:40:12+01:00
-
b474e869
by Tony Chemit at 2023-11-25T13:40:12+01:00
-
b009e471
by Tony Chemit at 2023-11-25T13:40:12+01:00
-
e810ab41
by Tony Chemit at 2023-11-25T13:40:12+01:00
-
40a629ff
by Tony Chemit at 2023-11-25T13:40:12+01:00
-
8fbbb17f
by Tony Chemit at 2023-11-25T14:47:48+01:00
-
bc7ebe50
by Tony Chemit at 2023-11-25T14:47:48+01:00
-
bdc2aff0
by Tony Chemit at 2023-11-25T14:48:58+01:00
25 changed files:
- core/api/services/src/main/java/fr/ird/observe/services/service/data/ps/AvdthService.java
- core/services/client/pom.xml
- core/services/client/src/main/java/fr/ird/observe/services/client/ObserveRequestBuilder.java
- core/services/client/src/main/java/fr/ird/observe/services/client/ObserveServiceFactoryClient.java
- pom.xml
- server/configuration/src/main/resources/log4j2.xml
- server/core/src/main/filtered-resources/META-INF/mapping-api-client.wm
- server/core/src/main/java/fr/ird/observe/server/ObserveWebApplicationListener.java
- server/core/src/main/java/fr/ird/observe/server/request/ObserveWebRequestContext.java
- server/runner/src/main/resources/META-INF/configuration/log.xml
- toolkit/api-services/src/main/java/fr/ird/observe/services/service/AnonymousService.java
- toolkit/api-services/src/main/java/fr/ird/observe/services/service/UsageService.java
- toolkit/api-services/src/main/java/fr/ird/observe/services/service/api/DataEntityService.java
- toolkit/api-services/src/main/java/fr/ird/observe/services/service/api/ReferentialEntityService.java
- toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/service/ServiceGenerateApiRunner.java
- toolkit/plugin/src/main/java/fr/ird/observe/toolkit/maven/plugin/service/ServiceLocalMethodDescriptionImpl.java
- toolkit/server/pom.xml
- toolkit/server/src/main/java/org/debux/webmotion/server/call/ServerContext.java
- toolkit/server/src/main/java/org/debux/webmotion/server/handler/ExecutorMethodInvokerHandler.java
- toolkit/server/src/main/java/org/debux/webmotion/server/handler/ExecutorParametersInjectorHandler.java
- toolkit/server/src/main/java/org/debux/webmotion/server/handler/ParametersMultipartHandler.java
- toolkit/server/src/main/java/org/debux/webmotion/server/call/FileProgressListener.java → toolkit/server/src/main/java/org/debux/webmotion/server/tools/upload/FileProgressListener.java
- + toolkit/server/src/main/java/org/debux/webmotion/server/tools/upload/FileUpload.java
- toolkit/server/src/main/java/org/debux/webmotion/server/tools/StringResponseHandler.java → toolkit/server/src/main/java/org/debux/webmotion/server/tools/upload/RequestContext.java
- toolkit/server/src/main/resources/META-INF/web-fragment.xml
Changes:
| ... | ... | @@ -25,6 +25,7 @@ package fr.ird.observe.services.service.data.ps; |
| 25 | 25 | import fr.ird.observe.datasource.security.Permission;
|
| 26 | 26 | import fr.ird.observe.services.service.MethodCredential;
|
| 27 | 27 | import fr.ird.observe.services.service.ObserveService;
|
| 28 | +import io.ultreia.java4all.http.spi.Get;
|
|
| 28 | 29 | import io.ultreia.java4all.http.spi.Service;
|
| 29 | 30 | |
| 30 | 31 | /**
|
| ... | ... | @@ -42,6 +43,7 @@ public interface AvdthService extends ObserveService { |
| 42 | 43 | * @param configuration configuration of import
|
| 43 | 44 | * @return result of import.
|
| 44 | 45 | */
|
| 46 | + @Get
|
|
| 45 | 47 | @MethodCredential(Permission.READ_ALL_AND_WRITE_DATA)
|
| 46 | 48 | AvdthDataImportResult importData(AvdthDataImportConfiguration configuration) throws MissingReferentialException;
|
| 47 | 49 |
| ... | ... | @@ -102,8 +102,12 @@ |
| 102 | 102 | <artifactId>commons-lang3</artifactId>
|
| 103 | 103 | </dependency>
|
| 104 | 104 | <dependency>
|
| 105 | - <groupId>org.apache.httpcomponents</groupId>
|
|
| 106 | - <artifactId>httpcore</artifactId>
|
|
| 105 | + <groupId>org.apache.httpcomponents.client5</groupId>
|
|
| 106 | + <artifactId>httpclient5</artifactId>
|
|
| 107 | + </dependency>
|
|
| 108 | + <dependency>
|
|
| 109 | + <groupId>org.apache.httpcomponents.core5</groupId>
|
|
| 110 | + <artifactId>httpcore5</artifactId>
|
|
| 107 | 111 | </dependency>
|
| 108 | 112 | <dependency>
|
| 109 | 113 | <groupId>org.apache.logging.log4j</groupId>
|
| ... | ... | @@ -163,22 +167,6 @@ |
| 163 | 167 | <groupId>commons-fileupload</groupId>
|
| 164 | 168 | <artifactId>commons-fileupload</artifactId>
|
| 165 | 169 | </exclusion>
|
| 166 | - <exclusion>
|
|
| 167 | - <groupId>commons-collections</groupId>
|
|
| 168 | - <artifactId>commons-collections</artifactId>
|
|
| 169 | - </exclusion>
|
|
| 170 | - <exclusion>
|
|
| 171 | - <groupId>org.apache.httpcomponents</groupId>
|
|
| 172 | - <artifactId>fluent-hc</artifactId>
|
|
| 173 | - </exclusion>
|
|
| 174 | - <exclusion>
|
|
| 175 | - <groupId>org.apache.httpcomponents</groupId>
|
|
| 176 | - <artifactId>httpcore</artifactId>
|
|
| 177 | - </exclusion>
|
|
| 178 | - <exclusion>
|
|
| 179 | - <groupId>org.apache.httpcomponents</groupId>
|
|
| 180 | - <artifactId>httpclient</artifactId>
|
|
| 181 | - </exclusion>
|
|
| 182 | 170 | <exclusion>
|
| 183 | 171 | <groupId>com.thoughtworks.paranamer</groupId>
|
| 184 | 172 | <artifactId>paranamer</artifactId>
|
| ... | ... | @@ -327,7 +315,7 @@ |
| 327 | 315 | <packageName>fr.ird.observe.services.client</packageName>
|
| 328 | 316 | <serviceSupportType>fr.ird.observe.services.client.ObserveServiceClientSupport</serviceSupportType>
|
| 329 | 317 | <gsonType>io.ultreia.java4all.util.json.JsonAware</gsonType>
|
| 330 | - <addAuthToken>true</addAuthToken>
|
|
| 318 | + <addAuthenticationToken>true</addAuthenticationToken>
|
|
| 331 | 319 | <classSuffix>Client</classSuffix>
|
| 332 | 320 | </configuration>
|
| 333 | 321 | </execution>
|
| ... | ... | @@ -24,10 +24,12 @@ package fr.ird.observe.services.client; |
| 24 | 24 | |
| 25 | 25 | import fr.ird.observe.datasource.configuration.rest.ObserveDataSourceConfigurationRestConstants;
|
| 26 | 26 | import fr.ird.observe.services.ObserveServiceInitializerConfig;
|
| 27 | +import io.ultreia.java4all.http.HRequest;
|
|
| 27 | 28 | import io.ultreia.java4all.http.HRequestBuilder;
|
| 29 | +import org.apache.logging.log4j.LogManager;
|
|
| 30 | +import org.apache.logging.log4j.Logger;
|
|
| 28 | 31 | |
| 29 | 32 | import java.util.Objects;
|
| 30 | -import java.util.concurrent.TimeUnit;
|
|
| 31 | 33 | |
| 32 | 34 | /**
|
| 33 | 35 | * Created by tchemit on 17/07/17.
|
| ... | ... | @@ -35,14 +37,13 @@ import java.util.concurrent.TimeUnit; |
| 35 | 37 | * @author Tony Chemit - dev@tchemit.fr
|
| 36 | 38 | */
|
| 37 | 39 | public class ObserveRequestBuilder extends HRequestBuilder {
|
| 40 | + private static final Logger log = LogManager.getLogger(ObserveRequestBuilder.class);
|
|
| 38 | 41 | |
| 39 | 42 | ObserveRequestBuilder(ObserveServiceClientContext serviceContext, String baseUrl) {
|
| 40 | 43 | super(serviceContext.getServiceUrl(baseUrl));
|
| 41 | 44 | ObserveServiceInitializerConfig initializerConfig = serviceContext.getInitializer().getInitializerConfig();
|
| 42 | - int defaultTimeout = initializerConfig.getHttpTimeout();
|
|
| 43 | - setTimeout(TimeUnit.MILLISECONDS, defaultTimeout);
|
|
| 44 | 45 | if (serviceContext.getInitializer().withConnection()) {
|
| 45 | - addAuthTokenSupplier(serviceContext.getAuthTokenSupplier());
|
|
| 46 | + addAuthenticationTokenSupplier(serviceContext.getAuthTokenSupplier());
|
|
| 46 | 47 | }
|
| 47 | 48 | if (initializerConfig.withApplicationLocale()) {
|
| 48 | 49 | addHeader(ObserveDataSourceConfigurationRestConstants.REQUEST_APPLICATION_LOCALE, initializerConfig.getApplicationLocale().toString());
|
| ... | ... | @@ -53,17 +54,16 @@ public class ObserveRequestBuilder extends HRequestBuilder { |
| 53 | 54 | }
|
| 54 | 55 | |
| 55 | 56 | @Override
|
| 56 | - protected void setAuthTokenInRequest() {
|
|
| 57 | - String authToken = authTokenSupplier.get();
|
|
| 58 | - Objects.requireNonNull(authToken, "Can't add null authToken");
|
|
| 59 | - addHeader(ObserveDataSourceConfigurationRestConstants.REQUEST_AUTHENTICATION_TOKEN, authToken);
|
|
| 57 | + protected void setAuthenticationTokenInRequest() {
|
|
| 58 | + String authenticationToken = authenticationTokenSupplier.get();
|
|
| 59 | + Objects.requireNonNull(authenticationToken, "Can't add null authenticationToken");
|
|
| 60 | + addHeader(ObserveDataSourceConfigurationRestConstants.REQUEST_AUTHENTICATION_TOKEN, authenticationToken);
|
|
| 60 | 61 | }
|
| 61 | 62 | |
| 62 | 63 | @Override
|
| 63 | - public HRequestBuilder setTimeout(TimeUnit timeUnit, int timeout) {
|
|
| 64 | - super.setTimeout(timeUnit, timeout);
|
|
| 65 | - //FIXME See the difference with timeout, but it seems strange to have a lesser value here
|
|
| 66 | - super.setSocketTimeout(timeUnit, timeout);
|
|
| 67 | - return this;
|
|
| 64 | + protected HRequest build() {
|
|
| 65 | + HRequest request = super.build();
|
|
| 66 | + log.debug("Created request: {}", request);
|
|
| 67 | + return request;
|
|
| 68 | 68 | }
|
| 69 | 69 | } |
| ... | ... | @@ -31,10 +31,17 @@ import fr.ird.observe.services.service.ObserveService; |
| 31 | 31 | import fr.ird.observe.spi.json.DtoGsonSupplier;
|
| 32 | 32 | import io.ultreia.java4all.http.HResponseBuilder;
|
| 33 | 33 | import io.ultreia.java4all.lang.Strings;
|
| 34 | +import org.apache.hc.client5.http.config.ConnectionConfig;
|
|
| 35 | +import org.apache.hc.client5.http.config.RequestConfig;
|
|
| 36 | +import org.apache.hc.client5.http.cookie.BasicCookieStore;
|
|
| 37 | +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
|
| 38 | +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
|
| 39 | +import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
|
|
| 34 | 40 | import org.apache.logging.log4j.LogManager;
|
| 35 | 41 | import org.apache.logging.log4j.Logger;
|
| 36 | 42 | |
| 37 | 43 | import java.util.Objects;
|
| 44 | +import java.util.concurrent.TimeUnit;
|
|
| 38 | 45 | |
| 39 | 46 | /**
|
| 40 | 47 | * Created on 16/08/15.
|
| ... | ... | @@ -48,7 +55,30 @@ public class ObserveServiceFactoryClient implements ObserveServiceFactory { |
| 48 | 55 | private final static ClassMappingClient CLASS_MAPPING = ClassMappingClient.get();
|
| 49 | 56 | private final static int LOCATE_PREFIX_LENGTH = ObserveServiceClientSupport.class.getPackage().getName().length();
|
| 50 | 57 | private final ObserveRequestBuilderFactory requestBuilderFactory = new ObserveRequestBuilderFactory();
|
| 51 | - private final HResponseBuilder responseBuilder = HResponseBuilder.create(new DtoGsonSupplier());
|
|
| 58 | + |
|
| 59 | + private HResponseBuilder responseBuilder;
|
|
| 60 | + |
|
| 61 | + private synchronized HResponseBuilder getResponseBuilder(ObserveServiceInitializer serviceInitializer) {
|
|
| 62 | + if (responseBuilder == null) {
|
|
| 63 | + int timeout = serviceInitializer.getInitializerConfig().getHttpTimeout();
|
|
| 64 | + ConnectionConfig connConfig = ConnectionConfig.custom()
|
|
| 65 | + .setSocketTimeout(timeout, TimeUnit.MILLISECONDS)
|
|
| 66 | + .build();
|
|
| 67 | + BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager();
|
|
| 68 | + cm.setConnectionConfig(connConfig);
|
|
| 69 | + CloseableHttpClient httpClient = HttpClientBuilder.create()
|
|
| 70 | + .setConnectionManager(cm)
|
|
| 71 | + .setDefaultCookieStore(new BasicCookieStore())
|
|
| 72 | + .setDefaultRequestConfig(RequestConfig.custom().setResponseTimeout(timeout, TimeUnit.MILLISECONDS).build())
|
|
| 73 | + //FIXME-migration
|
|
| 74 | +// .setMaxConnTotal(1000)
|
|
| 75 | +// .setMaxConnPerRoute(1000)
|
|
| 76 | +// .setConnectionTimeToLive(45, TimeUnit.SECONDS)
|
|
| 77 | + .build();
|
|
| 78 | + responseBuilder = HResponseBuilder.create(new DtoGsonSupplier(), httpClient);
|
|
| 79 | + }
|
|
| 80 | + return responseBuilder;
|
|
| 81 | + }
|
|
| 52 | 82 | |
| 53 | 83 | @Override
|
| 54 | 84 | public <S extends ObserveService> boolean accept(ObserveDataSourceConfiguration dataSourceConfiguration, Class<S> serviceType) {
|
| ... | ... | @@ -88,7 +118,7 @@ public class ObserveServiceFactoryClient implements ObserveServiceFactory { |
| 88 | 118 | serviceLocation = Strings.removeEnd(serviceLocation, "Client");
|
| 89 | 119 | ObserveServiceClientContext serviceRestApiContext = new ObserveServiceClientContext(
|
| 90 | 120 | serviceInitializer,
|
| 91 | - responseBuilder,
|
|
| 121 | + getResponseBuilder(serviceInitializer),
|
|
| 92 | 122 | requestBuilderFactory,
|
| 93 | 123 | serviceLocation);
|
| 94 | 124 | ((ObserveServiceClientSupport) service).setServiceContext(serviceRestApiContext);
|
| ... | ... | @@ -97,10 +127,12 @@ public class ObserveServiceFactoryClient implements ObserveServiceFactory { |
| 97 | 127 | |
| 98 | 128 | @Override
|
| 99 | 129 | public void close() {
|
| 100 | - try {
|
|
| 101 | - responseBuilder.close();
|
|
| 102 | - } catch (Exception e) {
|
|
| 103 | - log.error("Can't close response builder", e);
|
|
| 130 | + if (responseBuilder != null) {
|
|
| 131 | + try {
|
|
| 132 | + responseBuilder.close();
|
|
| 133 | + } catch (Exception e) {
|
|
| 134 | + log.error("Can't close response builder", e);
|
|
| 135 | + }
|
|
| 104 | 136 | }
|
| 105 | 137 | }
|
| 106 | 138 |
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 | <parent>
|
| 24 | 24 | <groupId>io.ultreia.maven</groupId>
|
| 25 | 25 | <artifactId>pom</artifactId>
|
| 26 | - <version>2023.47</version>
|
|
| 26 | + <version>2023.51</version>
|
|
| 27 | 27 | </parent>
|
| 28 | 28 | <groupId>fr.ird.observe</groupId>
|
| 29 | 29 | <artifactId>ird-observe</artifactId>
|
| ... | ... | @@ -277,6 +277,16 @@ |
| 277 | 277 | <artifactId>commons-fileupload</artifactId>
|
| 278 | 278 | <version>${lib.version.commons-fileupload}</version>
|
| 279 | 279 | </dependency>
|
| 280 | + <dependency>
|
|
| 281 | + <groupId>org.apache.commons</groupId>
|
|
| 282 | + <artifactId>commons-fileupload2-core</artifactId>
|
|
| 283 | + <version>${lib.version.commons-fileupload2}</version>
|
|
| 284 | + </dependency>
|
|
| 285 | + <dependency>
|
|
| 286 | + <groupId>org.apache.commons</groupId>
|
|
| 287 | + <artifactId>commons-fileupload2-jakarta</artifactId>
|
|
| 288 | + <version>${lib.version.commons-fileupload2}</version>
|
|
| 289 | + </dependency>
|
|
| 280 | 290 | <dependency>
|
| 281 | 291 | <groupId>commons-io</groupId>
|
| 282 | 292 | <artifactId>commons-io</artifactId>
|
| ... | ... | @@ -550,14 +560,14 @@ |
| 550 | 560 | <version>${lib.version.commons-text}</version>
|
| 551 | 561 | </dependency>
|
| 552 | 562 | <dependency>
|
| 553 | - <groupId>org.apache.httpcomponents</groupId>
|
|
| 554 | - <artifactId>httpclient</artifactId>
|
|
| 555 | - <version>${lib.version.httpclient}</version>
|
|
| 563 | + <groupId>org.apache.httpcomponents.client5</groupId>
|
|
| 564 | + <artifactId>httpclient5</artifactId>
|
|
| 565 | + <version>${lib.version.httpclient5}</version>
|
|
| 556 | 566 | </dependency>
|
| 557 | 567 | <dependency>
|
| 558 | - <groupId>org.apache.httpcomponents</groupId>
|
|
| 559 | - <artifactId>httpcore</artifactId>
|
|
| 560 | - <version>${lib.version.httpcore}</version>
|
|
| 568 | + <groupId>org.apache.httpcomponents.core5</groupId>
|
|
| 569 | + <artifactId>httpcore5</artifactId>
|
|
| 570 | + <version>${lib.version.httpcore5}</version>
|
|
| 561 | 571 | </dependency>
|
| 562 | 572 | <dependency>
|
| 563 | 573 | <groupId>org.apache.logging.log4j</groupId>
|
| ... | ... | @@ -64,6 +64,10 @@ |
| 64 | 64 | <Logger name="org.debux.webmotion.server" level="info" additivity="false">
|
| 65 | 65 | <AppenderRef ref="console"/>
|
| 66 | 66 | </Logger>
|
| 67 | + <!-- To See all multi-part loaded -->
|
|
| 68 | + <!--<Logger name="org.debux.webmotion.server.handler.ParametersMultipartHandler" level="debug" additivity="false">
|
|
| 69 | + <AppenderRef ref="console"/>
|
|
| 70 | + </Logger>-->
|
|
| 67 | 71 | <Logger name="fr.ird.observe" level="info" additivity="false">
|
| 68 | 72 | <AppenderRef ref="console"/>
|
| 69 | 73 | </Logger>
|
| ... | ... | @@ -64,7 +64,7 @@ DELETE /api/DataEntityService/delete api. |
| 64 | 64 | GET /api/DataEntityService/generateId api.DataEntityServiceRestApi.generateId
|
| 65 | 65 | GET /api/DataEntityService/getOne api.DataEntityServiceRestApi.getOne
|
| 66 | 66 | GET /api/DataEntityService/getSome api.DataEntityServiceRestApi.getSome
|
| 67 | -POST /api/DataEntityService/update api.DataEntityServiceRestApi.update
|
|
| 67 | +PUT /api/DataEntityService/update api.DataEntityServiceRestApi.update
|
|
| 68 | 68 | POST /api/ReferentialEntityService/create api.ReferentialEntityServiceRestApi.create
|
| 69 | 69 | DELETE /api/ReferentialEntityService/delete api.ReferentialEntityServiceRestApi.delete
|
| 70 | 70 | GET /api/ReferentialEntityService/generateId api.ReferentialEntityServiceRestApi.generateId
|
| ... | ... | @@ -53,12 +53,15 @@ public class ObserveWebApplicationListener implements WebMotionServerListener { |
| 53 | 53 | contextPath = contextPath.substring(1);
|
| 54 | 54 | }
|
| 55 | 55 | log.info(String.format("Application starting on [%s] at %s...", contextPath, new Date()));
|
| 56 | + ObserveWebApplicationContext applicationContext;
|
|
| 56 | 57 | try {
|
| 57 | - ObserveWebApplicationContext applicationContext = ObserveWebApplicationContext.init(contextPath);
|
|
| 58 | + applicationContext = ObserveWebApplicationContext.init(contextPath);
|
|
| 58 | 59 | servletContext.setAttribute(ObserveWebApplicationContext.APPLICATION_CONTEXT_PARAMETER, applicationContext);
|
| 59 | 60 | } catch (Exception e) {
|
| 60 | 61 | throw new ObserveWebApplicationContextInitException("Can't init application context", e);
|
| 61 | 62 | }
|
| 63 | + context.setTemporaryPath(applicationContext.getApplicationConfiguration().getTemporaryDirectory().toPath());
|
|
| 64 | + |
|
| 62 | 65 | log.info(String.format("Initializing %s done.", this));
|
| 63 | 66 | }
|
| 64 | 67 |
| ... | ... | @@ -141,7 +141,7 @@ public class ObserveWebRequestContext { |
| 141 | 141 | public void checkAuthentication(ObserveWebUserSession session, Class<? extends ObserveService> serviceType, Method method) {
|
| 142 | 142 | Method serviceMethod = getServiceMethod(serviceType, method);
|
| 143 | 143 | RequestAnnotation requestAnnotation = SpiHelper.getRequestAnnotation(serviceMethod);
|
| 144 | - boolean requiredAuthentication = requestAnnotation.isAddAuthToken();
|
|
| 144 | + boolean requiredAuthentication = requestAnnotation.isAddAuthenticationToken();
|
|
| 145 | 145 | boolean withConnection = session.withConnection();
|
| 146 | 146 | if (requiredAuthentication) {
|
| 147 | 147 | if (!withConnection) {
|
| ... | ... | @@ -106,6 +106,11 @@ |
| 106 | 106 | <AppenderRef ref="console"/>
|
| 107 | 107 | <AppenderRef ref="File"/>
|
| 108 | 108 | </Logger>
|
| 109 | + <!-- To See all multi-part loaded -->
|
|
| 110 | + <!--<Logger name="org.debux.webmotion.server.handler.ParametersMultipartHandler" level="debug" additivity="false">
|
|
| 111 | + <AppenderRef ref="console"/>
|
|
| 112 | + <AppenderRef ref="File"/>
|
|
| 113 | + </Logger>-->
|
|
| 109 | 114 | <Root level="error">
|
| 110 | 115 | <AppenderRef ref="console"/>
|
| 111 | 116 | <AppenderRef ref="File"/>
|
| ... | ... | @@ -49,45 +49,45 @@ import java.util.Set; |
| 49 | 49 | @Service
|
| 50 | 50 | public interface AnonymousService extends ObserveService {
|
| 51 | 51 | |
| 52 | - @Get(addAuthtoken = false)
|
|
| 52 | + @Get(addAuthenticationToken = false)
|
|
| 53 | 53 | Version getModelVersion();
|
| 54 | 54 | |
| 55 | - @Get(addAuthtoken = false)
|
|
| 55 | + @Get(addAuthenticationToken = false)
|
|
| 56 | 56 | Version getServerVersion();
|
| 57 | 57 | |
| 58 | - @Get(addAuthtoken = false)
|
|
| 58 | + @Get(addAuthenticationToken = false)
|
|
| 59 | 59 | ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration config) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException;
|
| 60 | 60 | |
| 61 | - @Get(addAuthtoken = false)
|
|
| 61 | + @Get(addAuthenticationToken = false)
|
|
| 62 | 62 | ObserveDataSourceInformation checkCanConnectOrBeEmpty(ObserveDataSourceConfiguration config) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException;
|
| 63 | 63 | |
| 64 | - @Post(addAuthtoken = false)
|
|
| 64 | + @Post(addAuthenticationToken = false)
|
|
| 65 | 65 | ObserveDataSourceConnection createEmpty(ObserveDataSourceConfiguration config) throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException, BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException;
|
| 66 | 66 | |
| 67 | - @Post(addAuthtoken = false, useMultiPartForm = true)
|
|
| 67 | + @Post(addAuthenticationToken = false, useMultiPartForm = true)
|
|
| 68 | 68 | ObserveDataSourceConnection createFromDump(ObserveDataSourceConfiguration config, SqlScript dump) throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException, BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException;
|
| 69 | 69 | |
| 70 | - @Post(addAuthtoken = false, useMultiPartForm = true)
|
|
| 70 | + @Post(addAuthenticationToken = false, useMultiPartForm = true)
|
|
| 71 | 71 | ObserveDataSourceConnection createFromImport(ObserveDataSourceConfiguration config, SqlScript dump, @Nullable SqlScript optionalDump) throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException, BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException;
|
| 72 | 72 | |
| 73 | - @Get(addAuthtoken = false)
|
|
| 73 | + @Get(addAuthenticationToken = false)
|
|
| 74 | 74 | ObserveDataSourceConnection open(ObserveDataSourceConfiguration config) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException;
|
| 75 | 75 | |
| 76 | - @Get(addAuthtoken = false)
|
|
| 76 | + @Get(addAuthenticationToken = false)
|
|
| 77 | 77 | Set<DataSourceUserDto> getUsers(ObserveDataSourceConfiguration config);
|
| 78 | 78 | |
| 79 | - @Get(addAuthtoken = false, timeOut = 100)
|
|
| 79 | + @Get(addAuthenticationToken = false, timeOut = 100)
|
|
| 80 | 80 | void applySecurity(ObserveDataSourceConfiguration config, Set<DataSourceUserDto> users);
|
| 81 | 81 | |
| 82 | - @Get(addAuthtoken = false, timeOut = 100)
|
|
| 82 | + @Get(addAuthenticationToken = false, timeOut = 100)
|
|
| 83 | 83 | void migrateData(ObserveDataSourceConfiguration config);
|
| 84 | 84 | |
| 85 | - @Get(addAuthtoken = false)
|
|
| 85 | + @Get(addAuthenticationToken = false)
|
|
| 86 | 86 | String generateHomeId();
|
| 87 | 87 | |
| 88 | 88 | /**
|
| 89 | 89 | * @return list of available databases (only available for server service)
|
| 90 | 90 | */
|
| 91 | - @Get(addAuthtoken = false)
|
|
| 91 | + @Get(addAuthenticationToken = false)
|
|
| 92 | 92 | Set<String> getAvailableDatabaseNames();
|
| 93 | 93 | } |
| ... | ... | @@ -26,6 +26,7 @@ import fr.ird.observe.datasource.security.Permission; |
| 26 | 26 | import fr.ird.observe.dto.BusinessDto;
|
| 27 | 27 | import fr.ird.observe.dto.ToolkitIdDtoBean;
|
| 28 | 28 | import fr.ird.observe.dto.ToolkitIdLabel;
|
| 29 | +import io.ultreia.java4all.http.spi.Get;
|
|
| 29 | 30 | import io.ultreia.java4all.http.spi.Post;
|
| 30 | 31 | import io.ultreia.java4all.http.spi.Service;
|
| 31 | 32 | |
| ... | ... | @@ -40,9 +41,11 @@ import java.util.Set; |
| 40 | 41 | @Service
|
| 41 | 42 | public interface UsageService extends ObserveService {
|
| 42 | 43 | |
| 44 | + @Get
|
|
| 43 | 45 | @MethodCredential(Permission.READ_ALL)
|
| 44 | 46 | UsageCount countReferential(ToolkitIdDtoBean request);
|
| 45 | 47 | |
| 48 | + @Get
|
|
| 46 | 49 | @MethodCredential(Permission.READ_ALL)
|
| 47 | 50 | UsageCount countReferentialInData(ToolkitIdDtoBean request);
|
| 48 | 51 | |
| ... | ... | @@ -50,9 +53,11 @@ public interface UsageService extends ObserveService { |
| 50 | 53 | @MethodCredential(Permission.READ_REFERENTIAL)
|
| 51 | 54 | <D extends BusinessDto> Set<ToolkitIdLabel> findReferential(ToolkitIdDtoBean request, Class<D> targetType);
|
| 52 | 55 | |
| 56 | + @Get
|
|
| 53 | 57 | @MethodCredential(Permission.READ_DATA)
|
| 54 | 58 | UsageCount countOptionalData(ToolkitIdDtoBean request);
|
| 55 | 59 | |
| 60 | + @Get
|
|
| 56 | 61 | @MethodCredential(Permission.READ_DATA)
|
| 57 | 62 | UsageCount countMandatoryData(ToolkitIdDtoBean request);
|
| 58 | 63 |
| ... | ... | @@ -33,6 +33,7 @@ import io.ultreia.java4all.http.spi.Delete; |
| 33 | 33 | import io.ultreia.java4all.http.spi.Get;
|
| 34 | 34 | import io.ultreia.java4all.http.spi.Nullable;
|
| 35 | 35 | import io.ultreia.java4all.http.spi.Post;
|
| 36 | +import io.ultreia.java4all.http.spi.Put;
|
|
| 36 | 37 | import io.ultreia.java4all.http.spi.Service;
|
| 37 | 38 | import io.ultreia.java4all.http.spi.Write;
|
| 38 | 39 | |
| ... | ... | @@ -62,7 +63,7 @@ public interface DataEntityService extends ObserveService { |
| 62 | 63 | return getSome(dtoType, config, filters, Map.of());
|
| 63 | 64 | }
|
| 64 | 65 | |
| 65 | - @Get(addAuthtoken = false)
|
|
| 66 | + @Get(addAuthenticationToken = false)
|
|
| 66 | 67 | List<String> generateId(Class<? extends DataDto> dtoType, int number);
|
| 67 | 68 | |
| 68 | 69 | @Post(useMultiPartForm = true)
|
| ... | ... | @@ -70,7 +71,7 @@ public interface DataEntityService extends ObserveService { |
| 70 | 71 | @Write
|
| 71 | 72 | ToolkitId create(Class<? extends DataDto> dtoType, String content) throws InvalidDataException;
|
| 72 | 73 | |
| 73 | - @Post(useMultiPartForm = true)
|
|
| 74 | + @Put(useMultiPartForm = true)
|
|
| 74 | 75 | @MethodCredential(Permission.READ_ALL_AND_WRITE_DATA)
|
| 75 | 76 | @Write
|
| 76 | 77 | ToolkitId update(Class<? extends DataDto> dtoType, String id, String content) throws InvalidDataException;
|
| ... | ... | @@ -81,7 +81,7 @@ public interface ReferentialEntityService extends ObserveService { |
| 81 | 81 | return getSome(dtoType, config, filters, Map.of());
|
| 82 | 82 | }
|
| 83 | 83 | |
| 84 | - @Get(addAuthtoken = false)
|
|
| 84 | + @Get(addAuthenticationToken = false)
|
|
| 85 | 85 | List<String> generateId(Class<? extends ReferentialDto> dtoType, int number);
|
| 86 | 86 | |
| 87 | 87 | @Post(useMultiPartForm = true)
|
| ... | ... | @@ -35,11 +35,8 @@ import fr.ird.observe.spi.navigation.model.tree.TreeProjectModelBuilder; |
| 35 | 35 | import fr.ird.observe.toolkit.maven.plugin.MojoRunnable;
|
| 36 | 36 | import io.ultreia.java4all.http.spi.Delete;
|
| 37 | 37 | import io.ultreia.java4all.http.spi.Get;
|
| 38 | -import io.ultreia.java4all.http.spi.Head;
|
|
| 39 | -import io.ultreia.java4all.http.spi.Patch;
|
|
| 40 | 38 | import io.ultreia.java4all.http.spi.Post;
|
| 41 | 39 | import io.ultreia.java4all.http.spi.Put;
|
| 42 | -import io.ultreia.java4all.http.spi.Trace;
|
|
| 43 | 40 | import io.ultreia.java4all.http.spi.Write;
|
| 44 | 41 | import io.ultreia.java4all.http.spi.model.ImportManager;
|
| 45 | 42 | import io.ultreia.java4all.http.spi.model.MethodDescription;
|
| ... | ... | @@ -227,6 +224,20 @@ public class ServiceGenerateApiRunner extends MojoRunnable { |
| 227 | 224 | |
| 228 | 225 | }
|
| 229 | 226 | |
| 227 | + private String addMethodAnnotation(boolean addAuthenticationToken, boolean useMultiPartForm, int timeOut) {
|
|
| 228 | + String parameters = "";
|
|
| 229 | + if (!addAuthenticationToken) {
|
|
| 230 | + parameters += ", addAuthenticationToken = false";
|
|
| 231 | + }
|
|
| 232 | + if (useMultiPartForm) {
|
|
| 233 | + parameters += ", useMultiPartForm = true";
|
|
| 234 | + }
|
|
| 235 | + if (timeOut != 0) {
|
|
| 236 | + parameters += ", timeOut = " + timeOut;
|
|
| 237 | + }
|
|
| 238 | + return parameters;
|
|
| 239 | + }
|
|
| 240 | + |
|
| 230 | 241 | protected void addMethod(ServiceLocalMethodDescriptionImpl methodDescription, List<String> methods) {
|
| 231 | 242 | Permission methodeCredentials = methodDescription.getMethodeCredentials();
|
| 232 | 243 | StringBuilder annotationsBuilder = new StringBuilder();
|
| ... | ... | @@ -243,104 +254,32 @@ public class ServiceGenerateApiRunner extends MojoRunnable { |
| 243 | 254 | parameters += ", " + Permission.class.getSimpleName() + "." + methodeCredentials.name();
|
| 244 | 255 | } else if (annotation instanceof Get) {
|
| 245 | 256 | Get annotation1 = (Get) annotation;
|
| 246 | - boolean addAuthToken = annotation1.addAuthtoken();
|
|
| 247 | - boolean useMultiPartForm = annotation1.useMultiPartForm();
|
|
| 257 | + boolean addAuthenticationToken = annotation1.addAuthenticationToken();
|
|
| 258 | + boolean useMultiPartForm = false;
|
|
| 248 | 259 | int timeOut = annotation1.timeOut();
|
| 249 | - if (!addAuthToken) {
|
|
| 250 | - parameters += ", addAuthtoken = false";
|
|
| 251 | - }
|
|
| 252 | - if (useMultiPartForm) {
|
|
| 253 | - parameters += ", useMultiPartForm = true";
|
|
| 254 | - }
|
|
| 255 | - if (timeOut != 1) {
|
|
| 256 | - parameters += ", timeOut = " + timeOut;
|
|
| 257 | - }
|
|
| 260 | + parameters += addMethodAnnotation(addAuthenticationToken, useMultiPartForm, timeOut);
|
|
| 258 | 261 | } else if (annotation instanceof Post) {
|
| 259 | 262 | Post annotation1 = (Post) annotation;
|
| 260 | - boolean addAuthToken = annotation1.addAuthtoken();
|
|
| 263 | + boolean addAuthenticationToken = annotation1.addAuthenticationToken();
|
|
| 261 | 264 | boolean useMultiPartForm = annotation1.useMultiPartForm();
|
| 262 | 265 | int timeOut = annotation1.timeOut();
|
| 263 | - if (!addAuthToken) {
|
|
| 264 | - parameters += ", addAuthtoken = false";
|
|
| 265 | - }
|
|
| 266 | - if (useMultiPartForm) {
|
|
| 267 | - parameters += ", useMultiPartForm = true";
|
|
| 268 | - }
|
|
| 269 | - if (timeOut != 1) {
|
|
| 270 | - parameters += ", timeOut = " + timeOut;
|
|
| 271 | - }
|
|
| 266 | + parameters += addMethodAnnotation(addAuthenticationToken, useMultiPartForm, timeOut);
|
|
| 267 | + |
|
| 272 | 268 | } else if (annotation instanceof Put) {
|
| 273 | 269 | Put annotation1 = (Put) annotation;
|
| 274 | - boolean addAuthToken = annotation1.addAuthtoken();
|
|
| 270 | + boolean addAuthenticationToken = annotation1.addAuthenticationToken();
|
|
| 275 | 271 | boolean useMultiPartForm = annotation1.useMultiPartForm();
|
| 276 | 272 | int timeOut = annotation1.timeOut();
|
| 277 | - if (!addAuthToken) {
|
|
| 278 | - parameters += ", addAuthtoken = false";
|
|
| 279 | - }
|
|
| 280 | - if (useMultiPartForm) {
|
|
| 281 | - parameters += ", useMultiPartForm = true";
|
|
| 282 | - }
|
|
| 283 | - if (timeOut != 1) {
|
|
| 284 | - parameters += ", timeOut = " + timeOut;
|
|
| 285 | - }
|
|
| 273 | + parameters += addMethodAnnotation(addAuthenticationToken, useMultiPartForm, timeOut);
|
|
| 274 | + |
|
| 286 | 275 | } else if (annotation instanceof Delete) {
|
| 287 | 276 | Delete annotation1 = (Delete) annotation;
|
| 288 | - boolean addAuthToken = annotation1.addAuthtoken();
|
|
| 277 | + boolean addAuthenticationToken = annotation1.addAuthenticationToken();
|
|
| 289 | 278 | boolean useMultiPartForm = annotation1.useMultiPartForm();
|
| 290 | 279 | int timeOut = annotation1.timeOut();
|
| 291 | - if (!addAuthToken) {
|
|
| 292 | - parameters += ", addAuthtoken = false";
|
|
| 293 | - }
|
|
| 294 | - if (useMultiPartForm) {
|
|
| 295 | - parameters += ", useMultiPartForm = true";
|
|
| 296 | - }
|
|
| 297 | - if (timeOut != 1) {
|
|
| 298 | - parameters += ", timeOut = " + timeOut;
|
|
| 299 | - }
|
|
| 300 | - } else if (annotation instanceof Patch) {
|
|
| 301 | - Patch annotation1 = (Patch) annotation;
|
|
| 302 | - boolean addAuthToken = annotation1.addAuthtoken();
|
|
| 303 | - boolean useMultiPartForm = annotation1.useMultiPartForm();
|
|
| 304 | - int timeOut = annotation1.timeOut();
|
|
| 305 | - if (!addAuthToken) {
|
|
| 306 | - parameters += ", addAuthtoken = false";
|
|
| 307 | - }
|
|
| 308 | - if (useMultiPartForm) {
|
|
| 309 | - parameters += ", useMultiPartForm = true";
|
|
| 310 | - }
|
|
| 311 | - if (timeOut != 1) {
|
|
| 312 | - parameters += ", timeOut = " + timeOut;
|
|
| 313 | - }
|
|
| 314 | - } else if (annotation instanceof Head) {
|
|
| 315 | - Head annotation1 = (Head) annotation;
|
|
| 316 | - boolean addAuthToken = annotation1.addAuthtoken();
|
|
| 317 | - boolean useMultiPartForm = annotation1.useMultiPartForm();
|
|
| 318 | - int timeOut = annotation1.timeOut();
|
|
| 319 | - if (!addAuthToken) {
|
|
| 320 | - parameters += ", addAuthtoken = false";
|
|
| 321 | - }
|
|
| 322 | - if (useMultiPartForm) {
|
|
| 323 | - parameters += ", useMultiPartForm = true";
|
|
| 324 | - }
|
|
| 325 | - if (timeOut != 1) {
|
|
| 326 | - parameters += ", timeOut = " + timeOut;
|
|
| 327 | - }
|
|
| 328 | - } else if (annotation instanceof Trace) {
|
|
| 329 | - Trace annotation1 = (Trace) annotation;
|
|
| 330 | - boolean addAuthToken = annotation1.addAuthtoken();
|
|
| 331 | - boolean useMultiPartForm = annotation1.useMultiPartForm();
|
|
| 332 | - int timeOut = annotation1.timeOut();
|
|
| 333 | - if (!addAuthToken) {
|
|
| 334 | - parameters += ", addAuthtoken = false";
|
|
| 335 | - }
|
|
| 336 | - if (useMultiPartForm) {
|
|
| 337 | - parameters += ", useMultiPartForm = true";
|
|
| 338 | - }
|
|
| 339 | - if (timeOut != 1) {
|
|
| 340 | - parameters += ", timeOut = " + timeOut;
|
|
| 341 | - }
|
|
| 280 | + parameters += addMethodAnnotation(addAuthenticationToken, useMultiPartForm, timeOut);
|
|
| 342 | 281 | }
|
| 343 | - if (parameters.length() > 0) {
|
|
| 282 | + if (!parameters.isEmpty()) {
|
|
| 344 | 283 | annotationsBuilder.append("(").append(parameters.substring(2)).append(")");
|
| 345 | 284 | }
|
| 346 | 285 | }
|
| ... | ... | @@ -75,7 +75,7 @@ public class ServiceLocalMethodDescriptionImpl implements MethodDescription { |
| 75 | 75 | |
| 76 | 76 | this.methodeCredentials = Optional.ofNullable(method.getAnnotation(MethodCredential.class)).map(MethodCredential::value).orElse(null);
|
| 77 | 77 | this.write = SpiHelper.write(method);
|
| 78 | - this.noTransaction = !SpiHelper.getRequestAnnotation(method).isAddAuthToken();
|
|
| 78 | + this.noTransaction = !SpiHelper.getRequestAnnotation(method).isAddAuthenticationToken();
|
|
| 79 | 79 | }
|
| 80 | 80 | |
| 81 | 81 | public Method getMethod() {
|
| ... | ... | @@ -42,8 +42,8 @@ |
| 42 | 42 | <artifactId>commons-configuration</artifactId>
|
| 43 | 43 | </dependency>
|
| 44 | 44 | <dependency>
|
| 45 | - <groupId>commons-fileupload</groupId>
|
|
| 46 | - <artifactId>commons-fileupload</artifactId>
|
|
| 45 | + <groupId>org.apache.commons</groupId>
|
|
| 46 | + <artifactId>commons-fileupload2-core</artifactId>
|
|
| 47 | 47 | </dependency>
|
| 48 | 48 | <dependency>
|
| 49 | 49 | <groupId>commons-io</groupId>
|
| ... | ... | @@ -65,14 +65,6 @@ |
| 65 | 65 | <groupId>org.apache.commons</groupId>
|
| 66 | 66 | <artifactId>commons-lang3</artifactId>
|
| 67 | 67 | </dependency>
|
| 68 | - <dependency>
|
|
| 69 | - <groupId>org.apache.httpcomponents</groupId>
|
|
| 70 | - <artifactId>httpclient</artifactId>
|
|
| 71 | - </dependency>
|
|
| 72 | - <dependency>
|
|
| 73 | - <groupId>org.apache.httpcomponents</groupId>
|
|
| 74 | - <artifactId>httpcore</artifactId>
|
|
| 75 | - </dependency>
|
|
| 76 | 68 | <dependency>
|
| 77 | 69 | <groupId>org.apache.logging.log4j</groupId>
|
| 78 | 70 | <artifactId>log4j-api</artifactId>
|
| ... | ... | @@ -25,6 +25,7 @@ import io.ultreia.java4all.lang.Objects2; |
| 25 | 25 | import org.apache.commons.beanutils.BeanUtilsBean;
|
| 26 | 26 | import org.apache.commons.beanutils.ConvertUtilsBean;
|
| 27 | 27 | import org.apache.commons.beanutils.Converter;
|
| 28 | +import org.apache.commons.fileupload2.core.DiskFileItemFactory;
|
|
| 28 | 29 | import org.apache.logging.log4j.LogManager;
|
| 29 | 30 | import org.apache.logging.log4j.Logger;
|
| 30 | 31 | import org.debux.webmotion.server.WebMotionController;
|
| ... | ... | @@ -44,6 +45,7 @@ import org.debux.webmotion.server.tools.SingletonFactory; |
| 44 | 45 | |
| 45 | 46 | import javax.servlet.ServletContext;
|
| 46 | 47 | import java.lang.reflect.Method;
|
| 48 | +import java.nio.file.Path;
|
|
| 47 | 49 | import java.util.ArrayList;
|
| 48 | 50 | import java.util.Arrays;
|
| 49 | 51 | import java.util.HashMap;
|
| ... | ... | @@ -136,6 +138,16 @@ public class ServerContext { |
| 136 | 138 | * Current exclude paths
|
| 137 | 139 | */
|
| 138 | 140 | protected String[] excludePaths = {};
|
| 141 | + /**
|
|
| 142 | + * Temporary path used
|
|
| 143 | + */
|
|
| 144 | + protected Path temporaryPath;
|
|
| 145 | + /**
|
|
| 146 | + * Use to read multi-parts.
|
|
| 147 | + *
|
|
| 148 | + * @see org.debux.webmotion.server.handler.ParametersMultipartHandler
|
|
| 149 | + */
|
|
| 150 | + protected DiskFileItemFactory fileItemFactory;
|
|
| 139 | 151 | |
| 140 | 152 | /**
|
| 141 | 153 | * Initialize the context.
|
| ... | ... | @@ -461,6 +473,24 @@ public class ServerContext { |
| 461 | 473 | this.excludePaths = excludePaths;
|
| 462 | 474 | }
|
| 463 | 475 | |
| 476 | + public Path getTemporaryPath() {
|
|
| 477 | + return temporaryPath;
|
|
| 478 | + }
|
|
| 479 | + |
|
| 480 | + public void setTemporaryPath(Path temporaryPath) {
|
|
| 481 | + this.temporaryPath = temporaryPath;
|
|
| 482 | + }
|
|
| 483 | + |
|
| 484 | + public synchronized DiskFileItemFactory getFileItemFactory() {
|
|
| 485 | + if (fileItemFactory == null) {
|
|
| 486 | + if (getTemporaryPath() == null) {
|
|
| 487 | + throw new IllegalStateException("No temporary path set in the ServerContext.");
|
|
| 488 | + }
|
|
| 489 | + fileItemFactory = DiskFileItemFactory.builder().setBufferSize(1024 * 1024 /* 1Mb */).setPath(getTemporaryPath()).get();
|
|
| 490 | + }
|
|
| 491 | + return fileItemFactory;
|
|
| 492 | + }
|
|
| 493 | + |
|
| 464 | 494 | private static final Logger log = LogManager.getLogger(ServerContext.class);
|
| 465 | 495 | |
| 466 | 496 | public void loadExecutors(Mapping mapping, Stream<? extends Rule> actionStream) {
|
| ... | ... | @@ -30,7 +30,7 @@ import org.debux.webmotion.server.WebMotionFilter; |
| 30 | 30 | import org.debux.webmotion.server.WebMotionHandler;
|
| 31 | 31 | import org.debux.webmotion.server.call.Call;
|
| 32 | 32 | import org.debux.webmotion.server.call.Executor;
|
| 33 | -import org.debux.webmotion.server.call.FileProgressListener;
|
|
| 33 | +import org.debux.webmotion.server.tools.upload.FileProgressListener;
|
|
| 34 | 34 | import org.debux.webmotion.server.call.HttpContext;
|
| 35 | 35 | import org.debux.webmotion.server.call.ServerContext;
|
| 36 | 36 | import org.debux.webmotion.server.mapping.Action;
|
| ... | ... | @@ -24,7 +24,7 @@ package org.debux.webmotion.server.handler; |
| 24 | 24 | import org.debux.webmotion.server.WebMotionHandler;
|
| 25 | 25 | import org.debux.webmotion.server.call.Call;
|
| 26 | 26 | import org.debux.webmotion.server.call.Executor;
|
| 27 | -import org.debux.webmotion.server.call.FileProgressListener;
|
|
| 27 | +import org.debux.webmotion.server.tools.upload.FileProgressListener;
|
|
| 28 | 28 | import org.debux.webmotion.server.call.HttpContext;
|
| 29 | 29 | import org.debux.webmotion.server.call.HttpContext.ErrorData;
|
| 30 | 30 | import org.debux.webmotion.server.call.ServerContext;
|
| ... | ... | @@ -21,25 +21,24 @@ |
| 21 | 21 | */
|
| 22 | 22 | package org.debux.webmotion.server.handler;
|
| 23 | 23 | |
| 24 | -import org.apache.commons.fileupload.FileItem;
|
|
| 25 | -import org.apache.commons.fileupload.FileItemFactory;
|
|
| 26 | -import org.apache.commons.fileupload.FileUploadException;
|
|
| 27 | -import org.apache.commons.fileupload.disk.DiskFileItem;
|
|
| 28 | -import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
| 29 | -import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
|
| 24 | +import io.ultreia.java4all.lang.Strings;
|
|
| 25 | +import org.apache.commons.fileupload2.core.DiskFileItem;
|
|
| 30 | 26 | import org.apache.commons.lang3.ArrayUtils;
|
| 27 | +import org.apache.logging.log4j.LogManager;
|
|
| 28 | +import org.apache.logging.log4j.Logger;
|
|
| 31 | 29 | import org.debux.webmotion.server.WebMotionException;
|
| 32 | 30 | import org.debux.webmotion.server.WebMotionHandler;
|
| 33 | 31 | import org.debux.webmotion.server.call.Call;
|
| 34 | -import org.debux.webmotion.server.call.FileProgressListener;
|
|
| 35 | 32 | import org.debux.webmotion.server.call.HttpContext;
|
| 36 | 33 | import org.debux.webmotion.server.call.UploadFile;
|
| 37 | 34 | import org.debux.webmotion.server.mapping.Mapping;
|
| 35 | +import org.debux.webmotion.server.tools.upload.FileUpload;
|
|
| 38 | 36 | |
| 39 | 37 | import javax.servlet.http.HttpServletRequest;
|
| 40 | -import javax.servlet.http.HttpSession;
|
|
| 41 | 38 | import java.io.File;
|
| 39 | +import java.io.IOException;
|
|
| 42 | 40 | import java.io.UnsupportedEncodingException;
|
| 41 | +import java.nio.charset.StandardCharsets;
|
|
| 43 | 42 | import java.util.List;
|
| 44 | 43 | import java.util.Map;
|
| 45 | 44 | |
| ... | ... | @@ -51,6 +50,8 @@ import java.util.Map; |
| 51 | 50 | */
|
| 52 | 51 | public class ParametersMultipartHandler extends AbstractHandler implements WebMotionHandler {
|
| 53 | 52 | |
| 53 | + private static final Logger log = LogManager.getLogger(ParametersMultipartHandler.class);
|
|
| 54 | + |
|
| 54 | 55 | @Override
|
| 55 | 56 | public void handle(Mapping mapping, Call call) {
|
| 56 | 57 | HttpContext context = call.getContext();
|
| ... | ... | @@ -58,29 +59,28 @@ public class ParametersMultipartHandler extends AbstractHandler implements WebMo |
| 58 | 59 | |
| 59 | 60 | Map<String, Object> extractParameters = call.getExtractParameters();
|
| 60 | 61 | |
| 61 | - boolean isMultipart = ServletFileUpload.isMultipartContent(request);
|
|
| 62 | + boolean isMultipart = FileUpload.isMultipartContent(request);
|
|
| 62 | 63 | if (isMultipart) {
|
| 63 | - FileItemFactory fileItemFactory = new DiskFileItemFactory(0, null);
|
|
| 64 | - ServletFileUpload upload = new ServletFileUpload(fileItemFactory);
|
|
| 65 | - |
|
| 66 | - HttpSession session = request.getSession();
|
|
| 67 | - if (session != null) {
|
|
| 68 | - FileProgressListener listener = new FileProgressListener();
|
|
| 69 | - upload.setProgressListener(listener);
|
|
| 70 | - session.setAttribute(FileProgressListener.SESSION_ATTRIBUTE_NAME, listener);
|
|
| 71 | - call.setFileUploadRequest(true);
|
|
| 72 | - }
|
|
| 64 | + FileUpload upload = new FileUpload(context.getServerContext().getFileItemFactory());
|
|
| 65 | + |
|
| 66 | +// HttpSession session = request.getSession();
|
|
| 67 | +// if (session != null) {
|
|
| 68 | +// FileProgressListener listener = new FileProgressListener();
|
|
| 69 | +// upload.setProgressListener(listener);
|
|
| 70 | +// session.setAttribute(FileProgressListener.SESSION_ATTRIBUTE_NAME, listener);
|
|
| 71 | +// call.setFileUploadRequest(true);
|
|
| 72 | +// }
|
|
| 73 | 73 | |
| 74 | 74 | try {
|
| 75 | - List<FileItem> items = upload.parseRequest(request);
|
|
| 76 | - for (FileItem item0 : items) {
|
|
| 77 | - DiskFileItem item = (DiskFileItem) item0;
|
|
| 75 | + List<DiskFileItem> items = upload.parseRequest(request);
|
|
| 76 | + for (DiskFileItem item : items) {
|
|
| 78 | 77 | String fieldName = item.getFieldName();
|
| 79 | 78 | |
| 79 | + log.debug("Multipart: {} - size: {} - in memory? {} - location: {}", fieldName, Strings.convertMemory(item.getSize()), item.isInMemory(), item.getPath());
|
|
| 80 | 80 | if (item.isFormField()) {
|
| 81 | 81 | String fieldValue;
|
| 82 | 82 | try {
|
| 83 | - fieldValue = item.getString("UTF-8");
|
|
| 83 | + fieldValue = item.getString(StandardCharsets.UTF_8);
|
|
| 84 | 84 | } catch (UnsupportedEncodingException e) {
|
| 85 | 85 | fieldValue = item.getString();
|
| 86 | 86 | }
|
| ... | ... | @@ -96,24 +96,12 @@ public class ParametersMultipartHandler extends AbstractHandler implements WebMo |
| 96 | 96 | }
|
| 97 | 97 | |
| 98 | 98 | } else {
|
| 99 | - UploadFile uploadFile = new UploadFile();
|
|
| 100 | - |
|
| 101 | - File file = item.getStoreLocation();
|
|
| 102 | - uploadFile.setFile(file);
|
|
| 103 | - |
|
| 104 | - String fileName = item.getName();
|
|
| 105 | - uploadFile.setName(fileName);
|
|
| 106 | - |
|
| 107 | - long fileSize = item.getSize();
|
|
| 108 | - uploadFile.setSize(fileSize);
|
|
| 109 | - |
|
| 110 | - String fileType = item.getContentType();
|
|
| 111 | - uploadFile.setContentType(fileType);
|
|
| 99 | + UploadFile uploadFile = getUploadFile(item);
|
|
| 112 | 100 | |
| 113 | 101 | extractParameters.put(fieldName, uploadFile);
|
| 114 | 102 | }
|
| 115 | 103 | }
|
| 116 | - } catch (FileUploadException fue) {
|
|
| 104 | + } catch (IOException fue) {
|
|
| 117 | 105 | throw new WebMotionException("Error during upload file on server", fue);
|
| 118 | 106 | }
|
| 119 | 107 | |
| ... | ... | @@ -122,4 +110,21 @@ public class ParametersMultipartHandler extends AbstractHandler implements WebMo |
| 122 | 110 | extractParameters.putAll(parameters);
|
| 123 | 111 | }
|
| 124 | 112 | }
|
| 113 | + |
|
| 114 | + private static UploadFile getUploadFile(DiskFileItem item) {
|
|
| 115 | + UploadFile uploadFile = new UploadFile();
|
|
| 116 | + |
|
| 117 | + File file = item.getPath().toFile();
|
|
| 118 | + uploadFile.setFile(file);
|
|
| 119 | + |
|
| 120 | + String fileName = item.getName();
|
|
| 121 | + uploadFile.setName(fileName);
|
|
| 122 | + |
|
| 123 | + long fileSize = item.getSize();
|
|
| 124 | + uploadFile.setSize(fileSize);
|
|
| 125 | + |
|
| 126 | + String fileType = item.getContentType();
|
|
| 127 | + uploadFile.setContentType(fileType);
|
|
| 128 | + return uploadFile;
|
|
| 129 | + }
|
|
| 125 | 130 | } |
| ... | ... | @@ -19,9 +19,9 @@ |
| 19 | 19 | * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| 20 | 20 | * #L%
|
| 21 | 21 | */
|
| 22 | -package org.debux.webmotion.server.call;
|
|
| 22 | +package org.debux.webmotion.server.tools.upload;
|
|
| 23 | 23 | |
| 24 | -import org.apache.commons.fileupload.ProgressListener;
|
|
| 24 | +import org.apache.commons.fileupload2.core.ProgressListener;
|
|
| 25 | 25 | import org.apache.logging.log4j.LogManager;
|
| 26 | 26 | import org.apache.logging.log4j.Logger;
|
| 27 | 27 | |
| ... | ... | @@ -30,7 +30,6 @@ import org.apache.logging.log4j.Logger; |
| 30 | 30 | * stored in session.
|
| 31 | 31 | *
|
| 32 | 32 | * @author julien
|
| 33 | - * @see org.apache.commons.fileupload.FileUpload
|
|
| 34 | 33 | */
|
| 35 | 34 | public class FileProgressListener implements ProgressListener {
|
| 36 | 35 |
| 1 | +package org.debux.webmotion.server.tools.upload;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Toolkit :: Server
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2023 IRD, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import org.apache.commons.fileupload2.core.AbstractFileUpload;
|
|
| 26 | +import org.apache.commons.fileupload2.core.DiskFileItem;
|
|
| 27 | +import org.apache.commons.fileupload2.core.DiskFileItemFactory;
|
|
| 28 | +import org.apache.commons.fileupload2.core.FileItemInputIterator;
|
|
| 29 | +import org.apache.commons.fileupload2.core.FileUploadException;
|
|
| 30 | + |
|
| 31 | +import javax.servlet.http.HttpServletRequest;
|
|
| 32 | +import java.io.IOException;
|
|
| 33 | +import java.util.List;
|
|
| 34 | +import java.util.Map;
|
|
| 35 | +import java.util.Objects;
|
|
| 36 | +import java.util.Set;
|
|
| 37 | + |
|
| 38 | +/**
|
|
| 39 | + * Created at 24/11/2023.
|
|
| 40 | + *
|
|
| 41 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 42 | + * @since 9.3.0
|
|
| 43 | + */
|
|
| 44 | +public class FileUpload extends AbstractFileUpload<HttpServletRequest, DiskFileItem, DiskFileItemFactory> {
|
|
| 45 | + |
|
| 46 | + public static final Set<String> ACCEPTED_METHOD = Set.of("post","put");
|
|
| 47 | + public FileUpload(DiskFileItemFactory fileItemFactory) {
|
|
| 48 | + setFileItemFactory(Objects.requireNonNull(fileItemFactory));
|
|
| 49 | + }
|
|
| 50 | + |
|
| 51 | + public static boolean isMultipartContent(final HttpServletRequest request) {
|
|
| 52 | + return ACCEPTED_METHOD.contains(request.getMethod().toLowerCase()) && AbstractFileUpload.isMultipartContent(new RequestContext(request));
|
|
| 53 | + }
|
|
| 54 | + |
|
| 55 | + @Override
|
|
| 56 | + public FileItemInputIterator getItemIterator(HttpServletRequest request) throws IOException {
|
|
| 57 | + return super.getItemIterator(new RequestContext(request));
|
|
| 58 | + }
|
|
| 59 | + |
|
| 60 | + @Override
|
|
| 61 | + public Map<String, List<DiskFileItem>> parseParameterMap(HttpServletRequest request) throws FileUploadException {
|
|
| 62 | + return super.parseParameterMap(new RequestContext(request));
|
|
| 63 | + }
|
|
| 64 | + |
|
| 65 | + @Override
|
|
| 66 | + public List<DiskFileItem> parseRequest(HttpServletRequest request) throws FileUploadException {
|
|
| 67 | + return super.parseRequest(new RequestContext(request));
|
|
| 68 | + }
|
|
| 69 | +} |
| 1 | -package org.debux.webmotion.server.tools;
|
|
| 1 | +package org.debux.webmotion.server.tools.upload;
|
|
| 2 | 2 | |
| 3 | -/*
|
|
| 3 | +/*-
|
|
| 4 | 4 | * #%L
|
| 5 | 5 | * ObServe Toolkit :: Server
|
| 6 | 6 | * %%
|
| ... | ... | @@ -22,31 +22,59 @@ package org.debux.webmotion.server.tools; |
| 22 | 22 | * #L%
|
| 23 | 23 | */
|
| 24 | 24 | |
| 25 | -import java.io.IOException;
|
|
| 25 | +import org.apache.commons.fileupload2.core.AbstractRequestContext;
|
|
| 26 | 26 | |
| 27 | -import org.apache.http.HttpEntity;
|
|
| 28 | -import org.apache.http.HttpResponse;
|
|
| 29 | -import org.apache.http.client.ClientProtocolException;
|
|
| 30 | -import org.apache.http.client.ResponseHandler;
|
|
| 31 | -import org.apache.http.util.EntityUtils;
|
|
| 27 | +import javax.servlet.http.HttpServletRequest;
|
|
| 28 | +import java.io.IOException;
|
|
| 29 | +import java.io.InputStream;
|
|
| 32 | 30 | |
| 33 | 31 | /**
|
| 34 | - * Return the content as String without test on status code.
|
|
| 35 | - * You can @see ContentResponseHandler for more information.
|
|
| 36 | - *
|
|
| 37 | - * @author julien
|
|
| 32 | + * Created at 24/11/2023.
|
|
| 33 | + *
|
|
| 34 | + * @author Tony Chemit - dev@tchemit.fr
|
|
| 35 | + * @since 9.3.0
|
|
| 38 | 36 | */
|
| 39 | -public class StringResponseHandler implements ResponseHandler<String> {
|
|
| 37 | +public class RequestContext extends AbstractRequestContext<HttpServletRequest> {
|
|
| 38 | + |
|
| 39 | + /**
|
|
| 40 | + * The request for which the context is being provided.
|
|
| 41 | + */
|
|
| 42 | + private final HttpServletRequest request;
|
|
| 43 | + |
|
| 44 | + protected RequestContext(HttpServletRequest request) {
|
|
| 45 | + super(request::getHeader, request::getContentLength, request);
|
|
| 46 | + this.request = request;
|
|
| 47 | + }
|
|
| 48 | + |
|
| 49 | + /**
|
|
| 50 | + * Gets the character encoding for the request.
|
|
| 51 | + *
|
|
| 52 | + * @return The character encoding for the request.
|
|
| 53 | + */
|
|
| 54 | + @Override
|
|
| 55 | + public String getCharacterEncoding() {
|
|
| 56 | + return request.getCharacterEncoding();
|
|
| 57 | + }
|
|
| 58 | + |
|
| 59 | + /**
|
|
| 60 | + * Gets the content type of the request.
|
|
| 61 | + *
|
|
| 62 | + * @return The content type of the request.
|
|
| 63 | + */
|
|
| 64 | + @Override
|
|
| 65 | + public String getContentType() {
|
|
| 66 | + return request.getContentType();
|
|
| 67 | + }
|
|
| 40 | 68 | |
| 69 | + /**
|
|
| 70 | + * Gets the input stream for the request.
|
|
| 71 | + *
|
|
| 72 | + * @return The input stream for the request.
|
|
| 73 | + * @throws java.io.IOException if a problem occurs.
|
|
| 74 | + */
|
|
| 41 | 75 | @Override
|
| 42 | - public String handleResponse(
|
|
| 43 | - final HttpResponse response) throws ClientProtocolException, IOException {
|
|
| 44 | - HttpEntity entity = response.getEntity();
|
|
| 45 | - if (entity != null) {
|
|
| 46 | - return EntityUtils.toString(entity);
|
|
| 47 | - } else {
|
|
| 48 | - return null;
|
|
| 49 | - }
|
|
| 76 | + public InputStream getInputStream() throws IOException {
|
|
| 77 | + return request.getInputStream();
|
|
| 50 | 78 | }
|
| 51 | 79 | |
| 52 | 80 | } |
| ... | ... | @@ -23,11 +23,7 @@ |
| 23 | 23 | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
|
| 24 | 24 |
|
| 25 | 25 | <name>webmotion</name>
|
| 26 | -
|
|
| 27 | - <listener>
|
|
| 28 | - <listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class>
|
|
| 29 | - </listener>
|
|
| 30 | -
|
|
| 26 | + |
|
| 31 | 27 | <listener>
|
| 32 | 28 | <listener-class>org.debux.webmotion.server.WebMotionServletContextListener</listener-class>
|
| 33 | 29 | </listener>
|