本文整理汇总了Java中org.odata4j.format.FormatWriter.write方法的典型用法代码示例。如果您正苦于以下问题:Java FormatWriter.write方法的具体用法?Java FormatWriter.write怎么用?Java FormatWriter.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.odata4j.format.FormatWriter
的用法示例。
在下文中一共展示了FormatWriter.write方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderEntityResponse
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
/**
* レスポンスボディを作成する.
* @param uriInfo UriInfo
* @param resp レスポンス
* @param format レスポンスボディのフォーマット
* @param acceptableMediaTypes 許可するMediaTypeのリスト
* @return レスポンスボディ
*/
protected String renderEntityResponse(
final UriInfo uriInfo,
final EntityResponse resp,
final String format,
final List<MediaType> acceptableMediaTypes) {
StringWriter w = new StringWriter();
try {
FormatWriter<EntityResponse> fw = PersoniumFormatWriterFactory.getFormatWriter(EntityResponse.class,
acceptableMediaTypes, format, null);
// UriInfo uriInfo2 = PersoniumCoreUtils.createUriInfo(uriInfo, 1);
fw.write(uriInfo, w, resp);
} catch (UnsupportedOperationException e) {
throw PersoniumCoreException.OData.FORMAT_INVALID_ERROR.params(format);
}
String responseStr = w.toString();
return responseStr;
}
示例2: getRoot
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
/**
* サービスドキュメントを返す.
* @param uriInfo UriInfo
* @param format String
* @param httpHeaders HttpHeaders
* @return JAX-RS Response Object
*/
@GET
// @Path("")
public Response getRoot(
@Context final UriInfo uriInfo,
@QueryParam("$format") final String format,
@Context HttpHeaders httpHeaders) {
// アクセス制御
this.checkAccessContext(this.getAccessContext(), BoxPrivilege.READ);
StringWriter w = new StringWriter();
log.debug(format);
List<MediaType> acceptableMediaTypes = null; // Enumerable.create(MediaType.APPLICATION_XML_TYPE).toList();
FormatWriter<EdmDataServices> fw = FormatWriterFactory.getFormatWriter(EdmDataServices.class,
acceptableMediaTypes, format, "");
fw.write(PersoniumCoreUtils.createUriInfo(uriInfo, 0), w, this.metadata);
return Response.ok(w.toString(), fw.getContentType())
.header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
.build();
}
示例3: getServiceDocument
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
@GET
@Produces({ ODataConstants.APPLICATION_XML_CHARSET_UTF8, ODataConstants.TEXT_JAVASCRIPT_CHARSET_UTF8, ODataConstants.APPLICATION_JAVASCRIPT_CHARSET_UTF8 })
public Response getServiceDocument(
@Context HttpHeaders httpHeaders,
@Context UriInfo uriInfo,
@Context ContextResolver<ODataProducer> producerResolver,
@QueryParam("$format") String format,
@QueryParam("$callback") String callback) {
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
EdmDataServices metadata = producer.getMetadata();
StringWriter w = new StringWriter();
FormatWriter<EdmDataServices> fw = FormatWriterFactory.getFormatWriter(EdmDataServices.class, httpHeaders.getAcceptableMediaTypes(), format, callback);
fw.write(uriInfo, w, metadata);
return Response.ok(w.toString(), fw.getContentType())
.header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
.build();
}
示例4: toResponse
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
public Response toResponse(RuntimeException e) {
ODataProducerException exception;
if (e instanceof ODataProducerException)
exception = (ODataProducerException) e;
else
exception = new ServerErrorException(e);
ErrorResponseExtension errorResponseExtension = producerResolver.getContext(ODataProducer.class).findExtension(ErrorResponseExtension.class);
boolean includeInnerError = errorResponseExtension != null && errorResponseExtension.returnInnerError(httpHeaders, uriInfo, exception);
FormatWriter<ErrorResponse> fw = FormatWriterFactory.getFormatWriter(ErrorResponse.class, httpHeaders.getAcceptableMediaTypes(),
getFormatParameter(), getCallbackParameter());
StringWriter sw = new StringWriter();
fw.write(uriInfo, sw, getErrorResponse(exception, includeInnerError));
return Response.status(exception.getHttpStatus())
.type(fw.getContentType())
.header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
.entity(sw.toString())
.build();
}
示例5: buildPayload
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
private String buildPayload(String entitySet, final List<OProperty<?>> props, EdmDataServices edm) {
final EdmEntitySet ees = edm.getEdmEntitySet(entitySet);
Entry entry = new Entry() {
public String getUri() {
return null;
}
public OEntity getEntity() {
return OEntities.createRequest(ees, props, null);
}
};
StringWriter sw = new StringWriter();
FormatWriter<Entry> fw = FormatWriterFactory.getFormatWriter(Entry.class, null, "ATOM", null); //$NON-NLS-1$
fw.write(null, sw, entry);
return sw.toString();
}
示例6: createEntity
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
protected Response createEntity(
HttpHeaders httpHeaders,
UriInfo uriInfo,
SecurityContext securityContext,
ODataProducer producer,
String entitySetName,
OEntity entity,
ODataContext odataContext, List<MediaType> mediaTypeList) throws Exception {
EntityResponse response = producer.createEntity(odataContext, entitySetName, entity);
FormatWriter<EntityResponse> writer = null;
if (mediaTypeList != null) {
writer = FormatWriterFactory.getFormatWriter(EntityResponse.class, mediaTypeList, null, null);
}
else {
writer = FormatWriterFactory.getFormatWriter(EntityResponse.class, httpHeaders.getAcceptableMediaTypes(), null, null);
}
StringWriter sw = new StringWriter();
writer.write(uriInfo, sw, response);
String relid = InternalUtil.getEntityRelId(response.getEntity());
String entryId = uriInfo.getBaseUri().toString() + relid;
String responseEntity = sw.toString();
return Response
.ok(responseEntity, writer.getContentType())
.status(Status.CREATED)
.location(URI.create(entryId))
.header(ODataConstants.Headers.DATA_SERVICE_VERSION,
ODataConstants.DATA_SERVICE_VERSION_HEADER).build();
}
示例7: createResponseForBatch
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
/**
* Creates the response for batch.
*
* @param httpHeaders the http headers
* @param uriInfo the uri info
* @param producer the producer
* @param entitySetName the entity set name
* @param entity the entity
* @param mediaTypeList
* @return the response
* @throws Exception the exception
*/
protected Response createResponseForBatch(
HttpHeaders httpHeaders,
UriInfo uriInfo,
ODataProducer producer,
String entitySetName,
OEntity entity, List<MediaType> mediaTypeList) throws Exception {
EntityResponse response = producer.createResponseForBatchPostOperation(entitySetName, entity);
FormatWriter<EntityResponse> writer = null;
if (mediaTypeList != null) {
writer = FormatWriterFactory
.getFormatWriter(EntityResponse.class, mediaTypeList, null, null);
} else {
writer = FormatWriterFactory
.getFormatWriter(EntityResponse.class, httpHeaders.getAcceptableMediaTypes(), null, null);
}
StringWriter sw = new StringWriter();
writer.write(uriInfo, sw, response);
String relid = InternalUtil.getEntityRelId(response.getEntity());
String entryId = uriInfo.getBaseUri().toString() + relid;
String responseEntity = sw.toString();
return Response
.ok(responseEntity, writer.getContentType())
.status(Status.CREATED)
.location(URI.create(entryId))
.header(ODataConstants.Headers.DATA_SERVICE_VERSION,
ODataConstants.DATA_SERVICE_VERSION_HEADER).build();
}
示例8: getNavProperty
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
/**
* NavPropに対するGETメソッドによる検索処理.
* @param uriInfo UriInfo
* @param accept Acceptヘッダ
* @param callback ?? なんだこれは?JSONP?
* @param skipToken ?? なんだこれは?
* @param q 全文検索パラメタ
* @return JAX-RS Response
*/
@GET
@Produces({ODataConstants.APPLICATION_ATOM_XML_CHARSET_UTF8, ODataConstants.TEXT_JAVASCRIPT_CHARSET_UTF8,
ODataConstants.APPLICATION_JAVASCRIPT_CHARSET_UTF8 })
public final Response getNavProperty(
@Context final UriInfo uriInfo,
@HeaderParam(HttpHeaders.ACCEPT) final String accept,
@QueryParam("$callback") final String callback,
@QueryParam("$skiptoken") final String skipToken,
@QueryParam("q") final String q) {
// アクセス制御
this.checkReadAccessContext();
// queryのパース
UriInfo uriInfo2 = PersoniumCoreUtils.createUriInfo(uriInfo, 2);
QueryInfo queryInfo = ODataEntitiesResource.queryInfo(uriInfo);
// NavigationProperty経由の一覧取得を実行する
BaseResponse response = getOdataProducer().getNavProperty(
this.sourceEntityId.getEntitySetName(),
this.sourceEntityId.getEntityKey(),
this.targetNavProp,
queryInfo);
StringWriter sw = new StringWriter();
// TODO 制限事項でAcceptは無視してJSONで返却するため固定でJSONを指定する.
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON_TYPE);
// TODO 制限事項でQueryは無視するため固定でnullを指定する.
FormatWriter<EntitiesResponse> fw = PersoniumFormatWriterFactory.getFormatWriter(EntitiesResponse.class,
acceptableMediaTypes, null, callback);
fw.write(uriInfo2, sw, (EntitiesResponse) response);
String entity = sw.toString();
// 制御コードのエスケープ処理
entity = escapeResponsebody(entity);
ODataVersion version = ODataVersion.V2;
return Response.ok(entity, fw.getContentType())
.header(ODataConstants.Headers.DATA_SERVICE_VERSION, version.asString).build();
}
示例9: listEntities
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
/**
* @param uriInfo UriInfo
* @param accept Acceptヘッダ
* @param format $format パラメタ
* @param callback コールバック
* @param skipToken スキップトークン
* @param q 全文検索パラメタ
* @return JAX-RS Response
*/
@GET
public Response listEntities(
@Context UriInfo uriInfo,
@HeaderParam(HttpHeaders.ACCEPT) final String accept,
@QueryParam("$format") String format,
@QueryParam("$callback") final String callback,
@QueryParam("$skiptoken") final String skipToken,
@QueryParam("q") final String q) {
// アクセス制御
this.odataResource.checkAccessContext(this.accessContext,
this.odataResource.getNecessaryReadPrivilege(getEntitySetName()));
// リクエストの取得をProducerに依頼
EntitiesResponse resp = getEntities(uriInfo, q);
StringWriter sw = new StringWriter();
// $formatとAcceptヘッダの値から出力形式を決定
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
MediaType contentType = decideOutputFormat(accept, format);
acceptableMediaTypes.add(contentType);
FormatWriter<EntitiesResponse> fw = PersoniumFormatWriterFactory.getFormatWriter(EntitiesResponse.class,
acceptableMediaTypes, null, callback);
UriInfo uriInfo2 = PersoniumCoreUtils.createUriInfo(uriInfo, 1);
fw.write(uriInfo2, sw, resp);
String entity = null;
entity = sw.toString();
// 制御コードのエスケープ処理
entity = escapeResponsebody(entity);
// TODO remove this hack, check whether we are Version 2.0 compatible anyway
ODataVersion version = null;
version = ODataVersion.V2;
return Response.ok(entity, fw.getContentType())
.header(ODataConstants.Headers.DATA_SERVICE_VERSION, version.asString).build();
}
示例10: list
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
/**
* バッチリクエストの一覧取得処理.
* @param uriInfo uriInfo
* @param bodyPart BatchBodyPart
* @return レスポンス
*/
private BatchResponse list(UriInfo uriInfo, BatchBodyPart bodyPart) {
BatchResponse res = new BatchResponse();
EntitiesResponse entitiesResp = null;
try {
// アクセス制御
checkReadAccessContext(bodyPart);
// NavigationProperty経由の一覧取得は 501
if (bodyPart.hasNavigationProperty()) {
throw PersoniumCoreException.Misc.METHOD_NOT_IMPLEMENTED;
}
ODataEntitiesResource entitiesResource = new ODataEntitiesResource(this.odataResource,
bodyPart.getEntitySetName());
// Entityの一覧取得
String query = bodyPart.getRequestQuery();
QueryInfo queryInfo = QueryParser.createQueryInfo(query);
entitiesResp = entitiesResource.getEntities(queryInfo);
// レスポンス作成
res.setResponseCode(HttpStatus.SC_OK);
// TODO 現状は、ContentTypeはJSON固定
res.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
res.setHeader(ODataConstants.Headers.DATA_SERVICE_VERSION, "2.0");
// レスポンスボディ
UriInfo resUriInfo = PersoniumCoreUtils.createUriInfo(uriInfo, 1);
StringWriter sw = new StringWriter();
// TODO 制限事項でAcceptは無視してJSONで返却するため固定でJSONを指定する.
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON_TYPE);
// TODO 制限事項でQueryは無視するため固定でnullを指定する.
FormatWriter<EntitiesResponse> fw = PersoniumFormatWriterFactory.getFormatWriter(EntitiesResponse.class,
acceptableMediaTypes, null, null);
UriInfo uriInfo2 = PersoniumCoreUtils.createUriInfo(resUriInfo, 1);
fw.write(uriInfo2, sw, entitiesResp);
String entity = sw.toString();
res.setBody(entity);
} catch (Exception e) {
res.setErrorResponse(e);
}
return res;
}
示例11: mergeEntity
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
@POST
public Response mergeEntity(
@Context HttpHeaders httpHeaders,
@Context UriInfo uriInfo,
@Context ContextResolver<ODataProducer> producerResolver,
@Context SecurityContext securityContext,
@PathParam("entitySetName") String entitySetName,
@PathParam("id") String id,
@PathParam("navProp") String navProp,
String payload) throws Exception {
String method = httpHeaders.getRequestHeaders().getFirst(ODataConstants.Headers.X_HTTP_METHOD);
if (!"MERGE".equals(method)) {
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
// determine the expected entity set
EdmDataServices metadata = producer.getMetadata();
EdmEntitySet ees = metadata
.getEdmEntitySet(metadata.getEdmEntitySet(entitySetName).getType()
.findNavigationProperty(navProp).getToRole().getType());
// parse the request entity
OEntity entity = getRequestEntity(httpHeaders, uriInfo, payload, metadata, ees.getName(), OEntityKey.parse(id));
// execute the create
EntityResponse response = producer.createEntity(ODataContextImpl.builder().aspect(httpHeaders).aspect(securityContext).build(),
entitySetName, OEntityKey.parse(id), navProp, entity);
if (response == null) {
throw new NotFoundException();
}
// get the FormatWriter for the accepted media types requested by client
StringWriter sw = new StringWriter();
FormatWriter<EntityResponse> fw = FormatWriterFactory
.getFormatWriter(EntityResponse.class, httpHeaders.getAcceptableMediaTypes(), null, null);
fw.write(uriInfo, sw, response);
// calculate the uri for the location header
String relid = InternalUtil.getEntityRelId(response.getEntity());
String entryId = uriInfo.getBaseUri().toString() + relid;
// create the response
String responseEntity = sw.toString();
return Response
.ok(responseEntity, fw.getContentType())
.status(Status.CREATED)
.location(URI.create(entryId))
.header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
.build();
}
throw new NotImplementedException("Not supported yet.");
}
示例12: formatSingleRequest
import org.odata4j.format.FormatWriter; //导入方法依赖的package包/类
public static String formatSingleRequest(ODataClientRequest req, FormatType formatType) {
StringBuilder sb = new StringBuilder();
boolean userDefinedContentType = false;
sb.append(ODataConstants.Headers.CONTENT_TYPE).append(": ").append(ODataConstants.APPLICATION_HTTP).append("\r\n");
sb.append(ODataConstants.Headers.CONTENT_TRANSFER_ENCODING).append(": ").append(ODataConstants.BINARY).append("\r\n");
sb.append("\r\n");
String url = req.getUrl();
Map<String, String> queryParams = req.getQueryParams();
if (queryParams != null && queryParams.size() > 0) {
UriBuilder ub = UriBuilder.fromUri(req.getUrl());
for (String qpn : queryParams.keySet()) {
ub.queryParam(qpn, queryParams.get(qpn));
}
url = ub.build().toString();
}
// now, adding this request, 1st URL
sb.append(req.getMethod()).append(" ").append(url).append(" HTTP/1.1\r\n");
// adding header
for (String header : req.getHeaders().keySet()) {
if (header.equals(ODataConstants.Headers.CONTENT_TYPE)) {
userDefinedContentType = true;
}
String value = req.getHeaders().get(header);
sb.append(header).append(": ").append(value).append("\r\n");
}
// request body
if (req.getPayload() != null) {
Class<?> payloadClass;
if (req.getPayload() instanceof Entry)
payloadClass = Entry.class;
else if (req.getPayload() instanceof SingleLink)
payloadClass = SingleLink.class;
else
throw new IllegalArgumentException("Unsupported payload: " + req.getPayload());
StringWriter sw = new StringWriter();
@SuppressWarnings("unchecked")
FormatWriter<Object> fw = (FormatWriter<Object>)
FormatWriterFactory.getFormatWriter(payloadClass, null, formatType.toString(), null);
fw.write(null, sw, req.getPayload());
String entity = sw.toString();
// allow the client to override the default format writer content-type
if (!userDefinedContentType) {
sb.append(ODataConstants.Headers.CONTENT_TYPE).append(": ").append(fw.getContentType()).append("\r\n");
}
// set content-length
sb.append(ODataConstants.Headers.CONTENT_LENGTH).append(": ").append(entity.length() + 2).append("\r\n");
// now add the pay load for this operation
sb.append("\r\n\r\n");
sb.append(entity).append("\r\n");
}
return sb.toString();
}