Java Code Examples for javax.ws.rs.core.MediaType#APPLICATION_ATOM_XML

The following examples show how to use javax.ws.rs.core.MediaType#APPLICATION_ATOM_XML . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Services.java    From olingo-odata4 with Apache License 2.0 7 votes vote down vote up
@PATCH
@Path("/{entitySetName}({entityId})")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public Response patchEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
    @PathParam("entitySetName") final String entitySetName,
    @PathParam("entityId") final String entityId,
    final String changes) {

  final Response response =
      getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
          accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY);
  return response.getStatus() >= 400 ?
      postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes) :
      patchEntityInternal(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
}
 
Example 2
Source File: Demo.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@PATCH
@Path("/{entitySetName}({entityId})")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Override
public Response patchEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
    @PathParam("entitySetName") final String entitySetName,
    @PathParam("entityId") final String entityId,
    final String changes) {

  return replaceServiceName(super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId,
      changes));
}
 
Example 3
Source File: KeyAsSegment.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@PATCH
@Path("/{entitySetName}/{entityId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Override
public Response patchEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
    @PathParam("entitySetName") final String entitySetName,
    @PathParam("entityId") final String entityId,
    final String changes) {

  return replaceServiceName(super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId,
      changes));
}
 
Example 4
Source File: KeyAsSegment.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@PUT
@Path("/{entitySetName}/{entityId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public Response putNewEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @PathParam("entitySetName") final String entitySetName,
    @PathParam("entityId") final String entityId,
    final String entity) {

  return replaceServiceName(super
      .replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity));
}
 
Example 5
Source File: Services.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@PUT
@Path("/{entitySetName}({entityId})")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public Response replaceEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @PathParam("entitySetName") final String entitySetName,
    @PathParam("entityId") final String entityId,
    final String entity) {

  try {
    getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
        accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY);
    return replaceEntity(uriInfo, accept, prefer, entitySetName, entityId, entity);
  } catch (NotFoundException e) {
    return postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId);
  }
}
 
Example 6
Source File: Services.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@POST
@Path("/People")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
public Response postPeople(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    final String entity) {

  if ("{\"@odata.type\":\"#Microsoft.Test.OData.Services.ODataWCFService.Person\"}".equals(entity)) {
    return xml.createFaultResponse(accept, new BadRequestException());
  }

  return postNewEntity(uriInfo, accept, contentType, prefer, "People", entity);
}
 
Example 7
Source File: UpdateTest.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * Cellの更新のJSONフォーマットエラー.
 * @param accept アクセプトヘッダの値
 */
private void cellJsonFormatErr(String accept) {

    // Cellを更新
    // リクエストヘッダをセット
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
    headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);

    if (accept != null) {
        headers.put(HttpHeaders.ACCEPT, accept);
    } else {
        accept = MediaType.APPLICATION_ATOM_XML;
    }

    // リクエストボディを生成
    DcRestAdapter rest = new DcRestAdapter();

    String data = "\"test\"";

    try {
        // リクエスト
        res = rest.post(UrlUtils.unitCtl(Cell.EDM_TYPE_NAME), data, headers);
    } catch (Exception e) {
        fail(e.getMessage());
    }

    // Cell更新のレスポンスチェック
    // 400になることを確認
    assertEquals(HttpStatus.SC_BAD_REQUEST, res.getStatusCode());
    assertEquals(MediaType.APPLICATION_JSON, res.getResponseHeaders(HttpHeaders.CONTENT_TYPE)[0].getValue());
    this.checkErrorResponse(res.bodyAsJson(), "PR400-OD-0001");

}
 
Example 8
Source File: OpenType.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@POST
@Path("/{entitySetName}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
@Override
public Response postNewEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @PathParam("entitySetName") final String entitySetName,
    final String entity) {

  return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
}
 
Example 9
Source File: Demo.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@PUT
@Produces({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.WILDCARD, MediaType.APPLICATION_OCTET_STREAM })
@Path("/{entitySetName}({entityId})/$value")
@Override
public Response replaceMediaEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @PathParam("entitySetName") final String entitySetName,
    @PathParam("entityId") final String entityId,
    final String value) {

  return super.replaceMediaEntity(uriInfo, prefer, entitySetName, entityId, value);
}
 
Example 10
Source File: Demo.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@POST
@Path("/{entitySetName}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
@Override
public Response postNewEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @PathParam("entitySetName") final String entitySetName,
    final String entity) {

  return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
}
 
Example 11
Source File: Services.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@PUT
@Produces({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.WILDCARD, MediaType.APPLICATION_OCTET_STREAM })
@Path("/{entitySetName}({entityId})/$value")
public Response replaceMediaEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @PathParam("entitySetName") final String entitySetName,
    @PathParam("entityId") final String entityId,
    final String value) {
  try {

    final AbstractUtilities utils = getUtilities(null);

    final InputStream res = utils.putMediaInMemory(
        entitySetName, entityId, IOUtils.toInputStream(value, Constants.ENCODING));

    final String location = uriInfo.getRequestUri().toASCIIString().replace("/$value", "");

    final Response response;
    if ("return-content".equalsIgnoreCase(prefer)) {
      response = xml.createResponse(location, res, null, null, Response.Status.OK);
    } else {
      res.close();
      response = xml.createResponse(location, null, null, null, Response.Status.NO_CONTENT);
    }

    if (StringUtils.isNotBlank(prefer)) {
      response.getHeaders().put("Preference-Applied", Collections.<Object> singletonList(prefer));
    }

    return response;

  } catch (Exception e) {
    LOG.error("Error retrieving entity", e);
    return xml.createFaultResponse(Accept.JSON.toString(), e);
  }
}
 
Example 12
Source File: Services.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@PATCH
@Path("/Company")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public Response patchSingletonCompany(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
    final String changes) {

  return patchEntityInternal(uriInfo, accept, contentType, prefer, ifMatch, "Company", StringUtils.EMPTY, changes);
}
 
Example 13
Source File: KeyAsSegment.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@POST
@Path("/{entitySetName}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
@Override
public Response postNewEntity(
    @Context final UriInfo uriInfo,
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
    @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
    @PathParam("entitySetName") final String entitySetName,
    final String entity) {

  return replaceServiceName(super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
}
 
Example 14
Source File: UpdateTest.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * Cellの更新の認証ヘッダ無しのテスト.
 * @param accept アクセプトヘッダの値
 */
@SuppressWarnings("unchecked")
private void cellAuthHeaderNone(String accept) {

    // Cellを更新
    // リクエストヘッダをセット
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    headers.put(HttpHeaders.IF_MATCH, "*");

    if (accept != null) {
        headers.put(HttpHeaders.ACCEPT, accept);
    } else {
        accept = MediaType.APPLICATION_ATOM_XML;
    }

    // リクエストボディを生成
    JSONObject requestBody = new JSONObject();
    requestBody.put("Name", cellName);

    this.res = updateCell(headers, requestBody);

    // Cell更新のレスポンスチェック
    // 401になることを確認
    assertEquals(HttpStatus.SC_UNAUTHORIZED, res.getStatusCode());

    // ContentTypeのチェック
    Header[] resContentTypeHeaders = res.getResponseHeaders(HttpHeaders.CONTENT_TYPE);
    assertEquals(1, resContentTypeHeaders.length);
    assertEquals(resContentTypeHeaders[0].getValue(), MediaType.APPLICATION_JSON);

    // ボディのチェック
    checkErrorResponse(this.res.bodyAsJson(), "PR401-AU-0001");
}
 
Example 15
Source File: UpdateTest.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * Cellの更新のXMLフォーマットエラー.
 * @param accept アクセプトヘッダの値
 */
private void cellXmlFormatErr(String accept) {

    // Cellを更新
    // リクエストヘッダをセット
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
    headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_ATOM_XML);

    if (accept != null) {
        headers.put(HttpHeaders.ACCEPT, accept);
    } else {
        accept = MediaType.APPLICATION_ATOM_XML;
    }

    // リクエストボディを生成
    DcRestAdapter rest = new DcRestAdapter();

    String data = "\"test\"";

    try {
        // リクエスト
        res = rest.post(UrlUtils.unitCtl(Cell.EDM_TYPE_NAME), data, headers);
    } catch (Exception e) {
        fail(e.getMessage());
    }

    // Cell更新のレスポンスチェック
    // 400になることを確認
    assertEquals(HttpStatus.SC_BAD_REQUEST, res.getStatusCode());
    assertEquals(MediaType.APPLICATION_JSON, res.getResponseHeaders(HttpHeaders.CONTENT_TYPE)[0].getValue());
    this.checkErrorResponse(res.bodyAsJson(), "PR400-OD-0001");
}
 
Example 16
Source File: UpdateTest.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * Cellの更新のNameが無いパターンのテスト.
 * @param accept アクセプトヘッダの値
 */
private void cellNameNull(String accept) {

    // Cellを更新
    // リクエストヘッダをセット
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
    headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    headers.put(HttpHeaders.IF_MATCH, "*");

    if (accept != null) {
        headers.put(HttpHeaders.ACCEPT, accept);
    } else {
        accept = MediaType.APPLICATION_ATOM_XML;
    }

    // リクエストボディを生成
    JSONObject requestBody = new JSONObject();

    res = updateCell(headers, requestBody);

    assertEquals(HttpStatus.SC_BAD_REQUEST, res.getStatusCode());
    assertEquals(MediaType.APPLICATION_JSON, res.getResponseHeaders(HttpHeaders.CONTENT_TYPE)[0].getValue());

    // ボディのチェック
    checkErrorResponse(this.res.bodyAsJson(), "PR400-OD-0009");
}
 
Example 17
Source File: UpdateTest.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * Cellの更新のPOSTメソッドのテスト.
 * @param accept アクセプトヘッダの値
 */
@SuppressWarnings("unchecked")
private void cellPost(String accept) {

    // Cellを更新
    // リクエストヘッダをセット
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
    headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);

    if (accept != null) {
        headers.put(HttpHeaders.ACCEPT, accept);
    } else {
        accept = MediaType.APPLICATION_ATOM_XML;
    }

    DcRestAdapter rest = new DcRestAdapter();

    try {
        // リクエストボディを生成
        JSONObject requestBody = new JSONObject();
        requestBody.put("Name", cellName);

        // リクエスト
        res = rest.post(UrlUtils.unitCtl(Cell.EDM_TYPE_NAME, cellName), requestBody.toJSONString(), headers);

        // Cell更新のレスポンスチェック
        // 405になることを確認
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, res.getStatusCode());

        // ContentTypeのチェック
        Header[] resContentTypeHeaders = res.getResponseHeaders(HttpHeaders.CONTENT_TYPE);
        assertEquals(1, resContentTypeHeaders.length);
        // 制限にてJSON固定
        assertEquals(MediaType.APPLICATION_JSON, resContentTypeHeaders[0].getValue());

        // ボディのチェック
        checkErrorResponse(this.res.bodyAsJson(), "PR405-MC-0001");
    } catch (Exception e) {
        fail(e.getMessage());
    }

}
 
Example 18
Source File: PubSubHubbubCallbackREST.java    From commafeed with Apache License 2.0 4 votes vote down vote up
@Path("/callback")
@POST
@UnitOfWork
@Consumes({ MediaType.APPLICATION_ATOM_XML, "application/rss+xml" })
@Timed
public Response callback() {

	if (!config.getApplicationSettings().getPubsubhubbub()) {
		return Response.status(Status.FORBIDDEN).entity("pubsubhubbub is disabled").build();
	}

	try {
		byte[] bytes = IOUtils.toByteArray(request.getInputStream());

		if (ArrayUtils.isEmpty(bytes)) {
			return Response.status(Status.BAD_REQUEST).entity("empty body received").build();
		}

		FetchedFeed fetchedFeed = parser.parse(null, bytes);
		String topic = fetchedFeed.getFeed().getPushTopic();
		if (StringUtils.isBlank(topic)) {
			return Response.status(Status.BAD_REQUEST).entity("empty topic received").build();
		}

		log.debug("content callback received for {}", topic);
		List<Feed> feeds = feedDAO.findByTopic(topic);
		if (feeds.isEmpty()) {
			return Response.status(Status.BAD_REQUEST).entity("no feeds found for that topic").build();
		}

		for (Feed feed : feeds) {
			log.debug("pushing content to queue for {}", feed.getUrl());
			queues.add(feed, false);
		}
		metricRegistry.meter(MetricRegistry.name(getClass(), "pushReceived")).mark();

	} catch (Exception e) {
		log.error("Could not parse pubsub callback: " + e.getMessage());
	}
	return Response.ok().build();
}