use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class JaxWsServiceFactoryBeanTest method testDocLiteralPartWithType.
@Test
public void testDocLiteralPartWithType() throws Exception {
ReflectionServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
serviceFactory.setBus(getBus());
serviceFactory.setServiceClass(NoBodyPartsImpl.class);
Service service = serviceFactory.create();
ServiceInfo serviceInfo = service.getServiceInfos().get(0);
QName qname = new QName("urn:org:apache:cxf:no_body_parts/wsdl", "operation1");
MessageInfo mi = serviceInfo.getMessage(qname);
qname = new QName("urn:org:apache:cxf:no_body_parts/wsdl", "mimeAttachment");
MessagePartInfo mpi = mi.getMessagePart(qname);
QName elementQName = mpi.getElementQName();
XmlSchemaElement element = serviceInfo.getXmlSchemaCollection().getElementByQName(elementQName);
assertNotNull(element);
}
use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class Wsdl11AttachmentPolicyProvider method getEffectivePolicy.
/**
* The effective policy for a specific WSDL message (input or output) is calculated
* in relation to a specific port, and includes the element policy of the wsdl:message
* element that defines the message's type merged with the element policy of the
* wsdl11:binding and wsdl11:portType message definitions that describe the message.
* For example, the effective policy of a specific input message for a specific port
* would be the (element policies of the) wsdl11:message element defining the message type,
* the wsdl11:portType/wsdl11:operation/wsdl11:input element and the corresponding
* wsdl11:binding/wsdl11:operation/wsdl11:input element for that message.
*
* @param bmi the BindingMessageInfo identifiying the message
* @return the effective policy
*/
public Policy getEffectivePolicy(BindingMessageInfo bmi, Message m) {
ServiceInfo si = bmi.getBindingOperation().getBinding().getService();
DescriptionInfo di = si.getDescription();
Policy p = getElementPolicy(bmi, false, di);
MessageInfo mi = bmi.getMessageInfo();
p = mergePolicies(p, getElementPolicy(mi, true, di));
Extensible ex = getMessageTypeInfo(mi.getName(), di);
p = mergePolicies(p, getElementPolicy(ex, false, di));
return p;
}
use of org.apache.cxf.service.model.MessageInfo 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)), WSSConstants.NS_SOAP12.equals(msg.getVersion().getNamespace()));
}
use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class WrappedOutInterceptor method handleMessage.
public void handleMessage(Message message) {
BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
if (bop != null && bop.isUnwrapped()) {
XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
MessageInfo messageInfo;
if (isRequestor(message)) {
messageInfo = bop.getWrappedOperation().getOperationInfo().getInput();
} else {
messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput();
}
QName name = messageInfo.getFirstMessagePart().getConcreteName();
try {
String pfx = null;
Service service = message.getExchange().getService();
if (service.getDataBinding().getDeclaredNamespaceMappings() != null) {
pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
}
if (pfx == null) {
pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
}
xmlWriter.setPrefix(pfx, name.getNamespaceURI());
xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
if (StringUtils.isEmpty(pfx)) {
xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
} else {
xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
}
} catch (XMLStreamException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
}
// Add a final interceptor to write end element
message.getInterceptorChain().add(ending);
}
}
use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class RequestWrapperTest method testBuildRequestFields.
@Test
public void testBuildRequestFields() {
// Test String[]
Class<?> testingClass = GreeterArray.class;
OperationInfo opInfo = getOperation(testingClass, "sayStringArray");
assertNotNull(opInfo);
RequestWrapper requestWrapper = new RequestWrapper();
MessageInfo message = opInfo.getUnwrappedOperation().getInput();
Method method = (Method) opInfo.getProperty("operation.method");
List<JavaField> fields = requestWrapper.buildFields(method, message);
assertEquals(1, fields.size());
JavaField field = fields.get(0);
assertEquals("arg0", field.getName());
assertEquals("String[]", field.getType());
// Test int[]
opInfo = getOperation(testingClass, "sayIntArray");
assertNotNull(opInfo);
message = opInfo.getUnwrappedOperation().getInput();
method = (Method) opInfo.getProperty("operation.method");
fields = requestWrapper.buildFields(method, message);
assertEquals(1, fields.size());
field = fields.get(0);
assertEquals("arg0", field.getName());
assertEquals("int[]", field.getType());
// Test TestDataBean[]
opInfo = getOperation(testingClass, "sayTestDataBeanArray");
assertNotNull(opInfo);
message = opInfo.getUnwrappedOperation().getInput();
method = (Method) opInfo.getProperty("operation.method");
fields = requestWrapper.buildFields(method, message);
assertEquals(1, fields.size());
field = fields.get(0);
assertEquals("arg0", field.getName());
assertEquals("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]", field.getType());
}
Aggregations