当前位置: 首页>>代码示例>>Java>>正文


Java ContentType类代码示例

本文整理汇总了Java中org.apache.olingo.commons.api.format.ContentType的典型用法代码示例。如果您正苦于以下问题:Java ContentType类的具体用法?Java ContentType怎么用?Java ContentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContentType类属于org.apache.olingo.commons.api.format包,在下文中一共展示了ContentType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readServiceDocument

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Override
public void readServiceDocument(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
		final ContentType requestedContentType) throws ODataApplicationException, ODataLibraryException {
	boolean isNotModified = false;
	ServiceMetadataETagSupport eTagSupport = serviceMetadata.getServiceMetadataETagSupport();
	if (eTagSupport != null && eTagSupport.getServiceDocumentETag() != null) {
		// Set application etag at response
		response.setHeader(HttpHeader.ETAG, eTagSupport.getServiceDocumentETag());
		// Check if service document has been modified
		ETagHelper eTagHelper = odata.createETagHelper();
		isNotModified = eTagHelper.checkReadPreconditions(eTagSupport.getServiceDocumentETag(),
				request.getHeaders(HttpHeader.IF_MATCH), request.getHeaders(HttpHeader.IF_NONE_MATCH));
	}

	// Send the correct response req.getRequestURL().toString().replace(req.getServletPath(), "")
	if (isNotModified) {
		response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
	} else {
		ODataSerializer serializer = odata.createSerializer(requestedContentType);
		//Provide serviceRoot with rawBaseUri as Excel PowerQuery does not like relative URIs
		response.setContent(serializer.serviceDocument(serviceMetadata, request.getRawBaseUri()).getContent());
		response.setStatusCode(HttpStatusCode.OK.getStatusCode());
		response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:26,代码来源:SparqlDefaultProcessor.java

示例2: readMetadata

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Override
public void readMetadata(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
		final ContentType requestedContentType) throws ODataApplicationException, ODataLibraryException {
	boolean isNotModified = false;
	ServiceMetadataETagSupport eTagSupport = serviceMetadata.getServiceMetadataETagSupport();
	if (eTagSupport != null && eTagSupport.getMetadataETag() != null) {
		// Set application etag at response
		response.setHeader(HttpHeader.ETAG, eTagSupport.getMetadataETag());
		// Check if metadata document has been modified
		ETagHelper eTagHelper = odata.createETagHelper();
		isNotModified = eTagHelper.checkReadPreconditions(eTagSupport.getMetadataETag(),
				request.getHeaders(HttpHeader.IF_MATCH), request.getHeaders(HttpHeader.IF_NONE_MATCH));
	}

	// Send the correct response
	if (isNotModified) {
		response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
	} else {
		ODataSerializer serializer = odata.createSerializer(requestedContentType);
		response.setContent(serializer.metadataDocument(serviceMetadata).getContent());
		response.setStatusCode(HttpStatusCode.OK.getStatusCode());
		response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:25,代码来源:SparqlDefaultProcessor.java

示例3: writePropertyValue

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
private void writePropertyValue(ODataResponse response, Property property) throws ODataApplicationException {
	if (property == null) {
		throw new ODataApplicationException("No property found", HttpStatusCode.NOT_FOUND.getStatusCode(),
				Locale.ENGLISH);
	} else {
		if (property.getValue() == null) {
			response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
		} else {
			String value = String.valueOf(property.getValue());
			ByteArrayInputStream serializerContent = new ByteArrayInputStream(value.getBytes());//Charset.forName("UTF-8")));
			response.setContent(serializerContent);
			response.setStatusCode(HttpStatusCode.OK.getStatusCode());
			response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.TEXT_PLAIN.toContentTypeString());
		}
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:17,代码来源:SparqlPrimitiveValueProcessor.java

示例4: createReference

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Override
public void createReference(ODataRequest request, ODataResponse response, UriInfo uriInfo,
		ContentType requestFormat) throws ODataApplicationException, ODataLibraryException {
	// 2. create the data in backend
	// 2.1. retrieve the payload from the POST request for the entity to create and deserialize it
	InputStream requestInputStream = request.getBody();
	ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat);
	DeserializerResult result = deserializer.entityReferences(requestInputStream);
	List<URI> requestEntityReferences = result.getEntityReferences();
	// 2.2 do the creation in backend, 

	try {
		SparqlBaseCommand.writeEntityReference(rdfEdmProvider, uriInfo, requestEntityReferences);
	} catch (EdmException | OData2SparqlException e) {
		throw new ODataApplicationException(e.getMessage(), HttpStatusCode.NO_CONTENT.getStatusCode(),
				Locale.ENGLISH);
	}
	// 3. serialize the response
	response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:21,代码来源:SparqlReferenceProcessor.java

示例5: updateReference

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Override
	public void updateReference(ODataRequest request, ODataResponse response, UriInfo uriInfo,
			ContentType requestFormat) throws ODataApplicationException, ODataLibraryException {
		// 1. Retrieve the entity type from the URI
//		EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
//		EdmEntityType edmEntityType = edmEntitySet.getEntityType();

		// 2. create the data in backend
		// 2.1. retrieve the payload from the POST request for the entity to create and deserialize it
		InputStream requestInputStream = request.getBody();
		ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat);
		DeserializerResult result = deserializer.entityReferences(requestInputStream);
		List<URI> requestEntityReferences = result.getEntityReferences();
		// 2.2 do the creation in backend, 

		try {
			SparqlBaseCommand.updateEntityReference(rdfEdmProvider, uriInfo, requestEntityReferences);
		} catch (EdmException | OData2SparqlException e) {
			throw new ODataApplicationException(e.getMessage(), HttpStatusCode.NO_CONTENT.getStatusCode(),
					Locale.ENGLISH);
		}
		// 3. serialize the response
		response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
	}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:25,代码来源:SparqlReferenceProcessor.java

示例6: createSerializer

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Override
public ODataSerializer createSerializer(ContentType contentType) throws SerializerException {
    ODataSerializer serializer = null;
    if (contentType.isCompatible(ContentType.APPLICATION_JSON)) {
        String metadata = contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA);
        if (metadata == null
                || ContentType.VALUE_ODATA_METADATA_MINIMAL.equalsIgnoreCase(metadata)
                || ContentType.VALUE_ODATA_METADATA_NONE.equalsIgnoreCase(metadata)
                || ContentType.VALUE_ODATA_METADATA_FULL.equalsIgnoreCase(metadata)) {
            serializer = new ElasticODataJsonSerializer(contentType);
        }
    } else if (contentType.isCompatible(ContentType.APPLICATION_XML)
            || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
        serializer = new ElasticODataXmlSerializer();
    }
    if (serializer == null) {
        throw new SerializerException(
                "Unsupported format: " + contentType.toContentTypeString(),
                SerializerException.MessageKeys.UNSUPPORTED_FORMAT,
                contentType.toContentTypeString());
    }
    return serializer;
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:24,代码来源:ElasticOData.java

示例7: read

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
/**
 * Method is a template to provide behavior for all read processors.
 */
@Override
public void read(ODataRequest request, ODataResponse response, UriInfo uriInfo,
        ContentType responseFormat) throws ODataApplicationException, ODataLibraryException {
    this.request = request;
    ESRequest searchRequest = createRequest(uriInfo);
    ElasticEdmEntitySet entitySet = searchRequest.getEntitySet();
    SearchResponse searchResponse = searchRequest.execute();
    InstanceData<T, V> data = parseResponse(searchResponse, entitySet);

    ODataSerializer serializer = odata.createSerializer(responseFormat);
    SerializerResult serializerResult = serialize(serializer, data, entitySet, uriInfo);
    response.setContent(serializerResult.getContent());
    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
    response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:19,代码来源:AbstractESReadProcessor.java

示例8: countEntitySet

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Override
public void countEntitySet(ODataRequest request, ODataResponse response,UriInfo uriInfo) {
    try {
        checkExpand(uriInfo.asUriInfoResource());
        ODataSQLBuilder visitor = new ODataSQLBuilder(this.client.getMetadataStore(), this.prepared);
        visitor.visit(uriInfo);
        Query query = visitor.selectQuery(true);
        List<SQLParam> parameters = visitor.getParameters();

        CountResponse countResponse = this.client.executeCount(query,parameters);
        ByteArrayInputStream bis = new ByteArrayInputStream(String.valueOf(countResponse.getCount()).getBytes());
        response.setContent(bis);
        response.setStatusCode(HttpStatusCode.OK.getStatusCode());
        response.setHeader(HttpHeader.CONTENT_TYPE,ContentType.TEXT_PLAIN.toContentTypeString());
    } catch (Exception e) {
        handleException(response, ContentType.APPLICATION_JSON, e);
    }
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:19,代码来源:TeiidProcessor.java

示例9: readParameters

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
private Map<String, Parameter> readParameters(final EdmAction action,
                                              final InputStream body,
                                              final ContentType requestFormat)
        throws ODataApplicationException,
               DeserializerException
{
    if (action.getParameterNames().size() - (action.isBound()
            ? 1
            : 0) > 0)
    {
        checkRequestFormat(requestFormat);

        return odata.createDeserializer(requestFormat).actionParameters(body,
                                                                        action).getActionParameters();
    }

    return Collections.<String, Parameter>emptyMap();
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:19,代码来源:RedHxDiscoveryProcessor.java

示例10: getEdmTest

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Test
public void getEdmTest() throws Exception {
  final ODataClient client = getODataClient();
  final String serviceUrl = getServiceUrl();
  final ODataServiceDocumentRequest reqeust =
      client.getRetrieveRequestFactory().getServiceDocumentRequest(serviceUrl);

  reqeust.setFormat(ContentType.APPLICATION_XML);

  final Edm redHelixEdm = readEdm(client, serviceUrl);

  Assert.assertEquals(1, redHelixEdm.getSchemas().size());

  for (EdmSchema schema : redHelixEdm.getSchemas()) {
    Assert.assertEquals(RED_HELIX_NAME_SPACE, schema.getNamespace());
  }
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:18,代码来源:EdmTest.java

示例11: dispatchPrimitivePropertyValue

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Test
public void dispatchPrimitivePropertyValue() throws Exception {
  final String uri = "ESAllPrim(0)/PropertyString/$value";
  final PrimitiveValueProcessor processor = mock(PrimitiveValueProcessor.class);

  dispatch(HttpMethod.GET, uri, processor);
  verify(processor).readPrimitiveValue(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
      any(ContentType.class));

  dispatch(HttpMethod.PUT, uri, null, HttpHeader.CONTENT_TYPE, ContentType.TEXT_PLAIN.toContentTypeString(),
      processor);
  verify(processor).updatePrimitiveValue(
      any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class),
      any(ContentType.class));

  dispatch(HttpMethod.DELETE, uri, processor);
  verify(processor).deletePrimitiveValue(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));

  dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
  dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
  dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:23,代码来源:ODataHandlerImplTest.java

示例12: updateEntity

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
                          ContentType requestFormat, ContentType responseFormat)
						throws ODataApplicationException, DeserializerException, SerializerException {
	
	// 1. Retrieve the entity set which belongs to the requested entity 
	List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
	// Note: only in our example we can assume that the first segment is the EntitySet
	UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); 
	EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
	EdmEntityType edmEntityType = edmEntitySet.getEntityType();

	// 2. update the data in backend
	// 2.1. retrieve the payload from the PUT request for the entity to be updated 
	InputStream requestInputStream = request.getBody();
	ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat);
	DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType);
	Entity requestEntity = result.getEntity();
	// 2.2 do the modification in backend
	List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates();
	// Note that this updateEntity()-method is invoked for both PUT or PATCH operations
	HttpMethod httpMethod = request.getMethod();
	storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod);
	
	//3. configure the response object
	response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:27,代码来源:DemoEntityProcessor.java

示例13: readEntity

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
public void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
    throws ODataApplicationException, SerializerException {

  // The sample service supports only functions imports and entity sets.
  // We do not care about bound functions and composable functions.

  UriResource uriResource = uriInfo.getUriResourceParts().get(0);

  if (uriResource instanceof UriResourceEntitySet) {
    readEntityInternal(request, response, uriInfo, responseFormat);
  } else if (uriResource instanceof UriResourceFunction) {
    readFunctionImportInternal(request, response, uriInfo, responseFormat);
  } else {
    throw new ODataApplicationException("Only EntitySet is supported",
        HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:18,代码来源:DemoEntityProcessor.java

示例14: nextAtomEntityFromEntitySet

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
private ResWrap<Entity> nextAtomEntityFromEntitySet(
        final InputStream input, final OutputStream osEntitySet, final String namespaces) {

  final ByteArrayOutputStream entity = new ByteArrayOutputStream();

  ResWrap<Entity> atomEntity = null;

  try {
    if (consume(input, "<entry>", osEntitySet, false) >= 0) {
      entity.write("<entry ".getBytes(Constants.UTF8));
      entity.write(namespaces.getBytes(Constants.UTF8));
      entity.write(">".getBytes(Constants.UTF8));

      if (consume(input, "</entry>", entity, true) >= 0) {
        atomEntity = odataClient.getDeserializer(ContentType.APPLICATION_ATOM_XML).
                toEntity(new ByteArrayInputStream(entity.toByteArray()));
      }
    }
  } catch (Exception e) {
    LOG.error("Error retrieving entities from EntitySet", e);
  }

  return atomEntity;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:25,代码来源:ClientEntitySetIterator.java

示例15: streamCountFalseJson

import org.apache.olingo.commons.api.format.ContentType; //导入依赖的package包/类
@Test
public void streamCountFalseJson() throws Exception {
  URL url = new URL(SERVICE_URI + "ESStreamServerSidePaging?$count=false&$format=json");

  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setRequestMethod(HttpMethod.GET.name());
  connection.connect();

  assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode());
  assertEquals(ContentType.JSON, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));

  final String content = IOUtils.toString(connection.getInputStream());

  assertTrue(content.contains("{\"PropertyInt16\":2,"+
  "\"[email protected]\":\"eTag\",\"[email protected]\":\"image/jpeg\"}"));
  assertTrue(content.contains("\"@odata.nextLink\""));
  assertTrue(content.contains("ESStreamServerSidePaging?$count=false&$format=json&%24skiptoken=1%2A10"));
  assertFalse(content.contains("\"@odata.count\":504"));
  }
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:20,代码来源:BasicStreamITCase.java


注:本文中的org.apache.olingo.commons.api.format.ContentType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。