本文整理汇总了Java中com.theoryinpractise.halbuilder.api.RepresentationFactory类的典型用法代码示例。如果您正苦于以下问题:Java RepresentationFactory类的具体用法?Java RepresentationFactory怎么用?Java RepresentationFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RepresentationFactory类属于com.theoryinpractise.halbuilder.api包,在下文中一共展示了RepresentationFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testUnmarshal
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
/**
* Test of unmarshal method, of class HalUnmarshaller.
*/
@Test
public void testUnmarshal() {
System.out.println("unmarshal");
Resource r1 = new Resource( 124L, new Name("John", "Doe"), Date.valueOf("1991-03-18"));
Resource r2 = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
HalMarshaller.marshal(r1, RepresentationFactory.HAL_JSON, baos);
String representation = baos.toString( "UTF-8");
InputStream is = new ByteArrayInputStream( representation.getBytes(StandardCharsets.UTF_8));
Object expResult = r1;
HalContext.registerPropertyBuilder( new NameBuilder());
r2 = (Resource) HalUnmarshaller.unmarshal(is, Resource.class);
} catch (Exception ex) {
Logger.getLogger(HalUnmarshallerTest.class.getName()).log(Level.SEVERE, null, ex);
}
assertEquals(r1, r2);
}
开发者ID:mcorcuera,项目名称:halbuilder-jaxrs,代码行数:26,代码来源:HalUnmarshallerTest.java
示例2: read
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@GET
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
public Response read(@Context final Request request) {
try {
final Booking booking = bookingService.findById(id);
final Response.ResponseBuilder responseBuilder = request.evaluatePreconditions(entityTag(booking));
if (responseBuilder == null) {
return Response.ok(bookingRepresentationAssembler.from(booking)).
tag(String.valueOf(booking.getVersion())).
build();
}
else {
return responseBuilder.build();
}
}
catch (final EntityNotFoundException e) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:21,代码来源:BookingResource.java
示例3: update
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
public Response update(
final BookingTransition transition,
@Context final Request request) {
try {
Booking booking = bookingService.findById(id);
final Response.ResponseBuilder responseBuilder = request.evaluatePreconditions(entityTag(booking));
if (responseBuilder == null) {
booking = bookingService.update(booking, transition);
return Response.ok(bookingRepresentationAssembler.from(booking)).
tag(entityTag(booking)).
build();
}
else {
return responseBuilder.build();
}
}
catch (final EntityNotFoundException e) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:25,代码来源:BookingResource.java
示例4: pay
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@POST
@Path("/payment")
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
@Consumes(MediaType.APPLICATION_JSON)
public Response pay(
final PayForBookingTransition transition,
@Context final Request request) {
try {
Booking booking = bookingService.findById(id);
final Response.ResponseBuilder responseBuilder = request.evaluatePreconditions(entityTag(booking));
if (responseBuilder == null) {
booking = bookingService.pay(booking, transition);
return Response.ok(bookingRepresentationAssembler.from(booking)).
tag(entityTag(booking)).
build();
}
else {
return responseBuilder.build();
}
}
catch (final EntityNotFoundException e) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:26,代码来源:BookingResource.java
示例5: payFullyAsync
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@POST
@Path("/payment-async-to-request")
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
@Consumes(MediaType.APPLICATION_JSON)
public Response payFullyAsync(
final PayForBookingTransition transition,
@Context final UriInfo uriInfo,
@Context final Request request) {
try {
final Booking booking = bookingService.findById(id);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
LOG.info("Payment done asynchronously in 20 seconds after initial request");
bookingService.pay(booking, transition);
}
}, 20000);
return Response.accepted().location(selfURI(booking, uriInfo)).build();
}
catch (final EntityNotFoundException e) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:24,代码来源:BookingResource.java
示例6: read
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
/**
* Read and return HalResource
* @param reader Reader
* @return Hal resource
*/
public HalResource read(final Reader reader)
{
final ContentRepresentation readableRepresentation = representationFactory.readRepresentation(RepresentationFactory.HAL_JSON, reader);
return new HalResource(objectMapper, readableRepresentation);
}
开发者ID:qmetric,项目名称:halreader,代码行数:12,代码来源:HalReader.java
示例7: demo
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
public void demo() {
RepresentationFactory representationFactory = new CustomRepresentationFactory();
Representation representation = representationFactory.newRepresentation().
withNamespace("take-a-rest", "http://localhost:8080/api/doc/rels/{rel}").
withProperty("paid", false).
withProperty("null", null).
withLink("take-a-rest:hotel", "http://localhost:8080/api/hotels/12345").
withLink("take-a-rest:get-hotel", "http://localhost:8080/api/hotels/12345").
withRepresentation("take-a-rest:booking",
representationFactory.newRepresentation().
withBean(new BookingRepresentationProducer().newSample()).
withLink("take-a-rest:hotel", "http://localhost:8080/api/hotels/12345")).
withBean(new BookingRepresentationProducer().newSample());
System.out.println(representation.toString(RepresentationFactory.HAL_JSON));
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:16,代码来源:UsingHalBuilder.java
示例8: browse
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@GET
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
public Response browse() {
return Response.
ok(bookingsRepresentationAssembler.from(bookingService.findAll())).
cacheControl(CacheControl.valueOf("max-age=" + Duration.ofMinutes(1).getSeconds())).
build();
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:9,代码来源:BookingsResource.java
示例9: create
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@POST
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
@Consumes("application/json")
public Response create(final CreateBookingAsPlaceTransition transition, @Context final UriInfo uriInfo) {
final Booking result;
try {
result = bookingService.create(transition);
} catch (EntityNotFoundException e) {
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
final URI bookingURI = BookingResource.selfURI(result, uriInfo);
return Response.created(bookingURI).build();
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:14,代码来源:BookingsResource.java
示例10: browse
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@GET
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
public Response browse(
@QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit) {
final Pagination pagination = Pagination.getPagination(offset, limit);
return Response.ok(
hotelsRepresentationAssembler.from(hotelService.findSeveral(pagination))).
build();
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:11,代码来源:HotelsResource.java
示例11: services
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@GET
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
public Response services() {
return Response.
ok(entryPointRepresentationAssembler.assemble()).
cacheControl(CacheControl.valueOf("max-age=" + Duration.ofDays(1).getSeconds())).
build();
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:9,代码来源:EntryPointResource.java
示例12: create
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@Path("/rooms/{roomId}/booking")
@POST
@Produces({ RepresentationFactory.HAL_JSON, Siren4J.JSON_MEDIATYPE })
@Consumes(MediaType.APPLICATION_JSON)
public Response create(final BookingTransition transition, @Context final UriInfo uriInfo,
@PathParam("roomId") final Long roomId) {
final Booking result;
try {
result = bookingService.create(roomId, transition);
} catch (EntityNotFoundException e) {
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
final URI bookingURI = BookingResource.selfURI(result, uriInfo);
return Response.created(bookingURI).entity(bookingRepresentationAssembler.from(result)).build();
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:16,代码来源:HotelResource.java
示例13: HalResponseEntityBuilderHandlerMethodArgumentResolver
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
/**
* Specify the {@link RepresentationFactory} but
* use the default value for the HTTP request
* variable name for specifying fields to include
* in a request
* @param representationFactory
*/
public HalResponseEntityBuilderHandlerMethodArgumentResolver(
RepresentationFactory representationFactory, RepresentationConverter converter) {
super();
this.representationFactory = representationFactory;
this.converter = converter;
this.fieldsParam = FIELDS_PARAM;
}
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:15,代码来源:HalResponseEntityBuilderHandlerMethodArgumentResolver.java
示例14: BaseHalRepresentationBuilder
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
public BaseHalRepresentationBuilder(RepresentationFactory representationFactory, RepresentationConverter converter, HttpServletRequest request, String fieldVariable) {
super(request);
// Set the RepresentationFactory
this.representationFactory = representationFactory;
// Set up the bean converter
this.converter = converter;
// Get requested fields from the request
this.requestedFields = request.getParameterValues(fieldVariable);
// Create representation
this.representation = representationFactory.newRepresentation(request.getRequestURI() + request.getQueryString());
}
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:16,代码来源:BaseHalRepresentationBuilder.java
示例15: HalPageResponseEntityBuilderHandlerMethodArgumentResolver
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
/**
* Specify the {@link RepresentationFactory} but
* use the default value for the HTTP request
* variable name for specifying fields to include
* in a request
* @param representationFactory
*/
public HalPageResponseEntityBuilderHandlerMethodArgumentResolver(
RepresentationFactory representationFactory, RepresentationConverter converter) {
super();
this.representationFactory = representationFactory;
this.converter = converter;
this.fieldsParam = FIELDS_PARAM;
}
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:15,代码来源:HalPageResponseEntityBuilderHandlerMethodArgumentResolver.java
示例16: HalSerializerImpl
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
public HalSerializerImpl(String halFormat) {
this.halFormat = halFormat;
representationFactory = new StandardRepresentationFactory().withFlag(RepresentationFactory.PRETTY_PRINT);
}
开发者ID:ModelSolv,项目名称:Kaboom,代码行数:5,代码来源:HalSerializerImpl.java
示例17: get
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@GET
@Produces({ RepresentationFactory.HAL_JSON, RepresentationFactory.HAL_XML })
public Response get(@Context Request request) {
return get(request, true);
}
开发者ID:spoonless,项目名称:rest-bookmarks,代码行数:6,代码来源:LatestBookmarkResource.java
示例18: writeTo
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@Override
public void writeTo(ReadableRepresentation representation, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {
representation.toString(mediaType.toString(), new OutputStreamWriter(outputStream, Charsets.UTF_8), RepresentationFactory.PRETTY_PRINT);
}
开发者ID:spoonless,项目名称:rest-bookmarks,代码行数:5,代码来源:HalBodyWriter.java
示例19: get
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@GET
@Produces({ RepresentationFactory.HAL_JSON, RepresentationFactory.HAL_XML })
public Response get(@Context Request request, @Context UriInfo uriInfo) {
return get(request, uriInfo, true);
}
开发者ID:spoonless,项目名称:rest-bookmarks,代码行数:6,代码来源:BookmarkResource.java
示例20: get
import com.theoryinpractise.halbuilder.api.RepresentationFactory; //导入依赖的package包/类
@GET
@Produces({ RepresentationFactory.HAL_JSON, RepresentationFactory.HAL_XML })
public Response get(@QueryParam("startIndex") @DefaultValue("0") int startIndex, @QueryParam("itemCount") @DefaultValue("10") int itemCount) {
return get(startIndex, itemCount, true);
}
开发者ID:spoonless,项目名称:rest-bookmarks,代码行数:6,代码来源:BookmarksResource.java
注:本文中的com.theoryinpractise.halbuilder.api.RepresentationFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论