Webviewer server can't access API on localhost

Product: webviewer

Product Version: [latest docker image on 2022-10-20]

Please give a brief summary of your issue:
webviewer server can’t access API on localhost

Please describe your issue and provide steps to reproduce it:
Our API (Java Springboot app) and webviewer server are running on docker, both in its own container, but both in same network, started with single docker-compose command. If webviewer server tries to access API via local IP address (192.168…) everything works fine. But if it tries to access API via “localhost”, we get an error. There is nothing in API log as it has never been hit, but there is an error in webviewer server’s container log:
20-Oct-2022 14:21:06.851 WARNING [pool-2-thread-6] com.pdftron.server.ServerJob.run During job id (Image/Fetched/p1_3wJH6dkzyqgR5qIbylmjDYi4izf-VmEZFxgPkRlo=19.png_dir/pageinfo.json):

Exception during job run of type pages
java.lang.Exception: WebViewer Server complete job (pageinfo.json) failed: unable to complete fetch of http://localhost:8086/secured/dataRooms/598d6de50f374626b6c34c993e4ab256/fileContent/19?version=7502.895981227744
Connection refused (Connection refused)
at com.pdftron.server.ServerJob.run(ServerJob.java:235)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
20-Oct-2022 14:21:06.851 WARNING [pool-2-thread-12] com.pdftron.server.ServerJob.run During job id (Image/Fetched/p1_3wJH6dkzyqgR5qIbylmjDYi4izf-VmEZFxgPkRlo=19.png_dir/pageimg0.jpg):
Exception during job run of type image
java.lang.Exception: WebViewer Server complete job (pageimg0.jpg) failed: unable to complete fetch of http://localhost:8086/secured/dataRooms/598d6de50f374626b6c34c993e4ab256/fileContent/19?version=7502.895981227744
Connection refused (Connection refused)
at com.pdftron.server.ServerJob.run(ServerJob.java:235)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
Closing ws connection from endpoint: CloseReason: code [1001], reason [null]
20-Oct-2022 14:21:07.013 INFO [http-apr-0.0.0.0-8090-exec-2] com.pdftron.server.ConnectionService$Connection.onCloseImpl Closing Connection, 0 outstanding

P.S. We need to use “localhost” because local IP address is transient.

Please provide a link to a minimal sample where the issue is reproducible:

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hello,

Thank you for contacting us about WebViewer. Since https://localhost inside the container with WebViewer Server is different from the https://localhost in the container your project is running, using “localhost” to load documents will fail (while using IP or URL paths will work).

One thing you can do is modify the docker compose used by the container with WebViewer Server, to point to the location of your project when using “localhost”

Best Regards,
Andrew Yip
Software Developer
PDFTron Systems, Inc.

Thanks for the quick answer.
By location, do you mean something like local file path? Could you please provide some example for this?

P.S.
Shouldn’t replacing “localhost” with service name from the container work? Our service is named “gateway” in docker-compose file, and I’ve tried replacing
http://localhost” with “gateway”
http://localhost:8086” with “gateway”
“localhost” with “gateway”
“localhost:8086” with gateway
but nothing seems to be working.

Regards,
Vedran

Hi,

Actually it looks like you can’t use “localhost” with docker composed. You will have to assign the container a name like the following

version: "3.0"
services:
    spring-project:
        image: spring-project-image
        ports:
           - 8081:8081
    pdfd-tomcat:
        image: pdftron/webviewer-server:latest

WebViewer Server can now be given URLs like spring-project:8081/filepath/myfile.pdf and it should be able to resolve them.

You can find out more about this in the docker networking guide

Best Regards,
Andrew Yip
Software Developer
PDFTron Systems, Inc.

Unfortunately this does not work. For URL gateway:8086/secured/dataRooms/598d6de50f374626b6c34c993e4ab256/fileContent/19?version=7502.895981227744 I’m getting error message java.lang.Exception: No default base address configured: cannot handle relative document URL. Maybe this would work for fetching local files, but it seems it’s not working for REST API.

P.S. SOLVED
We managed to solve the issue, at some point URL was formatted into hostname containing underscore, which is not valid character in this context.
Thanks again for helping!

Regards,
Vedran

Hello,

Thank you for the update. I’m glad you were able to resolve the issue.

Best Regards,
Andrew Yip
Software Developer
PDFTron Systems, Inc.