本文整理汇总了Java中org.restlet.data.MediaType类的典型用法代码示例。如果您正苦于以下问题:Java MediaType类的具体用法?Java MediaType怎么用?Java MediaType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaType类属于org.restlet.data包,在下文中一共展示了MediaType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTestForm
import org.restlet.data.MediaType; //导入依赖的package包/类
@Get
public FileRepresentation getTestForm() {
ExtensionTokenManager tokenManager = this.getTokenManager();
if (tokenManager.authenticationRequired()) {
getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
return null;
} else {
try {
File webDir = getWebDirectory();
File file = new File(webDir, TEST_FORM_HTML);
FileRepresentation htmlForm = new FileRepresentation(file, MediaType.TEXT_HTML);
return htmlForm;
} catch (Exception ex) {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return null;
}
}
}
示例2: process
import org.restlet.data.MediaType; //导入依赖的package包/类
/**
* Counts the FileTrackingStatus instances
*/
@Override
public void process(CommandLine cmdLine, OutputStream out) throws Exception {
int clientPort = configuration.getInt(AgentProperties.MONITORING_PORT,
8040);
ClientResource clientResource = new ClientResource("http://localhost:"
+ clientPort + "/agent/shutdown");
PrintWriter writer = new PrintWriter(out);
try {
try {
clientResource.get(MediaType.APPLICATION_JSON).write(writer);
} finally {
clientResource.release();
}
} finally {
writer.close();
}
}
示例3: getFilesHttp
import org.restlet.data.MediaType; //导入依赖的package包/类
/**
* Helper method that will call the Rest server via localhost only at
* http://localhost:$monitor.port/files/count/$status
*
* @param status may be null or not
* @return
* @throws ResourceException
* @throws IOException
*/
private long getFilesHttp(FileTrackingStatus.STATUS status) throws ResourceException, IOException {
int clientPort = configuration.getInt(AgentProperties.MONITORING_PORT,
8040);
LOG.info("Connecting client to " + clientPort);
String querySuffix = (status == null ) ? "/files/count" : "/files/count/" + status.toString().toUpperCase();
ClientResource clientResource = new ClientResource("http://localhost:"
+ clientPort + querySuffix);
StringWriter writer = new StringWriter();
Long count = 0L;
try {
clientResource.get(MediaType.APPLICATION_JSON).write(writer);
count = Long.valueOf(writer.toString());
} finally {
clientResource.release();
}
return count;
}
示例4: getStatusObject
import org.restlet.data.MediaType; //导入依赖的package包/类
/**
* Helper method. The method will call the client with the status parameter
* provided and using json return a FileTrackingStatus as response
*
* @param client
* @param status
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
private Collection<FileTrackingStatus> getStatusObject(Client client,
String status, int from, int max) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ClientResource clientResource = new ClientResource("http://localhost:"
+ port + "/files/list/" + status);
if (from > -1) {
clientResource.setRanges(Arrays.asList(new Range(from, max)));
}
clientResource.get(MediaType.APPLICATION_JSON).write(out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ObjectMapper om = new ObjectMapper();
return (Collection<FileTrackingStatus>) om.readValue(in,
Collection.class);
}
示例5: process
import org.restlet.data.MediaType; //导入依赖的package包/类
/**
* Counts the FileTrackingStatus instances
*/
@Override
public void process(CommandLine cmdLine, OutputStream out) throws Exception {
int clientPort = configuration.getInt(
CollectorProperties.WRITER.COLLECTOR_MON_PORT.toString(),
(Integer) CollectorProperties.WRITER.COLLECTOR_MON_PORT
.getDefaultValue());
ClientResource clientResource = new ClientResource("http://localhost:"
+ clientPort + "/view/collector/shutdown");
PrintWriter writer = new PrintWriter(out);
try {
try {
clientResource.get(MediaType.APPLICATION_JSON).write(writer);
} finally {
clientResource.release();
}
} finally {
writer.close();
}
}
示例6: process
import org.restlet.data.MediaType; //导入依赖的package包/类
/**
* Counts the FileTrackingStatus instances
*/
@Override
public void process(CommandLine cmdLine, OutputStream out) throws Exception {
int clientPort = configuration.getInt(
CoordinationProperties.PROP.COORDINATION_PORT.toString(),
(Integer) CoordinationProperties.PROP.COORDINATION_PORT
.getDefaultValue());
ClientResource clientResource = new ClientResource("http://localhost:"
+ clientPort + "/coordination/shutdown");
PrintWriter writer = new PrintWriter(out);
try {
try {
clientResource.get(MediaType.APPLICATION_JSON).write(writer);
} finally {
clientResource.release();
}
} finally {
writer.close();
}
}
示例7: getFilesHttp
import org.restlet.data.MediaType; //导入依赖的package包/类
/**
* Helper method that will call the Rest server via localhost only at
*
* @param querySuffix
* @return
* @throws ResourceException
* @throws IOException
*/
private long getFilesHttp(String querySuffix) throws ResourceException,
IOException {
int clientPort = configuration.getInt(
CoordinationProperties.PROP.COORDINATION_PORT.toString(),
(Integer) CoordinationProperties.PROP.COORDINATION_PORT
.getDefaultValue());
LOG.info("Connecting client to " + clientPort);
ClientResource clientResource = new ClientResource("http://localhost:"
+ clientPort + querySuffix);
StringWriter writer = new StringWriter();
try {
clientResource.get(MediaType.APPLICATION_JSON).write(writer);
} finally {
clientResource.release();
}
return Long.valueOf(writer.toString());
}
示例8: handlePost
import org.restlet.data.MediaType; //导入依赖的package包/类
@Post("json")
public Representation handlePost(Representation entity) {
String path = getReference().getPath();
String dbname = getDatabaseName(path);
if (!dbNameExists(dbname)) {
return databaseNotFound();
}
else if (path.endsWith("/_revs_diff")) {
return handleRevsDiff(dbname);
}
else if (path.endsWith("/_ensure_full_commit")) {
return handleEnsureFullCommitPost(dbname);
}
else if (path.endsWith("/_bulk_docs")) {
return handleBulkDocsPost(dbname);
}
else {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("{\"message\": \"Server error for request: " + getMethod() + " " + path + "\"}", MediaType.TEXT_PLAIN);
}
}
示例9: handlePut
import org.restlet.data.MediaType; //导入依赖的package包/类
@Put("json")
public Representation handlePut(Representation entity) {
String path = getReference().getPath();
String dbname = getDatabaseName(path);
String pathWithFirstAndLastSlashRemoved = path.replaceAll("^/", "").replaceAll("/$", "");
if (pathWithFirstAndLastSlashRemoved.equals(dbname)) {
// must be a PUT /target request
return handleCreateTargetPut(dbname);
}
else if (!dbNameExists(dbname)) {
return databaseNotFound();
}
else if (path.contains("/_local/")) {
return handleLocalPut(dbname);
} else {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation("{\"message\": \"Server error for request: " + getMethod() + " " + path + "\"}", MediaType.TEXT_PLAIN);
}
}
示例10: TopicManagementRestletResource
import org.restlet.data.MediaType; //导入依赖的package包/类
public TopicManagementRestletResource() {
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
getVariants().add(new Variant(MediaType.APPLICATION_JSON));
setNegotiated(false);
_helixMirrorMakerManager = (HelixMirrorMakerManager) getApplication().getContext()
.getAttributes().get(HelixMirrorMakerManager.class.toString());
_autoTopicWhitelistingManager = (AutoTopicWhitelistingManager) getApplication().getContext()
.getAttributes().get(AutoTopicWhitelistingManager.class.toString());
if (getApplication().getContext().getAttributes()
.containsKey(KafkaBrokerTopicObserver.class.toString())) {
_srcKafkaBrokerTopicObserver = (KafkaBrokerTopicObserver) getApplication().getContext()
.getAttributes().get(KafkaBrokerTopicObserver.class.toString());
} else {
_srcKafkaBrokerTopicObserver = null;
}
}
示例11: ValidationRestletResource
import org.restlet.data.MediaType; //导入依赖的package包/类
public ValidationRestletResource() {
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
getVariants().add(new Variant(MediaType.APPLICATION_JSON));
setNegotiated(false);
_validationManager = (ValidationManager) getApplication().getContext()
.getAttributes().get(ValidationManager.class.toString());
if (getApplication().getContext().getAttributes()
.containsKey(SourceKafkaClusterValidationManager.class.toString())) {
_srcKafkaValidationManager =
(SourceKafkaClusterValidationManager) getApplication().getContext()
.getAttributes().get(SourceKafkaClusterValidationManager.class.toString());
} else {
_srcKafkaValidationManager = null;
}
}
示例12: testBasicAuth
import org.restlet.data.MediaType; //导入依赖的package包/类
@Test
public void testBasicAuth() throws IOException {
// START SNIPPET: auth_request
final String id = "89531";
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(RestletConstants.RESTLET_LOGIN, "admin");
headers.put(RestletConstants.RESTLET_PASSWORD, "foo");
headers.put(Exchange.CONTENT_TYPE, MediaType.APPLICATION_XML);
headers.put("id", id);
String response = template.requestBodyAndHeaders(
"direct:start-auth", "<order foo='1'/>", headers, String.class);
// END SNIPPET: auth_request
assertEquals("received [<order foo='1'/>] as an order id = " + id, response);
}
示例13: getVariant
import org.restlet.data.MediaType; //导入依赖的package包/类
protected Variant getVariant( Request request,
List<Language> possibleLanguages,
List<MediaType> possibleMediaTypes
)
{
Language language = request.getClientInfo().getPreferredLanguage( possibleLanguages );
if( language == null )
{
language = possibleLanguages.get( 0 );
}
MediaType responseType = request.getClientInfo().getPreferredMediaType( possibleMediaTypes );
if( responseType == null && request.getClientInfo()
.getPreferredMediaType( Collections.singletonList( MediaType.ALL ) ) == MediaType.ALL )
{
responseType = possibleMediaTypes.get( 0 );
}
Variant variant = new Variant( responseType, language );
variant.setCharacterSet( CharacterSet.UTF_8 );
return variant;
}
示例14: createTextHtmlRepresentation
import org.restlet.data.MediaType; //导入依赖的package包/类
private Representation createTextHtmlRepresentation( final Object result, final Response response )
{
return new WriterRepresentation( MediaType.TEXT_HTML )
{
@Override
public void write( Writer writer )
throws IOException
{
Map<String, Object> context = new HashMap<>();
context.put( "request", response.getRequest() );
context.put( "response", response );
context.put( "result", result );
try
{
cfg.getTemplate( "links.htm" ).process( context, writer );
}
catch( TemplateException e )
{
throw new IOException( e );
}
}
};
}
示例15: createAtomRepresentation
import org.restlet.data.MediaType; //导入依赖的package包/类
private Representation createAtomRepresentation( final Object result, final Response response )
{
return new WriterRepresentation( MediaType.APPLICATION_ATOM )
{
@Override
public void write( Writer writer )
throws IOException
{
Map<String, Object> context = new HashMap<>();
context.put( "request", response.getRequest() );
context.put( "response", response );
context.put( "result", result );
try
{
cfg.getTemplate( "links.atom" ).process( context, writer );
}
catch( TemplateException e )
{
throw new IOException( e );
}
}
};
}