среда, 19 июля 2023 г.

Gloowroot

 https://glowroot.org/


Features

  • Trace capture for slow requests and errors
  • Continuous profiling (with very handy filtering)
  • Response time breakdown charts
  • Response time percentile charts
  • SQL capture and aggregation
  • Service call capture and aggregation
  • MBean attribute capture and charts
  • Configurable alerting
  • Historical rollup of all data (1m, 5m, 30m, 4h) with configurable retention
  • Full support for async requests that span multiple threads
  • Responsive UI with mobile support
  • Optional central collector

четверг, 2 февраля 2023 г.

Maven dependensy tree


Поиск того какие библиотеки тянут зависимость: 

mvn dependency:tree -Dincludes=org.slf4j 


ключ для отключения проверки сертов сервера:

-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true


Import the root certificate into the JVM trust store

  1. keytool -importcert -alias startssl -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -file ca.der

пятница, 24 июня 2022 г.

Maven test

 <plugin>

    <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} -Dfile.encoding=UTF-8 #supporting ru text in test</argLine>
    </configuration>
</plugin>

пятница, 27 мая 2022 г.

Json model generator

 


<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>ru.company.model</targetPackage>
<includeAdditionalProperties>false</includeAdditionalProperties>
<generateBuilders>true</generateBuilders>
<serializable>true</serializable>
<formatDates>true</formatDates>
<formatDateTimes>true</formatDateTimes>
<inclusionLevel>NON_EMPTY</inclusionLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

Валидация по json scheme

 

/**
* Получение строки из файла в ресурсах
*
* @param location- местоположение файла
* @return содержимое файла
*/
@SneakyThrows
public static String getJsonFromFile(String location) {
Resource resource = new DefaultResourceLoader().getResource(location);
return StreamUtils.copyToString(resource.getInputStream(), UTF_8);
}

/**
* Получение JSON схемы из файла
*
* @param source - местоположение файла с JSON схемой
* @return - схема
*/
@SneakyThrows
private static Schema getSchema(String source) {
JSONObject jsonObject = new JSONObject(new JSONTokener(new DefaultResourceLoader()
.getResource(source)
.getInputStream()));
return SchemaLoader.builder()
.schemaClient(SchemaClient.classPathAwareClient())
.schemaJson(jsonObject)
.resolutionScope(source)
.build().load().build();
}


private String SCHEMA_IN_RESOURCE = "classpath:/schema/MySchame.json";
Schema schema = getSchema(SCHEMA_IN_RESOURCE);
schema.validate(new org.json.JSONObject("{}"));

четверг, 10 февраля 2022 г.

Unzip, unrar


private static final ArchiveStreamFactory FACTORY = new ArchiveStreamFactory();

private void unpackZip(Resource resource) {

    try (InputStream bufferedInputStream = new BufferedInputStream(resource.getInputStream());
ArchiveInputStream archiveInputStream = FACTORY.createArchiveInputStream(bufferedInputStream)) {
ArchiveEntry archiveEntry;

while ((archiveEntry = archiveInputStream.getNextEntry()) != null) {
String entryPath = convertToText(((ZipArchiveEntry) archiveEntry).getRawName());
log.info("archiveEntry is {}", entryPath);
if (!archiveEntry.isDirectory() && archiveInputStream.canReadEntryData(archiveEntry)) {
doSomeWork(new InputStreamResource(archiveInputStream), Paths.get(entryPath).getFileName().toString());
}
}
}
catch (IOException | ArchiveException e) {
log.error("Произошла ошибка при попытке чтения вложенного архива", e);
}

}

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

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

 private void unpackWith7Zip(Resource resource) {

    try (IInStream inStream = new ByteArrayStream(getCopyResourceStream(resource), false);
IInArchive inArchive = SevenZip.openInArchive(null, inStream)) {
for (ISimpleInArchiveItem item : inArchive.getSimpleInterface().getArchiveItems()) {
log.info("archiveEntry is {}", item.getPath());
if (!item.isFolder()) {
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
ExtractOperationResult result = item.extractSlow(data -> {
try {
byteArrayOutputStream.write(data);
} catch (IOException e) {
log.error("Error write data from file {} , exception: {}", item.getPath(), e.getLocalizedMessage());
}
return data.length;
});
if (result == ExtractOperationResult.OK) {
doSomeWork(new ByteArrayResource(byteArrayOutputStream.toByteArray()), Paths.get(item.getPath()).getFileName().toString());
                    } else {
log.error("Error unpack archive {}, with type {} , status: {}", item.getPath(), inArchive.getArchiveFormat(), result);
}
}
}
}
}
catch (Exception e) {
log.error("Error extracting archive");
}

}