use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class XMLMessageOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
MessageInfo mi;
BindingMessageInfo bmi;
if (isRequestor(message)) {
mi = boi.getOperationInfo().getInput();
bmi = boi.getInput();
} else {
mi = boi.getOperationInfo().getOutput();
bmi = boi.getOutput();
}
XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
QName rootInModel = null;
if (xmf != null) {
rootInModel = xmf.getRootNode();
}
final int mpn = mi.getMessagePartsNumber();
if (boi.isUnwrapped() || mpn == 1) {
// wrapper out interceptor created the wrapper
// or if bare-one-param
new BareOutInterceptor().handleMessage(message);
} else {
if (rootInModel == null) {
rootInModel = boi.getName();
}
if (mpn == 0 && !boi.isUnwrapped()) {
// write empty operation qname
writeMessage(message, rootInModel, false);
} else {
// multi param, bare mode, needs write root node
writeMessage(message, rootInModel, true);
}
}
// in the end we do flush ;)
XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
try {
writer.flush();
} catch (XMLStreamException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
}
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class XMLMessageOutInterceptorTest method testBareOutMultiWithRoot.
@Test
public void testBareOutMultiWithRoot() throws Exception {
MyComplexStructType myComplexStruct = new MyComplexStructType();
myComplexStruct.setElem1("elem1");
myComplexStruct.setElem2("elem2");
myComplexStruct.setElem3(45);
params.add("tli");
params.add(myComplexStruct);
common("/wsdl/hello_world_xml_bare.wsdl", new QName(bareNs, "XMLPort"), MyComplexStructType.class);
BindingInfo bi = super.serviceInfo.getBinding(new QName(bareNs, "Greeter_XMLBinding"));
BindingOperationInfo boi = bi.getOperation(new QName(bareNs, "testMultiParamPart"));
xmlMessage.getExchange().put(BindingOperationInfo.class, boi);
out.handleMessage(xmlMessage);
XMLStreamReader reader = getXMLReader();
DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader);
StaxUtils.nextEvent(dxr);
StaxUtils.toNextElement(dxr);
assertEquals(bareNs, dxr.getNamespaceURI());
assertEquals("multiParamRootReq", dxr.getLocalName());
StaxUtils.nextEvent(dxr);
StaxUtils.toNextElement(dxr);
assertEquals(bareRequestTypeQName, dxr.getName());
StaxUtils.nextEvent(dxr);
if (StaxUtils.toNextText(dxr)) {
assertEquals("tli", dxr.getText());
}
boolean foundRequest = false;
while (true) {
StaxUtils.nextEvent(dxr);
StaxUtils.toNextElement(dxr);
QName requestType = new QName(dxr.getNamespaceURI(), dxr.getLocalName());
if (requestType.equals(bareMyComplexStructQName)) {
foundRequest = true;
break;
}
}
assertEquals("found request type", true, foundRequest);
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class XMLMessageOutInterceptorTest method testWrapOut.
@Test
public void testWrapOut() throws Exception {
GreetMe greetMe = new GreetMe();
greetMe.setRequestType("tli");
params.add(greetMe);
common("/wsdl/hello_world_xml_wrapped.wsdl", new QName(wrapNs, "XMLPort"), GreetMe.class);
BindingInfo bi = super.serviceInfo.getBinding(new QName(wrapNs, "Greeter_XMLBinding"));
BindingOperationInfo boi = bi.getOperation(new QName(wrapNs, "greetMe"));
xmlMessage.getExchange().put(BindingOperationInfo.class, boi);
out.handleMessage(xmlMessage);
XMLStreamReader reader = getXMLReader();
DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader);
StaxUtils.nextEvent(dxr);
StaxUtils.toNextElement(dxr);
assertEquals(wrapGreetMeQName.getNamespaceURI(), dxr.getNamespaceURI());
assertEquals(wrapGreetMeQName.getLocalPart(), dxr.getLocalName());
StaxUtils.toNextElement(dxr);
StaxUtils.toNextText(dxr);
assertEquals(greetMe.getRequestType(), dxr.getText());
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class XMLMessageOutInterceptorTest method testBareOutSingle.
@Test
public void testBareOutSingle() throws Exception {
MyComplexStructType myComplexStruct = new MyComplexStructType();
myComplexStruct.setElem1("elem1");
myComplexStruct.setElem2("elem2");
myComplexStruct.setElem3(45);
params.add(myComplexStruct);
common("/wsdl/hello_world_xml_bare.wsdl", new QName(bareNs, "XMLPort"), MyComplexStructType.class);
BindingInfo bi = super.serviceInfo.getBinding(new QName(bareNs, "Greeter_XMLBinding"));
BindingOperationInfo boi = bi.getOperation(new QName(bareNs, "sendReceiveData"));
xmlMessage.getExchange().put(BindingOperationInfo.class, boi);
out.handleMessage(xmlMessage);
XMLStreamReader reader = getXMLReader();
DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader);
StaxUtils.nextEvent(dxr);
StaxUtils.toNextElement(dxr);
assertEquals(bareMyComplexStructTypeQName.getLocalPart(), dxr.getLocalName());
StaxUtils.toNextElement(dxr);
StaxUtils.toNextText(dxr);
assertEquals(myComplexStruct.getElem1(), dxr.getText());
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class ClaimsAuthorizingInterceptor method getTargetMethod.
protected Method getTargetMethod(Message m) {
BindingOperationInfo bop = m.getExchange().getBindingOperationInfo();
if (bop != null) {
MethodDispatcher md = (MethodDispatcher) m.getExchange().getService().get(MethodDispatcher.class.getName());
return md.getMethod(bop);
}
Method method = (Method) m.get("org.apache.cxf.resource.method");
if (method != null) {
return method;
}
throw new AccessDeniedException("Method is not available : Unauthorized");
}
Aggregations