001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.rest.rrpc; 014 015import jakarta.servlet.*; 016 017import org.apache.juneau.*; 018import org.apache.juneau.http.remote.*; 019import org.apache.juneau.http.response.*; 020import org.apache.juneau.rest.*; 021 022/** 023 * A specialized {@link RestOpContext} for handling <js>"RRPC"</js> HTTP methods. 024 * 025 * <h5 class='section'>Notes:</h5><ul> 026 * <li class='note'>This class is thread safe and reusable. 027 * </ul> 028 * 029 * <h5 class='section'>See Also:</h5><ul> 030 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.RestRpc">REST/RPC</a> 031 * </ul> 032 */ 033public class RrpcRestOpContext extends RestOpContext { 034 035 private final RrpcInterfaceMeta meta; 036 037 /** 038 * Constructor. 039 * 040 * @param builder The builder for this method context. 041 * @throws ServletException Problem with metadata was detected. 042 */ 043 protected RrpcRestOpContext(RestOpContext.Builder builder) throws ServletException { 044 super(builder); 045 046 ClassMeta<?> interfaceClass = getBeanContext().getClassMeta(getJavaMethod().getGenericReturnType()); 047 meta = new RrpcInterfaceMeta(interfaceClass.getInnerClass(), null); 048 if (meta.getMethodsByPath().isEmpty()) 049 throw new InternalServerError("Method {0} returns an interface {1} that doesn't define any remote methods.", getJavaMethod().getName(), interfaceClass.getFullName()); 050 051 } 052 053 @Override 054 public RrpcRestOpSession.Builder createSession(RestSession session) { 055 return RrpcRestOpSession.create(this, session); 056 } 057 058 /** 059 * Returns the metadata about the RRPC Java method. 060 * 061 * @return The metadata about the RRPC Java method. 062 */ 063 protected RrpcInterfaceMeta getMeta() { 064 return meta; 065 } 066}