private void addTransformer(List<InvocationChain> chains, ClassLoader loader) throws BrokerException { for (InvocationChain chain : chains) { try { PhysicalOperationDefinition physicalOperation = chain.getPhysicalOperation(); List<DataType<?>> targetTypes = createTypes(physicalOperation, loader); Interceptor interceptor = interceptorFactory.createInterceptor(physicalOperation, TRANSPORT_TYPES, targetTypes, loader, loader); chain.addInterceptor(new WrappingInterceptor()); chain.addInterceptor(interceptor); } catch (InterceptorCreationException e) { throw new BrokerException(e); } } }
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; } }
public void attach(JUnitSourceDefinition source, PhysicalTargetDefinition target, Wire wire) throws WiringException { String testName = source.getTestName(); ContextConfiguration configuration = source.getConfiguration(); if (configuration != null) { if (authenticationService == null) { throw new WiringException("Security information set for the test but a security extension has not been installed in the runtime"); } // configuration an authentication interceptor to set the subject on the work context for (InvocationChain chain : wire.getInvocationChains()) { Interceptor next = chain.getHeadInterceptor(); String username = configuration.getUsername(); String password = configuration.getPassword(); AuthenticatingInterceptor interceptor = new AuthenticatingInterceptor(username, password, authenticationService, next); chain.addInterceptor(0, interceptor); } } holder.add(testName, wire); }
public void onAttach(Wire wire) { for (InvocationChain chain : wire.getInvocationChains()) { SecurityContextInterceptor interceptor = new SecurityContextInterceptor(); chain.addInterceptor(interceptor); } } }
/** * 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(); }
public void attach(PhysicalSourceDefinition source, FtpTargetDefinition target, Wire wire) throws WiringException { InvocationChain invocationChain = wire.getInvocationChains().iterator().next(); URI uri = target.getUri(); try { String host = uri.getHost(); int port = uri.getPort() == -1 ? 23 : uri.getPort(); InetAddress hostAddress = "localhost".equals(host) ? InetAddress.getLocalHost() : InetAddress.getByName(host); String remotePath = uri.getPath(); String tmpFileSuffix = target.getTmpFileSuffix(); FtpSecurity security = target.getSecurity(); boolean active = target.isActive(); int connectTimeout = target.getConectTimeout(); SocketFactory factory = new ExpiringSocketFactory(connectTimeout); int socketTimeout = target.getSocketTimeout(); List<String> cmds = target.getSTORCommands(); FtpTargetInterceptor targetInterceptor = new FtpTargetInterceptor(hostAddress, port, security, active, socketTimeout, factory, cmds, monitor); targetInterceptor.setTmpFileSuffix(tmpFileSuffix); targetInterceptor.setRemotePath(remotePath); invocationChain.addInterceptor(targetInterceptor); } catch (UnknownHostException e) { throw new WiringException(e); } }
/** * 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<PhysicalOperationDefinition, InvocationChain> map = new TreeMap<PhysicalOperationDefinition, InvocationChain>(); for (InvocationChain chain : wire.getInvocationChains()) { map.put(chain.getPhysicalOperation(), chain); } List<InvocationChain> sorted = new ArrayList<InvocationChain>(); sorted.addAll(map.values()); return sorted; }
public void connectToSender(String id, URI uri, List<InvocationChain> chains, ZeroMQMetadata metadata, ClassLoader loader) throws BrokerException { 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); try { PhysicalOperationDefinition physicalOperation = chain.getPhysicalOperation(); List<DataType<?>> sourceTypes = createTypes(physicalOperation, loader); Interceptor interceptor = interceptorFactory.createInterceptor(physicalOperation, sourceTypes, TRANSPORT_TYPES, loader, loader); chain.addInterceptor(interceptor); chain.addInterceptor(new UnwrappingInterceptor()); } catch (InterceptorCreationException e) { throw new BrokerException(e); } Interceptor interceptor = createInterceptor(holder, i); chain.addInterceptor(interceptor); } holder.getIds().add(id); }
Wire createWire(PhysicalWireDefinition definition) throws BuilderException { Wire wire = new WireImpl(); for (PhysicalOperationDefinition operation : definition.getOperations()) { InvocationChain chain = new InvocationChainImpl(operation); for (PhysicalInterceptorDefinition interceptorDefinition : operation.getInterceptors()) { InterceptorBuilder<? super PhysicalInterceptorDefinition> builder = getBuilder(interceptorDefinition); Interceptor interceptor = builder.build(interceptorDefinition); chain.addInterceptor(interceptor); } wire.addInvocationChain(chain); } processTransform(wire, definition); return wire; }
private void provision(RsSourceDefinition sourceDefinition, Wire wire, RsContainer container) throws ClassNotFoundException, RsContainerException { ClassLoader classLoader = classLoaderRegistry.getClassLoader(sourceDefinition.getClassLoaderId()); Map<String, InvocationChain> invocationChains = new HashMap<String, InvocationChain>(); for (InvocationChain chain : wire.getInvocationChains()) { PhysicalOperationDefinition operation = chain.getPhysicalOperation(); invocationChains.put(operation.getName(), chain); } Class<?> interfaze = classLoader.loadClass(sourceDefinition.getRsClass()); boolean authenticate = authenticate(sourceDefinition); F3ResourceHandler handler = new F3ResourceHandler(interfaze, invocationChains, authenticate, authenticator); // Set the class loader to the runtime one so Jersey loads the Resource config properly ClassLoader old = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Resource resource = createResource(handler); container.addResource(resource); } finally { Thread.currentThread().setContextClassLoader(old); } }
/** * 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; }
public void attach(PhysicalSourceDefinition sourceDefinition, RsTargetDefinition def, Wire wire) throws WiringException { ClassLoader targetClassLoader = classLoaderRegistry.getClassLoader(def.getClassLoaderId()); List<InvocationChain> invocationChains = wire.getInvocationChains(); URI uri = def.getUri(); String interfaze = def.getProxyInterface(); try { Class<?> interfaceClass = targetClassLoader.loadClass(interfaze); for (InvocationChain chain : invocationChains) { PhysicalOperationDefinition operation = chain.getPhysicalOperation(); String operationName = operation.getName(); List<String> targetParameterTypes = operation.getTargetParameterTypes(); Class<?> args[] = new Class<?>[targetParameterTypes.size()]; for (int i = 0; i < args.length; i++) { args[i] = targetClassLoader.loadClass(targetParameterTypes.get(i)); } chain.addInterceptor(new RsClientInterceptor(operationName, interfaceClass, uri, args)); } } catch (Exception e) { throw new WiringException(e); } }
private void setMessageReceivers(Wire wire, AxisService axisService) throws Exception { Map<String, InvocationChain> interceptors = new HashMap<String, InvocationChain>(); for (InvocationChain chain : wire.getInvocationChains()) { interceptors.put(chain.getPhysicalOperation().getName(), chain); } Utils.fillAxisService(axisService, configurationContext.getAxisConfiguration(), null, null); for (Iterator<?> i = axisService.getOperations(); i.hasNext();) { AxisOperation axisOp = (AxisOperation) i.next(); InvocationChain invocationChain = interceptors.get(axisOp.getName().getLocalPart()); MessageReceiver messageReceiver = null; if (WSDL2Constants.MEP_URI_IN_ONLY.equals(axisOp.getMessageExchangePattern()) || WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(axisOp.getMessageExchangePattern())) { messageReceiver = new InOnlyServiceProxyHandler(invocationChain); } else {//Default MEP is IN-OUT for backward compatibility messageReceiver = new InOutServiceProxyHandler(invocationChain); } axisOp.setMessageReceiver(messageReceiver); } }
protected void invokeBusinessLogic(MessageContext messageCtx) throws AxisFault { Interceptor head = invocationChain.getHeadInterceptor(); OMElement bodyContent = ServiceProxyHelper.getInBodyContent(messageCtx); Object[] args = bodyContent == null ? null : new Object[]{bodyContent};
public void attachToTarget(PhysicalWireSourceDefinition source, Axis2WireTargetDefinition target, Wire wire) throws WiringException { ClassLoader classLoader = classLoaderRegistry.getClassLoader(source.getClassLoaderId()); List<String> endpointUris = new LinkedList<String>(); String endpointUri = expandUri(target.getUri()); StringTokenizer tok = new StringTokenizer(endpointUri); while (tok.hasMoreElements()) { endpointUris.add(tok.nextToken().trim()); } AxisService axisService = createAxisClientService(target, classLoader); for (InvocationChain chain : wire.getInvocationChains()) { String operation = chain.getPhysicalOperation().getName(); Set<AxisPolicy> policies = target.getPolicies(operation); Map<String, String> opInfo = target.getOperationInfo() != null ? target.getOperationInfo().get(operation) : null; Interceptor interceptor = new Axis2TargetInterceptor(endpointUris, operation, policies, opInfo, target.getConfig(), f3Configurator, policyApplier, axisService, classLoader); chain.addInterceptor(interceptor); } }
public Object invoke(Method method, Object[] args) throws Throwable { InvocationChain invocationChain = chains.get(method.getName()); if (invocationChain == null) { throw new ServiceRuntimeException("Unknown resource method: " + method.toString()); } WorkContext context = WorkContextCache.getThreadWorkContext(); // work context set previously in RsContainer Message message = MessageCache.getAndResetMessage(); try { if (authenticate) { authenticate(context); } message.setWorkContext(context); message.setBody(args); if (invocationChain != null) { Interceptor headInterceptor = invocationChain.getHeadInterceptor(); Message ret = headInterceptor.invoke(message); if (ret.isFault()) { return handleFault(ret); } else { return ret.getBody(); } } else { return null; } } catch (RuntimeException e) { throw new InvocationTargetException(e); } finally { message.reset(); } }
public void attach(PhysicalSourceDefinition source, SpringTargetDefinition target, Wire wire) throws WiringException { String beanName = target.getBeanName(); ClassLoader loader = classLoaderRegistry.getClassLoader(target.getClassLoaderId()); Class<?> interfaze; try { interfaze = loader.loadClass(target.getBeanInterface()); } catch (ClassNotFoundException e) { throw new WiringException(e); } for (WireListener listener : listeners) { listener.onAttach(wire); } SpringComponent component = getComponent(target); for (InvocationChain chain : wire.getInvocationChains()) { PhysicalOperationDefinition operation = chain.getPhysicalOperation(); Method beanMethod = MethodUtils.findMethod(source, target, operation, interfaze, loader, classLoaderRegistry); SpringInvoker invoker = new SpringInvoker(beanName, beanMethod, component); chain.addInterceptor(invoker); } }
public void invokeBusinessLogic(MessageContext inMessage, MessageContext outMessage) throws AxisFault { Interceptor head = invocationChain.getHeadInterceptor(); OMElement bodyContent = ServiceProxyHelper.getInBodyContent(inMessage); Object[] args = bodyContent == null ? null : new Object[]{bodyContent};
PhysicalOperationDefinition operation = chain.getPhysicalOperation(); Method method = MethodUtils.findMethod(sourceDefinition, targetDefinition, operation, implementationClass, loader, classLoaderRegistry); ServiceInvoker invoker = reflectionFactory.createServiceInvoker(method); if (!expected.equals(Test.None.class)) { ExpectedExceptionInterceptor exceptionInterceptor = new ExpectedExceptionInterceptor(expected); chain.addInterceptor(exceptionInterceptor); chain.addInterceptor(interceptor);
ClassLoader targetLoader = null; for (InvocationChain chain : wire.getInvocationChains()) { if (checkPassByRef && chain.getPhysicalOperation().isAllowsPassByReference()) { continue; targetLoader = classLoaderRegistry.getClassLoader(targetId); PhysicalOperationDefinition operation = chain.getPhysicalOperation(); List<DataType<?>> sourceTypes = sourceDefinition.getPhysicalDataTypes(); List<DataType<?>> targetTypes = targetDefinition.getPhysicalDataTypes(); try { Interceptor interceptor = transformerFactory.createInterceptor(operation, sourceTypes, targetTypes, targetLoader, sourceLoader); chain.addInterceptor(interceptor); } catch (InterceptorCreationException e) { throw new WiringException(e);