Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Message
- $$fixit >>> customcommands >>> sendFileURL >>> https://my.mixtape.moe/ypzgwd.png
- //Error
- 11:47:43.006 [GuildCreateGroup-Thread-5] ERROR javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
- at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
- at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
- at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
- at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
- at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1497)
- at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:212)
- at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
- at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
- at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
- at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
- at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
- at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
- at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
- at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
- at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512)
- at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
- at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
- at com.github.vaerys.main.Utility.sendFileURL(Utility.java:297)
- at com.github.vaerys.handlers.CCHandler.handleCommand(CCHandler.java:133)
- at com.github.vaerys.handlers.CCHandler.<init>(CCHandler.java:52)
- at com.github.vaerys.handlers.MessageHandler.<init>(MessageHandler.java:43)
- at com.github.vaerys.main.AnnotationListener.onMessageReceivedEvent(AnnotationListener.java:77)
- at sx.blah.discord.api.events.EventDispatcher$MethodEventHandler.handle(EventDispatcher.java:723)
- at sx.blah.discord.api.events.EventDispatcher.lambda$null$19(EventDispatcher.java:653)
- at sx.blah.discord.api.events.EventDispatcher$$Lambda$48/921814994.run(Unknown Source)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
- at java.lang.Thread.run(Thread.java:745)
- Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
- at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
- at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
- at sun.security.validator.Validator.validate(Validator.java:260)
- at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
- at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
- at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
- at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1479)
- ... 23 more
- Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
- at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:145)
- at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:131)
- at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
- at sun.security.validator.P
- //Code
- public static IMessage sendFileURL(String message, String imageURL, IChannel channel, boolean loadMessage) {
- IMessage toDelete = null;
- if (loadMessage) {
- toDelete = sendMessage("`Loading...`", channel).get();
- }
- IMessage sentMessage = null;
- try {
- //setup for the stream
- final HttpURLConnection connection = (HttpURLConnection) new URL(imageURL).openConnection();
- connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) " + "AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31");
- InputStream stream = connection.getInputStream();
- sentMessage = (IMessage) XRequestBuffer.request(() -> {
- try {
- //set up the file name
- URL url = new URL(imageURL);
- String filename = FilenameUtils.getName(url.getPath());
- if (filename.equalsIgnoreCase("giphy.gif")) {
- return sendMessage(message + " " + imageURL, channel).get();
- }
- //checks if url is valid
- if (!isImageLink(filename)) {
- return sendMessage(message + " " + imageURL, channel).get();
- }
- //sends message/files
- if (StringUtils.containsOnly(message, "\n") || (message == null) || message.equals("") && imageURL != null) {
- return channel.sendFile("", stream, filename);
- } else if (message != null && !message.isEmpty() && imageURL != null) {
- return channel.sendFile(removeMentions(message), false, stream, filename);
- } else {
- logger.debug("Error sending File to channel with id: " + channel.getStringID() + " on guild with id: " + channel.getGuild().getStringID() +
- ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: No file to send");
- return null;
- }
- } catch (DiscordException e) {
- if (e.getMessage().contains("CloudFlare")) {
- return sendFileURL(message, imageURL, channel, false);
- } else {
- sendStack(e);
- return null;
- }
- } catch (MalformedURLException e) {
- return sendMessage(message + " " + imageURL, channel).get();
- } catch (IOException e) {
- sendStack(e);
- return null;
- } catch (MissingPermissionsException e) {
- logger.debug("Error sending File to channel with id: " + channel.getStringID() + " on guild with id: " + channel.getGuild().getStringID() +
- ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: Missing permissions.");
- return sendMessage(message + " <" + imageURL + ">", channel).get();
- }
- }).get();
- stream.close();
- } catch (MalformedURLException e) {
- sendStack(e);
- } catch (IOException e) {
- sendStack(e);
- }
- if (loadMessage && toDelete != null) {
- deleteMessage(toDelete);
- }
- return sentMessage;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement