use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class SoapOutInterceptor method writeSoapEnvelopeStart.
private void writeSoapEnvelopeStart(final SoapMessage message) {
final SoapVersion soapVersion = message.getVersion();
try {
XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
String soapPrefix = xtw.getPrefix(soapVersion.getNamespace());
if (StringUtils.isEmpty(soapPrefix)) {
soapPrefix = "soap";
}
if (message.hasAdditionalEnvNs()) {
Map<String, String> nsMap = message.getEnvelopeNs();
for (Map.Entry<String, String> entry : nsMap.entrySet()) {
if (soapVersion.getNamespace().equals(entry.getValue())) {
soapPrefix = entry.getKey();
}
}
xtw.setPrefix(soapPrefix, soapVersion.getNamespace());
xtw.writeStartElement(soapPrefix, soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace());
xtw.writeNamespace(soapPrefix, soapVersion.getNamespace());
for (Map.Entry<String, String> entry : nsMap.entrySet()) {
if (!soapVersion.getNamespace().equals(entry.getValue())) {
xtw.writeNamespace(entry.getKey(), entry.getValue());
}
}
} else {
xtw.setPrefix(soapPrefix, soapVersion.getNamespace());
xtw.writeStartElement(soapPrefix, soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace());
String s2 = xtw.getPrefix(soapVersion.getNamespace());
if (StringUtils.isEmpty(s2) || soapPrefix.equals(s2)) {
xtw.writeNamespace(soapPrefix, soapVersion.getNamespace());
} else {
soapPrefix = s2;
}
}
boolean preexistingHeaders = message.hasHeaders();
if (preexistingHeaders) {
xtw.writeStartElement(soapPrefix, soapVersion.getHeader().getLocalPart(), soapVersion.getNamespace());
List<Header> hdrList = message.getHeaders();
for (Header header : hdrList) {
XMLStreamWriter writer = xtw;
if (xtw instanceof W3CDOMStreamWriter) {
Element nd = ((W3CDOMStreamWriter) xtw).getCurrentNode();
if (header.getObject() instanceof Element && nd.isSameNode(((Element) header.getObject()).getParentNode())) {
continue;
}
}
if (header instanceof SoapHeader) {
SoapHeader soapHeader = (SoapHeader) header;
writer = new SOAPHeaderWriter(xtw, soapHeader, soapVersion, soapPrefix);
}
DataBinding b = header.getDataBinding();
if (b == null) {
HeaderProcessor hp = bus.getExtension(HeaderManager.class).getHeaderProcessor(header.getName().getNamespaceURI());
if (hp != null) {
b = hp.getDataBinding();
}
}
if (b != null) {
MessagePartInfo part = new MessagePartInfo(header.getName(), null);
part.setConcreteName(header.getName());
b.createWriter(XMLStreamWriter.class).write(header.getObject(), part, writer);
} else {
Element node = (Element) header.getObject();
StaxUtils.copy(node, writer);
}
}
}
boolean endedHeader = handleHeaderPart(preexistingHeaders, message, soapPrefix);
if (preexistingHeaders && !endedHeader) {
xtw.writeEndElement();
}
xtw.writeStartElement(soapPrefix, soapVersion.getBody().getLocalPart(), soapVersion.getNamespace());
// Interceptors followed such as Wrapped/RPC/Doc Interceptor will write SOAP body
} catch (XMLStreamException e) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ServiceModelUtilTest method testGetSchema.
@Test
public void testGetSchema() throws Exception {
BindingInfo bindingInfo = null;
bindingInfo = serviceInfo.getBindings().iterator().next();
QName name = new QName(serviceInfo.getName().getNamespaceURI(), "inHeader");
BindingOperationInfo inHeader = bindingInfo.getOperation(name);
BindingMessageInfo input = inHeader.getInput();
assertNotNull(input);
assertEquals(input.getMessageInfo().getName().getLocalPart(), "inHeaderRequest");
assertEquals(input.getMessageInfo().getName().getNamespaceURI(), "http://org.apache.cxf/headers");
assertEquals(input.getMessageInfo().getMessageParts().size(), 2);
assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
assertEquals(input.getMessageInfo().getMessageParts().get(0).getElementQName().getLocalPart(), "inHeader");
assertEquals(input.getMessageInfo().getMessageParts().get(0).getElementQName().getNamespaceURI(), "http://org.apache.cxf/headers");
assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
assertEquals(input.getMessageInfo().getMessageParts().get(1).getElementQName().getLocalPart(), "passenger");
assertEquals(input.getMessageInfo().getMessageParts().get(1).getElementQName().getNamespaceURI(), "http://mycompany.example.com/employees");
assertTrue(input.getMessageInfo().getMessageParts().get(1).isElement());
MessagePartInfo messagePartInfo = input.getMessageInfo().getMessageParts().get(0);
SchemaInfo schemaInfo = ServiceModelUtil.getSchema(serviceInfo, messagePartInfo);
assertEquals(schemaInfo.getNamespaceURI(), "http://org.apache.cxf/headers");
messagePartInfo = input.getMessageInfo().getMessageParts().get(1);
schemaInfo = ServiceModelUtil.getSchema(serviceInfo, messagePartInfo);
assertEquals(schemaInfo.getNamespaceURI(), "http://mycompany.example.com/employees");
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class SoapBindingFactoryTest method testSoap12Factory.
@Test
public void testSoap12Factory() throws Exception {
Definition d = createDefinition("/wsdl_soap/hello_world_soap12.wsdl");
Bus bus = getMockBus();
BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP12, bus);
expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm);
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
control.replay();
WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
ServiceInfo serviceInfo = builder.buildServices(d, new QName("http://apache.org/hello_world_soap12_http", "SOAPService")).get(0);
BindingInfo bi = serviceInfo.getBindings().iterator().next();
assertTrue(bi instanceof SoapBindingInfo);
SoapBindingInfo sbi = (SoapBindingInfo) bi;
assertEquals("document", sbi.getStyle());
assertEquals(WSDLConstants.NS_SOAP_HTTP_TRANSPORT, sbi.getTransportURI());
assertTrue(sbi.getSoapVersion() instanceof Soap12);
BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http", "sayHi"));
SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
assertNotNull(sboi);
assertEquals("document", sboi.getStyle());
assertEquals("sayHiAction", sboi.getAction());
BindingMessageInfo input = boi.getInput();
SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
assertEquals("literal", bodyInfo.getUse());
List<MessagePartInfo> parts = bodyInfo.getParts();
assertNotNull(parts);
assertEquals(1, parts.size());
boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http", "pingMe"));
sboi = boi.getExtensor(SoapOperationInfo.class);
assertNotNull(sboi);
assertEquals("document", sboi.getStyle());
assertEquals("", sboi.getAction());
Collection<BindingFaultInfo> faults = boi.getFaults();
assertEquals(1, faults.size());
BindingFaultInfo faultInfo = boi.getFault(new QName("http://apache.org/hello_world_soap12_http", "pingMeFault"));
assertNotNull(faultInfo);
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class SoapBindingFactoryTest method testNoBodyParts.
@Test
public void testNoBodyParts() throws Exception {
Definition d = createDefinition("/wsdl_soap/no_body_parts.wsdl");
Bus bus = getMockBus();
BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);
bus.getExtension(BindingFactoryManager.class);
expectLastCall().andReturn(bfm).anyTimes();
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
control.replay();
WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
ServiceInfo serviceInfo = builder.buildServices(d, new QName("urn:org:apache:cxf:no_body_parts/wsdl", "NoBodyParts")).get(0);
BindingInfo bi = serviceInfo.getBindings().iterator().next();
assertTrue(bi instanceof SoapBindingInfo);
SoapBindingInfo sbi = (SoapBindingInfo) bi;
assertEquals("document", sbi.getStyle());
assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
assertTrue(sbi.getSoapVersion() instanceof Soap11);
BindingOperationInfo boi = sbi.getOperation(new QName("urn:org:apache:cxf:no_body_parts/wsdl", "operation1"));
assertNotNull(boi);
SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
assertNotNull(sboi);
assertNull(sboi.getStyle());
assertEquals("", sboi.getAction());
BindingMessageInfo input = boi.getInput();
SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
assertNull(bodyInfo.getUse());
List<MessagePartInfo> parts = bodyInfo.getParts();
assertNotNull(parts);
assertEquals(0, parts.size());
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class XMLMessageInInterceptor method getBindingOperationInfo.
private BindingOperationInfo getBindingOperationInfo(boolean isRequestor, QName startQName, BindingInfo bi, XMLStreamReader xsr) {
for (BindingOperationInfo boi : bi.getOperations()) {
BindingMessageInfo bmi;
if (!isRequestor) {
bmi = boi.getInput();
} else {
bmi = boi.getOutput();
}
if (hasRootNode(bmi, startQName)) {
// Consume The rootNode tag
try {
xsr.nextTag();
} catch (XMLStreamException xse) {
throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", LOG));
}
return boi;
}
Collection<MessagePartInfo> bodyParts = bmi.getMessageParts();
if (bodyParts.size() == 1) {
MessagePartInfo p = bodyParts.iterator().next();
if (p.getConcreteName().equals(startQName)) {
return boi;
}
}
}
for (BindingOperationInfo boi : bi.getOperations()) {
if (startQName.equals(boi.getName())) {
// Consume The rootNode tag
try {
xsr.nextTag();
} catch (XMLStreamException xse) {
throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", LOG));
}
return boi;
}
}
return null;
}
Aggregations