use of org.apache.cxf.service.model.BindingOperationInfo in project camel by apache.
the class CxfProducer method checkParameterSize.
private void checkParameterSize(CxfEndpoint endpoint, Exchange exchange, Object[] parameters) {
BindingOperationInfo boi = getBindingOperationInfo(exchange);
if (boi == null) {
throw new RuntimeCamelException("Can't find the binding operation information from camel exchange");
}
if (!endpoint.isWrapped()) {
if (boi.isUnwrappedCapable()) {
boi = boi.getUnwrappedOperation();
}
}
int experctMessagePartsSize = boi.getInput().getMessageParts().size();
if (parameters.length < experctMessagePartsSize) {
throw new IllegalArgumentException("Get the wrong parameter size to invoke the out service, Expect size " + experctMessagePartsSize + ", Parameter size " + parameters.length + ". Please check if the message body matches the CXFEndpoint POJO Dataformat request.");
}
if (parameters.length > experctMessagePartsSize) {
// need to check the holder parameters
int holdersSize = 0;
for (Object parameter : parameters) {
if (parameter instanceof Holder) {
holdersSize++;
}
}
// need to check the soap header information
int soapHeadersSize = 0;
BindingMessageInfo bmi = boi.getInput();
if (bmi != null) {
List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
if (headers != null) {
soapHeadersSize = headers.size();
}
}
if (holdersSize + experctMessagePartsSize + soapHeadersSize < parameters.length) {
throw new IllegalArgumentException("Get the wrong parameter size to invoke the out service, Expect size " + (experctMessagePartsSize + holdersSize + soapHeadersSize) + ", Parameter size " + parameters.length + ". Please check if the message body matches the CXFEndpoint POJO Dataformat request.");
}
}
}
use of org.apache.cxf.service.model.BindingOperationInfo in project camel by apache.
the class DefaultCxfBinding method getPayloadBodyElements.
protected static List<Source> getPayloadBodyElements(Message message, Map<String, String> nsMap) {
// take the namespace attribute from soap envelop
Map<String, String> bodyNC = CastUtils.cast((Map<?, ?>) message.get("soap.body.ns.context"));
if (bodyNC != null) {
// if there is no Node and the addNamespaceContext option is enabled, this map is available
nsMap.putAll(bodyNC);
} else {
Document soapEnv = (Document) message.getContent(Node.class);
if (soapEnv != null) {
NamedNodeMap attrs = soapEnv.getFirstChild().getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Node node = attrs.item(i);
if (!node.getNodeValue().equals(Soap11.SOAP_NAMESPACE) && !node.getNodeValue().equals(Soap12.SOAP_NAMESPACE)) {
nsMap.put(node.getLocalName(), node.getNodeValue());
}
}
}
}
MessageContentsList inObjects = MessageContentsList.getContentsList(message);
if (inObjects == null) {
return new ArrayList<Source>(0);
}
org.apache.cxf.message.Exchange exchange = message.getExchange();
BindingOperationInfo boi = exchange.getBindingOperationInfo();
OperationInfo op = boi.getOperationInfo();
if (boi.isUnwrapped()) {
op = boi.getWrappedOperation().getOperationInfo();
}
List<MessagePartInfo> partInfos = null;
boolean client = Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE));
if (client) {
// it is a response
partInfos = op.getOutput().getMessageParts();
} else {
// it is a request
partInfos = op.getInput().getMessageParts();
}
List<Source> answer = new ArrayList<Source>();
for (MessagePartInfo partInfo : partInfos) {
if (!inObjects.hasValue(partInfo)) {
continue;
}
Object part = inObjects.get(partInfo);
if (part instanceof Holder) {
part = ((Holder<?>) part).value;
}
if (part instanceof Source) {
Element element = null;
if (part instanceof DOMSource) {
element = getFirstElement(((DOMSource) part).getNode());
}
if (element != null) {
addNamespace(element, nsMap);
answer.add(new DOMSource(element));
} else {
answer.add((Source) part);
}
if (LOG.isTraceEnabled()) {
LOG.trace("Extract body element {}", element == null ? "null" : getXMLString(element));
}
} else if (part instanceof Element) {
addNamespace((Element) part, nsMap);
answer.add(new DOMSource((Element) part));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Unhandled part type '{}'", part.getClass());
}
}
}
return answer;
}
use of org.apache.cxf.service.model.BindingOperationInfo in project camel by apache.
the class PersonProcessor method process.
public void process(Exchange exchange) throws Exception {
LOG.info("processing exchange in camel");
BindingOperationInfo boi = (BindingOperationInfo) exchange.getProperty(BindingOperationInfo.class.getName());
if (boi != null) {
LOG.info("boi.isUnwrapped" + boi.isUnwrapped());
}
GetPerson person = exchange.getIn().getBody(GetPerson.class);
String personId = person.getPersonId();
GetPersonResponse response = new GetPersonResponse();
if (personId == null || personId.length() == 0) {
LOG.info("person id 123, so throwing exception");
// Try to throw out the soap fault message
org.apache.camel.non_wrapper.types.UnknownPersonFault personFault = new org.apache.camel.non_wrapper.types.UnknownPersonFault();
personFault.setPersonId("");
org.apache.camel.non_wrapper.UnknownPersonFault fault = new org.apache.camel.non_wrapper.UnknownPersonFault("Get the null value of person name", personFault);
// Since camel has its own exception handler framework, we can't throw the exception to trigger it
// We just set the fault message in the exchange for camel-cxf component handling and return
exchange.getOut().setFault(true);
exchange.getOut().setBody(fault);
return;
}
response.setPersonId(personId);
response.setName("Bonjour");
response.setSsn("123");
LOG.info("setting Bonjour as the response");
// Set the response message, first element is the return value of the operation,
// the others are the holders of method parameters
exchange.getOut().setBody(new Object[] { response });
}
use of org.apache.cxf.service.model.BindingOperationInfo in project ddf by codice.
the class PEPAuthorizingInterceptor method getActionUri.
/**
* This method is an implementation of the WSA-M and WSA-W specs for determining the action URI.<br>
* <ul>
* <li>http://www.w3.org/TR/ws-addr-metadata/#actioninwsdl</li>
* <li>http://www.w3.org/TR/ws-addr-wsdl/#actioninwsdl</li>
* </ul>
* Adapted from {@link org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl} and
* {@link org.apache.cxf.ws.addressing.impl.InternalContextUtils}
*
* @param message
* @return
*/
private String getActionUri(Message message) {
String actionURI = null;
/**
* See if the action is explicitly defined in the WSDL message service model. Retrieves one
* of the Action attribute in the wsdl:input message.
*/
MessageInfo msgInfo = (MessageInfo) message.get(MessageInfo.class.getName());
if (msgInfo != null && msgInfo.getExtensionAttributes() != null) {
// wsaw:Action
Object attr = msgInfo.getExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME);
// wsam:Action
if (attr == null) {
attr = msgInfo.getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME);
}
// support for older usages
if (attr == null) {
attr = msgInfo.getExtensionAttributes().get(new QName(JAXWSAConstants.NS_WSA, Names.WSAW_ACTION_NAME));
}
if (attr == null) {
attr = msgInfo.getExtensionAttributes().get(new QName(Names.WSA_NAMESPACE_WSDL_NAME_OLD, Names.WSAW_ACTION_NAME));
}
if (attr instanceof QName) {
actionURI = ((QName) attr).getLocalPart();
} else {
actionURI = attr == null ? null : attr.toString();
}
}
/**
* See if the action is explicitly defined in the WSDL operation service model. Retrieves
* the operation soap:soapAction property.
*/
if (StringUtils.isEmpty(actionURI)) {
BindingOperationInfo bindingOpInfo = message.getExchange().get(BindingOperationInfo.class);
SoapOperationInfo soi = null;
if (bindingOpInfo != null) {
soi = bindingOpInfo.getExtensor(SoapOperationInfo.class);
if (soi == null && bindingOpInfo.isUnwrapped()) {
soi = bindingOpInfo.getWrappedOperation().getExtensor(SoapOperationInfo.class);
}
}
actionURI = soi == null ? null : soi.getAction();
actionURI = StringUtils.isEmpty(actionURI) ? null : actionURI;
}
/**
* If the service model doesn't explicitly defines the action, we'll construct the default
* URI string.
*/
if (StringUtils.isEmpty(actionURI)) {
QName op = (QName) message.get(MessageContext.WSDL_OPERATION);
QName port = (QName) message.get(MessageContext.WSDL_PORT);
if (op != null && port != null) {
actionURI = port.getNamespaceURI();
actionURI = addPath(actionURI, port.getLocalPart());
actionURI = addPath(actionURI, op.getLocalPart() + "Request");
}
}
return actionURI;
}
use of org.apache.cxf.service.model.BindingOperationInfo in project ddf by codice.
the class TestPepInterceptorActions method testMessageWithDefaultUriAction.
@Test
public void testMessageWithDefaultUriAction() throws SecurityServiceException {
PEPAuthorizingInterceptor interceptor = new PEPAuthorizingInterceptor();
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithAction = mock(Message.class);
SecurityAssertion mockSecurityAssertion = mock(SecurityAssertion.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
PowerMockito.mockStatic(SecurityAssertionStore.class);
PowerMockito.mockStatic(SecurityLogger.class);
when(SecurityAssertionStore.getSecurityAssertion(messageWithAction)).thenReturn(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getSecurityToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
QName op = new QName("urn:catalog:query", "search", "ns1");
QName port = new QName("urn:catalog:query", "query-port", "ns1");
when(messageWithAction.get(MessageContext.WSDL_OPERATION)).thenReturn(op);
when(messageWithAction.get(MessageContext.WSDL_PORT)).thenReturn(port);
Exchange mockExchange = mock(Exchange.class);
BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
when(messageWithAction.getExchange()).thenReturn(mockExchange);
when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(null);
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
CollectionPermission perm = (CollectionPermission) invocation.getArguments()[0];
assertEquals("urn:catalog:query:query-port:searchRequest", perm.getAction());
return true;
}
}).when(mockSubject).isPermitted(isA(CollectionPermission.class));
// This should work.
interceptor.handleMessage(messageWithAction);
PowerMockito.verifyStatic();
}
Aggregations