2017-10-17 142 views
1

我已經使用方解石幫助構建了我的自定義方案。現在我想通過servlet公開它並通過Avatica連接到它。我使用的是servlet,因爲我的容器是JIRA。這裏是一些servlet的相關代碼通過自定義servlet公開基於方解石的數據庫通過Avatica公開的方法

public class JDBCServlet extends HttpServlet { 

private final Service service; 
private final ProtobufHandler pbHandler; 
private final ProtobufTranslation protobufTranslation; 
private final MetricsSystem metrics; 

final ThreadLocal<UnsynchronizedBuffer> threadLocalBuffer; 

public JDBCServlet(LocalDBProvider provider) { 
    this.service = provider.service(); 
    this.metrics = provider.metrics(); 
    this.protobufTranslation = new ProtobufTranslationImpl(); 
    this.pbHandler = new ProtobufHandler(service, protobufTranslation, metrics); 
    this.threadLocalBuffer = new ThreadLocal<UnsynchronizedBuffer>() { 
     @Override 
     public UnsynchronizedBuffer initialValue() { 
      return new UnsynchronizedBuffer(); 
     } 
    }; 
} 

@Override 
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 
    System.out.println("DO GET DO GET"); 
    doPost(req, resp); 
} 

@Override 
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    System.out.println("DO POST DO POST"); 
    response.setContentType("application/octet-stream;charset=utf-8"); 
    response.setStatus(HttpServletResponse.SC_OK); 
    final byte[] requestBytes; 
    // Avoid a new buffer creation for every HTTP request 
    final UnsynchronizedBuffer buffer = threadLocalBuffer.get(); 
    try (ServletInputStream inputStream = request.getInputStream()) { 
     requestBytes = AvaticaUtils.readFullyToBytes(inputStream, buffer); 
    } finally { 
     buffer.reset(); 
    } 

    Handler.HandlerResponse<byte[]> handlerResponse; 
    try { 
     handlerResponse = pbHandler.apply(requestBytes); 
    } catch (Exception e) { 
     handlerResponse = pbHandler.convertToErrorResponse(e); 
    } 
    response.setStatus(handlerResponse.getStatusCode()); 
    response.getOutputStream().write(handlerResponse.getResponse()); 
    response.getOutputStream().close(); 
} 
} 

代碼是基於AvaticaProtobufHandler withouth Jet相關的東西。

服務使用本地服務和CalciteConnection與我的自定義模式內置:

new LocalService(DRIVER.createMeta((AvaticaConnection) bootstrap.getConnection())); 

當松鼠連接(與avatica罐子:)網址爲: JDBC:avatica:遠程:URL = http://127.0.0.1:2990/jira/plugins/servlet/smartqljdbctest;serialization=PROTOBUF

幾個HTTP POST請求與驅動程序握手,但Meta.toProto()方法中的所有內容都失敗:

} else { 
     // Can a "row" be a primitive? A struct? Only an Array? 
     throw new RuntimeException("Only arrays are supported"); 
    } 

我假設我已經錯誤地引導了servlet,但不知道爲什麼?

回答

0

搞亂了方解石我已經設法處理這從Evatica服務器示例使用JDBCMeta。

從我以前的解決方案中,我認爲基於CalciteConnection的驅動程序生成的Meta與avatica LocalService實現不兼容。

相關問題