/** * Add a custom resource implementation endpoint. * * @param ref * @param basePath prefix path of resource */ @Override public void addResourceFactory(ResourceFactory ref, String basePath) { // 多应用下改造点 super.addResourceFactory(ref, basePath); }
@Override public ResourceInvoker getResourceInvoker(HttpRequest request) { // 多应用下改造点 return super.getResourceInvoker(request); }
@Override public void invoke(HttpRequest request, HttpResponse response, ResourceInvoker invoker) { // 可以执行一下逻辑,例如切换ClassLoader等 super.invoke(request, response, invoker); } }
threadLocalProviderFactory = new ThreadLocalResteasyProviderFactory(providerFactory); ResteasyProviderFactory.setInstance(threadLocalProviderFactory); AsynchronousDispatcher asyncDispatcher = new AsynchronousDispatcher(providerFactory); asyncDispatcher.setMaxCacheSize(asyncJobServiceMaxJobResults); asyncDispatcher.setMaxWaitMilliSeconds(asyncJobServiceMaxWait); asyncDispatcher.setThreadPoolSize(asyncJobServiceThreadPoolSize); asyncDispatcher.setBasePath(asyncJobServiceBasePath); asyncDispatcher.getUnwrappedExceptions().addAll(unwrappedExceptions); dispatcher = asyncDispatcher; asyncDispatcher.start(); dis.getUnwrappedExceptions().addAll(unwrappedExceptions); dispatcher = dis; registry = dispatcher.getRegistry(); if (widerRequestMatching) ((ResourceMethodRegistry) registry).setWiderMatching(widerRequestMatching); dispatcher.getDefaultContextObjects().putAll(defaultContextObjects); dispatcher.getDefaultContextObjects().put(Configurable.class, providerFactory); dispatcher.getDefaultContextObjects().put(Providers.class, providerFactory); dispatcher.getDefaultContextObjects().put(Registry.class, registry); dispatcher.getDefaultContextObjects().put(Dispatcher.class, dispatcher); dispatcher.getDefaultContextObjects().put(InternalDispatcher.class, InternalDispatcher.getInstance()); contextDataMap.putAll(dispatcher.getDefaultContextObjects());
Registry registry = (Registry) context.getAttribute(Registry.class.getName()); if (registry == null) { registry = servletContainerDispatcher.getDispatcher().getRegistry(); Map<String, List<ResourceInvoker>> bounded = rm.getBounded(); for (Entry<String, List<ResourceInvoker>> e : bounded.entrySet()) { LOGGER.debug("Examining {}", e.getKey()); for (ResourceInvoker r : e.getValue()) { if(LOGGER.isLevelEnabled(Level.DEBUG)){ LOGGER.debug("Examining {} for method {} in class {}", e.getKey(), r.getMethod().getName(), r.getMethod().getDeclaringClass()); if (r.getMethod().getDeclaringClass().getName().equals(className)) { removeRegistration(rm, e.getKey(), r.getMethod());
deployment.start(); deployment.getDispatcher().getDefaultContextObjects() .put(ClusterMembershipService.class, atomix.getMembershipService()); deployment.getDispatcher().getDefaultContextObjects() .put(ClusterCommunicationService.class, atomix.getCommunicationService()); deployment.getDispatcher().getDefaultContextObjects() .put(ClusterEventService.class, atomix.getEventService()); deployment.getDispatcher().getDefaultContextObjects() .put(PrimitiveFactory.class, atomix.getPrimitivesService()); deployment.getDispatcher().getDefaultContextObjects() .put(PrimitivesService.class, atomix.getPrimitivesService()); deployment.getDispatcher().getDefaultContextObjects() .put(EventManager.class, new EventManager()); deployment.getDispatcher().getDefaultContextObjects() .put(AtomixRegistry.class, atomix.getRegistry()); deployment.getDispatcher().getProviderFactory().register(new JacksonProvider(createObjectMapper()));
rootNode.addInvoker(fullpath, invoker); } else { root.addInvoker(classExpression, fullpath, invoker); ResourceLocatorInvoker locator = new ResourceLocatorInvoker(rf, injectorFactory, providerFactory, method); if (widerMatching) { rootNode.addInvoker(fullpath, locator); } else { root.addInvoker(classExpression, fullpath, locator);
public void start() { try { startInternal(); } finally { ThreadLocalResteasyProviderFactory.pop(); } }
protected void sendBuiltResponse(BuiltResponse builtResponse, HttpRequest httpRequest, HttpResponse httpResponse, Consumer<Throwable> onComplete) throws IOException { // send headers only if we're not streaming, or if we're sending the first stream element boolean sendHeaders = sendHeaders(); ServerResponseWriter.writeNomapResponse(builtResponse, httpRequest, httpResponse, dispatcher.getProviderFactory(), onComplete, sendHeaders); }
public void asynchronousDelivery(HttpRequest request, HttpResponse response, Response jaxrsResponse, Consumer<Throwable> onComplete) throws IOException { if (jaxrsResponse == null) return; try { pushContextObjects(request, response); ServerResponseWriter.writeNomapResponse((BuiltResponse) jaxrsResponse, request, response, providerFactory, onComplete); } finally { ResteasyContext.removeContextDataLevel(); } }
private void removeRegistration(ResourceMethodRegistry rm, String path, Method method) { try { if (rm.isWiderMatching()) { RootNode rootNode = get(rm, "rootNode"); rootNode.removeBinding(path, method); } else { String methodpath = method.getAnnotation(Path.class).value(); String classExpression = path.replace(methodpath, ""); if (classExpression.endsWith("/")) { classExpression.substring(0, classExpression.length() - 1); } RootClassNode root = get(rm, "root"); root.removeBinding(classExpression, path, method); } } catch (Exception e) { LOGGER.error("Could not remove method registration from path {}, {}", e, path, method); } }
protected boolean internalResume(Throwable exc, Consumer<Throwable> onComplete) { ResteasyContext.pushContextDataMap(contextDataMap); dispatcher.asynchronousExceptionDelivery(request, response, exc, t -> { onComplete.accept(t); completionCallbacks(exc); }); return true; }
@Override public Map<Class<?>, ExceptionMapper> getExceptionMappers() { return ((ResteasyProviderFactoryImpl)getDelegate()).getExceptionMappers(); }
public int compare(Entry<?> entry, Entry<?> entry1) { int val = compareTypes(entry, entry1); if (val == 0) val = entry.compareTo(entry1); return val; } }
@Override public Object invoke(HttpRequest request, HttpResponse httpResponse, Object resource) throws Failure, ApplicationException { if (!Provider.class.isInstance(resource)) { return super.invoke(request, httpResponse, resource); } Object[] args = injectArguments(request, httpResponse); RestfulContainerRequest req = new RestfulContainerRequest(); req.setInterfaceName(method.getResourceClass().getClazz().getName()); req.setMethodName(method.getMethod().getName()); req.setParamtersDesc(ReflectUtil.getMethodParamDesc(method.getMethod())); req.setArguments(args); req.setHttpRequest(request); req.setAttachments(RestfulUtil.decodeAttachments(request.getMutableHeaders())); try { Response resp = Provider.class.cast(resource).call(req); RestfulUtil.encodeAttachments(httpResponse.getOutputHeaders(), resp.getAttachments()); return resp.getValue(); } catch (Exception e) { if (e != null && e instanceof RuntimeException) { throw (RuntimeException) e; } throw new InternalServerErrorException("provider call process error:" + e.getMessage(), e); } }
threadLocalProviderFactory = new ThreadLocalResteasyProviderFactory(providerFactory); ResteasyProviderFactory.setInstance(threadLocalProviderFactory); AsynchronousDispatcher asyncDispatcher = new AsynchronousDispatcher(providerFactory); asyncDispatcher.setMaxCacheSize(asyncJobServiceMaxJobResults); asyncDispatcher.setMaxWaitMilliSeconds(asyncJobServiceMaxWait); asyncDispatcher.setThreadPoolSize(asyncJobServiceThreadPoolSize); asyncDispatcher.setBasePath(asyncJobServiceBasePath); asyncDispatcher.getUnwrappedExceptions().addAll(unwrappedExceptions); dispatcher = asyncDispatcher; asyncDispatcher.start(); dis.getUnwrappedExceptions().addAll(unwrappedExceptions); dispatcher = dis; registry = dispatcher.getRegistry(); if (widerRequestMatching) ((ResourceMethodRegistry) registry).setWiderMatching(widerRequestMatching); dispatcher.getDefaultContextObjects().putAll(defaultContextObjects); dispatcher.getDefaultContextObjects().put(Configurable.class, providerFactory); dispatcher.getDefaultContextObjects().put(Providers.class, providerFactory); dispatcher.getDefaultContextObjects().put(Registry.class, registry); dispatcher.getDefaultContextObjects().put(Dispatcher.class, dispatcher); dispatcher.getDefaultContextObjects().put(InternalDispatcher.class, InternalDispatcher.getInstance()); contextDataMap.putAll(dispatcher.getDefaultContextObjects());
rootNode.addInvoker(fullpath, invoker); } else { root.addInvoker(classExpression, fullpath, invoker); ResourceLocatorInvoker locator = new ResourceLocatorInvoker(rf, injectorFactory, providerFactory, method); if (widerMatching) { rootNode.addInvoker(fullpath, locator); } else { root.addInvoker(classExpression, fullpath, locator);
@Override public void invoke(HttpRequest request, HttpResponse response, ResourceInvoker invoker) { // 可以执行一下逻辑,例如切换ClassLoader等 super.invoke(request, response, invoker); } }
/** * Add a custom resource implementation endpoint. * * @param ref * @param basePath prefix path of resource */ @Override public void addResourceFactory(ResourceFactory ref, String basePath) { // 多应用下改造点 super.addResourceFactory(ref, basePath); }
@Override public ResourceInvoker getResourceInvoker(HttpRequest request) { // 多应用下改造点 return super.getResourceInvoker(request); }