use of com.google.gson.reflect.TypeToken in project incubator-pulsar by apache.
the class ProxyPublishConsumeTest method verifyProxyMetrics.
private void verifyProxyMetrics(Client client, String baseUrl) {
// generate metrics
service.getProxyStats().generate();
// collect metrics
String statUrl = baseUrl + "metrics";
WebTarget webTarget = client.target(statUrl);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
Response response = (Response) invocationBuilder.get();
String responseStr = response.readEntity(String.class);
final Gson gson = new Gson();
final List<Metrics> data = gson.fromJson(responseStr, new TypeToken<List<Metrics>>() {
}.getType());
Assert.assertFalse(data.isEmpty());
}
use of com.google.gson.reflect.TypeToken in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionRestService method retract.
@POST
@Path("/retract")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "retract", description = "Retract a media package element from this distribution channel", returnDescription = "The job that can be used to track the retraction", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementIds", isRequired = true, description = "The elements to retract as Json Array['IdOne','IdTwo']", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the retraction job"), @RestResponse(responseCode = SC_NO_CONTENT, description = "There is no streaming distribution service available") })
public Response retract(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementIds") String elementIds) throws Exception {
Job job = null;
try {
Set<String> setElementIds = gson.fromJson(elementIds, new TypeToken<Set<String>>() {
}.getType());
MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
job = service.retract(channelId, mediapackage, setElementIds);
if (job == null) {
return Response.noContent().build();
} else {
return Response.ok(new JaxbJob(job)).build();
}
} catch (IllegalArgumentException e) {
logger.debug("Unable to retract element: {}", e.getMessage());
return status(Status.BAD_REQUEST).build();
} catch (Exception e) {
logger.warn("Unable to retract mediapackage '{}' from streaming channel: {}", new Object[] { mediaPackageXml, e });
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of com.google.gson.reflect.TypeToken in project opencast by opencast.
the class AwsS3DistributionServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
String channelId = arguments.get(0);
MediaPackage mediaPackage = MediaPackageParser.getFromXml(arguments.get(1));
Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
}.getType());
switch(op) {
case Distribute:
Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
MediaPackageElement[] distributedElements = distributeElements(channelId, mediaPackage, elementIds, checkAvailability);
return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
case Retract:
MediaPackageElement[] retractedElements = retractElements(channelId, mediaPackage, elementIds);
return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
/*
* TODO
* Commented out due to changes in the way the element IDs are passed (ie, a list rather than individual ones
* per job). This code is still useful long term, but I don't have time to write the necessary wrapper code
* around it right now.
* case Restore:
* String fileName = arguments.get(3);
* MediaPackageElement restoredElement = null;
* if (StringUtils.isNotBlank(fileName)) {
* restoredElement = restoreElement(channelId, mediaPackage, elementIds, fileName);
* } else {
* restoredElement = restoreElement(channelId, mediaPackage, elementIds, null);
* }
* return (restoredElement != null) ? MediaPackageElementParser.getAsXml(restoredElement) : null;
*/
default:
throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
}
} catch (IllegalArgumentException e) {
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
} catch (IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (Exception e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
use of com.google.gson.reflect.TypeToken in project opencast by opencast.
the class DownloadDistributionServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
String channelId = arguments.get(0);
MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(1));
Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
}.getType());
switch(op) {
case Distribute:
Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
Boolean preserveReference = Boolean.parseBoolean(arguments.get(4));
MediaPackageElement[] distributedElements = distributeElements(channelId, mediapackage, elementIds, checkAvailability, preserveReference);
return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
case Retract:
MediaPackageElement[] retractedElements = retractElements(channelId, mediapackage, elementIds);
return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
default:
throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
}
} catch (IllegalArgumentException e) {
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
} catch (IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (Exception e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
use of com.google.gson.reflect.TypeToken in project opencast by opencast.
the class StreamingDistributionServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
String channelId = arguments.get(0);
MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(1));
Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
}.getType());
switch(op) {
case Distribute:
MediaPackageElement[] distributedElements = distributeElements(channelId, mediapackage, elementIds);
return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
case Retract:
MediaPackageElement[] retractedElements = retractElements(channelId, mediapackage, elementIds);
return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
default:
throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
}
} catch (IllegalArgumentException e) {
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
} catch (IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (Exception e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
Aggregations