use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class PolicyBasedWSS4JStaxInInterceptor method createPolicyEnforcer.
private PolicyEnforcer createPolicyEnforcer(EndpointInfo endpointInfo, SoapMessage msg) throws WSSPolicyException {
EffectivePolicy dispatchPolicy = null;
List<OperationPolicy> operationPolicies = new ArrayList<>();
Collection<BindingOperationInfo> bindingOperationInfos = endpointInfo.getBinding().getOperations();
for (Iterator<BindingOperationInfo> bindingOperationInfoIterator = bindingOperationInfos.iterator(); bindingOperationInfoIterator.hasNext(); ) {
BindingOperationInfo bindingOperationInfo = bindingOperationInfoIterator.next();
QName operationName = bindingOperationInfo.getName();
// todo: I'm not sure what the effectivePolicy exactly contains,
// a) only the operation policy,
// or b) all policies for the service,
// or c) all policies which applies for the current operation.
// c) is that what we need for stax.
EffectivePolicy policy = (EffectivePolicy) bindingOperationInfo.getProperty("policy-engine-info-serve-request");
// PolicyEngineImpl.POLICY_INFO_REQUEST_SERVER);
if (MessageUtils.isRequestor(msg)) {
policy = (EffectivePolicy) bindingOperationInfo.getProperty("policy-engine-info-client-response");
// Save the Dispatch Policy as it may be used on another BindingOperationInfo
if (policy != null && "http://cxf.apache.org/jaxws/dispatch".equals(operationName.getNamespaceURI())) {
dispatchPolicy = policy;
}
if (bindingOperationInfo.getOutput() != null) {
MessageInfo messageInfo = bindingOperationInfo.getOutput().getMessageInfo();
operationName = messageInfo.getName();
if (messageInfo.getMessagePartsNumber() > 0) {
QName cn = messageInfo.getFirstMessagePart().getConcreteName();
if (cn != null) {
operationName = cn;
}
}
}
} else {
if (bindingOperationInfo.getInput() != null) {
MessageInfo messageInfo = bindingOperationInfo.getInput().getMessageInfo();
operationName = messageInfo.getName();
if (messageInfo.getMessagePartsNumber() > 0) {
QName cn = messageInfo.getFirstMessagePart().getConcreteName();
if (cn != null) {
operationName = cn;
}
}
}
}
SoapOperationInfo soapOperationInfo = bindingOperationInfo.getExtensor(SoapOperationInfo.class);
if (soapOperationInfo != null && policy == null && dispatchPolicy != null) {
policy = dispatchPolicy;
}
if (policy != null && soapOperationInfo != null) {
String soapNS;
BindingInfo bindingInfo = bindingOperationInfo.getBinding();
if (bindingInfo instanceof SoapBindingInfo) {
soapNS = ((SoapBindingInfo) bindingInfo).getSoapVersion().getNamespace();
} else {
// most probably throw an exception:
throw new IllegalArgumentException("BindingInfo is not an instance of SoapBindingInfo");
}
OperationPolicy operationPolicy = new OperationPolicy(operationName);
operationPolicy.setPolicy(policy.getPolicy());
operationPolicy.setOperationAction(soapOperationInfo.getAction());
operationPolicy.setSoapMessageVersionNamespace(soapNS);
operationPolicies.add(operationPolicy);
}
}
String soapAction = SoapActionInInterceptor.getSoapAction(msg);
if (soapAction == null) {
soapAction = "";
}
String actor = (String) msg.getContextualProperty(SecurityConstants.ACTOR);
final Collection<org.apache.cxf.message.Attachment> attachments = msg.getAttachments();
int attachmentCount = 0;
if (attachments != null && !attachments.isEmpty()) {
attachmentCount = attachments.size();
}
return new PolicyEnforcer(operationPolicies, soapAction, isRequestor(msg), actor, attachmentCount, new WSS4JPolicyAsserter(msg.get(AssertionInfoMap.class)));
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class ProxyTest method testInvoke.
@Test
public void testInvoke() throws Exception {
Method m = Proxy.class.getDeclaredMethod("createClient", new Class[] { Bus.class, Endpoint.class, ProtocolVariation.class, Conduit.class, org.apache.cxf.ws.addressing.EndpointReferenceType.class });
Proxy proxy = EasyMock.createMockBuilder(Proxy.class).addMockedMethod(m).createMock(control);
proxy.setReliableEndpoint(rme);
RMManager manager = control.createMock(RMManager.class);
EasyMock.expect(rme.getManager()).andReturn(manager).anyTimes();
Bus bus = control.createMock(Bus.class);
EasyMock.expect(manager.getBus()).andReturn(bus).anyTimes();
Endpoint endpoint = control.createMock(Endpoint.class);
EasyMock.expect(rme.getEndpoint(ProtocolVariation.RM10WSA200408)).andReturn(endpoint).anyTimes();
BindingInfo bi = control.createMock(BindingInfo.class);
EasyMock.expect(rme.getBindingInfo(ProtocolVariation.RM10WSA200408)).andReturn(bi).anyTimes();
Conduit conduit = control.createMock(Conduit.class);
EasyMock.expect(rme.getConduit()).andReturn(conduit).anyTimes();
org.apache.cxf.ws.addressing.EndpointReferenceType replyTo = control.createMock(org.apache.cxf.ws.addressing.EndpointReferenceType.class);
EasyMock.expect(rme.getReplyTo()).andReturn(replyTo).anyTimes();
OperationInfo oi = control.createMock(OperationInfo.class);
BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
EasyMock.expect(bi.getOperation(oi)).andReturn(boi).anyTimes();
Client client = control.createMock(Client.class);
EasyMock.expect(client.getRequestContext()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(proxy.createClient(bus, endpoint, ProtocolVariation.RM10WSA200408, conduit, replyTo)).andReturn(client).anyTimes();
Object[] args = new Object[] {};
Map<String, Object> context = new HashMap<>();
Object[] results = new Object[] { "a", "b", "c" };
Exchange exchange = control.createMock(Exchange.class);
EasyMock.expect(client.invoke(boi, args, context, exchange)).andReturn(results).anyTimes();
control.replay();
assertEquals("a", proxy.invoke(oi, ProtocolVariation.RM10WSA200408, args, context, exchange));
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class RMEndpoint method setPolicies.
void setPolicies(Message message) {
// use same WS-policies as for application endpoint
PolicyEngine engine = manager.getBus().getExtension(PolicyEngine.class);
if (null == engine || !engine.isEnabled()) {
return;
}
for (Endpoint endpoint : endpoints.values()) {
EndpointInfo ei = endpoint.getEndpointInfo();
EndpointPolicy epi = null == conduit ? engine.getServerEndpointPolicy(applicationEndpoint.getEndpointInfo(), null, message) : engine.getClientEndpointPolicy(applicationEndpoint.getEndpointInfo(), conduit, message);
if (conduit != null) {
engine.setClientEndpointPolicy(ei, epi);
} else {
engine.setServerEndpointPolicy(ei, epi);
}
EffectivePolicyImpl effectiveOutbound = new EffectivePolicyImpl();
effectiveOutbound.initialise(epi, engine, false, false, message);
EffectivePolicyImpl effectiveInbound = new EffectivePolicyImpl();
effectiveInbound.initialise(epi, engine, true, false, message);
BindingInfo bi = ei.getBinding();
Collection<BindingOperationInfo> bois = bi.getOperations();
for (BindingOperationInfo boi : bois) {
engine.setEffectiveServerRequestPolicy(ei, boi, effectiveInbound);
engine.setEffectiveServerResponsePolicy(ei, boi, effectiveOutbound);
engine.setEffectiveClientRequestPolicy(ei, boi, effectiveOutbound);
engine.setEffectiveClientResponsePolicy(ei, boi, effectiveInbound);
}
}
// TODO: FaultPolicy (SequenceFault)
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class RMSoapInInterceptor method updateServiceModelInfo.
/**
* When invoked inbound, check if the action indicates that this is one of the
* RM protocol messages (CreateSequence, CreateSequenceResponse, TerminateSequence)
* and if so, replace references to the application service model with references to
* the RM service model.
* The addressing protocol handler must have extracted the action beforehand.
* @see org.apache.cxf.transport.ChainInitiationObserver
*
* @param message the message
*/
private void updateServiceModelInfo(SoapMessage message) throws Fault {
AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false);
AttributedURIType actionURI = null == maps ? null : maps.getAction();
String action = null == actionURI ? null : actionURI.getValue().trim();
LOG.fine("action: " + action);
RMConstants consts;
if (RM10Constants.ACTIONS.contains(action)) {
consts = RM10Constants.INSTANCE;
} else if (RM11Constants.ACTIONS.contains(action)) {
consts = RM11Constants.INSTANCE;
} else {
return;
}
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
rmps.exposeAs(consts.getWSRMNamespace());
ProtocolVariation protocol = ProtocolVariation.findVariant(consts.getWSRMNamespace(), maps.getNamespaceURI());
LOG.info("Updating service model info in exchange");
RMManager manager = getManager(message);
assert manager != null;
RMEndpoint rme = null;
try {
rme = manager.getReliableEndpoint(message);
} catch (RMException e) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message("CANNOT_PROCESS", LOG), e, message.getVersion().getSender());
}
Exchange exchange = message.getExchange();
Endpoint ep = rme.getEndpoint(protocol);
exchange.put(Endpoint.class, ep);
exchange.put(Service.class, ep.getService());
exchange.put(Binding.class, ep.getBinding());
// Also set BindingOperationInfo as some operations (SequenceAcknowledgment) have
// neither in nor out messages, and thus the WrappedInInterceptor cannot
// determine the operation name.
BindingInfo bi = ep.getEndpointInfo().getBinding();
BindingOperationInfo boi = null;
boolean isOneway = true;
if (consts.getCreateSequenceAction().equals(action)) {
if (RMContextUtils.isServerSide(message)) {
boi = bi.getOperation(consts.getCreateSequenceOperationName());
isOneway = false;
} else {
boi = bi.getOperation(consts.getCreateSequenceOnewayOperationName());
}
} else if (consts.getCreateSequenceResponseAction().equals(action)) {
if (RMContextUtils.isServerSide(message)) {
boi = bi.getOperation(consts.getCreateSequenceResponseOnewayOperationName());
} else {
boi = bi.getOperation(consts.getCreateSequenceOperationName());
isOneway = false;
}
} else if (consts.getSequenceAckAction().equals(action)) {
boi = bi.getOperation(consts.getSequenceAckOperationName());
} else if (consts.getAckRequestedAction().equals(action)) {
boi = bi.getOperation(consts.getAckRequestedOperationName());
} else if (consts.getTerminateSequenceAction().equals(action)) {
boi = bi.getOperation(consts.getTerminateSequenceOperationName());
} else if (RM11Constants.INSTANCE.getTerminateSequenceResponseAction().equals(action)) {
// TODO add server-side TSR handling
boi = bi.getOperation(RM11Constants.INSTANCE.getTerminateSequenceOperationName());
isOneway = false;
} else if (consts.getCloseSequenceAction().equals(action)) {
boi = bi.getOperation(consts.getCloseSequenceOperationName());
} else if (RM11Constants.INSTANCE.getCloseSequenceResponseAction().equals(action)) {
boi = bi.getOperation(RM11Constants.INSTANCE.getCloseSequenceOperationName());
isOneway = false;
}
// make sure the binding information has been set
if (boi == null) {
LOG.fine("No BindingInfo for action " + action);
} else {
exchange.put(BindingOperationInfo.class, boi);
exchange.setOneWay(isOneway);
}
if (!consts.getCreateSequenceResponseAction().equals(action) && !consts.getSequenceAckAction().equals(action) && !RM11Constants.INSTANCE.getTerminateSequenceResponseAction().equals(action) && !RM11Constants.INSTANCE.getCloseSequenceResponseAction().equals(action)) {
LOG.fine("Changing requestor role from " + message.get(Message.REQUESTOR_ROLE) + " to false");
Object originalRequestorRole = message.get(Message.REQUESTOR_ROLE);
if (null != originalRequestorRole) {
message.put(RMMessageConstants.ORIGINAL_REQUESTOR_ROLE, originalRequestorRole);
}
message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
}
// replace WrappedInInterceptor with BareInInterceptor if necessary
// as RM protocol messages use parameter style BARE
InterceptorChain chain = message.getInterceptorChain();
ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
boolean bareIn = false;
boolean wrappedIn = false;
while (it.hasNext() && !wrappedIn && !bareIn) {
PhaseInterceptor<? extends Message> pi = (PhaseInterceptor<? extends Message>) it.next();
if (BareInInterceptor.class.getName().equals(pi.getId())) {
bareIn = true;
}
}
if (!bareIn) {
chain.add(new BareInInterceptor());
LOG.fine("Added BareInInterceptor to chain.");
}
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class ServiceProcessor method processOperation.
private void processOperation(JavaModel model, BindingOperationInfo bop, BindingInfo binding) throws ToolException {
boolean enableOpMime = false;
JAXWSBinding bind = binding.getExtensor(JAXWSBinding.class);
if (bind != null && bind.isEnableMime()) {
enableOpMime = true;
}
JAXWSBinding bopBinding = bop.getExtensor(JAXWSBinding.class);
if (bopBinding != null && bopBinding.isEnableMime()) {
enableOpMime = true;
if (bopBinding.getJaxwsParas() != null) {
jaxwsBinding.setJaxwsParas(bopBinding.getJaxwsParas());
}
}
JavaInterface jf = null;
for (JavaInterface jf2 : model.getInterfaces().values()) {
if (binding.getInterface().getName().getLocalPart().equals(jf2.getWebServiceName())) {
jf = jf2;
}
}
if (jf == null) {
throw new ToolException("No Java Interface available");
}
if (isSoapBinding()) {
SoapBinding soapBinding = (SoapBinding) bindingObj;
if (SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()) == null) {
jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
} else {
jf.setSOAPStyle(SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()));
}
} else {
// REVISIT: fix for xml binding
jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
}
Object[] methods = jf.getMethods().toArray();
for (int i = 0; i < methods.length; i++) {
JavaMethod jm = (JavaMethod) methods[i];
if (jm.getOperationName() != null && jm.getOperationName().equals(bop.getName().getLocalPart())) {
if (isSoapBinding()) {
// TODO: add customize here
// doCustomizeOperation(jf, jm, bop);
Map<String, Object> prop = getSoapOperationProp(bop);
String soapAction = prop.get(soapOPAction) == null ? "" : (String) prop.get(soapOPAction);
String soapStyle = prop.get(soapOPStyle) == null ? "" : (String) prop.get(soapOPStyle);
jm.setSoapAction(soapAction);
if (SOAPBindingUtil.getSoapStyle(soapStyle) == null && this.bindingObj == null) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("BINDING_STYLE_NOT_DEFINED", LOG);
throw new ToolException(msg);
}
if (SOAPBindingUtil.getSoapStyle(soapStyle) == null) {
jm.setSoapStyle(jf.getSOAPStyle());
} else {
jm.setSoapStyle(SOAPBindingUtil.getSoapStyle(soapStyle));
}
} else {
// REVISIT: fix for xml binding
jm.setSoapStyle(jf.getSOAPStyle());
}
if (jm.getSoapStyle().equals(javax.jws.soap.SOAPBinding.Style.RPC)) {
jm.getAnnotationMap().remove("SOAPBinding");
}
OperationProcessor processor = new OperationProcessor(context);
int headerType = isNonWrappable(bop);
OperationInfo opinfo = bop.getOperationInfo();
JAXWSBinding opBinding = opinfo.getExtensor(JAXWSBinding.class);
JAXWSBinding infBinding = opinfo.getInterface().getExtensor(JAXWSBinding.class);
boolean enableMime = enableOpMime;
boolean enableWrapperStyle = true;
if (infBinding != null && infBinding.isSetEnableWrapperStyle()) {
enableWrapperStyle = infBinding.isEnableWrapperStyle();
}
if (infBinding != null && infBinding.isSetEnableMime()) {
enableMime = infBinding.isEnableMime();
}
if (opBinding != null && opBinding.isSetEnableWrapperStyle()) {
enableWrapperStyle = opBinding.isEnableWrapperStyle();
}
if (opBinding != null && opBinding.isSetEnableMime()) {
enableMime = opBinding.isEnableMime();
}
if (jaxwsBinding.isEnableMime() || enableMime) {
jm.setMimeEnable(true);
}
if ((jm.isWrapperStyle() && headerType > this.noHEADER) || !jaxwsBinding.isEnableWrapperStyle() || (jm.enableMime() && jm.isWrapperStyle()) || !enableWrapperStyle) {
// changed wrapper style
jm.setWrapperStyle(false);
processor.processMethod(jm, bop.getOperationInfo());
jm.getAnnotationMap().remove("ResponseWrapper");
jm.getAnnotationMap().remove("RequestWrapper");
} else {
processor.processMethod(jm, bop.getOperationInfo());
}
if (headerType == this.resultHeader) {
JAnnotation resultAnno = jm.getAnnotationMap().get("WebResult");
if (resultAnno != null) {
resultAnno.addElement(new JAnnotationElement("header", true, true));
}
}
processParameter(jm, bop);
}
}
}
Aggregations