use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.
the class WSDLServiceBuilderTest method testParameterOrder2.
@Test
public void testParameterOrder2() throws Exception {
setUpWSDL("header2.wsdl", 0);
String ns = "http://apache.org/header2";
OperationInfo operation = serviceInfo.getInterface().getOperation(new QName(ns, "headerMethod"));
assertNotNull(operation);
List<MessagePartInfo> parts = operation.getInput().getMessageParts();
assertNotNull(parts);
assertEquals(2, parts.size());
assertEquals("header_info", parts.get(0).getName().getLocalPart());
assertEquals("the_request", parts.get(1).getName().getLocalPart());
control.verify();
}
use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.
the class WSDLServiceBuilderTest method testOperationInfo.
@Test
public void testOperationInfo() throws Exception {
setUpBasic();
QName name = new QName(serviceInfo.getName().getNamespaceURI(), "sayHi");
assertEquals(4, serviceInfo.getInterface().getOperations().size());
OperationInfo sayHi = serviceInfo.getInterface().getOperation(new QName(serviceInfo.getName().getNamespaceURI(), "sayHi"));
assertNotNull(sayHi);
assertEquals(sayHi.getName(), name);
assertFalse(sayHi.isOneWay());
assertTrue(sayHi.hasInput());
assertTrue(sayHi.hasOutput());
assertNull(sayHi.getParameterOrdering());
name = new QName(serviceInfo.getName().getNamespaceURI(), "greetMe");
OperationInfo greetMe = serviceInfo.getInterface().getOperation(name);
assertNotNull(greetMe);
assertEquals(greetMe.getName(), name);
assertFalse(greetMe.isOneWay());
assertTrue(greetMe.hasInput());
assertTrue(greetMe.hasOutput());
List<MessagePartInfo> inParts = greetMe.getInput().getMessageParts();
assertEquals(1, inParts.size());
MessagePartInfo part = inParts.get(0);
assertNotNull(part.getXmlSchema());
assertTrue(part.getXmlSchema() instanceof XmlSchemaElement);
List<MessagePartInfo> outParts = greetMe.getOutput().getMessageParts();
assertEquals(1, outParts.size());
part = outParts.get(0);
assertNotNull(part.getXmlSchema());
assertTrue(part.getXmlSchema() instanceof XmlSchemaElement);
assertTrue("greatMe should be wrapped", greetMe.isUnwrappedCapable());
OperationInfo greetMeUnwrapped = greetMe.getUnwrappedOperation();
assertNotNull(greetMeUnwrapped.getInput());
assertNotNull(greetMeUnwrapped.getOutput());
assertEquals("wrapped part not set", 1, greetMeUnwrapped.getInput().size());
assertEquals("wrapped part not set", 1, greetMeUnwrapped.getOutput().size());
assertEquals("wrapper part name wrong", "requestType", greetMeUnwrapped.getInput().getMessagePartByIndex(0).getName().getLocalPart());
assertEquals("wrapper part type name wrong", "MyStringType", greetMeUnwrapped.getInput().getMessagePartByIndex(0).getTypeQName().getLocalPart());
assertEquals("wrapper part name wrong", "responseType", greetMeUnwrapped.getOutput().getMessagePartByIndex(0).getName().getLocalPart());
assertEquals("wrapper part type name wrong", "string", greetMeUnwrapped.getOutput().getMessagePartByIndex(0).getTypeQName().getLocalPart());
name = new QName(serviceInfo.getName().getNamespaceURI(), "greetMeOneWay");
OperationInfo greetMeOneWay = serviceInfo.getInterface().getOperation(name);
assertNotNull(greetMeOneWay);
assertEquals(greetMeOneWay.getName(), name);
assertTrue(greetMeOneWay.isOneWay());
assertTrue(greetMeOneWay.hasInput());
assertFalse(greetMeOneWay.hasOutput());
OperationInfo greetMeOneWayUnwrapped = greetMeOneWay.getUnwrappedOperation();
assertNotNull(greetMeOneWayUnwrapped);
assertNotNull(greetMeOneWayUnwrapped.getInput());
assertNull(greetMeOneWayUnwrapped.getOutput());
assertEquals("wrapped part not set", 1, greetMeOneWayUnwrapped.getInput().size());
assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "requestType"), greetMeOneWayUnwrapped.getInput().getMessagePartByIndex(0).getConcreteName());
name = new QName(serviceInfo.getName().getNamespaceURI(), "pingMe");
OperationInfo pingMe = serviceInfo.getInterface().getOperation(name);
assertNotNull(pingMe);
assertEquals(pingMe.getName(), name);
assertFalse(pingMe.isOneWay());
assertTrue(pingMe.hasInput());
assertTrue(pingMe.hasOutput());
assertNull(serviceInfo.getInterface().getOperation(new QName("what ever")));
control.verify();
}
use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.
the class BareInInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message) && message.getContent(List.class) != null) {
LOG.fine("BareInInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
Exchange exchange = message.getExchange();
DataReader<XMLStreamReader> dr = getDataReader(message);
MessageContentsList parameters = new MessageContentsList();
Endpoint ep = exchange.getEndpoint();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
ServiceInfo si = ep.getEndpointInfo().getService();
BindingMessageInfo msgInfo = null;
boolean client = isRequestor(message);
Collection<OperationInfo> ops = null;
if (bop == null) {
ops = new ArrayList<>();
ops.addAll(si.getInterface().getOperations());
if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT && !client) {
// TO DO : check duplicate operation with no input
for (OperationInfo op : ops) {
MessageInfo bmsg = op.getInput();
if (bmsg.getMessagePartsNumber() == 0) {
BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
exchange.put(BindingOperationInfo.class, boi);
exchange.setOneWay(op.isOneWay());
}
}
}
} else {
getMessageInfo(message, bop);
if (client) {
msgInfo = bop.getOutput();
} else {
msgInfo = bop.getInput();
}
}
int paramNum = 0;
while (StaxUtils.toNextElement(xmlReader)) {
QName elName = xmlReader.getName();
Object o = null;
MessagePartInfo p;
if (msgInfo != null && msgInfo.getMessageParts() != null) {
assert msgInfo.getMessageParts().size() > paramNum;
p = msgInfo.getMessageParts().get(paramNum);
} else {
p = findMessagePart(exchange, ops, elName, client, paramNum, message);
}
if (p == null) {
throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", LOG, elName), Fault.FAULT_CODE_CLIENT);
}
try {
o = dr.read(p, xmlReader);
} catch (Fault fault) {
if (!isRequestor(message)) {
fault.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw fault;
}
if (o != null) {
parameters.put(p, o);
}
paramNum++;
}
if (!parameters.isEmpty()) {
message.setContent(List.class, parameters);
}
}
use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.
the class DocLiteralInInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message) && message.getContent(List.class) != null) {
LOG.fine("DocLiteralInInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
MessageContentsList parameters = new MessageContentsList();
Exchange exchange = message.getExchange();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
boolean client = isRequestor(message);
// operation anymore, just return
if (bop != null && !StaxUtils.toNextElement(xmlReader)) {
// body may be empty for partial response to decoupled request
return;
}
Service service = ServiceModelUtil.getService(message.getExchange());
bop = getBindingOperationInfo(xmlReader, exchange, bop, client);
boolean forceDocLitBare = false;
if (bop != null && bop.getBinding() != null) {
forceDocLitBare = Boolean.TRUE.equals(bop.getBinding().getService().getProperty("soap.force.doclit.bare"));
}
DataReader<XMLStreamReader> dr = getDataReader(message);
try {
if (!forceDocLitBare && bop != null && bop.isUnwrappedCapable()) {
ServiceInfo si = bop.getBinding().getService();
// Wrapped case
MessageInfo msgInfo = setMessage(message, bop, client, si);
setDataReaderValidation(service, message, dr);
// Determine if we should keep the parameters wrapper
if (shouldWrapParameters(msgInfo, message)) {
QName startQName = xmlReader.getName();
MessagePartInfo mpi = msgInfo.getFirstMessagePart();
if (!mpi.getConcreteName().equals(startQName)) {
throw new Fault("UNEXPECTED_WRAPPER_ELEMENT", LOG, null, startQName, mpi.getConcreteName());
}
Object wrappedObject = dr.read(mpi, xmlReader);
parameters.put(mpi, wrappedObject);
} else {
// Unwrap each part individually if we don't have a wrapper
bop = bop.getUnwrappedOperation();
msgInfo = setMessage(message, bop, client, si);
List<MessagePartInfo> messageParts = msgInfo.getMessageParts();
Iterator<MessagePartInfo> itr = messageParts.iterator();
// stuck
if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
StaxUtils.nextEvent(xmlReader);
}
// loop through each child element
getPara(xmlReader, dr, parameters, itr, message);
}
} else {
// Bare style
BindingMessageInfo msgInfo = null;
Endpoint ep = exchange.getEndpoint();
ServiceInfo si = ep.getEndpointInfo().getService();
if (bop != null) {
// for xml binding or client side
if (client) {
msgInfo = bop.getOutput();
} else {
msgInfo = bop.getInput();
if (bop.getOutput() == null) {
exchange.setOneWay(true);
}
}
if (msgInfo == null) {
return;
}
setMessage(message, bop, client, si, msgInfo.getMessageInfo());
}
Collection<OperationInfo> operations = null;
operations = new ArrayList<>();
operations.addAll(si.getInterface().getOperations());
if (xmlReader == null || !StaxUtils.toNextElement(xmlReader)) {
// empty input
getBindingOperationForEmptyBody(operations, ep, exchange);
return;
}
setDataReaderValidation(service, message, dr);
int paramNum = 0;
do {
QName elName = xmlReader.getName();
Object o = null;
MessagePartInfo p;
if (!client && msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().isEmpty()) {
// no input messagePartInfo
return;
}
if (msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().size() > 0) {
if (msgInfo.getMessageParts().size() > paramNum) {
p = msgInfo.getMessageParts().get(paramNum);
} else {
p = null;
}
} else {
p = findMessagePart(exchange, operations, elName, client, paramNum, message);
}
if (!forceDocLitBare) {
// Make sure the elName found on the wire is actually OK for
// the purpose we need it
validatePart(p, elName, message);
}
o = dr.read(p, xmlReader);
if (forceDocLitBare && parameters.isEmpty()) {
// webservice provider does not need to ensure size
parameters.add(o);
} else {
parameters.put(p, o);
}
paramNum++;
if (message.getContent(XMLStreamReader.class) == null || o == xmlReader) {
xmlReader = null;
}
} while (xmlReader != null && StaxUtils.toNextElement(xmlReader));
}
message.setContent(List.class, parameters);
} catch (Fault f) {
if (!isRequestor(message)) {
f.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw f;
}
}
use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.
the class DocLiteralInInterceptor method validatePart.
private void validatePart(MessagePartInfo p, QName elName, Message m) {
if (p == null) {
throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", LOG, elName), Fault.FAULT_CODE_CLIENT);
}
boolean synth = false;
if (p.getMessageInfo() != null && p.getMessageInfo().getOperation() != null) {
OperationInfo op = p.getMessageInfo().getOperation();
Boolean b = (Boolean) op.getProperty("operation.is.synthetic");
if (b != null) {
synth = b;
}
}
if (MessageUtils.getContextualBoolean(m, "soap.no.validate.parts", false)) {
// something like a Provider service or similar that is forcing a
// doc/lit/bare on an endpoint that may not really be doc/lit/bare.
// we need to just let these through per spec so the endpoint
// can process it
synth = true;
}
if (synth) {
return;
}
if (p.isElement()) {
if (p.getConcreteName() != null && !elName.equals(p.getConcreteName()) && !synth) {
throw new Fault("UNEXPECTED_ELEMENT", LOG, null, elName, p.getConcreteName());
}
} else {
if (!(elName.equals(p.getName()) || elName.equals(p.getConcreteName())) && !synth) {
throw new Fault("UNEXPECTED_ELEMENT", LOG, null, elName, p.getConcreteName());
}
}
}
Aggregations