use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class InternalContextUtils method getActionFromServiceModel.
/**
* Get action from service model.
*
* @param message the current message
* @param fault the fault if one is set
*/
private static String getActionFromServiceModel(Message message, Exception fault) {
String action = null;
BindingOperationInfo bindingOpInfo = message.getExchange().getBindingOperationInfo();
if (bindingOpInfo != null) {
if (bindingOpInfo.isUnwrappedCapable()) {
bindingOpInfo = bindingOpInfo.getUnwrappedOperation();
}
if (fault == null) {
action = (String) message.get(ContextUtils.ACTION);
if (StringUtils.isEmpty(action)) {
action = (String) message.get(SoapBindingConstants.SOAP_ACTION);
}
if (action == null || "".equals(action)) {
MessageInfo msgInfo = ContextUtils.isRequestor(message) ? bindingOpInfo.getOperationInfo().getInput() : bindingOpInfo.getOperationInfo().getOutput();
String cachedAction = (String) msgInfo.getProperty(ContextUtils.ACTION);
if (cachedAction == null) {
action = getActionFromMessageAttributes(msgInfo);
} else {
action = cachedAction;
}
if (action == null && ContextUtils.isRequestor(message)) {
SoapOperationInfo soi = getSoapOperationInfo(bindingOpInfo);
action = soi == null ? null : soi.getAction();
action = StringUtils.isEmpty(action) ? null : action;
}
}
} else {
Throwable t = fault.getCause();
// http://www.w3.org/2005/02/addressing/wsdl schema
for (BindingFaultInfo bfi : bindingOpInfo.getFaults()) {
FaultInfo fi = bfi.getFaultInfo();
if (fi.size() == 0) {
continue;
}
if (t != null && matchFault(t, fi)) {
if (fi.getExtensionAttributes() == null) {
continue;
}
String attr = (String) fi.getExtensionAttributes().get(Names.WSAW_ACTION_QNAME);
if (attr == null) {
attr = (String) fi.getExtensionAttributes().get(new QName(Names.WSA_NAMESPACE_WSDL_NAME_OLD, Names.WSAW_ACTION_NAME));
}
if (attr != null) {
action = attr;
break;
}
}
}
}
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("action determined from service model: " + action);
}
return action;
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class ContextUtilsTest method testGetActionFromMessage.
@Test
public void testGetActionFromMessage() {
Message msg = control.createMock(Message.class);
Exchange exchange = control.createMock(Exchange.class);
QName mqname = new QName("http://foo.com", "bar");
QName fqname = new QName("urn:foo:test:4", "fault");
OperationInfo operationInfo = new OperationInfo();
MessageInfo messageInfo = new MessageInfo(operationInfo, Type.OUTPUT, mqname);
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo"), null));
operationInfo.setOutput("outputName", messageInfo);
FaultInfo faultInfo = new FaultInfo(fqname, mqname, operationInfo);
operationInfo.addFault(faultInfo);
BindingOperationInfo boi = new BindingOperationInfo(null, operationInfo);
// test 1 : retrieving the normal action prop from the message
EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
EasyMock.expect(msg.get(ContextUtils.ACTION)).andReturn("urn:foo:test:1");
control.replay();
AttributedURIType action = InternalContextUtils.getAction(msg);
assertNotNull(action);
assertEquals("urn:foo:test:1", action.getValue());
control.reset();
// test 2 : retrieving the normal soap action prop from the message
EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
EasyMock.expect(msg.get(SoapBindingConstants.SOAP_ACTION)).andReturn("urn:foo:test:2");
control.replay();
action = InternalContextUtils.getAction(msg);
assertNotNull(action);
assertEquals("urn:foo:test:2", action.getValue());
control.reset();
// test 3 : retrieving the action prop from the message info
EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
messageInfo.setProperty(ContextUtils.ACTION, "urn:foo:test:3");
control.replay();
action = InternalContextUtils.getAction(msg);
assertNotNull(action);
assertEquals("urn:foo:test:3", action.getValue());
control.reset();
// test 4 : retrieving the action for a fault without message part
SoapFault fault = new SoapFault("faulty service", new RuntimeException(), fqname);
EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes();
EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
control.replay();
action = InternalContextUtils.getAction(msg);
assertNull(action);
control.reset();
// test 5 : retrieving the action for a fault with matching message part
faultInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "faultInfo"), null));
faultInfo.getMessagePart(0).setTypeClass(RuntimeException.class);
faultInfo.addExtensionAttribute(Names.WSAW_ACTION_QNAME, "urn:foo:test:4");
EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes();
EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
control.replay();
action = InternalContextUtils.getAction(msg);
assertNotNull(action);
assertEquals("urn:foo:test:4", action.getValue());
control.reset();
// test 6 : retrieving the action for a ws-addr fault with matching message part
fault = new SoapFault("Action Mismatch", new QName(Names.WSA_NAMESPACE_NAME, Names.ACTION_MISMATCH_NAME));
EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes();
EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
control.replay();
action = InternalContextUtils.getAction(msg);
assertNotNull(action);
assertEquals(Names.WSA_DEFAULT_FAULT_ACTION, action.getValue());
control.reset();
// test 7 : retrieve the action for a fault matching the fault class with the WebFault annotation
fault = new SoapFault("faulty service", new TestFault(), Fault.FAULT_CODE_SERVER);
faultInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com:7", "faultInfo"), null));
faultInfo.getMessagePart(0).setTypeClass(Object.class);
faultInfo.getMessagePart(0).setConcreteName(new QName("urn:foo:test:7", "testFault"));
faultInfo.addExtensionAttribute(Names.WSAW_ACTION_QNAME, "urn:foo:test:7");
EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes();
EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
control.replay();
action = InternalContextUtils.getAction(msg);
assertNotNull(action);
assertEquals("urn:foo:test:7", action.getValue());
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class JavaToProcessorTest method testTransientMessage.
@Test
public void testTransientMessage() throws Exception {
// CXF-5744
env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/transient_message.wsdl");
env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.Echo4");
env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
try {
processor.setEnvironment(env);
processor.process();
} catch (Exception e) {
e.printStackTrace();
}
File wsdlFile = new File(output, "transient_message.wsdl");
assertTrue(wsdlFile.exists());
Document doc = StaxUtils.read(wsdlFile);
// StaxUtils.print(doc);
Map<String, String> map = new HashMap<>();
map.put("xsd", "http://www.w3.org/2001/XMLSchema");
map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
map.put("tns", "http://cxf.apache.org/test/HelloService");
XPathUtils util = new XPathUtils(map);
String path = "//xsd:complexType[@name='TransientMessageException']//xsd:sequence/xsd:element[@name='message']";
Element nd = (Element) util.getValueNode(path, doc);
assertNull(nd);
// ok, we didn't map it into the schema. Make sure the runtime won't write it out.
List<ServiceInfo> sl = CastUtils.cast((List<?>) env.get("serviceList"));
FaultInfo mi = sl.get(0).getInterface().getOperation(new QName("http://cxf.apache.org/test/HelloService", "echo")).getFault(new QName("http://cxf.apache.org/test/HelloService", "TransientMessageException"));
MessagePartInfo mpi = mi.getMessagePart(0);
JAXBContext ctx = JAXBContext.newInstance(String.class, Integer.TYPE);
StringWriter sw = new StringWriter();
XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(sw);
TransientMessageException tme = new TransientMessageException(12, "Exception Message");
Marshaller ms = ctx.createMarshaller();
ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
JAXBEncoderDecoder.marshallException(ms, tme, mpi, writer);
writer.flush();
writer.close();
assertEquals(-1, sw.getBuffer().indexOf("Exception Message"));
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class ServiceWSDLBuilder method buildPortTypeOperation.
protected void buildPortTypeOperation(PortType portType, Collection<OperationInfo> operationInfos, final Definition def) {
for (OperationInfo operationInfo : operationInfos) {
Operation operation = null;
try {
operation = operationInfo.getProperty(WSDLServiceBuilder.WSDL_OPERATION, Operation.class);
} catch (ClassCastException e) {
// do nothing
}
if (operation == null) {
operation = def.createOperation();
addDocumentation(operation, operationInfo.getDocumentation());
operation.setUndefined(false);
operation.setName(operationInfo.getName().getLocalPart());
addNamespace(operationInfo.getName().getNamespaceURI(), def);
if (operationInfo.isOneWay()) {
operation.setStyle(OperationType.ONE_WAY);
}
addExtensibilityElements(def, operation, getWSDL11Extensors(operationInfo));
Input input = def.createInput();
addDocumentation(input, operationInfo.getInput().getDocumentation());
input.setName(operationInfo.getInputName());
Message message = def.createMessage();
buildMessage(message, operationInfo.getInput(), def);
this.addExtensibilityAttributes(def, input, getInputExtensionAttributes(operationInfo));
this.addExtensibilityElements(def, input, getWSDL11Extensors(operationInfo.getInput()));
input.setMessage(message);
operation.setInput(input);
operation.setParameterOrdering(operationInfo.getParameterOrdering());
if (operationInfo.getOutput() != null) {
Output output = def.createOutput();
addDocumentation(output, operationInfo.getOutput().getDocumentation());
output.setName(operationInfo.getOutputName());
message = def.createMessage();
buildMessage(message, operationInfo.getOutput(), def);
this.addExtensibilityAttributes(def, output, getOutputExtensionAttributes(operationInfo));
this.addExtensibilityElements(def, output, getWSDL11Extensors(operationInfo.getOutput()));
output.setMessage(message);
operation.setOutput(output);
}
// loop to add fault
Collection<FaultInfo> faults = operationInfo.getFaults();
Fault fault = null;
for (FaultInfo faultInfo : faults) {
fault = def.createFault();
addDocumentation(fault, faultInfo.getDocumentation());
fault.setName(faultInfo.getFaultName().getLocalPart());
message = def.createMessage();
buildMessage(message, faultInfo, def);
this.addExtensibilityAttributes(def, fault, faultInfo.getExtensionAttributes());
this.addExtensibilityElements(def, fault, getWSDL11Extensors(faultInfo));
fault.setMessage(message);
operation.addFault(fault);
}
}
portType.addOperation(operation);
}
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class WSDLServiceBuilder method buildInterfaceOperation.
private void buildInterfaceOperation(InterfaceInfo inf, Operation op) {
OperationInfo opInfo = inf.addOperation(new QName(inf.getName().getNamespaceURI(), op.getName()));
if (recordOriginal) {
opInfo.setProperty(WSDL_OPERATION, op);
}
copyDocumentation(opInfo, op);
List<String> porderList = CastUtils.cast((List<?>) op.getParameterOrdering());
opInfo.setParameterOrdering(porderList);
this.copyExtensors(opInfo, op.getExtensibilityElements());
this.copyExtensionAttributes(opInfo, op);
Input input = op.getInput();
if (input != null) {
if (input.getMessage() == null) {
throw new WSDLRuntimeException(LOG, "NO_MESSAGE", "input", op.getName(), input.getName());
}
MessageInfo minfo = opInfo.createMessage(input.getMessage().getQName(), MessageInfo.Type.INPUT);
opInfo.setInput(input.getName(), minfo);
buildMessage(minfo, input.getMessage());
copyExtensors(minfo, input.getExtensibilityElements());
copyExtensionAttributes(minfo, input);
}
Output output = op.getOutput();
if (output != null) {
if (output.getMessage() == null) {
throw new WSDLRuntimeException(LOG, "NO_MESSAGE", "output", op.getName(), output.getName());
}
MessageInfo minfo = opInfo.createMessage(output.getMessage().getQName(), MessageInfo.Type.OUTPUT);
opInfo.setOutput(output.getName(), minfo);
buildMessage(minfo, output.getMessage());
copyExtensors(minfo, output.getExtensibilityElements());
copyExtensionAttributes(minfo, output);
}
Map<?, ?> m = op.getFaults();
for (Map.Entry<?, ?> rawentry : m.entrySet()) {
Map.Entry<String, Fault> entry = cast(rawentry, String.class, Fault.class);
FaultInfo finfo = opInfo.addFault(new QName(inf.getName().getNamespaceURI(), entry.getKey()), entry.getValue().getMessage().getQName());
copyDocumentation(finfo, entry.getValue());
buildMessage(finfo, entry.getValue().getMessage());
copyExtensors(finfo, entry.getValue().getExtensibilityElements());
copyExtensionAttributes(finfo, entry.getValue());
}
checkForWrapped(opInfo, allowRefs, false, unwrapLogLevel);
}
Aggregations