use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.
the class ServiceDescriptionImpl method setWSDLDefinitionOnDBC.
/**
* This method accepts a location of a WSDL document and attempts to
* load and set the WSDL definition on the DBC object.
* @param wsdlLocation
*/
private void setWSDLDefinitionOnDBC(String wsdlLocation) {
if (log.isDebugEnabled()) {
log.debug("Attempting to load WSDL file from location specified in annotation: " + wsdlLocation);
}
if (composite.getClassLoader() == null) {
if (log.isDebugEnabled()) {
log.debug("A classloader could not be found for class: " + composite.getClassName() + ". The WSDL file: " + wsdlLocation + " will not be " + "processed, and the ServiceDescription will be built from " + "annotations");
}
}
try {
if (log.isDebugEnabled()) {
log.debug("Attempting to read WSDL: " + wsdlLocation + " for web " + "service endpoint: " + composite.getClassName());
}
if (log.isDebugEnabled()) {
if (configContext != null) {
log.debug("new WSDL4JWrapper-ConfigContext not null5");
} else {
log.debug("new WSDL4JWrapper-ConfigContext null5");
}
}
URL url = getWSDLURL(wsdlLocation);
ConfigurationContext cc = composite.getConfigurationContext();
if (cc != null) {
this.wsdlWrapper = new WSDL4JWrapper(url, cc, this.catalogManager);
} else {
// Probably shouldn't get here. But if we do, use a memory sensitive
// wsdl wrapper
this.wsdlWrapper = new WSDL4JWrapper(url, this.catalogManager, true, 2);
}
composite.setWsdlDefinition(wsdlWrapper.getDefinition());
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("The WSDL file: " + wsdlLocation + " for class: " + composite.getClassName() + "could not be processed. The ServiceDescription will be built from " + "annotations");
}
}
}
use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.
the class Axis2EndpointReferenceFactoryImpl method createEndpointReference.
/*
* (non-Javadoc)
* @see org.apache.axis2.jaxws.addressing.factory.Axis2EndpointReferenceFactory#createEndpointReference(java.lang.String, javax.xml.namespace.QName, javax.xml.namespace.QName, java.lang.String, java.lang.String)
*/
public EndpointReference createEndpointReference(String address, QName serviceName, QName portName, String wsdlDocumentLocation, String addressingNamespace) {
EndpointReference axis2EPR = null;
if (address != null) {
if (serviceName == null && portName != null) {
throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr", portName.toString()));
}
axis2EPR = createEndpointReference(address);
} else if (serviceName != null && portName != null) {
axis2EPR = createEndpointReference(serviceName, portName);
} else {
throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr2"));
}
// should simply use those.
try {
// This code is locate here instead of in the createEndpointReference(QName, QName)
// method so that if the address is also specified the EPR metadata will still be
// filled in correctly.
EndpointReferenceUtils.addService(axis2EPR, serviceName, portName, addressingNamespace);
if (wsdlDocumentLocation != null) {
URL wsdlURL;
try {
wsdlURL = new URL(wsdlDocumentLocation);
} catch (MalformedURLException e) {
// just to keep it clean:
if (axis2EPR.getAddress().endsWith("/") && wsdlDocumentLocation.startsWith("/")) {
wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation.substring(1);
} else if (axis2EPR.getAddress().endsWith("/")) {
String eprAddress = axis2EPR.getAddress();
wsdlDocumentLocation = eprAddress.substring(0, eprAddress.length() - 1) + wsdlDocumentLocation;
} else {
wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation;
}
}
wsdlURL = new URL(wsdlDocumentLocation);
// This is a temporary usage, so use a memory sensitive wrapper
WSDLWrapper wrapper = new WSDL4JWrapper(wsdlURL, true, 2);
if (serviceName != null) {
QName serviceNameNoTrailingSlash = new QName("");
// TODO: why in the world would we have to do this?
if (serviceName.getNamespaceURI().endsWith("/")) {
String ns = serviceName.getNamespaceURI();
serviceNameNoTrailingSlash = new QName(ns.substring(0, ns.length() - 1), serviceName.getLocalPart());
}
if ((wrapper.getService(serviceName) == null) && (wrapper.getService(serviceNameNoTrailingSlash) == null)) {
throw new IllegalStateException(Messages.getMessage("MissingServiceName", serviceName.toString(), wsdlDocumentLocation));
}
if (portName != null) {
String[] ports = wrapper.getPorts(serviceName);
// search the other name. TODO: again, why do we have to do this?
if (ports == null) {
ports = wrapper.getPorts(serviceNameNoTrailingSlash);
}
String portLocalName = portName.getLocalPart();
boolean found = false;
if (ports != null) {
for (String port : ports) {
// TODO: axis2 perhaps is deploying with "TypeImplPort" appended, but not reading/honoring the WSDL?
if (port.equals(portLocalName) || (port + "TypeImplPort").equals(portLocalName)) {
log.debug("found port: " + port);
found = true;
break;
}
}
}
if (!found) {
throw new IllegalStateException(Messages.getMessage("MissingPortName", portName.toString(), wsdlDocumentLocation));
}
log.debug("Setting wsdlDocumentLocation to " + wsdlDocumentLocation + " for EndpointReference at port " + portName);
EndpointReferenceUtils.addLocation(axis2EPR, portName.getNamespaceURI(), wsdlDocumentLocation, addressingNamespace);
}
}
}
} catch (IllegalStateException ise) {
throw ise;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointRefCreationError"), e);
}
return axis2EPR;
}
use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.
the class SchemaReaderTests method testSchemaReader.
public void testSchemaReader() {
SchemaReaderImpl sri = new SchemaReaderImpl();
String wsdlLocation = "/test-resources/wsdl/shapes.wsdl";
URL url = null;
try {
try {
String baseDir = new File(System.getProperty("basedir", ".")).getCanonicalPath();
wsdlLocation = new File(baseDir + wsdlLocation).getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
fail();
}
File file = new File(wsdlLocation);
url = file.toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
try {
WSDL4JWrapper w4j = new WSDL4JWrapper(url);
Definition wsdlDef = w4j.getDefinition();
assertNotNull(wsdlDef);
Set<String> pkg = sri.readPackagesFromSchema(wsdlDef);
TestLogger.logger.debug("Packages:");
for (String pkgName : pkg) {
TestLogger.logger.debug(pkgName);
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.
the class DescriptionBuilderComposite method setWsdlDefinition.
/**
* @param wsdlDefinition The wsdlDefinition to set.
*/
public void setWsdlDefinition(Definition wsdlDef) {
Definition def = null;
if (wsdlDef != null) {
if (wsdlDef instanceof WSDL4JWrapper) {
wsdlWrapper = (WSDL4JWrapper) wsdlDef;
def = wsdlWrapper.getDefinition();
} else {
try {
if (myConfigContext != null) {
// Construct WSDL4JWrapper with configuration information
wsdlWrapper = new WSDL4JWrapper(wsdlDef, myConfigContext);
} else {
// If there is no configuration, default to using a
// memory sensitive wrapper
wsdlWrapper = new WSDL4JWrapper(wsdlDef, true, 2);
}
def = wsdlWrapper.getDefinition();
} catch (Exception ex) {
// absorb
}
}
if (def != null) {
String wsdlDefinitionBaseURI = def.getDocumentBaseURI();
if ((wsdlDefinitionBaseURI != null) && (wsdlURL == null)) {
try {
wsdlURL = new URL(wsdlDefinitionBaseURI);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("DescriptionBuilderComposite:setWsdlDefinition(): " + "Caught exception creating WSDL URL :" + wsdlDefinitionBaseURI + "; exception: " + e.toString(), e);
}
}
}
}
}
}
use of org.apache.axis2.jaxws.util.WSDL4JWrapper in project axis-axis2-java-core by apache.
the class MultiRedirectionCatalogTest method verifySuccess.
/**
* Ensure that the catalog is used to locate imported resources.
*/
private void verifySuccess(String wsdlLocation, String catalogFile) {
URL url = getURLFromLocation(wsdlLocation);
try {
OASISCatalogManager catalogManager = new OASISCatalogManager();
catalogManager.setCatalogFiles(getURLFromLocation(catalogFile).toString());
WSDL4JWrapper w4j = new WSDL4JWrapper(url, catalogManager, false, 0);
Definition wsdlDef = w4j.getDefinition();
assertNotNull(wsdlDef);
QName portTypeName = new QName("http://www.example.com/test/calculator", "CalculatorService", "");
PortType portType = wsdlDef.getPortType(portTypeName);
assertNotNull(portType);
Operation clearOp = portType.getOperation("clear", null, null);
assertNotNull(clearOp);
Input clearOpInput = clearOp.getInput();
assertNotNull(clearOpInput);
Message msg = clearOpInput.getMessage();
assertNotNull(msg);
Part expectedPart = msg.getPart("part1");
assertNotNull(expectedPart);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations