jduo commented on a change in pull request #8583: URL: https://github.com/apache/arrow/pull/8583#discussion_r517155574
########## File path: java/flight/flight-core/src/main/java/org/apache/arrow/flight/ServerSessionMiddleware.java ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.arrow.flight; + +/** + * Middleware to add an optional set-session/session header. + */ +public class ServerSessionMiddleware implements FlightServerMiddleware { + + /** + * Factory class to provide instances of ServerSessionMiddleware for each call. + */ + public static class Factory implements FlightServerMiddleware.Factory<ServerSessionMiddleware> { + private final ServerSessionHandler sessionHandler; + + public Factory(ServerSessionHandler sessionHandler) { + this.sessionHandler = sessionHandler; + } + + @Override + public ServerSessionMiddleware onCallStarted(CallInfo info, CallHeaders incomingHeaders, + RequestContext context) { + + String session = sessionHandler.getSession(incomingHeaders); + + if (session == null) { + // No existing session provided, establishing a new session. + // Insert SET-SESSION header if ServerSessionHandler returns a non-null session. + session = sessionHandler.beginSession(incomingHeaders); + incomingHeaders.insert(FlightConstants.SET_SESSION_HEADER, session); + } + + return new ServerSessionMiddleware(session); + } + } + + private String session; + + private ServerSessionMiddleware(String session) { + this.session = session; + } + + @Override + public void onBeforeSendingHeaders(CallHeaders outgoingHeaders) { + outgoingHeaders.insert(FlightConstants.SET_SESSION_HEADER, session); Review comment: Do we have to send the session token back on every response? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
