use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.
the class JAXRSServiceImpl method getServiceInfos.
public List<ServiceInfo> getServiceInfos() {
if (!createServiceModel) {
return Collections.emptyList();
}
// try to convert to WSDL-centric model so that CXF DataBindings can get initialized
// might become useful too if we support wsdl2
// make databindings to use databinding-specific information
// like @XmlRootElement for ex to select a namespace
this.put("org.apache.cxf.databinding.namespace", "true");
List<ServiceInfo> infos = new ArrayList<>();
for (ClassResourceInfo cri : classResourceInfos) {
ServiceInfo si = new ServiceInfo();
infos.add(si);
QName qname = JAXRSUtils.getClassQName(cri.getServiceClass());
si.setName(qname);
InterfaceInfo inf = new InterfaceInfo(si, qname);
si.setInterface(inf);
for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) {
Method m = ori.getMethodToInvoke();
QName oname = new QName(qname.getNamespaceURI(), m.getName());
OperationInfo oi = inf.addOperation(oname);
createMessagePartInfo(oi, m.getReturnType(), qname, m, false);
for (Parameter pm : ori.getParameters()) {
if (pm.getType() == ParameterType.REQUEST_BODY) {
createMessagePartInfo(oi, ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()], qname, m, true);
}
}
}
}
return infos;
}
use of org.apache.cxf.service.model.OperationInfo 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.OperationInfo in project cxf by apache.
the class JAXBDataBase method getReturnMethodAnnotations.
private Annotation[] getReturnMethodAnnotations(MessagePartInfo mpi) {
AbstractMessageContainer mi = mpi.getMessageInfo();
if (mi == null || !isOutputMessage(mi)) {
return null;
}
OperationInfo oi = mi != null ? mi.getOperation() : null;
return oi != null ? (Annotation[]) oi.getProperty("method.return.annotations") : null;
}
use of org.apache.cxf.service.model.OperationInfo 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.OperationInfo 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);
}
Aggregations