use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.
the class XMLFormatValidator method findXMLFormatRootNode.
private boolean findXMLFormatRootNode(Iterator<XMLBindingMessageFormat> it, BindingOperationInfo bo, String errorPath) {
while (it != null && it.hasNext()) {
XMLBindingMessageFormat xmlFormat = it.next();
if (xmlFormat.getRootNode() == null) {
QName rootNodeName = bo.getName();
addErrorMessage(errorPath + ": empty value of rootNode attribute, the value should be " + rootNodeName);
return false;
}
}
return true;
}
use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.
the class XMLMessageOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
MessageInfo mi;
BindingMessageInfo bmi;
if (isRequestor(message)) {
mi = boi.getOperationInfo().getInput();
bmi = boi.getInput();
} else {
mi = boi.getOperationInfo().getOutput();
bmi = boi.getOutput();
}
XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
QName rootInModel = null;
if (xmf != null) {
rootInModel = xmf.getRootNode();
}
final int mpn = mi.getMessagePartsNumber();
if (boi.isUnwrapped() || mpn == 1) {
// wrapper out interceptor created the wrapper
// or if bare-one-param
new BareOutInterceptor().handleMessage(message);
} else {
if (rootInModel == null) {
rootInModel = boi.getName();
}
if (mpn == 0 && !boi.isUnwrapped()) {
// write empty operation qname
writeMessage(message, rootInModel, false);
} else {
// multi param, bare mode, needs write root node
writeMessage(message, rootInModel, true);
}
}
// in the end we do flush ;)
XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
try {
writer.flush();
} catch (XMLStreamException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
}
}
use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.
the class XmlIoPlugin method createExtension.
public ExtensibilityElement createExtension(final Map<String, Object> args) throws WSDLException {
XMLBindingMessageFormat xmlFormat = null;
Class<?> clz = getOption(args, Class.class);
QName qname = getOption(args, QName.class);
ExtensibilityElement ext = registry.createExtension(clz, ToolConstants.XML_FORMAT);
if (ext instanceof JAXBExtensibilityElement) {
xmlFormat = (XMLBindingMessageFormat) ((JAXBExtensibilityElement) ext).getValue();
} else {
xmlFormat = (XMLBindingMessageFormat) ext;
}
xmlFormat.setRootNode(qname);
return ext;
}
use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.
the class JAXWSDefinitionBuilderTest method testBuildDefinitionWithXMLBinding.
@Test
public void testBuildDefinitionWithXMLBinding() {
String qname = "http://apache.org/hello_world_xml_http/bare";
String wsdlUrl = getClass().getResource("resources/hello_world_xml_bare.wsdl").toString();
JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
builder.setBus(BusFactory.getDefaultBus());
builder.setContext(env);
Definition def = builder.build(wsdlUrl);
assertNotNull(def);
Map<?, ?> services = def.getServices();
assertNotNull(services);
assertEquals(1, services.size());
Service service = (Service) services.get(new QName(qname, "XMLService"));
assertNotNull(service);
Map<?, ?> ports = service.getPorts();
assertNotNull(ports);
assertEquals(1, ports.size());
Port port = service.getPort("XMLPort");
assertNotNull(port);
assertEquals(1, port.getExtensibilityElements().size());
Object obj = port.getExtensibilityElements().get(0);
if (obj instanceof JAXBExtensibilityElement) {
obj = ((JAXBExtensibilityElement) obj).getValue();
}
assertTrue(obj.getClass().getName() + " is not an AddressType", obj instanceof AddressType);
Binding binding = port.getBinding();
assertNotNull(binding);
assertEquals(new QName(qname, "Greeter_XMLBinding"), binding.getQName());
BindingOperation operation = binding.getBindingOperation("sayHi", null, null);
assertNotNull(operation);
BindingInput input = operation.getBindingInput();
assertNotNull(input);
assertEquals(1, input.getExtensibilityElements().size());
obj = input.getExtensibilityElements().get(0);
if (obj instanceof JAXBExtensibilityElement) {
obj = ((JAXBExtensibilityElement) obj).getValue();
}
assertTrue(obj.getClass().getName() + " is not an XMLBindingMessageFormat", obj instanceof XMLBindingMessageFormat);
}
use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.
the class WSDLToXMLProcessorTest method testAllDefault.
@Test
public void testAllDefault() throws Exception {
String[] args = new String[] { "-i", "Greeter", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
WSDLToXML.main(args);
File outputFile = new File(output, "hello_world-xmlbinding.wsdl");
assertTrue("New wsdl file is not generated", outputFile.exists());
WSDLToXMLProcessor processor = new WSDLToXMLProcessor();
processor.setEnvironment(env);
processor.parseWSDL(outputFile.getAbsolutePath());
Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_XMLBinding"));
if (binding == null) {
fail("Element wsdl:binding Greeter_XMLBinding Missed!");
}
boolean found = false;
for (Object obj : binding.getExtensibilityElements()) {
if (obj instanceof XMLFormatBinding) {
found = true;
break;
}
}
if (!found) {
fail("Element <xformat:binding/> Missed!");
}
BindingOperation bo = binding.getBindingOperation("sayHi", null, null);
if (bo == null) {
fail("Element <wsdl:operation name=\"sayHi\"> Missed!");
}
found = false;
for (Object obj : bo.getBindingInput().getExtensibilityElements()) {
if (obj instanceof XMLBindingMessageFormat && ((XMLBindingMessageFormat) obj).getRootNode().getLocalPart().equals("sayHi")) {
found = true;
break;
}
}
if (!found) {
fail("Element <xformat:body rootNode=\"tns:sayHi\" /> Missed!");
}
Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_XMLService"));
if (service == null) {
fail("Element wsdl:service Greeter_XMLService Missed!");
}
found = false;
for (Object obj : service.getPort("Greeter_XMLPort").getExtensibilityElements()) {
if (obj instanceof HTTPAddress) {
HTTPAddress xmlHttpAddress = (HTTPAddress) obj;
if (xmlHttpAddress.getLocationURI() != null) {
found = true;
break;
}
}
}
if (!found) {
fail("Element http:address of service port Missed!");
}
}
Aggregations