use of org.apache.cxf.wsdl11.WSDLServiceFactory in project cxf by apache.
the class CorbaBindingFactoryTest method setupServiceInfo.
protected void setupServiceInfo(String ns, String wsdl, String serviceName, String portName) {
URL wsdlUrl = getClass().getResource(wsdl);
assertNotNull(wsdlUrl);
WSDLServiceFactory f = new WSDLServiceFactory(bus, wsdlUrl.toString(), new QName(ns, serviceName));
Service service = f.create();
endpointInfo = service.getEndpointInfo(new QName(ns, portName));
}
use of org.apache.cxf.wsdl11.WSDLServiceFactory in project cxf by apache.
the class DynamicClientFactory method createClient.
public Client createClient(String wsdlUrl, QName service, ClassLoader classLoader, QName port, List<String> bindingFiles) {
if (classLoader == null) {
classLoader = Thread.currentThread().getContextClassLoader();
}
LOG.log(Level.FINE, "Creating client from WSDL " + wsdlUrl);
WSDLServiceFactory sf = (service == null) ? (new WSDLServiceFactory(bus, wsdlUrl)) : (new WSDLServiceFactory(bus, wsdlUrl, service));
sf.setAllowElementRefs(allowRefs);
Service svc = sf.create();
// all SI's should have the same schemas
SchemaCollection schemas = svc.getServiceInfos().get(0).getXmlSchemaCollection();
SchemaCompiler compiler = createSchemaCompiler();
InnerErrorListener listener = new InnerErrorListener(wsdlUrl);
Object elForRun = ReflectionInvokationHandler.createProxyWrapper(listener, JAXBUtils.getParamClass(compiler, "setErrorListener"));
compiler.setErrorListener(elForRun);
OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
hackInNewInternalizationLogic(compiler, catalog);
addSchemas(compiler.getOptions(), compiler, svc.getServiceInfos(), schemas);
addBindingFiles(bindingFiles, compiler);
S2JJAXBModel intermediateModel = compiler.bind();
listener.throwException();
JCodeModel codeModel = intermediateModel.generateCode(null, elForRun);
StringBuilder sb = new StringBuilder();
boolean firstnt = false;
for (Iterator<JPackage> packages = codeModel.packages(); packages.hasNext(); ) {
JPackage jpackage = packages.next();
if (!isValidPackage(jpackage)) {
continue;
}
if (firstnt) {
sb.append(':');
} else {
firstnt = true;
}
sb.append(jpackage.name());
}
JAXBUtils.logGeneratedClassNames(LOG, codeModel);
String packageList = sb.toString();
// our hashcode + timestamp ought to be enough.
String stem = toString() + "-" + System.currentTimeMillis();
File src = new File(tmpdir, stem + "-src");
if (!src.mkdir()) {
throw new IllegalStateException("Unable to create working directory " + src.getPath());
}
try {
Object writer = JAXBUtils.createFileCodeWriter(src);
codeModel.build(writer);
} catch (Exception e) {
throw new IllegalStateException("Unable to write generated Java files for schemas: " + e.getMessage(), e);
}
File classes = new File(tmpdir, stem + "-classes");
if (!classes.mkdir()) {
throw new IllegalStateException("Unable to create working directory " + classes.getPath());
}
StringBuilder classPath = new StringBuilder();
try {
setupClasspath(classPath, classLoader);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
List<File> srcFiles = FileUtils.getFilesRecurse(src, ".+\\.java$");
if (!srcFiles.isEmpty() && !compileJavaSrc(classPath.toString(), srcFiles, classes.toString())) {
LOG.log(Level.SEVERE, new Message("COULD_NOT_COMPILE_SRC", LOG, wsdlUrl).toString());
}
FileUtils.removeDir(src);
URL[] urls = null;
try {
urls = new URL[] { classes.toURI().toURL() };
} catch (MalformedURLException mue) {
throw new IllegalStateException("Internal error; a directory returns a malformed URL: " + mue.getMessage(), mue);
}
final ClassLoader cl = ClassLoaderUtils.getURLClassLoader(urls, classLoader);
JAXBContext context;
Map<String, Object> contextProperties = jaxbContextProperties;
if (contextProperties == null) {
contextProperties = Collections.emptyMap();
}
try {
if (StringUtils.isEmpty(packageList)) {
context = JAXBContext.newInstance(new Class[0], contextProperties);
} else {
context = JAXBContext.newInstance(packageList, cl, contextProperties);
}
} catch (JAXBException jbe) {
throw new IllegalStateException("Unable to create JAXBContext for generated packages: " + jbe.getMessage(), jbe);
}
JAXBDataBinding databinding = new JAXBDataBinding();
databinding.setContext(context);
svc.setDataBinding(databinding);
ClientImpl client = new DynamicClientImpl(bus, svc, port, getEndpointImplFactory(), cl);
ServiceInfo svcfo = client.getEndpoint().getEndpointInfo().getService();
// Setup the new classloader!
ClassLoaderUtils.setThreadContextClassloader(cl);
TypeClassInitializer visitor = new TypeClassInitializer(svcfo, intermediateModel, allowWrapperOps());
visitor.walk();
// delete the classes files
FileUtils.removeDir(classes);
return client;
}
use of org.apache.cxf.wsdl11.WSDLServiceFactory in project cxf by apache.
the class AbstractSTSClient method createClient.
protected void createClient() throws BusException, EndpointException {
if (client != null) {
return;
}
if (wsdlLocation != null) {
WSDLServiceFactory factory = new WSDLServiceFactory(bus, wsdlLocation, serviceName);
SourceDataBinding dataBinding = new SourceDataBinding();
factory.setDataBinding(dataBinding);
Service service = factory.create();
service.setDataBinding(dataBinding);
EndpointInfo ei = service.getEndpointInfo(endpointName);
Endpoint endpoint = new EndpointImpl(bus, service, ei);
client = new ClientImpl(bus, endpoint);
} else if (location != null) {
Endpoint endpoint = STSUtils.createSTSEndpoint(bus, namespace, null, location, soapVersion, policy, endpointName);
client = new ClientImpl(bus, endpoint);
} else {
throw new TrustException(LOG, "NO_LOCATION");
}
client.getInFaultInterceptors().addAll(inFault);
client.getInInterceptors().addAll(in);
client.getOutInterceptors().addAll(out);
client.getOutFaultInterceptors().addAll(outFault);
if (tlsClientParameters != null) {
HTTPConduit http = (HTTPConduit) client.getConduit();
http.setTlsClientParameters(tlsClientParameters);
}
in = null;
out = null;
inFault = null;
outFault = null;
if (features != null) {
for (Feature f : features) {
f.initialize(client, bus);
}
}
}
use of org.apache.cxf.wsdl11.WSDLServiceFactory in project cxf by apache.
the class CorbaConduitTest method setupServiceInfo.
protected void setupServiceInfo(String ns, String wsdl, String serviceName, String portName) {
URL wsdlUrl = getClass().getResource(wsdl);
assertNotNull(wsdlUrl);
WSDLServiceFactory f = new WSDLServiceFactory(bus, wsdlUrl.toString(), new QName(ns, serviceName));
Service service = f.create();
endpointInfo = service.getEndpointInfo(new QName(ns, portName));
}
use of org.apache.cxf.wsdl11.WSDLServiceFactory in project cxf by apache.
the class AbstractSTSClient method configureViaEPR.
public void configureViaEPR(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
if (client != null) {
return;
}
location = EndpointReferenceUtils.getAddress(ref);
if (location != null) {
location = location.trim();
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("EPR address: " + location);
}
final QName sName = EndpointReferenceUtils.getServiceName(ref, bus);
if (sName != null) {
serviceName = sName;
final QName epName = EndpointReferenceUtils.getPortQName(ref, bus);
if (epName != null) {
endpointName = epName;
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("EPR endpoint: " + serviceName + " " + endpointName);
}
}
final String wsdlLoc = EndpointReferenceUtils.getWSDLLocation(ref);
if (wsdlLoc != null) {
wsdlLocation = wsdlLoc;
}
String mexLoc = findMEXLocation(ref, useEPRWSAAddrAsMEXLocation);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("WS-MEX location: " + mexLoc);
}
if (mexLoc != null) {
try {
JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
proxyFac.setBindingId(soapVersion);
proxyFac.setAddress(mexLoc);
MetadataExchange exc = proxyFac.create(MetadataExchange.class);
Metadata metadata = exc.get2004();
Definition definition = null;
List<Schema> schemas = new ArrayList<>();
// Parse the MetadataSections into WSDL definition + associated schemas
for (MetadataSection s : metadata.getMetadataSection()) {
if ("http://schemas.xmlsoap.org/wsdl/".equals(s.getDialect())) {
definition = bus.getExtension(WSDLManager.class).getDefinition((Element) s.getAny());
} else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
Element schemaElement = (Element) s.getAny();
if (schemaElement == null) {
String schemaLocation = s.getLocation();
LOG.info("XSD schema location: " + schemaLocation);
schemaElement = downloadSchema(schemaLocation);
}
QName schemaName = new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
ExtensibilityElement exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
((Schema) exElement).setElement(schemaElement);
schemas.add((Schema) exElement);
}
}
if (definition != null) {
// Add any extra schemas to the WSDL definition
for (Schema schema : schemas) {
definition.getTypes().addExtensibilityElement(schema);
}
WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
SourceDataBinding dataBinding = new SourceDataBinding();
factory.setDataBinding(dataBinding);
Service service = factory.create();
service.setDataBinding(dataBinding);
// Get the endpoint + service names by matching the 'location' to the
// address in the WSDL. If the 'location' is 'anonymous' then just fall
// back to the first service + endpoint name in the WSDL, if the endpoint
// name is not defined in the Metadata
List<ServiceInfo> services = service.getServiceInfos();
String anonymousAddress = "http://www.w3.org/2005/08/addressing/anonymous";
if (!anonymousAddress.equals(location)) {
for (ServiceInfo serv : services) {
for (EndpointInfo ei : serv.getEndpoints()) {
if (ei.getAddress().equals(location)) {
endpointName = ei.getName();
serviceName = serv.getName();
LOG.fine("Matched endpoint to location");
}
}
}
}
EndpointInfo ei = service.getEndpointInfo(endpointName);
if (ei == null && anonymousAddress.equals(location) && !services.isEmpty() && !services.get(0).getEndpoints().isEmpty()) {
LOG.fine("Anonymous location so taking first endpoint");
serviceName = services.get(0).getName();
endpointName = services.get(0).getEndpoints().iterator().next().getName();
ei = service.getEndpointInfo(endpointName);
}
if (ei == null) {
throw new TrustException(LOG, "ADDRESS_NOT_MATCHED", location);
}
if (location != null && !anonymousAddress.equals(location)) {
ei.setAddress(location);
}
Endpoint endpoint = new EndpointImpl(bus, service, ei);
client = new ClientImpl(bus, endpoint);
}
} catch (Exception ex) {
throw new TrustException("WS_MEX_ERROR", ex, LOG);
}
}
}
Aggregations