среда, 26 мая 2021 г.

Reactive spring - Get polling

 

Polling GET request of report with 5 times repeat with 1 second delay.


return client

        .get()
.uri(uriBuilder -> uriBuilder
.path("/report/{target}")
.build(target)
)
.retrieve()
.onStatus(HttpStatus::isError, clientResponse -> {
return Mono.error(new ReportException(ReportException.Type.GET));
})
.bodyToMono(MyPayload.class)
.delaySubscription(Duration.ofSeconds(1))
.repeat(5)
.skipUntil(myPayload-> ReportStatus.DONE == myPayload.getReportStatus())
.limitRequest(1)
.doOnError(ex -> log.error("getReport method had broken down...", ex))
.single()
.onErrorResume(NoSuchElementException.class, e -> Mono.empty());

пятница, 7 мая 2021 г.

Jaxb xsd to java maven plugin

            

        <dependency>

            <groupId>org.jvnet.jaxb2_commons</groupId>

            <artifactId>jaxb2-basics</artifactId>

            <version>${jaxb2-basics.version}</version>

        </dependency>

        <dependency>

            <groupId>org.jvnet.jaxb2_commons</groupId>

            <artifactId>jaxb2-basics-annotate</artifactId>

            <version>${jaxb2-basics-annotate.version}</version>

        </dependency>

        <dependency>

            <groupId>com.fasterxml.jackson.datatype</groupId>

            <artifactId>jackson-datatype-jdk8</artifactId>

        </dependency>



 <plugin>

                <groupId>org.jvnet.jaxb2.maven2</groupId>

                <artifactId>maven-jaxb2-plugin</artifactId>

                <version>0.13.2</version>

                <executions>

                    <execution>

                        <goals>

                            <goal>generate</goal>

                        </goals>

                    </execution>

                </executions>

                <configuration>

                    <schemaDirectory>${project.basedir}/src/main/resources/xsd/</schemaDirectory>

                    <bindingDirectory>${project.basedir}/src/main/resources/xsd/</bindingDirectory>

                    <generateDirectory>${project.build.directory}/generated-sources/model</generateDirectory>

                    <extension>true</extension>

                    <verbose>true</verbose>

                    <args>

                        <arg>-XtoString</arg>

                        <arg>-Xequals</arg>

                        <arg>-XhashCode</arg>

                        <arg>-Xsimplify</arg>

                        <arg>-Xannotate</arg>

                        <arg>-XautoNameResolution</arg>

                    </args>

                    <plugins>

                        <plugin>

                            <groupId>org.jvnet.jaxb2_commons</groupId>

                            <artifactId>jaxb2-basics</artifactId>

                            <version>${jaxb2-basics.version}</version>

                        </plugin>

                        <plugin>

                            <groupId>org.jvnet.jaxb2_commons</groupId>

                            <artifactId>jaxb2-basics-annotate</artifactId>

                            <version>${jaxb2-basics-annotate.version}</version>

                        </plugin>

                        <plugin>

                            <groupId>com.fasterxml.jackson.core</groupId>

                            <artifactId>jackson-annotations</artifactId>

                        </plugin>

                        <plugin>

                            <groupId>com.fasterxml.jackson.datatype</groupId>

                            <artifactId>jackson-datatype-jsr310</artifactId>

                        </plugin>

                    </plugins>

                </configuration>

            </plugin>

пятница, 15 января 2021 г.

File type detect

 Библиотека для определения типа файла Apache tika

<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.25</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.25</version>
</dependency>

Detector detector = TikaConfig.getDefaultConfig().getDetector();
MediaType mimetype = detector.detect(TikaInputStream.get(resource.getInputStream()), new Metadata());

zipEntry fileName encoding problem.
private String convertToText(byte[] name) {
Charset detectedCharset = IBM_866;
try {
detectedCharset = new UniversalEncodingDetector().detect(new ByteArrayInputStream(name), new Metadata());
} catch (IOException e) {
log.error("Error on charset detecting");
}

if (detectedCharset.equals(UTF_8)) {
return new String(name, UTF_8);
} else {
return new String(name, IBM_866);
}
}