private MetroGeneratorDelegate getDelegate(ServiceContract contract) throws GenerationException { MetroGeneratorDelegate<?> delegate = delegates.get(contract.getClass()); if (delegate == null) { throw new GenerationException("Generator delegate not found for type: " + contract.getClass().getName()); } return delegate; }
/** * Merges policy sets into the given WSDL document. * * @param wsdl the WSDL * @param policyExpressions the policy set expressions * @param mappings policy set to operation mappings * @return the merged WSDL * @throws GenerationException if the merge is unsuccessful */ private String mergePolicy(String wsdl, List<Element> policyExpressions, List<PolicyExpressionMapping> mappings) throws GenerationException { try { Document wsdlDocument = documentBuilder.parse(new ByteArrayInputStream(wsdl.getBytes())); policyAttacher.attach(wsdlDocument, policyExpressions, mappings); // Write the DOM representing the abstract WSDL back to the file Source source = new DOMSource(wsdlDocument); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(source, result); return writer.toString(); } catch (IOException | TransformerException | SAXException e) { throw new GenerationException(e); } }
private FtpSecurity processPolicies(EffectivePolicy policy) throws GenerationException { Set<PolicySet> policySets = policy.getEndpointPolicySets(); if (policySets == null || policySets.size() == 0) { return null; } if (policySets.size() != 1) { throw new GenerationException("Invalid policy configuration, only supports security policy"); } PolicySet policySet = policySets.iterator().next(); QName policyQName = policySet.getExpressionName(); if (!policyQName.equals(Constants.POLICY_QNAME)) { throw new GenerationException("Unexpected policy element " + policyQName); } Element expression = policySet.getExpression(); String user = expression.getAttribute("user"); if (user == null) { throw new GenerationException("User name not specified in security policy"); } String password = expression.getAttribute("password"); if (password == null) { throw new GenerationException("Password not specified in security policy"); } return new FtpSecurity(user, password); }
/** * Serializes the contents of a parsed WSDL as a string. * * @param wsdl the WSDL * @return the serialized WSDL * @throws GenerationException if an error occurs reading the URL */ private String serializeToString(Definition wsdl) throws GenerationException { try { WSDLWriter writer = wsdlFactory.newWriter(); StringWriter stringWriter = new StringWriter(); writer.writeWSDL(wsdl, stringWriter); return stringWriter.toString(); } catch (WSDLException e) { throw new GenerationException(e); } }
/** * Loads a service contract class in either a host environment that supports classloader isolation or one that does not, in which case the TCCL is used. * * @param javaContract the contract * @param contributionUri the contribution URI the contract class is loaded in * @return the loaded class */ private Class<?> loadServiceClass(JavaServiceContract javaContract, URI contributionUri) throws GenerationException { ClassLoader loader = classLoaderRegistry.getClassLoader(contributionUri); try { return loader.loadClass(javaContract.getInterfaceClass()); } catch (ClassNotFoundException e) { throw new GenerationException(e); } }
private ServiceContract getServiceContract(BindableDefinition parent) throws GenerationException { ServiceContract serviceContract; if (parent instanceof AbstractService) { serviceContract = ((AbstractService) parent).getServiceContract(); } else if (parent instanceof AbstractReference) { serviceContract = ((AbstractReference) parent).getServiceContract(); } else { throw new GenerationException("Unsupported bindable type: " + parent); } return serviceContract; }
/** * Returns the WSDL location if one is defined in the binding configuration or null. * * @param binding the logical binding * @return the WSDL location or null * @throws GenerationException if the WSDL location is invalid */ private URL getWsdlLocation(LogicalBinding<WsBindingDefinition> binding) throws GenerationException { WsBindingDefinition definition = binding.getDefinition(); try { String location = definition.getWsdlLocation(); if (location != null) { return new URL(location); } } catch (MalformedURLException e) { throw new GenerationException(e); } return null; }
/** * Merges policy sets into the given WSDL document. * * @param wsdl the WSDL * @param policyExpressions the policy set expressions * @param mappings policy set to operation mappings * @return the merged WSDL * @throws GenerationException if the merge is unsuccessful */ private String mergePolicy(Definition wsdl, List<Element> policyExpressions, List<PolicyExpressionMapping> mappings) throws GenerationException { try { Document wsdlDocument = wsdlFactory.newWriter().getDocument(wsdl); policyAttacher.attach(wsdlDocument, policyExpressions, mappings); // Write the DOM representing the abstract WSDL back to the file Source source = new DOMSource(wsdlDocument); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(source, result); return writer.toString(); } catch (TransformerException | WSDLException e) { throw new GenerationException(e); } }
public MetroWireTargetDefinition generateTarget(LogicalBinding<WsBindingDefinition> binding, WsdlServiceContract contract, EffectivePolicy policy) throws GenerationException { URL targetUrl = null; URI targetUri = binding.getDefinition().getTargetUri(); if (targetUri != null) { try { targetUrl = targetUri.toURL(); } catch (MalformedURLException e) { throw new GenerationException(e); } } return generateTarget(binding, targetUrl, contract, policy); }
/** * Returns the WSDL location if one is defined in the binding configuration or null. * * @param definition the binding configuration * @param serviceClass the service endpoint interface * @return the WSDL location or null * @throws GenerationException if the WSDL location is invalid */ private URL getWsdlLocation(WsBindingDefinition definition, Class<?> serviceClass) throws GenerationException { try { String location = definition.getWsdlLocation(); if (location != null) { return new URL(location); } WebService annotation = serviceClass.getAnnotation(WebService.class); if (annotation != null) { String wsdlLocation = annotation.wsdlLocation(); if (wsdlLocation.length() > 0) { return new URL(wsdlLocation); } else { return null; } } } catch (MalformedURLException e) { throw new GenerationException(e); } return null; }
public URL resolveUrl(LogicalBinding<WsBindingDefinition> serviceBinding, EffectivePolicy policy) throws GenerationException { try { URL targetUrl; String path = serviceBinding.getDefinition().getTargetUri().toString(); if (path == null) { path = serviceBinding.getParent().getUri().getFragment(); } boolean https = requiresHttps(policy); if (RuntimeMode.VM == hostInfo.getRuntimeMode()) { // single VM if (https) { targetUrl = new URL("https://localhost:" + servletHost.getHttpsPort() + "/" + path); } else { targetUrl = new URL("http://localhost:" + servletHost.getHttpPort() + "/" + path); } } else { throw new GenerationException("Resolve URL not supported in distributed configuration"); } return targetUrl; } catch (MalformedURLException e) { throw new GenerationException(e); } }
public FtpWireSourceDefinition generateSource(LogicalBinding<FtpBindingDefinition> binding, ServiceContract contract, List<LogicalOperation> operations, EffectivePolicy policy) throws GenerationException { if (contract.getOperations().size() != 1) { throw new GenerationException("Expects only one operation"); } FtpWireSourceDefinition hwsd = new FtpWireSourceDefinition(); URI targetUri = binding.getDefinition().getTargetUri(); hwsd.setUri(targetUri); return hwsd; }
URI uri = policySet.getContributionUri(); QName expressionName = policySet.getExpressionName(); throw new GenerationException("Invalid policy in contribution " + uri + ". No id specified: " + expressionName);
public MetroWireTargetDefinition generateTarget(LogicalBinding<WsBindingDefinition> binding, JavaServiceContract contract, EffectivePolicy policy) throws GenerationException { URL targetUrl = null; WsBindingDefinition definition = binding.getDefinition(); URI targetUri = definition.getTargetUri(); if (binding.isCallback() && targetUri != null) { throw new GenerationException("A web services callback binding cannot be used with a binding URI on a service: " + binding.getParent().getUri()); } if (targetUri != null) { if (!targetUri.isAbsolute() && !binding.isCallback()) { throw new GenerationException("Web service binding URI must be absolute on reference: " + binding.getParent().getUri()); } try { targetUrl = targetUri.toURL(); } catch (MalformedURLException e) { throw new GenerationException(e); } } else if (definition.getWsdlElement() == null && definition.getWsdlLocation() == null && !binding.isCallback()) { throw new GenerationException("A web service binding URI must be specified: " + binding.getParent().getUri()); } return generateTarget(binding, targetUrl, contract, policy); }
private ServiceEndpointDefinition synthesizeEndpointFromClass(LogicalBinding<WsBindingDefinition> binding, JavaServiceContract contract, Class<?> serviceClass) throws GenerationException { URI targetUri; Bindable service = binding.getParent(); for (LogicalBinding<?> otherBinding : service.getBindings()) { if (binding == otherBinding) { continue; } if (WsBindingDefinition.BINDING_QNAME.equals(otherBinding.getDefinition().getType())) { // check to see if other WS bindings also use a default WsBindingDefinition wsDefinition = (WsBindingDefinition) otherBinding.getDefinition(); if (wsDefinition.getTargetUri() == null && wsDefinition.getWsdlElement() == null) { throw new GenerationException("If there is more than one web service binding, one must provide a URI or WSDLElement:" + service.getUri()); } } } targetUri = URI.create(service.getUri().getFragment()); return synthesizer.synthesizeServiceEndpoint(contract, serviceClass, targetUri); }
public <T> T resolve(Class<T> interfaze, String name) throws ResolverException { try { LogicalChannel logicalChannel = getChannel(name); LogicalProducer producer = createProducer(interfaze, logicalChannel.getUri()); PhysicalChannelDefinition channelDefinition = channelGenerator.generateChannelDefinition(logicalChannel, SYNTHETIC_DEPLOYABLE, ChannelDirection.PRODUCER); channelBuilderRegistry.build(channelDefinition); Map<LogicalChannel, ChannelDeliveryType> channels = Collections.singletonMap(logicalChannel, ChannelDeliveryType.DEFAULT); List<PhysicalChannelConnectionDefinition> physicalDefinitions = connectionGenerator.generateProducer(producer, channels); for (PhysicalChannelConnectionDefinition physicalDefinition : physicalDefinitions) { channelConnector.connect(physicalDefinition); } for (PhysicalChannelConnectionDefinition physicalDefinition : physicalDefinitions) { PhysicalConnectionSourceDefinition source = physicalDefinition.getSource(); if (!(source instanceof NonManagedPhysicalConnectionSourceDefinition)) { continue; } NonManagedPhysicalConnectionSourceDefinition sourceDefinition = (NonManagedPhysicalConnectionSourceDefinition) source; return interfaze.cast(sourceDefinition.getProxy()); } throw new GenerationException("Source generator not found"); } catch (GenerationException | ContainerException e) { throw new ResolverException(e); } }
public FtpWireTargetDefinition generateTarget(LogicalBinding<FtpBindingDefinition> binding, ServiceContract contract, List<LogicalOperation> operations, EffectivePolicy policy) throws GenerationException { if (operations.size() != 1) { throw new GenerationException("Expects only one operation"); } URI id = binding.getParent().getParent().getParent().getUri(); FtpBindingDefinition definition = binding.getDefinition(); boolean active = definition.getTransferMode() == TransferMode.ACTIVE; FtpSecurity security = processPolicies(policy); FtpWireTargetDefinition hwtd = new FtpWireTargetDefinition(id, active, security, connectTimeout, socketTimeout); hwtd.setUri(definition.getTargetUri()); if (!definition.getSTORCommands().isEmpty()) { hwtd.setSTORCommands(definition.getSTORCommands()); } hwtd.setTmpFileSuffix(binding.getDefinition().getTmpFileSuffix()); return hwtd; }
serviceUri = new URI(component.getUri() + "#" + service.getDefinition().getName()); } catch (URISyntaxException e) { throw new GenerationException(e);
if (wsdlElementString == null) { URI bindableUri = binding.getParent().getUri(); throw new GenerationException("Either a uri or wsdlElement must be specified for the web service binding on " + bindableUri);
WsdlElement wsdlElement = GenerationHelper.parseWsdlElement(wsdlElementString); if (wsdlElement.getType() == WsdlElement.Type.SERVICE) { throw new GenerationException("Services cannot specify a wsdl.service in the web service binding: " + binding.getParent().getUri());