use of javax.ws.rs.WebApplicationException in project pulsar by yahoo.
the class PersistentTopics method getPartitionedTopicMetadata.
public PartitionedTopicMetadata getPartitionedTopicMetadata(String property, String cluster, String namespace, String destination, boolean authoritative) {
DestinationName dn = DestinationName.get(domain(), property, cluster, namespace, destination);
validateClusterOwnership(dn.getCluster());
try {
checkConnect(dn);
} catch (WebApplicationException e) {
validateAdminAccessOnProperty(dn.getProperty());
} catch (Exception e) {
// unknown error marked as internal server error
log.warn("Unexpected error while authorizing lookup. destination={}, role={}. Error: {}", destination, clientAppId(), e.getMessage(), e);
throw new RestException(e);
}
String path = path(PARTITIONED_TOPIC_PATH_ZNODE, property, cluster, namespace, domain(), dn.getEncodedLocalName());
PartitionedTopicMetadata partitionMetadata = fetchPartitionedTopicMetadata(pulsar(), path);
if (log.isDebugEnabled()) {
log.debug("[{}] Total number of partitions for topic {} is {}", clientAppId(), dn, partitionMetadata.partitions);
}
return partitionMetadata;
}
use of javax.ws.rs.WebApplicationException in project pulsar by yahoo.
the class Namespaces method clearNamespaceBacklog.
@POST
@Path("/{property}/{cluster}/{namespace}/clearBacklog")
@ApiOperation(value = "Clear backlog for all destinations on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public void clearNamespaceBacklog(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
validateAdminAccessOnProperty(property);
NamespaceName nsName = new NamespaceName(property, cluster, namespace);
try {
NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName);
Exception exception = null;
for (NamespaceBundle nsBundle : bundles.getBundles()) {
try {
// clear
if (pulsar().getNamespaceService().getOwner(nsBundle).isPresent()) {
// TODO: make this admin call asynchronous
pulsar().getAdminClient().namespaces().clearNamespaceBundleBacklog(nsName.toString(), nsBundle.getBundleRange());
}
} catch (Exception e) {
if (exception == null) {
exception = e;
}
}
}
if (exception != null) {
if (exception instanceof PulsarAdminException) {
throw new RestException((PulsarAdminException) exception);
} else {
throw new RestException(exception.getCause());
}
}
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception e) {
throw new RestException(e);
}
log.info("[{}] Successfully cleared backlog on all the bundles for namespace {}", clientAppId(), nsName.toString());
}
use of javax.ws.rs.WebApplicationException in project midpoint by Evolveum.
the class MidpointAbstractProvider method readFrom.
@Override
public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
if (entityStream == null) {
return null;
}
PrismParser parser = getParser(entityStream);
T object;
try {
LOGGER.info("type of request: {}", type);
if (PrismObject.class.isAssignableFrom(type)) {
object = (T) parser.parse();
} else {
// TODO consider prescribing type here (if no convertor is specified)
object = parser.parseRealValue();
}
if (object != null && !type.isAssignableFrom(object.getClass())) {
// TODO treat multivalues here
Optional<Annotation> convertorAnnotation = Arrays.stream(annotations).filter(a -> a instanceof Convertor).findFirst();
if (convertorAnnotation.isPresent()) {
Class<? extends ConvertorInterface> convertorClass = ((Convertor) convertorAnnotation.get()).value();
ConvertorInterface convertor;
try {
convertor = convertorClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new SystemException("Couldn't instantiate convertor class " + convertorClass, e);
}
object = (T) convertor.convert(object);
}
}
return object;
} catch (SchemaException ex) {
throw new WebApplicationException(ex);
}
}
use of javax.ws.rs.WebApplicationException in project ORCID-Source by ORCID.
the class OrcidMarshallerContextResolver method getContext.
@Override
public Marshaller getContext(Class<?> type) {
try {
context = JAXBContext.newInstance(type);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
return new OrcidMarshallerWrapper(marshaller);
} catch (JAXBException e) {
logger.error("Cannot create new marshaller", e);
throw new WebApplicationException(getResponse(e));
}
}
use of javax.ws.rs.WebApplicationException in project ORCID-Source by ORCID.
the class OrcidValidationJaxbContextResolver method getContext.
@Override
public Unmarshaller getContext(Class<?> type) {
try {
String apiVersion = getApiVersion();
String schemaFilenamePrefix = getSchemaFilenamePrefix(type, apiVersion);
Unmarshaller unmarshaller = getJAXBContext(apiVersion).createUnmarshaller();
// the controller
if (OrcidMessage.class.equals(type) || org.orcid.jaxb.model.record_rc3.WorkBulk.class.equals(type) || org.orcid.jaxb.model.record_rc4.WorkBulk.class.equals(type) || org.orcid.jaxb.model.record_v2.WorkBulk.class.equals(type)) {
return unmarshaller;
}
if (schemaFilenamePrefix != null) {
Schema schema = getSchema(schemaFilenamePrefix, apiVersion);
unmarshaller.setSchema(schema);
unmarshaller.setEventHandler(new OrcidValidationHandler());
}
return unmarshaller;
} catch (JAXBException e) {
throw new WebApplicationException(getResponse(e));
} catch (SAXException e) {
throw new WebApplicationException(getResponse(e));
}
}
Aggregations