use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class WSDLGeneratorImpl method testPartialWSDL2.
/**
* Tests the binding, service, and port not specified in the WSDL.
* <p/>
* This test is based on the FVT test AddNumbersImplPartial2
*/
public void testPartialWSDL2() {
String wsdlRelativeLocation = "test-resources/wsdl/";
String wsdlFileName = "PartialWSDL2.wsdl";
String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
// Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
Definition wsdlDefn = DescriptionTestUtils.createWSDLDefinition(wsdlURL);
assertNotNull(wsdlDefn);
WebServiceAnnot webServiceAnnot = WebServiceAnnot.createWebServiceAnnotImpl();
assertNotNull(webServiceAnnot);
webServiceAnnot.setWsdlLocation(wsdlLocation);
webServiceAnnot.setTargetNamespace(targetNamespace);
MethodDescriptionComposite mdc = new MethodDescriptionComposite();
mdc.setMethodName("addTwoNumbers");
mdc.setReturnType("int");
ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
pdc1.setParameterType("int");
ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
pdc1.setParameterType("int");
mdc.addParameterDescriptionComposite(pdc1);
mdc.addParameterDescriptionComposite(pdc2);
dbc.addMethodDescriptionComposite(mdc);
dbc.setWebServiceAnnot(webServiceAnnot);
dbc.setClassName(AddNumbersImplPartial1.class.getName());
dbc.setWsdlDefinition(wsdlDefn);
dbc.setwsdlURL(wsdlURL);
dbc.setCustomWsdlGenerator(new WSDLGeneratorImpl(wsdlDefn));
HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
dbcMap.put(AddNumbersImplPartial1.class.getName(), dbc);
List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
assertEquals(1, serviceDescList.size());
ServiceDescription sd = serviceDescList.get(0);
assertNotNull(sd);
EndpointDescription[] edArray = sd.getEndpointDescriptions();
assertNotNull(edArray);
assertEquals(1, edArray.length);
EndpointDescription ed = edArray[0];
assertNotNull(ed);
// Test for presence of generated WSDL
AxisService as = ed.getAxisService();
assertNotNull(as);
Parameter compositeParam = as.getParameter(MDQConstants.WSDL_COMPOSITE);
assertNotNull(compositeParam);
assertNotNull(compositeParam.getValue());
EndpointInterfaceDescription eid = ed.getEndpointInterfaceDescription();
assertNotNull(eid);
OperationDescription[] odArray = eid.getOperations();
assertNotNull(odArray);
assertEquals(1, odArray.length);
OperationDescription od = odArray[0];
}
use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class WSDLGeneratorImpl method testPartialWSDL1.
/**
* Tests the binding, service, and port not specified in the WSDL.
* <p/>
* This test is based on the FVT test AddNumbersImplPartial1
*/
public void testPartialWSDL1() {
String wsdlRelativeLocation = "test-resources/wsdl/";
String wsdlFileName = "PartialWSDL1.wsdl";
String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
// Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
Definition wsdlDefn = DescriptionTestUtils.createWSDLDefinition(wsdlURL);
assertNotNull(wsdlDefn);
WebServiceAnnot webServiceAnnot = WebServiceAnnot.createWebServiceAnnotImpl();
assertNotNull(webServiceAnnot);
webServiceAnnot.setWsdlLocation(wsdlLocation);
webServiceAnnot.setTargetNamespace(targetNamespace);
MethodDescriptionComposite mdc = new MethodDescriptionComposite();
mdc.setMethodName("addTwoNumbers");
mdc.setReturnType("int");
ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
pdc1.setParameterType("int");
ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
pdc1.setParameterType("int");
mdc.addParameterDescriptionComposite(pdc1);
mdc.addParameterDescriptionComposite(pdc2);
dbc.addMethodDescriptionComposite(mdc);
dbc.setWebServiceAnnot(webServiceAnnot);
dbc.setClassName(AddNumbersImplPartial1.class.getName());
dbc.setWsdlDefinition(wsdlDefn);
dbc.setwsdlURL(wsdlURL);
dbc.setCustomWsdlGenerator(new WSDLGeneratorImpl(wsdlDefn));
HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
dbcMap.put(AddNumbersImplPartial1.class.getName(), dbc);
List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
assertEquals(1, serviceDescList.size());
ServiceDescription sd = serviceDescList.get(0);
assertNotNull(sd);
EndpointDescription[] edArray = sd.getEndpointDescriptions();
assertNotNull(edArray);
assertEquals(1, edArray.length);
EndpointDescription ed = edArray[0];
assertNotNull(ed);
// Test for presence of generated WSDL
AxisService as = ed.getAxisService();
assertNotNull(as);
Parameter compositeParam = as.getParameter(MDQConstants.WSDL_COMPOSITE);
assertNotNull(compositeParam);
assertNotNull(compositeParam.getValue());
EndpointInterfaceDescription eid = ed.getEndpointInterfaceDescription();
assertNotNull(eid);
OperationDescription[] odArray = eid.getOperations();
assertNotNull(odArray);
assertEquals(1, odArray.length);
OperationDescription od = odArray[0];
}
use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class ValidateWSDLImpl2 method testValidatePortType.
/**
* The SEI used by the service impl does not contain all the methods defined on the PortType
*/
public void testValidatePortType() {
String wsdlRelativeLocation = System.getProperty("basedir", ".") + "/" + "test-resources/wsdl/";
String wsdlFileName = "ValidateWSDL1.wsdl";
String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
// Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
Definition wsdlDefn = DescriptionTestUtils.createWSDLDefinition(wsdlURL);
assertNotNull(wsdlDefn);
WebServiceAnnot webServiceAnnot = WebServiceAnnot.createWebServiceAnnotImpl();
assertNotNull(webServiceAnnot);
webServiceAnnot.setWsdlLocation(wsdlLocation);
webServiceAnnot.setTargetNamespace(targetNamespace);
MethodDescriptionComposite mdc = new MethodDescriptionComposite();
mdc.setMethodName("addTwoNumbers");
mdc.setReturnType("int");
ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
pdc1.setParameterType("int");
ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
pdc1.setParameterType("int");
mdc.addParameterDescriptionComposite(pdc1);
mdc.addParameterDescriptionComposite(pdc2);
dbc.addMethodDescriptionComposite(mdc);
dbc.setWebServiceAnnot(webServiceAnnot);
dbc.setClassName(ValidateWSDLImpl1.class.getName());
dbc.setWsdlDefinition(wsdlDefn);
dbc.setwsdlURL(wsdlURL);
HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
dbcMap.put(ValidateWSDLImpl1.class.getName(), dbc);
try {
List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
// Removing the fail() call here as we removed the Valdiation Error from
// EndpointInterfaceDescriptionValidator.
// Expected code path
} catch (WebServiceException e) {
// Expected code path
}
}
use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class AnnotationServiceImplWithDBCTests method testLoadWSDLSEI.
public void testLoadWSDLSEI() {
String wsdlLocation = getEchoMessageServiceWSDLLocation();
// Build up a DBC, including the WSDL Definition and the annotation information for
// the impl class.
JavaClassToDBCConverter converter = new JavaClassToDBCConverter(EchoMessageServiceSEI.class);
HashMap<String, DescriptionBuilderComposite> dbcMap = converter.produceDBC();
assertNotNull(dbcMap);
DescriptionBuilderComposite dbc = dbcMap.get(EchoMessageServiceSEI.class.getName());
assertNotNull(dbc);
DescriptionBuilderComposite seiDBC = dbcMap.get(EchoMessageServiceInterface.class.getName());
assertNotNull(seiDBC);
dbc.setClassLoader(this.getClass().getClassLoader());
WebServiceAnnot webServiceAnnot = seiDBC.getWebServiceAnnot();
assertNotNull(webServiceAnnot);
webServiceAnnot.setWsdlLocation(wsdlLocation);
seiDBC.setWebServiceAnnot(webServiceAnnot);
dbcMap.put(EchoMessageServiceInterface.class.getName(), seiDBC);
List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
assertEquals(1, serviceDescList.size());
ServiceDescription sd = serviceDescList.get(0);
assertNotNull(sd);
// make sure the WSDL definition was read in from the appropriate location
assertNotNull(((ServiceDescriptionWSDL) sd).getWSDLDefinition());
}
use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.
the class WSDL11Writer method writeWSDL.
private void writeWSDL(Definition definition, String fileName, Map changedMap, Map baseURIwsdlNameMap) throws Exception {
// first process the imports and save them.
Map imports = definition.getImports();
if (imports != null && (imports.size() > 0)) {
Vector importsVector = null;
Import wsdlImport = null;
String wsdlName = null;
String wsdlLocation = null;
for (Iterator improtsVectorIter = imports.values().iterator(); improtsVectorIter.hasNext(); ) {
importsVector = (Vector) improtsVectorIter.next();
for (Iterator importsIter = importsVector.iterator(); importsIter.hasNext(); ) {
wsdlImport = (Import) importsIter.next();
wsdlLocation = wsdlImport.getDefinition().getDocumentBaseURI();
// we have to process this wsdl file only if it has not been processed earlier
if (!baseURIwsdlNameMap.containsKey(wsdlLocation)) {
wsdlName = wsdlLocation.substring(wsdlLocation.lastIndexOf('/') + 1);
if (!wsdlName.endsWith(".wsdl") && !wsdlName.endsWith(".xsd")) {
// this seems to be an online wsdl so we generate a dummy name
if (wsdlName.indexOf("xsd") > -1) {
wsdlName = "xsd" + count++ + ".xsd";
} else {
wsdlName = "wsdl" + count++ + ".wsdl";
}
}
// trim the wsdl part
while (baseURIwsdlNameMap.containsValue(wsdlName)) {
// import file name can either be xsd or wsdl
String fileNamePart = wsdlName.substring(0, wsdlName.lastIndexOf("."));
String extension = wsdlName.substring(wsdlName.lastIndexOf("."));
wsdlName = fileNamePart + count++ + extension;
}
baseURIwsdlNameMap.put(wsdlLocation, wsdlName);
Definition innerDefinition = wsdlImport.getDefinition();
writeWSDL(innerDefinition, wsdlName, changedMap, baseURIwsdlNameMap);
}
wsdlImport.setLocationURI((String) baseURIwsdlNameMap.get(wsdlLocation));
}
}
}
// change the locations on the imported schemas
adjustWSDLSchemaLocations(definition, changedMap);
// finally save the file
WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
File outputFile = FileWriter.createClassFile(baseFolder, null, fileName, null);
FileOutputStream out = new FileOutputStream(outputFile);
if (definition.getServices().size() > 1) {
List removedServices = new ArrayList();
List servicesList = new ArrayList();
Map services = definition.getServices();
// populate the services list
for (Iterator iter = services.values().iterator(); iter.hasNext(); ) {
servicesList.add(iter.next());
}
Service service;
String serviceNameFromFileName = fileName;
if (fileName.indexOf(".wsdl") > -1) {
serviceNameFromFileName = fileName.substring(0, fileName.lastIndexOf(".wsdl"));
}
if (fileName.indexOf(".xsd") > -1) {
serviceNameFromFileName = fileName.substring(0, fileName.lastIndexOf(".xsd"));
}
for (Iterator iter = servicesList.iterator(); iter.hasNext(); ) {
service = (Service) iter.next();
if (!service.getQName().getLocalPart().equals(serviceNameFromFileName)) {
definition.removeService(service.getQName());
removedServices.add(service);
}
}
// now we have only the required service so write it
wsdlWriter.writeWSDL(definition, out);
// again add the removed services
for (Iterator iter = removedServices.iterator(); iter.hasNext(); ) {
service = (Service) iter.next();
definition.addService(service);
}
} else {
// no problem proceed normaly
wsdlWriter.writeWSDL(definition, out);
}
out.flush();
out.close();
}
Aggregations