Skip to content

Commit

Permalink
Fix triple protocol for native image
Browse files Browse the repository at this point in the history
Signed-off-by: JermaineHua <[email protected]>
  • Loading branch information
CrazyHZM committed Feb 9, 2025
1 parent 0871406 commit bd56cbb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.dubbo.aot.api.JdkProxyDescriber;
import org.apache.dubbo.aot.api.ProxyDescriberRegistrar;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.MetadataServiceV2;
import org.apache.dubbo.rpc.service.Destroyable;
import org.apache.dubbo.rpc.service.EchoService;

Expand All @@ -30,6 +31,7 @@ public class MetadataProxyDescriberRegistrar implements ProxyDescriberRegistrar
public List<JdkProxyDescriber> getJdkProxyDescribers() {
List<JdkProxyDescriber> describers = new ArrayList<>();
describers.add(buildJdkProxyDescriber(MetadataService.class));
describers.add(buildJdkProxyDescriber(MetadataServiceV2.class));
return describers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.apache.dubbo.aot.api.ReflectionTypeDescriberRegistrar;
import org.apache.dubbo.aot.api.TypeDescriber;
import org.apache.dubbo.metadata.MetadataInfo;
import org.apache.dubbo.metadata.MetadataInfoV2;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.MetadataServiceV2;

import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -33,7 +35,9 @@ public class MetadataReflectionTypeDescriberRegistrar implements ReflectionTypeD
public List<TypeDescriber> getTypeDescribers() {
List<TypeDescriber> typeDescribers = new ArrayList<>();
typeDescribers.add(buildTypeDescriberWithPublicMethod(MetadataService.class));
typeDescribers.add(buildTypeDescriberWithPublicMethod(MetadataServiceV2.class));
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(MetadataInfo.class));
typeDescribers.add(buildTypeDescriberWithDeclaredConstructors(MetadataInfoV2.class));
return typeDescribers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.dubbo.rpc.protocol.tri.rest.support.spring;

import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
import org.apache.dubbo.common.utils.DefaultParameterNameReader;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ScopeModelInitializer;
import org.apache.dubbo.rpc.protocol.tri.rest.argument.CompositeArgumentResolver;
import org.apache.dubbo.rpc.protocol.tri.rest.argument.GeneralTypeConverter;

public class RestSpringScopeModelInitializer implements ScopeModelInitializer {
@Override
public void initializeFrameworkModel(FrameworkModel frameworkModel) {
ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory();
beanFactory.registerBean(GeneralTypeConverter.class);
beanFactory.registerBean(DefaultParameterNameReader.class);
beanFactory.registerBean(CompositeArgumentResolver.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rest-spring=org.apache.dubbo.rpc.protocol.tri.rest.support.spring.RestSpringScopeModelInitializer
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegationV2;
import org.apache.dubbo.registry.integration.ExporterFactory;
import org.apache.dubbo.registry.support.RegistryManager;
import org.apache.dubbo.rpc.model.ApplicationModel;
Expand All @@ -37,5 +38,7 @@ public void initializeApplicationModel(ApplicationModel applicationModel) {
ScopeBeanFactory beanFactory = applicationModel.getBeanFactory();
beanFactory.registerBean(RegistryManager.class);
beanFactory.registerBean(MetadataServiceDelegation.class);
beanFactory.registerBean(MetadataServiceDelegationV2.class);
beanFactory.registerBean(MetadataServiceDelegationV2.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static RemoteMetadataService referMetadataService(ServiceInstance instanc
RemoteMetadataService remoteMetadataService;
ProxyFactory proxyFactory =
applicationModel.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
if (useV2) {
if (useV2 && !inNativeImage) {
Invoker<MetadataServiceV2> invoker = protocol.refer(MetadataServiceV2.class, url);

if (url.getParameter(AUTH_KEY, false)) {
Expand Down

0 comments on commit bd56cbb

Please sign in to comment.