use of com.sun.xml.ws.addressing.model.MissingAddressingHeaderException in project metro-jax-ws by eclipse-ee4j.
the class Messages method createAddressingFaultMessage.
/**
* Creates a fault {@link Message} that captures the code/subcode/subsubcode
* defined by WS-Addressing if one of the expected WS-Addressing headers is
* missing in the message
*
* @param binding WSBinding
* @param p
* {@link Packet} that was missing a WS-Addressing header.
* @param missingHeader The missing WS-Addressing Header
* @return
* A message representing SOAPFault that contains the WS-Addressing code/subcode/subsubcode.
*/
public static Message createAddressingFaultMessage(WSBinding binding, Packet p, QName missingHeader) {
AddressingVersion av = binding.getAddressingVersion();
if (av == null) {
// Addressing is not enabled.
throw new WebServiceException(AddressingMessages.ADDRESSING_SHOULD_BE_ENABLED());
}
WsaTubeHelper helper = av.getWsaHelper(null, null, binding);
return create(helper.newMapRequiredFault(new MissingAddressingHeaderException(missingHeader, p)));
}
use of com.sun.xml.ws.addressing.model.MissingAddressingHeaderException in project metro-jax-ws by eclipse-ee4j.
the class W3CWsaServerTube method checkMandatoryHeaders.
@Override
protected void checkMandatoryHeaders(Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo, boolean foundFaultTo, boolean foundMessageId, boolean foundRelatesTo) {
super.checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo, foundFaultTo, foundMessageId, foundRelatesTo);
// find Req/Response or Oneway using WSDLModel(if it is availabe)
WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
// Taking care of protocol messages as they do not have any corresponding operations
if (wbo != null) {
// if two-way and no wsa:MessageID is found
if (!wbo.getOperation().isOneWay() && !foundMessageId) {
throw new MissingAddressingHeaderException(addressingVersion.messageIDTag, packet);
}
}
}
use of com.sun.xml.ws.addressing.model.MissingAddressingHeaderException in project metro-jax-ws by eclipse-ee4j.
the class WsaTube method checkCardinality.
/**
* Checks the cardinality of WS-Addressing headers on an inbound {@link Packet}. This method
* checks for the cardinality if WS-Addressing is engaged (detected by the presence of wsa:Action
* header) or wsdl:required=true.
*
* @param packet The inbound packet.
* @throws WebServiceException if:
* <ul>
* <li>there is an error reading ReplyTo or FaultTo</li>
* <li>WS-Addressing is required and {@link Message} within <code>packet</code> is null</li>
* <li>WS-Addressing is required and no headers are found in the {@link Message}</li>
* <li>an uknown WS-Addressing header is present</li>
* </ul>
*/
protected void checkCardinality(Packet packet) {
Message message = packet.getMessage();
if (message == null) {
if (addressingRequired)
throw new WebServiceException(AddressingMessages.NULL_MESSAGE());
else
return;
}
Iterator<Header> hIter = message.getHeaders().getHeaders(addressingVersion.nsUri, true);
if (!hIter.hasNext()) {
// no WS-A headers are found
if (addressingRequired)
// if WS-A is required, then throw an exception looking for wsa:Action header
throw new MissingAddressingHeaderException(addressingVersion.actionTag, packet);
else
// else no need to process
return;
}
boolean foundFrom = false;
boolean foundTo = false;
boolean foundReplyTo = false;
boolean foundFaultTo = false;
boolean foundAction = false;
boolean foundMessageId = false;
boolean foundRelatesTo = false;
QName duplicateHeader = null;
while (hIter.hasNext()) {
Header h = hIter.next();
// check if the Header is in current role
if (!isInCurrentRole(h, binding)) {
continue;
}
String local = h.getLocalPart();
if (local.equals(addressingVersion.fromTag.getLocalPart())) {
if (foundFrom) {
duplicateHeader = addressingVersion.fromTag;
break;
}
foundFrom = true;
} else if (local.equals(addressingVersion.toTag.getLocalPart())) {
if (foundTo) {
duplicateHeader = addressingVersion.toTag;
break;
}
foundTo = true;
} else if (local.equals(addressingVersion.replyToTag.getLocalPart())) {
if (foundReplyTo) {
duplicateHeader = addressingVersion.replyToTag;
break;
}
foundReplyTo = true;
try {
// verify that the header is in a good shape
h.readAsEPR(addressingVersion);
} catch (XMLStreamException e) {
throw new WebServiceException(AddressingMessages.REPLY_TO_CANNOT_PARSE(), e);
}
} else if (local.equals(addressingVersion.faultToTag.getLocalPart())) {
if (foundFaultTo) {
duplicateHeader = addressingVersion.faultToTag;
break;
}
foundFaultTo = true;
try {
// verify that the header is in a good shape
h.readAsEPR(addressingVersion);
} catch (XMLStreamException e) {
throw new WebServiceException(AddressingMessages.FAULT_TO_CANNOT_PARSE(), e);
}
} else if (local.equals(addressingVersion.actionTag.getLocalPart())) {
if (foundAction) {
duplicateHeader = addressingVersion.actionTag;
break;
}
foundAction = true;
} else if (local.equals(addressingVersion.messageIDTag.getLocalPart())) {
if (foundMessageId) {
duplicateHeader = addressingVersion.messageIDTag;
break;
}
foundMessageId = true;
} else if (local.equals(addressingVersion.relatesToTag.getLocalPart())) {
foundRelatesTo = true;
} else if (local.equals(addressingVersion.faultDetailTag.getLocalPart())) {
// TODO: should anything be done here ?
// TODO: fault detail element - only for SOAP 1.1
} else {
System.err.println(AddressingMessages.UNKNOWN_WSA_HEADER());
}
}
// check for invalid cardinality first before checking for mandatory headers
if (duplicateHeader != null) {
throw new InvalidAddressingHeaderException(duplicateHeader, addressingVersion.invalidCardinalityTag);
}
// WS-A is engaged if wsa:Action header is found
boolean engaged = foundAction;
// response messages (for oneway and request/response MEP only)
if (engaged || addressingRequired) {
// Check for mandatory headers always (even for Protocol messages).
// If it breaks any interop scenarios, Remove the comments.
/*
WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
// no need to check for for non-application messages
if (wbo == null)
return;
*/
checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo, foundFaultTo, foundMessageId, foundRelatesTo);
}
}
use of com.sun.xml.ws.addressing.model.MissingAddressingHeaderException in project metro-jax-ws by eclipse-ee4j.
the class WsaTube method validateInboundHeaders.
/**
* Validates the inbound message. If an error is found, create
* a fault message and returns that. Otherwise
* it will pass through the parameter 'packet' object to the return value.
*/
protected Packet validateInboundHeaders(Packet packet) {
SOAPFault soapFault;
FaultDetailHeader s11FaultDetailHeader;
try {
checkMessageAddressingProperties(packet);
return packet;
} catch (InvalidAddressingHeaderException e) {
LOGGER.log(Level.WARNING, addressingVersion.getInvalidMapText() + ", Problem header:" + e.getProblemHeader() + ", Reason: " + e.getSubsubcode(), e);
soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion);
s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader());
} catch (MissingAddressingHeaderException e) {
LOGGER.log(Level.WARNING, addressingVersion.getMapRequiredText() + ", Problem header:" + e.getMissingHeaderQName(), e);
soapFault = helper.newMapRequiredFault(e);
s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getMissingHeaderQName());
}
if (soapFault != null) {
// WS-A fault processing for one-way methods
if ((wsdlPort != null) && packet.getMessage().isOneWay(wsdlPort)) {
return packet.createServerResponse(null, wsdlPort, null, binding);
}
Message m = Messages.create(soapFault);
if (soapVersion == SOAPVersion.SOAP_11) {
m.getHeaders().add(s11FaultDetailHeader);
}
return packet.createServerResponse(m, wsdlPort, null, binding);
}
return packet;
}
Aggregations