use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class SoapHeaderInterceptor method handleMessage.
public void handleMessage(Message m) throws Fault {
SoapMessage message = (SoapMessage) m;
SoapVersion soapVersion = message.getVersion();
Exchange exchange = message.getExchange();
MessageContentsList parameters = MessageContentsList.getContentsList(message);
if (null == parameters) {
parameters = new MessageContentsList();
}
BindingOperationInfo bop = exchange.getBindingOperationInfo();
if (null == bop) {
return;
}
if (bop.isUnwrapped()) {
bop = bop.getWrappedOperation();
}
boolean client = isRequestor(message);
BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
if (bmi == null) {
// one way operation.
return;
}
List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
if (headers == null || headers.isEmpty()) {
return;
}
boolean supportsNode = this.supportsDataReader(message, Node.class);
Service service = ServiceModelUtil.getService(message.getExchange());
for (SoapHeaderInfo header : headers) {
MessagePartInfo mpi = header.getPart();
try {
if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.IN, message)) {
Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0), message.getExchange().getBus());
validateHeader(message, mpi, schema);
}
} catch (Fault f) {
if (!isRequestor(message)) {
f.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw f;
}
if (mpi.getTypeClass() != null) {
Header param = findHeader(message, mpi);
Object object = null;
if (param != null) {
message.getHeaders().remove(param);
if (param.getDataBinding() == null) {
Node source = (Node) param.getObject();
if (source instanceof Element) {
// need to remove these attributes as they
// would cause validation failures
Element el = (Element) source;
el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameMustUnderstand());
el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameRole());
}
if (supportsNode) {
object = getNodeDataReader(message).read(mpi, source);
} else {
W3CDOMStreamReader reader = new W3CDOMStreamReader((Element) source);
try {
// advance into the first tag
reader.nextTag();
} catch (XMLStreamException e) {
// ignore
}
object = getDataReader(message, XMLStreamReader.class).read(mpi, reader);
}
} else {
object = param.getObject();
}
}
parameters.put(mpi, object);
}
}
if (!parameters.isEmpty()) {
message.setContent(List.class, parameters);
}
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class SoapPreProtocolOutInterceptor method setSoapAction.
private void setSoapAction(SoapMessage message) {
BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
// The soap action is set on the wrapped operation.
if (boi != null && boi.isUnwrapped()) {
boi = boi.getWrappedOperation();
}
String action = getSoapAction(message, boi);
if (message.getVersion() instanceof Soap11) {
Map<String, List<String>> tempReqHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
Map<String, List<String>> reqHeaders = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
if (reqHeaders != null) {
tempReqHeaders.putAll(reqHeaders);
}
if (!tempReqHeaders.containsKey(SoapBindingConstants.SOAP_ACTION)) {
tempReqHeaders.put(SoapBindingConstants.SOAP_ACTION, Collections.singletonList(action));
}
message.put(Message.PROTOCOL_HEADERS, tempReqHeaders);
} else if (message.getVersion() instanceof Soap12 && !"\"\"".equals(action)) {
String ct = (String) message.get(Message.CONTENT_TYPE);
if (ct.indexOf("action=\"") == -1) {
ct = new StringBuilder().append(ct).append("; action=").append(action).toString();
message.put(Message.CONTENT_TYPE, ct);
}
}
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class SoapBindingInfo method getSoapAction.
/**
* Get the soap action for an operation. Will never return null.
*
* @param operation
* @return
*/
public String getSoapAction(OperationInfo operation) {
BindingOperationInfo b = getOperation(operation.getName());
SoapOperationInfo opInfo = b.getExtensor(SoapOperationInfo.class);
if (opInfo != null && opInfo.getAction() != null) {
return opInfo.getAction();
}
return "";
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class MustUnderstandInterceptorTest method testHandleMessageWithSoapHeader11Param.
@Test
public void testHandleMessageWithSoapHeader11Param() throws Exception {
prepareSoapMessage("test-soap-header.xml");
dsi.getUnderstoodHeaders().add(RESERVATION);
ServiceInfo serviceInfo = getMockedServiceModel(getClass().getResource("test-soap-header.wsdl").toString());
BindingInfo binding = serviceInfo.getBinding(new QName("http://org.apache.cxf/headers", "headerTesterSOAPBinding"));
BindingOperationInfo bop = binding.getOperation(new QName("http://org.apache.cxf/headers", "inHeader"));
soapMessage.getExchange().put(BindingOperationInfo.class, bop);
soapMessage.getInterceptorChain().doIntercept(soapMessage);
assertEquals("DummaySoapInterceptor getRoles has been called!", true, dsi.isCalledGetRoles());
assertEquals("DummaySoapInterceptor getUnderstood has been called!", true, dsi.isCalledGetUnderstood());
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class RPCInInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
ServiceInfo si = getMockedServiceModel(this.getClass().getResource("/wsdl_soap/hello_world_rpc_lit.wsdl").toString());
BindingInfo bi = si.getBinding(new QName(TNS, "Greeter_SOAPBinding_RPCLit"));
BindingOperationInfo boi = bi.getOperation(new QName(TNS, OPNAME));
boi.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(MyComplexStruct.class);
boi.getOperationInfo().getInput().getMessagePartByIndex(0).setIndex(1);
boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(MyComplexStruct.class);
boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setIndex(0);
soapMessage.getExchange().put(BindingOperationInfo.class, boi);
control.reset();
Service service = control.createMock(Service.class);
JAXBDataBinding dataBinding = new JAXBDataBinding(MyComplexStruct.class);
service.getDataBinding();
EasyMock.expectLastCall().andReturn(dataBinding).anyTimes();
service.getServiceInfos();
List<ServiceInfo> list = Arrays.asList(si);
EasyMock.expectLastCall().andReturn(list).anyTimes();
EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
soapMessage.getExchange().put(Service.class, service);
soapMessage.getExchange().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
control.replay();
}
Aggregations