use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class JAXBContextInitializer method begin.
@Override
public void begin(MessagePartInfo part) {
Class<?> clazz = part.getTypeClass();
if (clazz == null) {
return;
}
if (Exception.class.isAssignableFrom(clazz)) {
// exceptions are handled special, make sure we mark it
part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
}
boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
if (isFromWrapper && !Boolean.TRUE.equals(part.getProperty("messagepart.isheader"))) {
UnwrappedOperationInfo uop = (UnwrappedOperationInfo) part.getMessageInfo().getOperation();
OperationInfo op = uop.getWrappedOperation();
MessageInfo inf = null;
if (uop.getInput() == part.getMessageInfo()) {
inf = op.getInput();
} else if (uop.getOutput() == part.getMessageInfo()) {
inf = op.getOutput();
}
if (inf != null && inf.getFirstMessagePart().getTypeClass() != null) {
// wrapper type (unless it's a header which wouldn't be in the wrapper)
return;
}
}
if (isFromWrapper && clazz.isArray() && !Byte.TYPE.equals(clazz.getComponentType())) {
clazz = clazz.getComponentType();
}
Annotation[] a = (Annotation[]) part.getProperty("parameter.annotations");
checkForAdapter(clazz, a);
Type genericType = (Type) part.getProperty("generic.type");
if (genericType != null) {
boolean isList = Collection.class.isAssignableFrom(clazz);
if (isFromWrapper) {
if (genericType instanceof Class && ((Class<?>) genericType).isArray()) {
Class<?> cl2 = (Class<?>) genericType;
if (cl2.isArray() && !Byte.TYPE.equals(cl2.getComponentType())) {
genericType = cl2.getComponentType();
}
addType(genericType);
} else if (!isList) {
addType(genericType);
}
} else {
addType(genericType, true);
}
if (isList && genericType instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) genericType;
if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof Class) {
Class<? extends Object> arrayCls = Array.newInstance((Class<?>) pt.getActualTypeArguments()[0], 0).getClass();
clazz = arrayCls;
part.setTypeClass(clazz);
if (isFromWrapper) {
addType(clazz.getComponentType(), true);
}
} else if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof GenericArrayType) {
GenericArrayType gat = (GenericArrayType) pt.getActualTypeArguments()[0];
gat.getGenericComponentType();
Class<? extends Object> arrayCls = Array.newInstance((Class<?>) gat.getGenericComponentType(), 0).getClass();
clazz = Array.newInstance(arrayCls, 0).getClass();
part.setTypeClass(clazz);
if (isFromWrapper) {
addType(clazz.getComponentType(), true);
}
}
}
if (isFromWrapper && isList) {
clazz = null;
}
}
if (clazz != null) {
if (!isFromWrapper && clazz.getAnnotation(XmlRootElement.class) == null && clazz.getAnnotation(XmlType.class) != null && StringUtils.isEmpty(clazz.getAnnotation(XmlType.class).name())) {
Object ref = createTypeReference(part.getName(), clazz);
if (ref != null) {
typeReferences.add(ref);
}
}
addClass(clazz);
}
}
use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class SoapBindingFactory method createBindingInfo.
public BindingInfo createBindingInfo(ServiceInfo si, String bindingid, Object conf) {
SoapBindingConfiguration config;
if (conf instanceof SoapBindingConfiguration) {
config = (SoapBindingConfiguration) conf;
} else {
config = new SoapBindingConfiguration();
}
if (WSDLConstants.NS_SOAP12.equals(bindingid) || WSDLConstants.NS_SOAP12_HTTP_BINDING.equals(bindingid)) {
config.setVersion(Soap12.getInstance());
config.setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
}
SoapBindingInfo info = new SoapBindingInfo(si, bindingid, config.getVersion());
info.setName(config.getBindingName(si));
info.setStyle(config.getStyle());
info.setTransportURI(config.getTransportURI());
if (config.isMtomEnabled()) {
info.setProperty(Message.MTOM_ENABLED, Boolean.TRUE);
}
for (OperationInfo op : si.getInterface().getOperations()) {
SoapOperationInfo sop = new SoapOperationInfo();
sop.setAction(config.getSoapAction(op));
sop.setStyle(config.getStyle(op));
BindingOperationInfo bop = info.buildOperation(op.getName(), op.getInputName(), op.getOutputName());
bop.addExtensor(sop);
info.addOperation(bop);
BindingMessageInfo bInput = bop.getInput();
if (bInput != null) {
MessageInfo input = null;
BindingMessageInfo unwrappedMsg = bInput;
if (bop.isUnwrappedCapable()) {
input = bop.getOperationInfo().getUnwrappedOperation().getInput();
unwrappedMsg = bop.getUnwrappedOperation().getInput();
} else {
input = bop.getOperationInfo().getInput();
}
setupHeaders(bop, bInput, unwrappedMsg, input, config);
}
BindingMessageInfo bOutput = bop.getOutput();
if (bOutput != null) {
MessageInfo output = null;
BindingMessageInfo unwrappedMsg = bOutput;
if (bop.isUnwrappedCapable()) {
output = bop.getOperationInfo().getUnwrappedOperation().getOutput();
unwrappedMsg = bop.getUnwrappedOperation().getOutput();
} else {
output = bop.getOperationInfo().getOutput();
}
setupHeaders(bop, bOutput, unwrappedMsg, output, config);
}
}
try {
createSoapBinding(info);
} catch (WSDLException e) {
e.printStackTrace();
}
return info;
}
use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class SoapBindingFactory method addOutOfBandParts.
private void addOutOfBandParts(final BindingOperationInfo bop, final javax.wsdl.Message msg, final SchemaCollection schemas, boolean isInput, final String partName) {
MessageInfo minfo = null;
MessageInfo.Type type;
int nextId = 0;
minfo = bop.getOperationInfo().getInput();
if (minfo != null) {
for (MessagePartInfo part : minfo.getMessageParts()) {
if (part.getIndex() >= nextId) {
nextId = part.getIndex() + 1;
}
}
}
minfo = bop.getOperationInfo().getOutput();
if (minfo != null) {
for (MessagePartInfo part : minfo.getMessageParts()) {
if (part.getIndex() >= nextId) {
nextId = part.getIndex() + 1;
}
}
}
if (isInput) {
type = MessageInfo.Type.INPUT;
minfo = bop.getOperationInfo().getInput();
} else {
type = MessageInfo.Type.OUTPUT;
minfo = bop.getOperationInfo().getOutput();
}
if (minfo == null) {
minfo = new MessageInfo(bop.getOperationInfo(), type, msg.getQName());
}
buildMessage(minfo, msg, schemas, nextId, partName);
// for wrapped style
OperationInfo unwrapped = bop.getOperationInfo().getUnwrappedOperation();
if (unwrapped == null) {
return;
}
nextId = 0;
if (isInput) {
minfo = unwrapped.getInput();
type = MessageInfo.Type.INPUT;
if (minfo != null) {
for (MessagePartInfo part : minfo.getMessageParts()) {
if (part.getIndex() >= nextId) {
nextId = part.getIndex() + 1;
}
}
}
} else {
minfo = unwrapped.getOutput();
type = MessageInfo.Type.OUTPUT;
if (minfo != null) {
for (MessagePartInfo part : minfo.getMessageParts()) {
if (part.getIndex() >= nextId) {
nextId = part.getIndex() + 1;
}
}
}
}
if (minfo == null) {
minfo = new MessageInfo(unwrapped, type, msg.getQName());
}
buildMessage(minfo, msg, schemas, nextId, partName);
}
use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class SoapBindingFactory method initializeMessage.
private void initializeMessage(SoapBindingInfo bi, BindingOperationInfo boi, BindingMessageInfo bmsg) {
MessageInfo msg = bmsg.getMessageInfo();
List<MessagePartInfo> messageParts = new ArrayList<>();
messageParts.addAll(msg.getMessageParts());
List<SoapHeader> headers = SOAPBindingUtil.getSoapHeaders(bmsg.getExtensors(ExtensibilityElement.class));
if (headers != null) {
for (SoapHeader header : headers) {
SoapHeaderInfo headerInfo = new SoapHeaderInfo();
headerInfo.setUse(header.getUse());
if (StringUtils.isEmpty(header.getPart())) {
throw new RuntimeException("Problem with WSDL: soap:header element in operation " + boi.getName().getLocalPart() + " does not specify a part.");
}
MessagePartInfo part = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), header.getPart()));
if (part != null && header.getMessage() != null && !part.getMessageInfo().getName().equals(header.getMessage())) {
part = null;
// out of band, let's find it
for (MessagePartInfo mpi : msg.getOutOfBandParts()) {
if (mpi.getName().getLocalPart().equals(header.getPart()) && mpi.getMessageInfo().getName().equals(header.getMessage())) {
part = mpi;
}
}
}
if (part != null) {
headerInfo.setPart(part);
messageParts.remove(part);
bmsg.addExtensor(headerInfo);
}
}
// Exclude the header parts from the message part list.
bmsg.setMessageParts(messageParts);
}
SoapBodyInfo bodyInfo = new SoapBodyInfo();
SoapBody soapBody = SOAPBindingUtil.getSoapBody(bmsg.getExtensors(ExtensibilityElement.class));
List<?> parts = null;
if (soapBody == null) {
MIMEMultipartRelated mmr = bmsg.getExtensor(MIMEMultipartRelated.class);
if (mmr != null) {
parts = mmr.getMIMEParts();
}
} else {
bmsg.addExtensor(soapBody);
bodyInfo.setUse(soapBody.getUse());
parts = soapBody.getParts();
}
// Initialize the body parts.
List<MessagePartInfo> attParts = null;
if (parts != null) {
List<MessagePartInfo> bodyParts = new ArrayList<>();
for (Iterator<?> itr = parts.iterator(); itr.hasNext(); ) {
Object part = itr.next();
if (part instanceof MIMEPart) {
MIMEPart mpart = (MIMEPart) part;
attParts = handleMimePart(mpart, attParts, msg, bmsg, bodyParts, messageParts);
} else {
addSoapBodyPart(msg, bodyParts, (String) part);
}
}
bodyInfo.setParts(bodyParts);
bodyInfo.setAttachments(attParts);
} else {
bodyInfo.setParts(messageParts);
}
bmsg.addExtensor(bodyInfo);
}
use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class SoapBindingFactory method buildMessage.
private void buildMessage(MessageInfo minfo, javax.wsdl.Message msg, SchemaCollection schemas, int nextId, String partNameFilter) {
for (Part part : cast(msg.getParts().values(), Part.class)) {
if (StringUtils.isEmpty(partNameFilter) || part.getName().equals(partNameFilter)) {
if (StringUtils.isEmpty(part.getName())) {
throw new RuntimeException("Problem with WSDL: part element in message " + msg.getQName().getLocalPart() + " does not specify a name.");
}
QName pqname = new QName(minfo.getName().getNamespaceURI(), part.getName());
MessagePartInfo pi = minfo.getMessagePart(pqname);
if (pi != null && pi.getMessageInfo().getName().equals(msg.getQName())) {
continue;
}
pi = minfo.addOutOfBandMessagePart(pqname);
if (!minfo.getName().equals(msg.getQName())) {
pi.setMessageContainer(new MessageInfo(minfo.getOperation(), null, msg.getQName()));
}
if (part.getTypeName() != null) {
pi.setTypeQName(part.getTypeName());
pi.setElement(false);
pi.setXmlSchema(schemas.getTypeByQName(part.getTypeName()));
} else {
pi.setElementQName(part.getElementName());
pi.setElement(true);
pi.setXmlSchema(schemas.getElementByQName(part.getElementName()));
}
pi.setProperty(OUT_OF_BAND_HEADER, Boolean.TRUE);
pi.setProperty(HEADER, Boolean.TRUE);
pi.setIndex(nextId);
nextId++;
}
}
}
Aggregations