use of org.apache.cxf.service.model.MessageInfo in project cxf by apache.
the class RMEndpoint method buildTerminateSequenceOperationInfo.
void buildTerminateSequenceOperationInfo(InterfaceInfo ii, ProtocolVariation protocol) {
OperationInfo operationInfo = null;
MessagePartInfo partInfo = null;
MessageInfo messageInfo = null;
RMConstants consts = protocol.getConstants();
operationInfo = ii.addOperation(consts.getTerminateSequenceOperationName());
messageInfo = operationInfo.createMessage(consts.getTerminateSequenceOperationName(), MessageInfo.Type.INPUT);
operationInfo.setInput(messageInfo.getName().getLocalPart(), messageInfo);
partInfo = messageInfo.addMessagePart(TERMINATE_PART_NAME);
partInfo.setElementQName(consts.getTerminateSequenceOperationName());
partInfo.setElement(true);
partInfo.setTypeClass(protocol.getCodec().getTerminateSequenceType());
if (RM11Constants.NAMESPACE_URI.equals(protocol.getWSRMNamespace())) {
messageInfo = operationInfo.createMessage(RM11Constants.INSTANCE.getTerminateSequenceResponseOperationName(), MessageInfo.Type.OUTPUT);
operationInfo.setOutput(messageInfo.getName().getLocalPart(), messageInfo);
partInfo = messageInfo.addMessagePart(TERMINATE_RESPONSE_PART_NAME);
partInfo.setElementQName(RM11Constants.INSTANCE.getTerminateSequenceResponseOperationName());
partInfo.setElement(true);
partInfo.setTypeClass(protocol.getCodec().getTerminateSequenceResponseType());
partInfo.setIndex(0);
}
// for the TerminateSequence operation to an anonymous endpoint
operationInfo = ii.addOperation(consts.getTerminateSequenceAnonymousOperationName());
messageInfo = operationInfo.createMessage(consts.getTerminateSequenceAnonymousOperationName(), MessageInfo.Type.OUTPUT);
operationInfo.setOutput(messageInfo.getName().getLocalPart(), messageInfo);
partInfo = messageInfo.addMessagePart(TERMINATE_PART_NAME);
partInfo.setElementQName(consts.getTerminateSequenceOperationName());
partInfo.setElement(true);
partInfo.setTypeClass(protocol.getCodec().getTerminateSequenceType());
}
use of org.apache.cxf.service.model.MessageInfo 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.MessageInfo 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.MessageInfo in project steve by RWTH-i5-IDSG.
the class FromAddressInterceptor method getChargeBoxId.
private String getChargeBoxId(Message message) {
MessageContentsList lst = MessageContentsList.getContentsList(message);
if (lst == null) {
return null;
}
MessageInfo mi = (MessageInfo) message.get("org.apache.cxf.service.model.MessageInfo");
for (MessagePartInfo mpi : mi.getMessageParts()) {
if (CHARGEBOX_ID_HEADER.equals(mpi.getName().getLocalPart())) {
return (String) lst.get(mpi);
}
}
return null;
}
Aggregations