comparison src/main/java/org/monetdb/mcl/net/MapiSocket.java @ 905:a52bc2dcdb8c

Implement ClientInfo API And move ClientInfo out out MapiSocket
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Mon, 17 Jun 2024 15:54:45 +0200 (10 months ago)
parents 2d880f90be2a
children d416e9b6b3d0
comparison
equal deleted inserted replaced
904:2d880f90be2a 905:a52bc2dcdb8c
23 import java.io.Writer; 23 import java.io.Writer;
24 import java.net.*; 24 import java.net.*;
25 import java.nio.charset.StandardCharsets; 25 import java.nio.charset.StandardCharsets;
26 import java.security.MessageDigest; 26 import java.security.MessageDigest;
27 import java.security.NoSuchAlgorithmException; 27 import java.security.NoSuchAlgorithmException;
28 import java.sql.SQLClientInfoException;
29 import java.util.*; 28 import java.util.*;
30 29
31 import javax.net.ssl.SSLException; 30 import javax.net.ssl.SSLException;
32 31
33 import org.monetdb.mcl.MCLException; 32 import org.monetdb.mcl.MCLException;
116 private BufferedMCLReader reader; 115 private BufferedMCLReader reader;
117 /** MCLWriter on the OutputStream */ 116 /** MCLWriter on the OutputStream */
118 private BufferedMCLWriter writer; 117 private BufferedMCLWriter writer;
119 /** protocol version of the connection */ 118 /** protocol version of the connection */
120 private int version; 119 private int version;
121 private ClientInfo clientInfo; 120 private boolean supportsClientInfo;
122 121
123 /** Whether we should follow redirects. 122 /** Whether we should follow redirects.
124 * Not sure why this needs to be separate 123 * Not sure why this needs to be separate
125 * from 'ttl' but someone someday explicitly documented setTtl 124 * from 'ttl' but someone someday explicitly documented setTtl
126 * with 'to disable completely, use followRedirects' so 125 * with 'to disable completely, use followRedirects' so
497 // String endianPart = parts[4]; 496 // String endianPart = parts[4];
498 String passwordHashPart = parts[5]; 497 String passwordHashPart = parts[5];
499 String optionsPart = parts.length > 6 ? parts[6] : null; 498 String optionsPart = parts.length > 6 ? parts[6] : null;
500 // String binaryPart = parts.length > 7 ? parts[7] : null; 499 // String binaryPart = parts.length > 7 ? parts[7] : null;
501 500
502 if (parts.length > 9 && target.isClientInfo()) { 501 if (parts.length > 9)
503 clientInfo = new ClientInfo(); 502 supportsClientInfo = true;
504 try {
505 String clientApplication = target.getClientApplication();
506 String clientRemark = target.getClientRemark();
507 if (!clientApplication.isEmpty())
508 clientInfo.set("ApplicationName", clientApplication);
509 if (!clientRemark.isEmpty())
510 clientInfo.set("ClientRemark", clientRemark);
511 } catch (SQLClientInfoException e) {
512 String keys = String.join(", ", e.getFailedProperties().keySet());
513 throw new MCLException("Could not set ClientInfo properties: " + keys, e);
514 }
515 }
516 503
517 String userResponse; 504 String userResponse;
518 String password = target.getPassword(); 505 String password = target.getPassword();
519 if (serverTypePart.equals("merovingian") && !target.getLanguage().equals("control")) { 506 if (serverTypePart.equals("merovingian") && !target.getLanguage().equals("control")) {
520 userResponse = "merovingian"; 507 userResponse = "merovingian";
786 773
787 public boolean isDebug() { 774 public boolean isDebug() {
788 return target.isDebug(); 775 return target.isDebug();
789 } 776 }
790 777
791 public boolean hasClientInfo() { 778 public boolean canClientInfo() {
792 return clientInfo != null; 779 return supportsClientInfo;
793 } 780 }
794 781
795 public ClientInfo getClientInfo() {
796 if (clientInfo == null)
797 clientInfo = new ClientInfo();
798 return clientInfo;
799 }
800 782
801 /** 783 /**
802 * Inner class that is used to write data on a normal stream as a 784 * Inner class that is used to write data on a normal stream as a
803 * blocked stream. A call to the flush() method will write a 785 * blocked stream. A call to the flush() method will write a
804 * "final" block to the underlying stream. Non-final blocks are 786 * "final" block to the underlying stream. Non-final blocks are