Skip to content

Commit

Permalink
add SSL support, with local builds using no ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
barnhill committed Jun 20, 2024
1 parent 9a588ca commit c53f092
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ MAINTAINER [email protected]

ADD build/libs/barcode-api.jar /

ENV PROFILE=${PROFILE:-nossl}

VOLUME /tmp

EXPOSE 8080

ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/barcode-api.jar"]
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "-Dspring.profiles.active=${PROFILE}", "/barcode-api.jar"]
52 changes: 47 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,63 @@ Barcode Java API is a lightweight and easy-to-use Java library for generating ba

## Usage

To use SSL:

- Mount a docker volume `/ssl` that points to a host folder that contains the SSL certificates for the server.
Name the full chain certificate as `fullchain.pem` and the private key as `privkey.pem`
- Pass the environment variable to the container: `PROFILE=prod`

To use without SSL:
- Pass the environment variable to the container: `PROFILE=nossl` or pass no value for `PROFILE`

```
docker run --rm -p 8080:8080 bradbarnhill/barcode-api
docker run --rm -p 8443:8443 bradbarnhill/barcode-api
```

Then browse to the following url to check out the documentation:

### Test
To generate a sample barcode using this API go to:
#### SSL
```
http://localhost:8080/swagger-ui/index.html
https://localhost:8443/v1/barcode/upca/data/636711605328?imageFormat=png&w=600&h=300&label=false
```

To generate a sample barcode using this API go to:
#### No SSL
```
http://localhost:8080/v1/barcode/upca/data/636711605328?imageFormat=png&w=600&h=300&label=false
```

Error codes will be returned in the headers for cases of invalid input parameters.
## Response Headers
#### Error codes will be returned in the headers for cases of invalid input parameters.

| Header | Value |
|:-----------------:|:-----------------------------------------------------------------------------------------------:|
| x-error | EUPCA-1: Data length invalid. (Length must be 11 or 12) |

#### Standard Headers

| Header | Value |
|:-----------------:|:-----------------------------------------------------------------------------------------------:|
| X-Barcode-Version | Barcode for Java 2.6.4 |
| X-Draw-Time | 0.374072 ms |
| X-Encoded-Type | UPCA |
| X-Encoded-Value | 10100110010010011011110101000110110001010111101010100010010010001110100111001011001101101100101 |
| X-Encoding-Time | 0.576274 ms |
| X-Label-Font | Serif |
| X-Raw-Value | 123456789012 |
| X-Served-By | barcode-api-c9f7bdd88-rq9wp |
| X-Served-By | barcode.someserver.com |

## Documentation:
#### SSL
```
https://localhost:8443/swagger-ui/index.html
```

#### No SSL
```
http://localhost:8080/swagger-ui/index.html
```

## Contributing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@OpenAPIDefinition(servers = {
@Server(url = "https://barcode.pnuema.com/", description = "Remote"),
@Server(url = "https://barcodeapi.link/", description = "Remote"),
@Server(url = "http://localhost:8080/", description = "Local")
@Server(url = "http://localhost:8443/", description = "Local")
})
@SpringBootApplication
@EnableCaching
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions src/main/resources/application-ssl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server:
port: 8443
http2:
enabled: true
compression:
enabled: true
min-response-size: 2048
mime-types: application/hal+json,application/json,application/xml,text/html,text/xml,text/plain,image/png
servlet:
session:
timeout: 10s
error:
whitelabel:
enabled: false
ssl:
certificate: /ssl/fullchain.pem
certificate-private-key: /ssl/privkey.pem
logging:
level:
org:
springframework:
web:
filter:
CommonsRequestLoggingFilter: DEBUG
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
spring:
profiles:
active: prod
active: nossl

0 comments on commit c53f092

Please sign in to comment.