|
|
|
@ -18,6 +18,14 @@
|
|
|
|
|
package com.tencent.cloud.rpc.enhancement.plugin;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
import com.tencent.polaris.configuration.client.JustForTest;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import org.springframework.cloud.client.DefaultServiceInstance;
|
|
|
|
|
import org.springframework.cloud.client.ServiceInstance;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -27,6 +35,8 @@ import org.springframework.cloud.client.ServiceInstance;
|
|
|
|
|
*/
|
|
|
|
|
public class EnhancedPluginContext {
|
|
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(EnhancedPluginContext.class);
|
|
|
|
|
|
|
|
|
|
private EnhancedRequestContext request;
|
|
|
|
|
|
|
|
|
|
private EnhancedResponseContext response;
|
|
|
|
@ -86,8 +96,30 @@ public class EnhancedPluginContext {
|
|
|
|
|
return targetServiceInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JustForTest
|
|
|
|
|
public void setTargetServiceInstance(ServiceInstance targetServiceInstance) {
|
|
|
|
|
this.targetServiceInstance = targetServiceInstance;
|
|
|
|
|
this.setTargetServiceInstance(targetServiceInstance, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTargetServiceInstance(ServiceInstance targetServiceInstance, URI url) {
|
|
|
|
|
if (Objects.nonNull(targetServiceInstance)) {
|
|
|
|
|
this.targetServiceInstance = targetServiceInstance;
|
|
|
|
|
}
|
|
|
|
|
else if (Objects.nonNull(url)) {
|
|
|
|
|
DefaultServiceInstance defaultServiceInstance = new DefaultServiceInstance();
|
|
|
|
|
defaultServiceInstance.setUri(url);
|
|
|
|
|
if (defaultServiceInstance.isSecure()) {
|
|
|
|
|
defaultServiceInstance.setPort(443);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
defaultServiceInstance.setPort(80);
|
|
|
|
|
}
|
|
|
|
|
this.targetServiceInstance = defaultServiceInstance;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.targetServiceInstance = new DefaultServiceInstance();
|
|
|
|
|
LOGGER.warn("TargetServiceInstance is empty.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|