Skip to content

Commit

Permalink
Merge pull request #1160 from lilai23/1.0.x
Browse files Browse the repository at this point in the history
【bugfix】修复上下文类加载器切换恢复异常问题(1.0.x)
  • Loading branch information
robotLJW authored Mar 31, 2023
2 parents 9abdba2 + 19874af commit c68dd3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,14 @@ private HttpRequest rebuildRequest(String uriNew, String method, HttpRequest htt
return httpPost;
} else {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(HttpClient.class.getClassLoader());
final Optional<Object> result = ReflectUtils
.buildWithConstructor(COMMON_REQUEST_CLASS,
new Class[]{String.class, String.class}, new Object[]{method, uriNew});
Thread.currentThread().setContextClassLoader(contextClassLoader);
final Optional<Object> result;
try {
Thread.currentThread().setContextClassLoader(HttpClient.class.getClassLoader());
result = ReflectUtils.buildWithConstructor(COMMON_REQUEST_CLASS,
new Class[]{String.class, String.class}, new Object[]{method, uriNew});
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
return (HttpRequest) result.orElse(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public Collection<ServiceInstance> getInstances(String serviceId) throws QueryIn
LOGGER.log(Level.WARNING, "Can not query service instances from registry center!", exception);
Thread.currentThread().setContextClassLoader(contextClassLoader);
throw new QueryInstanceException(exception.getMessage());
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}

Expand Down Expand Up @@ -270,7 +272,9 @@ public void close() {
*/
public static class ZkInstanceSerializer<T> implements InstanceSerializer<T> {
private final ObjectMapper mapper;

private final Class<T> payloadClass;

private final JavaType type;

/**
Expand Down

0 comments on commit c68dd3b

Please sign in to comment.