Skip to content

Commit

Permalink
Merge pull request #32 from swisspost/feature/update_vertx
Browse files Browse the repository at this point in the history
Updated Vert.x and dependencies
  • Loading branch information
mcweba authored Jan 17, 2024
2 parents 33452a3 + 4bd8f10 commit 95e7164
Show file tree
Hide file tree
Showing 5 changed files with 789 additions and 19 deletions.
28 changes: 10 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.swisspush</groupId>
<artifactId>rest-mirror</artifactId>
<version>3.0.5-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<name>rest-mirror</name>
<description>
A verticle that mirrors resources, which are provided as zip into a rest storage.
Expand Down Expand Up @@ -37,14 +37,6 @@
<url>https://github.com/swisspush/vertx-rest-mirror.git</url>
</scm>
<dependencies>
<!-- swisspush dependencies -->
<dependency>
<groupId>org.swisspush</groupId>
<artifactId>rest-storage</artifactId>
<version>3.0.0</version>
</dependency>

<!-- other deps -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
Expand All @@ -60,25 +52,25 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<version>2.15.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
<version>2.0.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.6</version>
<artifactId>slf4j-reload4j</artifactId>
<version>2.0.10</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -91,7 +83,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -101,9 +93,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.1</version>
<version>5.4.0</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -381,7 +373,7 @@
</profile>
</profiles>
<properties>
<vertx.version>4.2.1</vertx.version>
<vertx.version>4.5.1</vertx.version>
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
<sonatypeOssDistMgmtSnapshotsUrl>
https://oss.sonatype.org/content/repositories/snapshots/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/swisspush/mirror/ZipEntryPutter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swisspush.reststorage.MimeTypeResolver;
import org.swisspush.mirror.util.MimeTypeResolver;

import java.util.Map;

Expand Down
61 changes: 61 additions & 0 deletions src/main/java/org/swisspush/mirror/util/MimeTypeResolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.swisspush.mirror.util;

import org.slf4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import static org.slf4j.LoggerFactory.getLogger;

public class MimeTypeResolver {

private static final Logger log = getLogger(MimeTypeResolver.class);
private Map<String, String> mimeTypes = new HashMap<>();

private final String defaultMimeType;

public MimeTypeResolver(String defaultMimeType) {
this.defaultMimeType = defaultMimeType;
Properties props = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("mime-types.properties");
try {
props.load(in);
} catch (IOException e) {
throw new RuntimeException(e);

Check warning on line 27 in src/main/java/org/swisspush/mirror/util/MimeTypeResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/mirror/util/MimeTypeResolver.java#L26-L27

Added lines #L26 - L27 were not covered by tests
} finally {
try {
if(in != null) {
in.close();
}
} catch (IOException ex) {
log.debug("close() failed", ex);

Check warning on line 34 in src/main/java/org/swisspush/mirror/util/MimeTypeResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/swisspush/mirror/util/MimeTypeResolver.java#L33-L34

Added lines #L33 - L34 were not covered by tests
}
}

for( Map.Entry<Object, Object> entry : props.entrySet()) {
mimeTypes.put(((String)entry.getKey()).toLowerCase(), (String)entry.getValue());
}
}

public String resolveMimeType(String path) {
int lastSlash = path.lastIndexOf("/");
String part = path;
if(lastSlash >= 0 && !path.endsWith("/")) {
part = part.substring(lastSlash+1);
}
int dot = part.lastIndexOf(".");
if(dot == -1 || part.endsWith(".")) {
return defaultMimeType;
} else {
String extension = part.substring(dot+1);
String type = mimeTypes.get(extension.toLowerCase());
if(type==null) {
type = "text/plain";
}
return type;
}
}
}
Loading

0 comments on commit 95e7164

Please sign in to comment.