use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class StaxDataBinding method initialize.
public void initialize(Service service) {
for (ServiceInfo serviceInfo : service.getServiceInfos()) {
SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
if (schemaCollection.getXmlSchemas().length > 1) {
// Schemas are already populated.
continue;
}
new ServiceModelVisitor(serviceInfo) {
@Override
public void begin(MessagePartInfo part) {
if (part.getTypeQName() != null || part.getElementQName() != null) {
return;
}
part.setTypeQName(Constants.XSD_ANYTYPE);
}
}.walk();
}
}
use of org.apache.cxf.service.model.ServiceInfo 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);
applySchemaCompilerOptions(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.getFilesRecurseUsingSuffix(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);
final URL[] urls;
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(bus, svcfo, intermediateModel, allowWrapperOps());
visitor.walk();
// delete the classes files
FileUtils.removeDir(classes);
return client;
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class JavascriptGetInterceptor method writeResponse.
private void writeResponse(URI uri, Map<String, String> map, OutputStream os, Endpoint serverEndpoint) {
OutputStreamWriter writer = new OutputStreamWriter(os, UTF_8);
if (!map.containsKey(NO_UTILS_QUERY_KEY)) {
writeUtilsToResponseStream(JavascriptGetInterceptor.class, os);
}
if (map.containsKey(CODE_QUERY_KEY)) {
ServiceInfo serviceInfo = serverEndpoint.getService().getServiceInfos().get(0);
Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
// we need to move this to the bus.
BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, serverEndpoint);
NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
try {
for (SchemaInfo schema : schemata) {
SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), prefixManager, nameManager);
String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
writer.append(allThatJavascript);
}
ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, serverEndpoint.getEndpointInfo().getAddress(), prefixManager, nameManager);
serviceBuilder.walk();
String serviceJavascript = serviceBuilder.getCode();
writer.append(serviceJavascript);
writer.flush();
} catch (IOException e) {
throw new UncheckedException(e);
}
} else {
throw new RuntimeException("Invalid query " + uri.toString());
}
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class ReflectionServiceFactoryTest method testWrappedBuild.
@Test
public void testWrappedBuild() throws Exception {
Service service = createService(true);
ServiceInfo si = service.getServiceInfos().get(0);
InterfaceInfo intf = si.getInterface();
assertEquals(4, intf.getOperations().size());
String ns = si.getName().getNamespaceURI();
OperationInfo sayHelloOp = intf.getOperation(new QName(ns, "sayHello"));
assertNotNull(sayHelloOp);
assertEquals("sayHello", sayHelloOp.getInput().getName().getLocalPart());
List<MessagePartInfo> messageParts = sayHelloOp.getInput().getMessageParts();
assertEquals(1, messageParts.size());
assertNotNull(messageParts.get(0).getXmlSchema());
// test unwrapping
assertTrue(sayHelloOp.isUnwrappedCapable());
OperationInfo unwrappedOp = sayHelloOp.getUnwrappedOperation();
assertEquals("sayHello", unwrappedOp.getInput().getName().getLocalPart());
messageParts = unwrappedOp.getInput().getMessageParts();
assertEquals(0, messageParts.size());
// test output
messageParts = sayHelloOp.getOutput().getMessageParts();
assertEquals(1, messageParts.size());
assertEquals("sayHelloResponse", sayHelloOp.getOutput().getName().getLocalPart());
messageParts = unwrappedOp.getOutput().getMessageParts();
assertEquals("sayHelloResponse", unwrappedOp.getOutput().getName().getLocalPart());
assertEquals(1, messageParts.size());
MessagePartInfo mpi = messageParts.get(0);
assertEquals("return", mpi.getName().getLocalPart());
assertEquals(String.class, mpi.getTypeClass());
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class DocLiteralInInterceptorTest method testUnmarshalSourceData.
@Test
public void testUnmarshalSourceData() throws Exception {
XMLStreamReader reader = StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("resources/multiPartDocLitBareReq.xml"));
assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
XMLStreamReader filteredReader = new PartialXMLStreamReader(reader, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"));
// advance the xml reader to the message parts
StaxUtils.read(filteredReader);
assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
Message m = new MessageImpl();
Exchange exchange = new ExchangeImpl();
Service service = control.createMock(Service.class);
exchange.put(Service.class, service);
EasyMock.expect(service.getDataBinding()).andReturn(new SourceDataBinding());
EasyMock.expect(service.size()).andReturn(0).anyTimes();
EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
Endpoint endpoint = control.createMock(Endpoint.class);
exchange.put(Endpoint.class, endpoint);
OperationInfo operationInfo = new OperationInfo();
operationInfo.setProperty("operation.is.synthetic", Boolean.TRUE);
MessageInfo messageInfo = new MessageInfo(operationInfo, Type.INPUT, new QName("http://foo.com", "bar"));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo1"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo2"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo3"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo4"), null));
for (MessagePartInfo mpi : messageInfo.getMessageParts()) {
mpi.setMessageContainer(messageInfo);
}
operationInfo.setInput("inputName", messageInfo);
BindingOperationInfo boi = new BindingOperationInfo(null, operationInfo);
exchange.put(BindingOperationInfo.class, boi);
EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
BindingInfo binding = control.createMock(BindingInfo.class);
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
EasyMock.expect(endpointInfo.getBinding()).andReturn(binding).anyTimes();
EasyMock.expect(binding.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(endpointInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(endpoint.size()).andReturn(0).anyTimes();
EasyMock.expect(endpoint.isEmpty()).andReturn(true).anyTimes();
ServiceInfo serviceInfo = control.createMock(ServiceInfo.class);
EasyMock.expect(endpointInfo.getService()).andReturn(serviceInfo).anyTimes();
EasyMock.expect(serviceInfo.getName()).andReturn(new QName("http://foo.com", "service")).anyTimes();
InterfaceInfo interfaceInfo = control.createMock(InterfaceInfo.class);
EasyMock.expect(serviceInfo.getInterface()).andReturn(interfaceInfo).anyTimes();
EasyMock.expect(interfaceInfo.getName()).andReturn(new QName("http://foo.com", "interface")).anyTimes();
EasyMock.expect(endpointInfo.getName()).andReturn(new QName("http://foo.com", "endpoint")).anyTimes();
EasyMock.expect(endpointInfo.getProperty("URI", URI.class)).andReturn(new URI("dummy")).anyTimes();
List<OperationInfo> operations = new ArrayList<>();
EasyMock.expect(interfaceInfo.getOperations()).andReturn(operations).anyTimes();
m.setExchange(exchange);
m.put(Message.SCHEMA_VALIDATION_ENABLED, false);
m.setContent(XMLStreamReader.class, reader);
control.replay();
new DocLiteralInInterceptor().handleMessage(m);
MessageContentsList params = (MessageContentsList) m.getContent(List.class);
assertEquals(4, params.size());
assertEquals("StringDefaultInputElem", ((DOMSource) params.get(0)).getNode().getFirstChild().getNodeName());
assertEquals("IntParamInElem", ((DOMSource) params.get(1)).getNode().getFirstChild().getNodeName());
}
Aggregations