use of org.apache.cxf.service.model.MessagePartInfo 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.MessagePartInfo in project cxf by apache.
the class HeaderUtil method getHeaderQNames.
private static Set<QName> getHeaderQNames(BindingMessageInfo bmi) {
Set<QName> set = new HashSet<>();
List<MessagePartInfo> mps = bmi.getMessageInfo().getMessageParts();
List<ExtensibilityElement> extList = bmi.getExtensors(ExtensibilityElement.class);
if (extList != null) {
for (ExtensibilityElement ext : extList) {
if (SOAPBindingUtil.isSOAPHeader(ext)) {
SoapHeader header = SOAPBindingUtil.getSoapHeader(ext);
String pn = header.getPart();
for (MessagePartInfo mpi : mps) {
if (pn.equals(mpi.getName().getLocalPart())) {
if (mpi.isElement()) {
set.add(mpi.getElementQName());
} else {
set.add(mpi.getTypeQName());
}
break;
}
}
}
}
}
return set;
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class SoapBindingFactory method createSoapBinding.
private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException {
boolean isSoap12 = bi.getSoapVersion() instanceof Soap12;
Bus bs = getBus();
WSDLManager m = bs.getExtension(WSDLManager.class);
ExtensionRegistry extensionRegistry = m.getExtensionRegistry();
SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12);
soapBinding.setStyle(bi.getStyle());
soapBinding.setTransportURI(bi.getTransportURI());
bi.addExtensor(soapBinding);
for (BindingOperationInfo b : bi.getOperations()) {
for (BindingFaultInfo faultInfo : b.getFaults()) {
SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12);
soapFault.setUse("literal");
soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart());
faultInfo.addExtensor(soapFault);
}
SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class);
SoapOperation soapOperation = SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12);
soapOperation.setSoapActionURI(soi.getAction());
soapOperation.setStyle(soi.getStyle());
boolean isRpc = "rpc".equals(soapOperation.getStyle());
b.addExtensor(soapOperation);
if (b.getInput() != null) {
List<String> bodyParts = null;
List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class);
if (headerInfos != null && !headerInfos.isEmpty()) {
bodyParts = new ArrayList<>();
for (MessagePartInfo part : b.getInput().getMessageParts()) {
bodyParts.add(part.getName().getLocalPart());
}
for (SoapHeaderInfo headerInfo : headerInfos) {
SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12);
soapHeader.setMessage(b.getInput().getMessageInfo().getName());
soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
soapHeader.setUse("literal");
bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
headerInfo.getPart().setProperty(HEADER, true);
b.getInput().addExtensor(soapHeader);
}
}
SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12);
body.setUse("literal");
if (isRpc) {
body.setNamespaceURI(b.getName().getNamespaceURI());
}
if (bodyParts != null) {
body.setParts(bodyParts);
}
b.getInput().addExtensor(body);
}
if (b.getOutput() != null) {
List<String> bodyParts = null;
List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class);
if (headerInfos != null && !headerInfos.isEmpty()) {
bodyParts = new ArrayList<>();
for (MessagePartInfo part : b.getOutput().getMessageParts()) {
bodyParts.add(part.getName().getLocalPart());
}
for (SoapHeaderInfo headerInfo : headerInfos) {
SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12);
soapHeader.setMessage(b.getOutput().getMessageInfo().getName());
soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
soapHeader.setUse("literal");
bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
b.getOutput().addExtensor(soapHeader);
}
}
SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12);
body.setUse("literal");
if (isRpc) {
body.setNamespaceURI(b.getName().getNamespaceURI());
}
if (bodyParts != null) {
body.setParts(bodyParts);
}
b.getOutput().addExtensor(body);
}
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class SoapBindingFactory method addSoapBodyPart.
private void addSoapBodyPart(MessageInfo msg, List<MessagePartInfo> bodyParts, String partName) {
MessagePartInfo mpi = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), partName));
bodyParts.add(mpi);
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class RPCInInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message)) {
LOG.fine("RPCInInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
if (!StaxUtils.toNextElement(xmlReader)) {
message.setContent(Exception.class, new RuntimeException("There must be a method name element."));
}
String opName = xmlReader.getLocalName();
if (isRequestor(message) && opName.endsWith("Response")) {
opName = opName.substring(0, opName.length() - 8);
}
final BindingOperationInfo operation;
if (message.getExchange().getBindingOperationInfo() == null) {
operation = getOperation(message, new QName(xmlReader.getNamespaceURI(), opName));
if (operation == null) {
// it's doc-lit-bare
new BareInInterceptor().handleMessage(message);
return;
}
setMessage(message, operation);
} else {
operation = message.getExchange().getBindingOperationInfo();
if (!operation.getName().getLocalPart().equals(opName)) {
String sa = (String) message.get(SoapBindingConstants.SOAP_ACTION);
throw new Fault("SOAP_ACTION_MISMATCH_OP", LOG, null, sa, opName);
}
}
MessageInfo msg;
DataReader<XMLStreamReader> dr = getDataReader(message, XMLStreamReader.class);
if (!isRequestor(message)) {
msg = operation.getOperationInfo().getInput();
} else {
msg = operation.getOperationInfo().getOutput();
}
message.put(MessageInfo.class, msg);
MessageContentsList parameters = new MessageContentsList();
StaxUtils.nextEvent(xmlReader);
boolean hasNext = true;
Iterator<MessagePartInfo> itr = msg.getMessageParts().iterator();
while (itr.hasNext()) {
MessagePartInfo part = itr.next();
if (hasNext) {
hasNext = StaxUtils.toNextElement(xmlReader);
}
if (hasNext) {
QName qn = xmlReader.getName();
if (qn.equals(SOAP12_RESULT)) {
// just ignore this. The parts should work correctly.
try {
while (xmlReader.getEventType() != XMLStreamConstants.END_ELEMENT) {
xmlReader.next();
}
xmlReader.next();
} catch (XMLStreamException e) {
// ignore
}
StaxUtils.toNextElement(xmlReader);
qn = xmlReader.getName();
}
// WSI-BP states that RPC/Lit part accessors should be completely unqualified
// However, older toolkits (Axis 1.x) are qualifying them. We'll go
// ahead and just match on the localpart. The RPCOutInterceptor
// will always generate WSI-BP compliant messages so it's unknown if
// the non-WSI-BP toolkits will be able to understand the CXF
// generated messages if they are expecting it to be qualified.
Iterator<MessagePartInfo> partItr = msg.getMessageParts().iterator();
while (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart()) && partItr.hasNext()) {
part = partItr.next();
}
// only check the localpart as explained above
if (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart())) {
throw new Fault(new org.apache.cxf.common.i18n.Message("UNKNOWN_RPC_LIT_PART", LOG, qn));
}
try {
parameters.put(part, dr.read(part, xmlReader));
} catch (Fault f) {
if (!isRequestor(message)) {
f.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw f;
}
}
}
message.setContent(List.class, parameters);
}
Aggregations