-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix method annotation callback do not work problem (#7754)
* fix method annotation callback * fix method callback annotation do not work issue * remove log file * remove static import
- Loading branch information
1 parent
ccbcccf
commit dee7373
Showing
7 changed files
with
213 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/api/MethodCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.config.spring.api; | ||
|
||
public interface MethodCallback { | ||
void oninvoke(String request); | ||
|
||
void onreturn(String response, String request); | ||
|
||
void onthrow(Throwable ex, String request); | ||
|
||
String getOnInvoke(); | ||
|
||
String getOnReturn(); | ||
|
||
String getOnThrow(); | ||
} |
81 changes: 81 additions & 0 deletions
81
...ava/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.config.spring.beans.factory.annotation; | ||
|
||
import org.apache.dubbo.config.annotation.DubboReference; | ||
import org.apache.dubbo.config.annotation.Method; | ||
import org.apache.dubbo.config.bootstrap.DubboBootstrap; | ||
import org.apache.dubbo.config.spring.api.HelloService; | ||
import org.apache.dubbo.config.spring.api.MethodCallback; | ||
import org.apache.dubbo.config.spring.impl.MethodCallbackImpl; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.EnableAspectJAutoProxy; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.event.annotation.AfterTestMethod; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration( | ||
classes = { | ||
ServiceAnnotationTestConfiguration.class, | ||
MethodConfigCallbackTest.class, | ||
}) | ||
@TestPropertySource(properties = { | ||
"packagesToScan = org.apache.dubbo.config.spring.context.annotation.provider", | ||
"consumer.version = ${demo.service.version}", | ||
"consumer.url = dubbo://127.0.0.1:12345?version=2.5.7", | ||
}) | ||
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) | ||
public class MethodConfigCallbackTest { | ||
|
||
@AfterTestMethod | ||
public void setUp() { | ||
DubboBootstrap.reset(); | ||
} | ||
|
||
@Bean("referenceAnnotationBeanPostProcessor") | ||
public ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor() { | ||
return new ReferenceAnnotationBeanPostProcessor(); | ||
} | ||
|
||
@Autowired | ||
private ConfigurableApplicationContext context; | ||
|
||
@Bean("methodCallback") | ||
public MethodCallback methodCallback() { | ||
return new MethodCallbackImpl(); | ||
} | ||
|
||
@DubboReference(check = false,methods = {@Method(name = "sayHello",oninvoke = "methodCallback.oninvoke",onreturn = "methodCallback.onreturn",onthrow = "methodCallback.onthrow")}) | ||
private HelloService helloServiceMethodCallBack; | ||
|
||
@Test | ||
public void testMethodAnnotationCallBack() { | ||
helloServiceMethodCallBack.sayHello("dubbo"); | ||
MethodCallback notify = (MethodCallback) context.getBean("methodCallback"); | ||
Assertions.assertEquals("dubbo invoke success", notify.getOnInvoke()); | ||
Assertions.assertEquals("dubbo return success", notify.getOnReturn()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...o-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/MethodCallbackImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.config.spring.impl; | ||
|
||
import org.apache.dubbo.config.spring.api.MethodCallback; | ||
|
||
public class MethodCallbackImpl implements MethodCallback { | ||
private String onInvoke; | ||
private String onReturn; | ||
private String onThrow; | ||
|
||
@Override | ||
public void oninvoke(String request) { | ||
this.onInvoke = "dubbo invoke success"; | ||
} | ||
|
||
@Override | ||
public void onreturn(String response, String request) { | ||
this.onReturn = "dubbo return success"; | ||
} | ||
|
||
@Override | ||
public void onthrow(Throwable ex, String request) { | ||
this.onThrow = "dubbo throw exception"; | ||
} | ||
|
||
public String getOnInvoke() { | ||
return this.onInvoke; | ||
} | ||
|
||
public String getOnReturn() { | ||
return this.onReturn; | ||
} | ||
|
||
public String getOnThrow() { | ||
return this.onThrow; | ||
} | ||
} |