use of com.webcohesion.enunciate.modules.jaxws.WsdlInfo in project enunciate by stoicflame.
the class TestEnunciateIDLModule method testAgainstFullAPI.
/**
* Tests the xml artifact generation against the "full" API.
*/
public void testAgainstFullAPI() throws Exception {
Map<String, String> prefixes = new HashMap<String, String>();
prefixes.put(FULL_NAMESPACE, "full");
prefixes.put(DATA_NAMESPACE, "data");
prefixes.put(CITE_NAMESPACE, "cite");
Properties testProperties = new Properties();
testProperties.load(TestEnunciateIDLModule.class.getResourceAsStream("/test.properties"));
String samplePath = testProperties.getProperty("api.sample.dir");
assertNotNull(samplePath);
File sampleDir = new File(samplePath);
assertTrue(sampleDir.exists());
Enunciate engine = new Enunciate().addSourceDir(sampleDir).loadConfiguration(TestEnunciateIDLModule.class.getResourceAsStream("test-idl-module-config.xml")).loadDiscoveredModules();
String cp = System.getProperty("java.class.path");
String[] path = cp.split(File.pathSeparator);
List<File> classpath = new ArrayList<File>(path.length);
for (String element : path) {
File entry = new File(element);
if (entry.exists() && !new File(entry, "test.properties").exists()) {
classpath.add(entry);
}
}
engine.setClasspath(classpath);
engine.run();
IDLModule idlModule = null;
for (EnunciateModule candidate : engine.getModules()) {
if (candidate instanceof IDLModule) {
idlModule = (IDLModule) candidate;
break;
}
}
assertNotNull(idlModule);
assertNotNull(idlModule.jaxbModule);
assertNotNull(idlModule.jaxwsModule);
assertNotNull(idlModule.jaxrsModule);
final Map<String, String> schemas = new HashMap<String, String>();
for (SchemaInfo schemaInfo : idlModule.jaxbModule.getJaxbContext().getSchemas().values()) {
assertNotNull(schemaInfo.getSchemaFile());
assertTrue(schemaInfo.getSchemaFile() instanceof JaxbSchemaFile);
String filename = ((JaxbSchemaFile) schemaInfo.getSchemaFile()).filename;
assertNotNull(filename);
if (prefixes.containsKey(schemaInfo.getNamespace())) {
assertEquals(prefixes.get(schemaInfo.getNamespace()) + ".xsd", filename);
}
StringWriter schemaOut = new StringWriter();
((JaxbSchemaFile) schemaInfo.getSchemaFile()).writeTo(schemaOut);
schemaOut.flush();
schemas.put(filename, schemaOut.toString());
}
WsdlInfo fullWsdlInfo = idlModule.jaxwsModule.getJaxwsContext().getWsdls().get(FULL_NAMESPACE);
assertNotNull(fullWsdlInfo);
assertEquals("full.wsdl", fullWsdlInfo.getFilename());
assertNotNull(fullWsdlInfo.getWsdlFile());
assertTrue(fullWsdlInfo.getWsdlFile() instanceof JaxwsWsdlFile);
JaxwsWsdlFile fullWsdl = (JaxwsWsdlFile) fullWsdlInfo.getWsdlFile();
assertEquals("full.wsdl", fullWsdl.filename);
final StringWriter output = new StringWriter();
fullWsdl.writeTo(output);
output.flush();
// make sure the wsdl is built correctly
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
Definition definition = wsdlReader.readWSDL(new InMemoryWSDLLocator(output, schemas));
assertEquals(FULL_NAMESPACE, definition.getTargetNamespace());
Types types = definition.getTypes();
List extensibilityElements = types.getExtensibilityElements();
assertEquals(1, extensibilityElements.size());
ExtensibilityElement ee = (ExtensibilityElement) extensibilityElements.get(0);
assertEquals(new QName(W3C_XML_SCHEMA_NS_URI, "schema"), ee.getElementType());
Schema schema = (Schema) ee;
Map imports = schema.getImports();
assertEquals(3, imports.size());
assertNotNull(imports.get(DATA_NAMESPACE));
assertNotNull(imports.get(CITE_NAMESPACE));
assertNotNull(imports.get(null));
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
Element schemaElement = schema.getElement();
// these namespaces need to be explicitly added because the transformer won't see any references to them...
schemaElement.setAttribute("xmlns:data", DATA_NAMESPACE);
schemaElement.setAttribute("xmlns:cite", CITE_NAMESPACE);
schemaElement.setAttribute("xmlns:full", FULL_NAMESPACE);
// write out the wsdl schema to its xml form so we can parse it with XSOM...
DOMSource source = new DOMSource(schemaElement);
StringWriter fullSchemaOutput = new StringWriter();
StreamResult result = new StreamResult(fullSchemaOutput);
transformer.transform(source, result);
fullSchemaOutput.flush();
// set up the XSOM Parser.
final InputSource fullSource = new InputSource(new StringReader(fullSchemaOutput.toString()));
fullSource.setSystemId("file:/");
XSOMParser parser = new XSOMParser(new JAXPParser());
// throw all errors and warnings.
parser.setErrorHandler(new ThrowEverythingHandler());
parser.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
String xsd = schemas.get(systemId.substring("file:/".length()));
if (xsd == null) {
return null;
}
InputSource source = new InputSource(new StringReader(xsd));
source.setSystemId("file:/");
return source;
}
});
// make sure the schema included in the wsdl is correct.
parser.parse(fullSource);
XSSchemaSet schemaSet = parser.getResult();
XSSchema wsdlSchema = schemaSet.getSchema(FULL_NAMESPACE);
assertNotNull(wsdlSchema);
// make sure the data schema is imported and correct.
XSSchema dataSchema = schemaSet.getSchema(DATA_NAMESPACE);
assertNotNull(dataSchema);
assertDataSchemaStructure(dataSchema);
// make sure the cite schema is imported and correct.
XSSchema citeSchema = schemaSet.getSchema(CITE_NAMESPACE);
assertNotNull(citeSchema);
assertCiteSchemaStructure(citeSchema);
// now verify the rest of the WSDL...
assertWebServiceDefinition(definition);
}
use of com.webcohesion.enunciate.modules.jaxws.WsdlInfo in project enunciate by stoicflame.
the class JavaXMLClientModule method generateClientSources.
protected File generateClientSources() {
File sourceDir = getSourceDir();
sourceDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
Map<String, String> conversions = getClientPackageConversions();
EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
model.put("packageFor", new ClientPackageForMethod(conversions, this.context));
model.put("classnameFor", new ClientClassnameForMethod(conversions, jaxbContext));
model.put("simpleNameFor", new SimpleNameForMethod(new ClientClassnameForMethod(conversions, jaxbContext, true)));
model.put("file", new FileDirective(sourceDir, this.enunciate.getLogger()));
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
model.put("annotationValue", new AnnotationValueMethod());
Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
facetIncludes.addAll(getFacetIncludes());
Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
facetExcludes.addAll(getFacetExcludes());
FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
boolean upToDate = isUpToDateWithSources(sourceDir);
if (!upToDate) {
try {
debug("Generating the Java client classes...");
HashMap<String, WebFault> allFaults = new HashMap<String, WebFault>();
AntPatternMatcher matcher = new AntPatternMatcher();
matcher.setPathSeparator(".");
if (this.jaxwsModule != null) {
Set<String> seeAlsos = new TreeSet<String>();
// for each endpoint interface.
for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (facetFilter.accept(ei)) {
for (WebMethod webMethod : ei.getWebMethods()) {
if (facetFilter.accept(webMethod)) {
for (WebMessage webMessage : webMethod.getMessages()) {
if (webMessage instanceof RequestWrapper) {
model.put("message", webMessage);
processTemplate(getTemplateURL("client-request-bean.fmt"), model);
seeAlsos.add(getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), ((RequestWrapper) webMessage).getRequestBeanName()));
} else if (webMessage instanceof ResponseWrapper) {
model.put("message", webMessage);
processTemplate(getTemplateURL("client-response-bean.fmt"), model);
seeAlsos.add(getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), ((ResponseWrapper) webMessage).getResponseBeanName()));
} else if (webMessage instanceof WebFault) {
WebFault fault = (WebFault) webMessage;
allFaults.put(fault.getQualifiedName().toString(), fault);
}
}
}
}
}
}
}
// gather the annotation information and process the possible beans for each web fault.
for (WebFault webFault : allFaults.values()) {
boolean implicit = webFault.isImplicitSchemaElement();
String faultBean = implicit ? getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), webFault.getImplicitFaultBeanQualifiedName()) : new ClientClassnameForMethod(conversions, jaxbContext).convert(webFault.getExplicitFaultBeanType());
seeAlsos.add(faultBean);
if (implicit) {
model.put("fault", webFault);
processTemplate(getTemplateURL("client-fault-bean.fmt"), model);
}
}
model.put("seeAlsoBeans", seeAlsos);
model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot());
for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) {
if (wsdlInfo.getWsdlFile() == null) {
throw new EnunciateException("WSDL " + wsdlInfo.getId() + " doesn't have a filename.");
}
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (facetFilter.accept(ei)) {
model.put("endpointInterface", ei);
model.put("wsdlFileName", wsdlInfo.getFilename());
processTemplate(getTemplateURL("client-endpoint-interface.fmt"), model);
processTemplate(getTemplateURL("client-soap-endpoint-impl.fmt"), model);
}
}
}
for (WebFault webFault : allFaults.values()) {
if (useServerSide(webFault, matcher)) {
copyServerSideType(sourceDir, webFault);
} else {
TypeElement superFault = (TypeElement) ((DeclaredType) webFault.getSuperclass()).asElement();
if (superFault != null && allFaults.containsKey(superFault.getQualifiedName().toString()) && allFaults.get(superFault.getQualifiedName().toString()).isImplicitSchemaElement()) {
model.put("superFault", allFaults.get(superFault.getQualifiedName().toString()));
} else {
model.remove("superFault");
}
model.put("fault", webFault);
processTemplate(getTemplateURL("client-web-fault.fmt"), model);
}
}
}
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (facetFilter.accept(typeDefinition)) {
if (useServerSide(typeDefinition, matcher)) {
copyServerSideType(sourceDir, typeDefinition);
} else {
model.put("rootEl", this.jaxbModule.getJaxbContext().findElementDeclaration(typeDefinition));
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? typeDefinition instanceof QNameEnumTypeDefinition ? getTemplateURL("client-qname-enum-type.fmt") : getTemplateURL("client-enum-type.fmt") : typeDefinition.isSimple() ? getTemplateURL("client-simple-type.fmt") : getTemplateURL("client-complex-type.fmt");
processTemplate(template, model);
}
}
}
for (Registry registry : schemaInfo.getRegistries()) {
model.put("registry", registry);
processTemplate(getTemplateURL("client-registry.fmt"), model);
}
}
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping generation of Java client sources as everything appears up-to-date...");
}
context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
return sourceDir;
}
use of com.webcohesion.enunciate.modules.jaxws.WsdlInfo in project enunciate by stoicflame.
the class CSharpXMLClientModule method generateSources.
private File generateSources(Map<String, String> packageToNamespaceConversions) {
File srcDir = getSourceDir();
srcDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
ClientPackageForMethod namespaceFor = new ClientPackageForMethod(packageToNamespaceConversions, this.context);
Collection<WsdlInfo> wsdls = new ArrayList<WsdlInfo>();
if (this.jaxwsModule != null) {
wsdls = this.jaxwsModule.getJaxwsContext().getWsdls().values();
}
model.put("wsdls", wsdls);
EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
model.put("schemas", jaxbContext.getSchemas().values());
model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot());
model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
model.put("namespaceFor", namespaceFor);
model.put("findRootElement", new FindRootElementMethod(jaxbContext));
model.put("requestDocumentQName", new RequestDocumentQNameMethod());
model.put("responseDocumentQName", new ResponseDocumentQNameMethod());
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jaxbContext);
model.put("classnameFor", classnameFor);
model.put("listsAsArraysClassnameFor", new ListsAsArraysClientClassnameForMethod(packageToNamespaceConversions, jaxbContext));
model.put("simpleNameFor", new SimpleNameFor(classnameFor));
model.put("csFileName", getSourceFileName());
model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
facetIncludes.addAll(getFacetIncludes());
Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
facetExcludes.addAll(getFacetExcludes());
FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
if (!isUpToDateWithSources(srcDir)) {
debug("Generating the C# client classes...");
URL apiTemplate = isSingleFilePerClass() ? getTemplateURL("api-multiple-files.fmt") : getTemplateURL("api.fmt");
try {
processTemplate(apiTemplate, model);
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
} else {
info("Skipping C# code generation because everything appears up-to-date.");
}
this.context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
return srcDir;
}
use of com.webcohesion.enunciate.modules.jaxws.WsdlInfo in project enunciate by stoicflame.
the class JaxwsServiceApi method getServiceGroups.
@Override
public List<ServiceGroup> getServiceGroups() {
Map<String, WsdlInfo> wsdls = this.context.getWsdls();
ArrayList<ServiceGroup> serviceGroups = new ArrayList<ServiceGroup>();
for (WsdlInfo wsdlInfo : wsdls.values()) {
serviceGroups.add(new ServiceGroupImpl(wsdlInfo, registrationContext));
}
return serviceGroups;
}
use of com.webcohesion.enunciate.modules.jaxws.WsdlInfo in project enunciate by stoicflame.
the class IDLModule method call.
@Override
public void call(EnunciateContext context) {
Map<String, SchemaInfo> ns2schema = Collections.emptyMap();
Map<String, String> ns2prefix = Collections.emptyMap();
if (this.jaxbModule != null) {
ns2schema = this.jaxbModule.getJaxbContext().getSchemas();
ns2prefix = this.jaxbModule.getJaxbContext().getNamespacePrefixes();
}
Map<String, WsdlInfo> ns2wsdl = Collections.emptyMap();
if (this.jaxwsModule != null) {
ns2wsdl = this.jaxwsModule.getJaxwsContext().getWsdls();
}
Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
facetIncludes.addAll(getFacetIncludes());
Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
facetExcludes.addAll(getFacetExcludes());
FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
Map<String, SchemaConfig> schemaConfigs = getSchemaConfigs();
for (SchemaInfo schemaInfo : ns2schema.values()) {
String defaultFilename = ns2prefix.get(schemaInfo.getNamespace()) + ".xsd";
SchemaConfig explicitConfig = schemaConfigs.get(schemaInfo.getNamespace());
if (explicitConfig != null && explicitConfig.getUseFile() != null) {
schemaInfo.setFilename(explicitConfig.getUseFile().getName());
schemaInfo.setSchemaFile(new StaticInterfaceDescriptionFile(explicitConfig.getUseFile(), this.enunciate));
} else if (explicitConfig != null) {
schemaInfo.setAppinfo(explicitConfig.getAppinfo());
schemaInfo.setFilename(explicitConfig.getFilename() != null ? explicitConfig.getFilename() : defaultFilename);
schemaInfo.setExplicitLocation(explicitConfig.getLocation());
schemaInfo.setJaxbBindingVersion(explicitConfig.getJaxbBindingVersion());
schemaInfo.setSchemaFile(new JaxbSchemaFile(this.enunciate, defaultFilename, this.jaxbModule.getJaxbContext(), schemaInfo, facetFilter, ns2prefix));
} else {
schemaInfo.setFilename(defaultFilename);
schemaInfo.setSchemaFile(new JaxbSchemaFile(this.enunciate, defaultFilename, this.jaxbModule.getJaxbContext(), schemaInfo, facetFilter, ns2prefix));
}
}
String baseUri = this.enunciate.getConfiguration().getApplicationRoot();
Map<String, WsdlConfig> wsdlConfigs = getWsdlConfigs();
for (WsdlInfo wsdlInfo : ns2wsdl.values()) {
String defaultFilename = ns2prefix.get(wsdlInfo.getTargetNamespace()) + ".wsdl";
WsdlConfig explicitConfig = wsdlConfigs.get(wsdlInfo.getTargetNamespace());
if (explicitConfig != null && explicitConfig.getUseFile() != null) {
wsdlInfo.setFilename(explicitConfig.getUseFile().getName());
wsdlInfo.setWsdlFile(new StaticInterfaceDescriptionFile(explicitConfig.getUseFile(), this.enunciate));
} else if (explicitConfig != null) {
wsdlInfo.setFilename(explicitConfig.getFilename() != null ? explicitConfig.getFilename() : defaultFilename);
wsdlInfo.setInlineSchema(explicitConfig.isInlineSchema());
wsdlInfo.setWsdlFile(new JaxwsWsdlFile(this.enunciate, defaultFilename, wsdlInfo, this.jaxbModule.getJaxbContext(), baseUri, ns2prefix, facetFilter));
} else {
wsdlInfo.setFilename(defaultFilename);
wsdlInfo.setWsdlFile(new JaxwsWsdlFile(this.enunciate, defaultFilename, wsdlInfo, this.jaxbModule.getJaxbContext(), baseUri, ns2prefix, facetFilter));
}
}
if (this.jaxrsModule != null && this.jaxbModule != null && !isDisableWadl()) {
this.jaxrsModule.getJaxrsContext().setWadlFile(new JaxrsWadlFile(this.enunciate, "application.wadl", this.jaxrsModule.getJaxrsContext(), this.jaxbModule.getJaxbContext(), new ArrayList<SchemaInfo>(ns2schema.values()), getWadlStylesheetUri(), baseUri, ns2prefix, facetFilter, isLinkJsonToXml()));
}
}
Aggregations