use of org.apache.cxf.jaxrs.ext.MessageContext in project carbon-apimgt by wso2.
the class AlertSubscriptionsApiServiceImpl method getSubscribedAlertTypes.
/**
* Retrieves all the admin alert subscriptions of the logged in user
*
* @param messageContext
* @return
*/
public Response getSubscribedAlertTypes(MessageContext messageContext) {
String fullyQualifiedUsername = getFullyQualifiedUsername(RestApiCommonUtil.getLoggedInUsername());
try {
AdminAlertConfigurator adminAlertConfigurator = (AdminAlertConfigurator) AlertConfigManager.getInstance().getAlertConfigurator(AlertMgtConstants.ADMIN_DASHBOARD_AGENT);
List<Integer> subscribedAlertTypes = adminAlertConfigurator.getSubscribedAlerts(fullyQualifiedUsername);
List<org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO> supportedAlertTypeDTOS = adminAlertConfigurator.getSupportedAlertTypes();
// Filter out the subscribed alerts
List<org.wso2.carbon.apimgt.impl.dto.AlertTypeDTO> subscribedAlertsList = supportedAlertTypeDTOS.stream().filter(supportedAlertTypes -> subscribedAlertTypes.stream().anyMatch(subscribedAlerts -> supportedAlertTypes.getId().equals(subscribedAlerts))).collect(Collectors.toList());
// Retrieve the list of subscribed emails
List<String> subscribedEmails = adminAlertConfigurator.getSubscribedEmailAddresses(fullyQualifiedUsername);
AlertsSubscriptionDTO alertsSubscriptionDTO = new AlertsSubscriptionDTO();
alertsSubscriptionDTO.setAlerts(AlertsMappingUtil.fromAlertTypesListToAlertTypeDTOList(subscribedAlertsList));
alertsSubscriptionDTO.setEmailList(subscribedEmails);
return Response.status(Response.Status.OK).entity(alertsSubscriptionDTO).build();
} catch (AlertManagementException e) {
return Response.status(Response.Status.NO_CONTENT).entity("API Manager analytics is not enabled").build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Internal Error occurred", e, log);
}
return Response.status(Response.Status.NO_CONTENT).build();
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project cxf by apache.
the class JSONProvider method marshal.
protected void marshal(Marshaller ms, Object actualObject, Class<?> actualClass, Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception {
OutputStream actualOs = os;
MessageContext mc = getContext();
if (mc != null && PropertyUtils.isTrue(mc.get(Marshaller.JAXB_FORMATTED_OUTPUT))) {
actualOs = new CachedOutputStream();
}
XMLStreamWriter writer = createWriter(actualObject, actualClass, genericType, enc, actualOs, isCollection);
if (namespaceMap.size() > 1 || namespaceMap.size() == 1 && !namespaceMap.containsKey(JSONUtils.XSI_URI)) {
setNamespaceMapper(ms, namespaceMap);
}
org.apache.cxf.common.jaxb.JAXBUtils.setNoEscapeHandler(ms);
ms.marshal(actualObject, writer);
writer.close();
if (os != actualOs) {
StringIndenter formatter = new StringIndenter(IOUtils.newStringFromBytes(((CachedOutputStream) actualOs).getBytes()));
Writer outWriter = new OutputStreamWriter(os, enc);
IOUtils.copy(new StringReader(formatter.result()), outWriter, 2048);
outWriter.close();
}
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project cxf by apache.
the class SourceProvider method getPreferredSource.
protected String getPreferredSource() {
MessageContext mc = getContext();
String source = null;
if (mc != null) {
source = (String) mc.getContextualProperty(PREFERRED_FORMAT);
}
return source != null ? source : "sax";
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project cxf by apache.
the class JAXBElementProvider method marshal.
// CHECKSTYLE:OFF
protected final void marshal(Object obj, Class<?> cls, Type genericType, String enc, OutputStream os, Annotation[] anns, MediaType mt, Marshaller ms) throws Exception {
// CHECKSTYLE:ON
for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
ms.setProperty(entry.getKey(), entry.getValue());
}
MessageContext mc = getContext();
if (mc != null) {
// they'll overwrite statically configured ones
for (String key : MARSHALLER_PROPERTIES) {
Object value = mc.get(key);
if (value != null) {
ms.setProperty(key, value);
}
}
}
XMLStreamWriter writer = getStreamWriter(obj, os, mt);
if (writer != null) {
if (os == null) {
ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
} else if (mc != null) {
if (mc.getContent(XMLStreamWriter.class) != null) {
ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
}
mc.put(XMLStreamWriter.class.getName(), writer);
}
marshalToWriter(ms, obj, writer, anns, mt);
if (mc != null) {
writer.writeEndDocument();
}
} else {
marshalToOutputStream(ms, obj, os, anns, mt);
}
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project cxf by apache.
the class JAXBElementProvider method resolveXMLResourceURI.
protected String resolveXMLResourceURI(String path) {
MessageContext mc = getContext();
if (mc != null) {
String httpBasePath = (String) mc.get("http.base.path");
final UriBuilder builder;
if (httpBasePath != null) {
builder = UriBuilder.fromPath(httpBasePath);
} else {
builder = mc.getUriInfo().getBaseUriBuilder();
}
return builder.path(path).path(xmlResourceOffset).build().toString();
}
return path;
}
Aggregations