use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class InputStreamDataSource method getXMLBytes.
@Override
public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
// Return the byte array directly if it is the same encoding
// Otherwise convert the bytes to the proper encoding
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
try {
serialize(baos, format);
} catch (XMLStreamException e) {
throw new OMException(e);
}
return baos.toByteArray();
}
use of org.apache.axiom.om.OMException in project webservices-axiom by apache.
the class FirstElementNameWithParserTestCase method runTest.
@Override
protected final void runTest() throws Throwable {
SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
SOAPBody body = builder.getSOAPEnvelope().getBody();
runTest(body);
if (supportsOptimization) {
// The expectation is that even after looking at the payload element name, registering
// a custom builder still transforms the element.
((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new CustomBuilder() {
@Override
public OMDataSource create(OMElement element) throws OMException {
try {
element.getXMLStreamReaderWithoutCaching().close();
} catch (XMLStreamException ex) {
throw new OMException(ex);
}
return new AbstractPushOMDataSource() {
@Override
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
xmlWriter.writeEmptyElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
}
@Override
public boolean isDestructiveWrite() {
return false;
}
};
}
});
assertThat(body.getFirstElement()).isInstanceOf(OMSourcedElement.class);
}
}
use of org.apache.axiom.om.OMException in project carbon-business-process by wso2.
the class HTCoordinationContextHandler method invoke.
@Override
public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
if (serverConfig == null || !serverConfig.isTaskRegistrationEnabled()) {
return InvocationResponse.CONTINUE;
}
SOAPHeader soapHeader;
try {
soapHeader = messageContext.getEnvelope().getHeader();
} catch (OMException ex) {
throw new AxisFault("Error while extracting SOAP header", ex);
}
if (soapHeader == null) {
if (log.isDebugEnabled()) {
log.debug("No SOAP Header received. Continuing as an uncoordinated HumanTask.");
}
return InvocationResponse.CONTINUE;
}
Iterator headers = soapHeader.getChildElements();
SOAPHeaderBlock coordinationHeaderBlock = null;
// Searching for WS-Coor Coordination Context
while (headers.hasNext()) {
SOAPHeaderBlock hb = (SOAPHeaderBlock) headers.next();
if (hb.getLocalName().equals(Constants.WS_COOR_COORDINATION_CONTEXT) && hb.getNamespace().getNamespaceURI().equals(Constants.WS_COOR_NAMESPACE)) {
coordinationHeaderBlock = hb;
break;
}
}
if (coordinationHeaderBlock == null) {
if (log.isDebugEnabled()) {
log.debug("No coordination context received. Processing as an uncoordinated HumanTask.");
}
return InvocationResponse.CONTINUE;
}
// We have received a ws-coordination context. Now validate it for HT coordination type
String coordinationType = SOAPUtils.getCoordinationType(coordinationHeaderBlock);
if (!Constants.WS_HT_COORDINATION_TYPE.equals(coordinationType)) {
// Found wrong coordination Type. We Only support http://docs.oasis-open.org/ns/bpel4people/ws-humantask/protocol/200803.
// So we cannot allow message to go forward.
String errorMsg = "Message aborted ! Invalid coordination type" + coordinationType + " . Support only " + Constants.WS_HT_COORDINATION_TYPE;
log.error(errorMsg);
return InvocationResponse.ABORT;
}
if (log.isDebugEnabled()) {
log.debug("HT coordination context received.");
}
String identifier = SOAPUtils.getCoordinationIdentifier(coordinationHeaderBlock);
String registrationService = SOAPUtils.getRegistrationService(coordinationHeaderBlock);
// validating values. These values cannot be empty
if (identifier == null || identifier.isEmpty() || registrationService == null || registrationService.isEmpty()) {
String errorMsg = "Message aborted ! Invalid coordination context parameters.";
log.error(errorMsg);
return InvocationResponse.ABORT;
}
// Service URL of the HumanTask Coordination Protocol Handler AdminService
String humanTaskProtocolHandlerServiceURL;
try {
humanTaskProtocolHandlerServiceURL = ServiceUtils.getTaskProtocolHandlerURL(messageContext.getConfigurationContext());
} catch (HumanTaskCoordinationException e) {
String errorMsg = "Error while generating HumanTask engine's protocol Handler Service URL.";
log.error(errorMsg);
throw new AxisFault(e.getLocalizedMessage(), e);
}
// We are OK to invokeRegistrationService Registration service
try {
OMElement response = invokeRegistrationServiceUsingServiceClient(identifier, humanTaskProtocolHandlerServiceURL, registrationService);
// But we are validating it for successful completion.
if (!SOAPUtils.validateResponse(response, identifier)) {
String errorMsg = "Message aborted ! registration response validation failed.";
log.error(errorMsg);
return InvocationResponse.ABORT;
}
// successful coordination
if (log.isDebugEnabled()) {
log.debug("RegistrationResponse received. Task is successfully coordinated with Task parent.");
}
} catch (AxisFault e) {
String errorMsg = "Error while invoking registration service";
log.error(errorMsg);
throw new AxisFault(e.getLocalizedMessage(), e);
}
return InvocationResponse.CONTINUE;
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIDescriptionGenUtil method getTimeDuration.
/**
* This method is used to get time duration of a tier
*
* @param policy tier policy
* @return time duration for requests
* @throws APIManagementException if error occurs when processing XML
*/
public static long getTimeDuration(OMElement policy) throws APIManagementException {
try {
OMElement duration = policy.getFirstChildWithName(APIConstants.POLICY_ELEMENT).getFirstChildWithName(APIConstants.THROTTLE_CONTROL_ELEMENT).getFirstChildWithName(APIConstants.POLICY_ELEMENT).getFirstChildWithName(APIConstants.THROTTLE_UNIT_TIME_ELEMENT);
if (duration.getText().isEmpty()) {
String message = APIConstants.THROTTLE_UNIT_TIME_ELEMENT.getLocalPart() + " element data not found empty in the policy.";
log.warn(message);
throw new APIManagementException(message);
}
// Reason - We need the ability to do fine grained throttling configurations.
return Long.parseLong(duration.getText().trim());
} catch (OMException e) {
String errorMessage = "Policy could not be parsed correctly based on " + "http://schemas.xmlsoap.org/ws/2004/09/policy specification";
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e);
} catch (NumberFormatException e) {
String message = "Error in retrieving time duration from the tiers xml";
log.error(message, e);
throw new APIManagementException(message, e);
}
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIDescriptionGenUtil method getAllowedRequestCount.
/**
* This method is used to get Allowed Requests count for a tier
*
* @param policy tier policy
* @return Allowed Requests Count
* @throws APIManagementException if error occurs when processing XML
*/
public static long getAllowedRequestCount(OMElement policy) throws APIManagementException {
try {
OMElement maxCount = policy.getFirstChildWithName(APIConstants.POLICY_ELEMENT).getFirstChildWithName(APIConstants.THROTTLE_CONTROL_ELEMENT).getFirstChildWithName(APIConstants.POLICY_ELEMENT).getFirstChildWithName(APIConstants.THROTTLE_MAXIMUM_COUNT_ELEMENT);
if (maxCount.getText().isEmpty()) {
String message = APIConstants.THROTTLE_MAXIMUM_COUNT_ELEMENT.getLocalPart() + " element data not found empty in the policy.";
log.warn(message);
throw new APIManagementException(message);
}
return Long.parseLong(maxCount.getText().trim());
} catch (OMException e) {
// We capture the runtime exception here.
String errorMessage = "Policy could not be parsed correctly based on " + "http://schemas.xmlsoap.org/ws/2004/09/policy specification";
log.error(errorMessage, e);
throw new APIManagementException(errorMessage + e.getMessage());
} catch (NumberFormatException e) {
log.error("Error in retrieving request count in tier xml.", e);
throw new APIManagementException("Error in retrieving request count in tier xml." + e.getMessage());
}
}
Aggregations