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