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.*;
020import org.apache.juneau.http.remote.*;
021import org.apache.juneau.http.response.*;
022import org.apache.juneau.rest.*;
023
024import jakarta.servlet.*;
025
026/**
027 * A specialized {@link RestOpContext} for handling <js>"RRPC"</js> HTTP methods.
028 *
029 * <h5 class='section'>Notes:</h5><ul>
030 *    <li class='note'>This class is thread safe and reusable.
031 * </ul>
032 *
033 * <h5 class='section'>See Also:</h5><ul>
034 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestRpc">REST/RPC</a>
035 * </ul>
036 */
037public class RrpcRestOpContext extends RestOpContext {
038
039   private final RrpcInterfaceMeta meta;
040
041   /**
042    * Constructor.
043    *
044    * @param builder The builder for this method context.
045    * @throws ServletException Problem with metadata was detected.
046    */
047   protected RrpcRestOpContext(RestOpContext.Builder builder) throws ServletException {
048      super(builder);
049
050      ClassMeta<?> interfaceClass = getBeanContext().getClassMeta(getJavaMethod().getGenericReturnType());
051      meta = new RrpcInterfaceMeta(interfaceClass.getInnerClass(), null);
052      if (meta.getMethodsByPath().isEmpty())
053         throw new InternalServerError("Method {0} returns an interface {1} that doesn't define any remote methods.", getJavaMethod().getName(), interfaceClass.getFullName());
054
055   }
056
057   @Override
058   public RrpcRestOpSession.Builder createSession(RestSession session) {
059      return RrpcRestOpSession.create(this, session);
060   }
061
062   /**
063    * Returns the metadata about the RRPC Java method.
064    *
065    * @return The metadata about the RRPC Java method.
066    */
067   protected RrpcInterfaceMeta getMeta() {
068      return meta;
069   }
070}