use of org.apache.cxf.annotations.Policies in project cxf by apache.
the class PolicyAnnotationListener method addPolicies.
private void addPolicies(AbstractServiceFactoryBean factory, OperationInfo inf, Method m) {
if (m == null) {
return;
}
Policy p = m.getAnnotation(Policy.class);
Policies ps = m.getAnnotation(Policies.class);
if (p != null || ps != null) {
List<Policy> list = new ArrayList<>();
if (p != null) {
list.add(p);
}
if (ps != null) {
Collections.addAll(list, ps.value());
}
ListIterator<Policy> it = list.listIterator();
while (it.hasNext()) {
p = it.next();
Policy.Placement place = p.placement();
if (place == Policy.Placement.DEFAULT) {
place = Policy.Placement.BINDING_OPERATION;
}
ServiceInfo service = inf.getInterface().getService();
Class<?> cls = m.getDeclaringClass();
switch(place) {
case PORT_TYPE_OPERATION:
addPolicy(inf, service, p, cls, inf.getName().getLocalPart() + "PortTypeOpPolicy");
it.remove();
break;
case PORT_TYPE_OPERATION_INPUT:
addPolicy(inf.getInput(), service, p, cls, inf.getName().getLocalPart() + "PortTypeOpInputPolicy");
it.remove();
break;
case PORT_TYPE_OPERATION_OUTPUT:
addPolicy(inf.getOutput(), service, p, cls, inf.getName().getLocalPart() + "PortTypeOpOutputPolicy");
it.remove();
break;
case PORT_TYPE_OPERATION_FAULT:
{
for (FaultInfo f : inf.getFaults()) {
if (p.faultClass().equals(f.getProperty(Class.class.getName()))) {
addPolicy(f, service, p, cls, f.getName().getLocalPart() + "PortTypeOpFaultPolicy");
it.remove();
}
}
break;
}
default:
}
}
if (!list.isEmpty()) {
List<Policy> stuff = CastUtils.cast((List<?>) inf.getProperty(EXTRA_POLICIES));
if (stuff != null) {
for (Policy p2 : list) {
if (!stuff.contains(p2)) {
stuff.add(p2);
}
}
} else {
inf.setProperty(EXTRA_POLICIES, list);
}
}
}
}
use of org.apache.cxf.annotations.Policies in project cxf by apache.
the class DoubleItPortTypeImplJavaFirst method doubleIt.
@Policies({ @Policy(uri = "classpath:/org/apache/cxf/systest/ws/fault/SymmetricUTPolicy.xml"), @Policy(uri = "classpath:/org/apache/cxf/systest/ws/fault/SignedEncryptedPolicy.xml", placement = Placement.BINDING_OPERATION_OUTPUT) })
public int doubleIt(int numberToDouble) throws DoubleItFault {
Principal pr = wsContext.getUserPrincipal();
if ("alice".equals(pr.getName())) {
return numberToDouble * 2;
}
org.example.schema.doubleit.DoubleItFault internalFault = new org.example.schema.doubleit.DoubleItFault();
internalFault.setMajor((short) 124);
internalFault.setMinor((short) 1256);
throw new DoubleItFault("This is a fault", internalFault);
}
use of org.apache.cxf.annotations.Policies in project cxf by apache.
the class PolicyAnnotationListener method addPolicies.
private void addPolicies(AbstractServiceFactoryBean factory, InterfaceInfo ii, Class<?> cls) {
if (cls == null) {
return;
}
Policy p = cls.getAnnotation(Policy.class);
Policies ps = cls.getAnnotation(Policies.class);
if (p != null || ps != null) {
List<Policy> list = new ArrayList<>();
if (p != null) {
list.add(p);
}
if (ps != null) {
Collections.addAll(list, ps.value());
}
ListIterator<Policy> it = list.listIterator();
while (it.hasNext()) {
p = it.next();
Policy.Placement place = p.placement();
if (place == Policy.Placement.DEFAULT) {
place = Policy.Placement.BINDING;
}
switch(place) {
case PORT_TYPE:
{
addPolicy(ii, ii.getService(), p, cls, ii.getName().getLocalPart() + "PortTypePolicy");
it.remove();
break;
}
case SERVICE:
{
addPolicy(ii.getService(), ii.getService(), p, cls, ii.getService().getName().getLocalPart() + "ServicePolicy");
it.remove();
break;
}
default:
}
}
if (!list.isEmpty()) {
List<Policy> stuff = CastUtils.cast((List<?>) ii.getProperty(EXTRA_POLICIES));
if (stuff != null) {
for (Policy p2 : list) {
if (!stuff.contains(p2)) {
stuff.add(p2);
}
}
} else {
ii.setProperty(EXTRA_POLICIES, list);
}
}
}
}
use of org.apache.cxf.annotations.Policies in project cxf by apache.
the class PolicyAnnotationListener method addEndpointImplPolicies.
private void addEndpointImplPolicies(AbstractServiceFactoryBean factory, Endpoint endpoint, Class<?> cls) {
List<Policy> list = CastUtils.cast((List<?>) endpoint.getEndpointInfo().getInterface().removeProperty(EXTRA_POLICIES));
if (list != null) {
addPolicies(factory, endpoint, cls, list, Policy.Placement.BINDING);
}
if (cls == null) {
return;
}
Policy p = cls.getAnnotation(Policy.class);
Policies ps = cls.getAnnotation(Policies.class);
if (p != null || ps != null) {
list = new ArrayList<>();
if (p != null) {
list.add(p);
}
if (ps != null) {
Collections.addAll(list, ps.value());
}
addPolicies(factory, endpoint, cls, list, Policy.Placement.SERVICE);
}
}
Aggregations