translator icon indicating copy to clipboard operation
translator copied to clipboard

KTOR 3.0.0 breaks it

Open gigitalz opened this issue 1 year ago • 4 comments

It looks like this breaks with the new KTOR:

Caused by: java.lang.ClassNotFoundException: io.ktor.client.plugins.UserAgent
        at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

Any quick fix other than rolling back KTOR version before 3.0.0?

Code:
`                val translator by lazy { Translator() }
                val ret = translator.translate("שר החוץ האמריקני טוני בלינקן ושר ההגנה האמריקני לוייד אוסטין שיגרו אתמול (שני) מכתב לשרים דרמר וגלנט ובו הם דורשים כי ישראל תבצע תוך 30 יום צעדים לשיפור המצב ההומניטארי בעזה כדי להימנע מהשלכות על אספקת הנשק האמריקני לישראל. זה המכתב המלא (עליו דיווחה לראשונה)", Language.ENGLISH)`

gigitalz avatar Oct 15 '24 16:10 gigitalz

I believe if you pass your own HttpClient to the Translator constructor it should fix the issue. I set a user agent in the default HttpClient in the constructor.

I might not fix this in a timely manner however you are welcome to submit a pull request fixing the issue.

therealbush avatar Oct 16 '24 02:10 therealbush

Translator(HttpClient(CIO) {
        HttpResponseValidator {
            // This is run for all responses
            validateResponse { response ->
                if (!response.status.isSuccess()) {
                    throw TranslationException("Error caught from HTTP request: ${response.status}")
                }
            }
            // This is run only when an exception is thrown, including our custom ones
            handleResponseExceptionWithRequest { cause, _ ->
                if (cause !is TranslationException) {
                    throw TranslationException("Exception caught from HTTP request", cause)
                }
            }
        })

therealbush avatar Oct 16 '24 02:10 therealbush

the above just removes the user agent setup. I don't remember if the user agent was necessary, if it is you would have to figure out how to set the user agent on this new ktor version.

therealbush avatar Oct 16 '24 02:10 therealbush

I can't reproduce this issue. Are you still having troubles?

therealbush avatar Nov 12 '24 20:11 therealbush