private void addTransformer(List<InvocationChain> chains, ClassLoader loader) throws Fabric3Exception { for (InvocationChain chain : chains) { PhysicalOperation physicalOperation = chain.getPhysicalOperation(); List<DataType> targetTypes = createTypes(physicalOperation); Interceptor interceptor = interceptorFactory.createInterceptor(physicalOperation, TRANSPORT_TYPES, targetTypes, loader, loader); chain.addInterceptor(new WrappingInterceptor()); chain.addInterceptor(interceptor); } }
private Interceptor getInterceptor() { // lazy load the interceptor as it may not have been added when the instance was created in the wire attacher if (interceptor == null) { interceptor = wire.getInvocationChains().iterator().next().getHeadInterceptor(); } return interceptor; } }
/** * Constructor. * * @param chains Invocation chains. */ public JaxbInvoker(List<InvocationChain> chains) { for (InvocationChain chain : chains) { this.chains.put(chain.getPhysicalOperation().getName(), chain); } }
private void addJAXBInterceptor(PhysicalWireSource source, PhysicalOperation op, InvocationChain chain, ClassLoader targetClassLoader) { ClassLoader sourceClassLoader = source.getClassLoader(); List<DataType> jaxTypes = DataTypeHelper.createTypes(op); Interceptor jaxbInterceptor = interceptorFactory.createInterceptor(op, jaxTypes, DataTypeHelper.JAXB_TYPES, targetClassLoader, sourceClassLoader); chain.addInterceptor(jaxbInterceptor); }
Interceptor interceptor = holder.getChain().getHeadInterceptor(); boolean oneWay = holder.getChain().getPhysicalOperation().isOneWay(); OperationPayloadTypes payloadTypes = holder.getPayloadTypes(); PayloadType inputType = payloadTypes.getInputType();
/** * Constructor. * * @param chains Invocation chains. */ public JaxbInvoker(List<InvocationChain> chains) { for (InvocationChain chain : chains) { this.chains.put(chain.getPhysicalOperation().getName(), chain); } }
public void attach(PhysicalWireSource source, FileBindingWireTarget target, Wire wire) throws Fabric3Exception { File location = resolve(target.getLocation()); location.mkdirs(); ReferenceAdapter adapter = getAdaptor(target); FileSystemInterceptor interceptor = new FileSystemInterceptor(location, adapter); for (InvocationChain chain : wire.getInvocationChains()) { chain.addInterceptor(interceptor); } }
private void attachInterceptors(Class<?> seiClass, MetroJavaWireTarget target, Wire wire, Supplier<?> factory) { Method[] methods = seiClass.getMethods(); int retries = target.getRetries(); for (InvocationChain chain : wire.getInvocationChains()) { Method method = null; for (Method m : methods) { if (chain.getPhysicalOperation().getName().equals(m.getName())) { method = m; break; } } boolean oneWay = chain.getPhysicalOperation().isOneWay(); MetroJavaTargetInterceptor targetInterceptor = new MetroJavaTargetInterceptor(factory, method, oneWay, retries, monitor); chain.addInterceptor(targetInterceptor); } }
/** * Determines if the wire is one-way or request-reply. The first operation is used to determine if the contract is one-way as the binding does not support * mixing one-way and request-response operations on a service contract. * * @param chains the wire invocation chains * @param uri thr service URI. * @return true if the wire is one-way */ private boolean isOneWay(List<InvocationChain> chains, URI uri) { if (chains.size() < 1) { throw new AssertionError("Contract must have at least one operation: " + uri); } return chains.get(0).getPhysicalOperation().isOneWay(); }
private void addJAXBInterceptor(JmsWireSource source, PhysicalWireTarget target, PhysicalOperation op, InvocationChain chain) { ClassLoader sourceClassLoader = source.getClassLoader(); ClassLoader targetClassLoader = target.getClassLoader(); List<DataType> jaxTypes = DataTypeHelper.createTypes(op); Interceptor jaxbInterceptor = interceptorFactory.createInterceptor(op, DataTypeHelper.JAXB_TYPES, jaxTypes, targetClassLoader, sourceClassLoader); chain.addInterceptor(jaxbInterceptor); }
/** * Constructor. * * @param manager the ZeroMQ Context manager * @param address the address to receive messages on * @param chains the invocation chains for dispatching invocations * @param socketType the socket type as defined by ZeroMQ * @param metadata metadata * @param executorService the executor for scheduling work * @param monitor the monitor */ public AbstractReceiver(ContextManager manager, SocketAddress address, List<InvocationChain> chains, int socketType, ZeroMQMetadata metadata, ExecutorService executorService, MessagingMonitor monitor) { this.manager = manager; this.address = address; this.executorService = executorService; this.interceptors = new Interceptor[chains.size()]; for (int i = 0, chainsSize = chains.size(); i < chainsSize; i++) { InvocationChain chain = chains.get(i); interceptors[i] = chain.getHeadInterceptor(); } this.socketType = socketType; this.metadata = metadata; this.monitor = monitor; }
private void attachInterceptors(Class<?> seiClass, MetroJavaWireTargetDefinition target, Wire wire, ObjectFactory<?> factory) { Method[] methods = seiClass.getMethods(); int retries = target.getRetries(); for (InvocationChain chain : wire.getInvocationChains()) { Method method = null; for (Method m : methods) { if (chain.getPhysicalOperation().getName().equals(m.getName())) { method = m; break; } } boolean oneWay = chain.getPhysicalOperation().isOneWay(); MetroJavaTargetInterceptor targetInterceptor = new MetroJavaTargetInterceptor(factory, method, oneWay, retries, monitor); chain.addInterceptor(targetInterceptor); } }
/** * Returns the invocation chains for a wire in their natural order. * * @param wire the wire * @return the invocation chains */ public static List<InvocationChain> sortChains(Wire wire) { TreeMap<PhysicalOperation, InvocationChain> map = new TreeMap<>(); for (InvocationChain chain : wire.getInvocationChains()) { map.put(chain.getPhysicalOperation(), chain); } List<InvocationChain> sorted = new ArrayList<>(); sorted.addAll(map.values()); return sorted; }
Wire createWire(PhysicalWire physicalWire) throws Fabric3Exception { Wire wire = new WireImpl(); for (PhysicalOperation operation : physicalWire.getOperations()) { InvocationChain chain = new InvocationChainImpl(operation); for (PhysicalInterceptor physicalInterceptor : operation.getInterceptors()) { InterceptorBuilder<? super PhysicalInterceptor> builder = Cast.cast(interceptorBuilders.get(physicalInterceptor.getClass())); Interceptor interceptor = builder.build(physicalInterceptor); chain.addInterceptor(interceptor); } wire.addInvocationChain(chain); } return wire; }
public Object invoke(Packet packet, Method method, Object... args) throws InvocationTargetException { // the work context is populated by the current tubeline WorkContext workContext = (WorkContext) packet.invocationProperties.get(MetroConstants.WORK_CONTEXT); if (workContext == null) { // programming error throw new AssertionError("Work context not set"); } Message input = MessageCache.getAndResetMessage(); try { input.setWorkContext(workContext); input.setBody(args); Interceptor head = chains.get(method.getName()).getHeadInterceptor(); Message ret = head.invoke(input); if (!ret.isFault()) { return ret.getBody(); } else { Throwable th = (Throwable) ret.getBody(); throw new InvocationTargetException(th); } } finally { input.reset(); } }
public void connectToSender(String id, URI uri, List<InvocationChain> chains, ZeroMQMetadata metadata, ClassLoader loader) throws Fabric3Exception { SenderHolder holder; if (ZMQ.equals(uri.getScheme())) { DelegatingOneWaySender sender = new DelegatingOneWaySender(id, this, metadata); holder = new SenderHolder(sender); } else { holder = senders.get(uri.toString()); } if (holder == null) { boolean oneWay = isOneWay(chains, uri); holder = createSender(uri.toString(), oneWay, metadata); managementService.registerSender(id, holder.getSender()); } for (int i = 0, chainsSize = chains.size(); i < chainsSize; i++) { InvocationChain chain = chains.get(i); PhysicalOperation physicalOperation = chain.getPhysicalOperation(); List<DataType> sourceTypes = createTypes(physicalOperation); Interceptor interceptor = interceptorFactory.createInterceptor(physicalOperation, sourceTypes, TRANSPORT_TYPES, loader, loader); chain.addInterceptor(interceptor); chain.addInterceptor(new UnwrappingInterceptor()); interceptor = createInterceptor(holder, i); chain.addInterceptor(interceptor); } holder.getIds().add(id); }
/** * Constructor. * * @param chains the invocation chains for the wire. */ public DocumentInvoker(List<InvocationChain> chains) { for (InvocationChain chain : chains) { this.chains.put(chain.getPhysicalOperation().getName(), chain); } ClassLoader old = Thread.currentThread().getContextClassLoader(); try { // set classloader to pick up correct SAAJ implementation Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); factory = MessageFactory.newInstance(); } catch (SOAPException e) { // programming error throw new AssertionError(e); } finally { Thread.currentThread().setContextClassLoader(old); } }
Wire createWire(PhysicalWire physicalWire) throws Fabric3Exception { Wire wire = new WireImpl(); for (PhysicalOperation operation : physicalWire.getOperations()) { InvocationChain chain = new InvocationChainImpl(operation); for (PhysicalInterceptor physicalInterceptor : operation.getInterceptors()) { InterceptorBuilder<? super PhysicalInterceptor> builder = Cast.cast(interceptorBuilders.get(physicalInterceptor.getClass())); Interceptor interceptor = builder.build(physicalInterceptor); chain.addInterceptor(interceptor); } wire.addInvocationChain(chain); } return wire; }
public Object invoke(Packet packet, Method method, Object... args) throws InvocationTargetException { // the work context is populated by the current tubeline WorkContext workContext = (WorkContext) packet.invocationProperties.get(MetroConstants.WORK_CONTEXT); if (workContext == null) { // programming error throw new AssertionError("Work context not set"); } Message input = MessageCache.getAndResetMessage(); try { input.setWorkContext(workContext); input.setBody(args); Interceptor head = chains.get(method.getName()).getHeadInterceptor(); Message ret = head.invoke(input); if (!ret.isFault()) { return ret.getBody(); } else { Throwable th = (Throwable) ret.getBody(); throw new InvocationTargetException(th); } } finally { input.reset(); } }
public void attach(PhysicalWireSource source, SystemWireTarget target, Wire wire) throws Fabric3Exception { URI targetId = UriHelper.getDefragmentedName(target.getUri()); SystemComponent targetComponent = (SystemComponent) manager.getComponent(targetId); Class<?> implementationClass = targetComponent.getImplementationClass(); for (InvocationChain chain : wire.getInvocationChains()) { PhysicalOperation operation = chain.getPhysicalOperation(); List<Class<?>> params = operation.getSourceParameterTypes(); Method method; try { method = implementationClass.getMethod(operation.getName(), params.toArray(new Class[params.size()])); } catch (NoSuchMethodException e) { throw new Fabric3Exception("No matching method found", e); } SystemInvokerInterceptor interceptor = new SystemInvokerInterceptor(method, targetComponent); chain.addInterceptor(interceptor); } }