本文整理汇总了Java中org.apache.olingo.client.api.ODataClient类的典型用法代码示例。如果您正苦于以下问题:Java ODataClient类的具体用法?Java ODataClient怎么用?Java ODataClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataClient类属于org.apache.olingo.client.api包,在下文中一共展示了ODataClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEdmTest
import org.apache.olingo.client.api.ODataClient; //导入依赖的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());
}
}
示例2: read
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void read(final ODataClient client, final ContentType contentType) {
final URIBuilder uriBuilder =
client.newURIBuilder(testOAuth2ServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8);
final ODataEntityRequest<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(contentType);
final ODataRetrieveResponse<ClientEntity> res = req.execute();
assertEquals(200, res.getStatusCode());
final String etag = res.getETag();
assertTrue(StringUtils.isNotBlank(etag));
final ClientEntity order = res.getBody();
assertEquals(etag, order.getETag());
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Order", order.getTypeName().toString());
assertEquals("Edm.Int32", order.getProperty("OrderID").getPrimitiveValue().getTypeName());
assertEquals("Edm.DateTimeOffset", order.getProperty("OrderDate").getPrimitiveValue().getTypeName());
assertEquals("Edm.Duration", order.getProperty("ShelfLife").getPrimitiveValue().getTypeName());
assertEquals("Collection(Edm.Duration)", order.getProperty("OrderShelfLifes").getCollectionValue().getTypeName());
}
示例3: read
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void read(final ODataClient client, final ContentType contentType) throws IOException {
final URIBuilder builder = client.newURIBuilder(testDemoServiceRootURL).
appendEntitySetSegment("Advertisements").
appendKeySegment(UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7"));
final ODataEntityRequest<ClientEntity> entityReq =
client.getRetrieveRequestFactory().getEntityRequest(builder.build());
entityReq.setFormat(contentType);
final ClientEntity entity = entityReq.execute().getBody();
assertNotNull(entity);
assertTrue(entity.isMediaEntity());
// cast to workaround JDK 6 bug, fixed in JDK 7
assertEquals(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName().toString(),
((ClientValuable) entity.getProperty("AirDate")).getValue().getTypeName());
final ODataMediaRequest streamReq = client.getRetrieveRequestFactory().
getMediaRequest(entity.getMediaContentSource());
final ODataRetrieveResponse<InputStream> streamRes = streamReq.execute();
assertEquals(200, streamRes.getStatusCode());
final byte[] actual = new byte[Integer.parseInt(streamRes.getHeader("Content-Length").iterator().next())];
IOUtils.read(streamRes.getBody(), actual, 0, actual.length);
}
示例4: singleEntityWithExpand
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void singleEntityWithExpand() {
/* A single entity request will be dispatched to a different processor method than entity set request */
final ODataClient client = getEdmEnabledClient();
Map<String, Object> keys = new HashMap<String, Object>();
keys.put("PropertyInt16", 1);
keys.put("PropertyString", "1");
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(keys)
.expandWithOptions(NAV_PROPERTY_ET_KEY_NAV_MANY,
Collections.singletonMap(QueryOption.FILTER, (Object) "PropertyInt16 lt 2"))
.build();
final ODataRetrieveResponse<ClientEntity> response =
client.getRetrieveRequestFactory().getEntityRequest(uri).execute();
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
final ClientEntitySet entitySet =
response.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
assertEquals(1, entitySet.getEntities().size());
assertShortOrInt(1, entitySet.getEntities().get(0).getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
}
示例5: checkResponse
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
protected void checkResponse(
final ODataClient odataClient, final HttpResponse response, final String accept) {
if (response.getStatusLine().getStatusCode() >= 400) {
try {
final ODataRuntimeException exception = ODataErrorResponseChecker.checkResponse(
odataClient,
response.getStatusLine(),
response.getEntity() == null ? null : response.getEntity().getContent(),
accept);
if (exception != null) {
throw exception;
}
} catch (IOException e) {
throw new ODataRuntimeException(
"Received '" + response.getStatusLine() + "' but could not extract error body", e);
}
}
}
示例6: expandWithSearchQuery
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void expandWithSearchQuery() {
final ODataClient client = getEdmEnabledClient();
Map<QueryOption, Object> expandOptions = new EnumMap<QueryOption, Object>(QueryOption.class);
expandOptions.put(QueryOption.SEARCH, "abc");
expandOptions.put(QueryOption.FILTER, "PropertyInt16 eq 1");
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.expandWithOptions(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY, expandOptions)
.build();
final ODataEntitySetRequest<ClientEntitySet> request = client.getRetrieveRequestFactory().getEntitySetRequest(uri);
try {
request.execute();
} catch(ODataServerErrorException e) {
assertEquals("HTTP/1.1 501 Not Implemented", e.getMessage());
}
}
示例7: entityNavigationReference
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
/**
* 9. MAY request entity references in place of entities previously returned in the response (section 11.2.7).
*/
@Test
public void entityNavigationReference() {
final ODataClient client = getClient();
final URIBuilder uriBuilder = client.newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(32767)
.appendNavigationSegment("NavPropertyETAllPrimOne")
.appendRefSegment();
ODataEntityRequest<ClientEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
ODataRetrieveResponse<ClientEntity> res = req.execute();
assertNotNull(res);
final ClientEntity entity = res.getBody();
assertNotNull(entity);
assertTrue(entity.getId().toASCIIString().endsWith("ESAllPrim(32767)"));
}
示例8: supportMetadataMinimal
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
/**
* 12. MAY support odata.metadata=minimal in a JSON response (see [OData-JSON]).
*/
@Test
public void supportMetadataMinimal() {
assumeTrue("format should be json", isJson());
ODataClient client = getClient();
final URIBuilder uriBuilder = client.newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(32767)
.expand("NavPropertyETAllPrimOne");
final ODataEntityRequest<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(ContentType.JSON);
assertEquals("application/json;odata.metadata=minimal", req.getHeader("Accept"));
assertEquals("application/json;odata.metadata=minimal", req.getAccept());
final ODataRetrieveResponse<ClientEntity> res = req.execute();
assertTrue(res.getContentType().startsWith("application/json; odata.metadata=minimal"));
assertNotNull(res.getBody());
}
示例9: getResponseTemplate
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
/**
* Gets an empty response that can be initialized by a stream.
* <br/>
* This method has to be used to build response items about a batch request.
*
* @param <V> ODataResponse type.
* @return empty OData response instance.
*/
@SuppressWarnings("unchecked")
public <V extends ODataResponse> V getResponseTemplate() {
for (Class<?> clazz : this.getClass().getDeclaredClasses()) {
if (ODataResponse.class.isAssignableFrom(clazz)) {
try {
final Constructor<?> constructor = clazz.getDeclaredConstructor(
this.getClass(), ODataClient.class, HttpClient.class, HttpResponse.class);
constructor.setAccessible(true);
return (V) constructor.newInstance(this, odataClient, httpClient, null);
} catch (Exception e) {
LOG.error("Error retrieving response class template instance", e);
}
}
}
throw new IllegalStateException("No response class template has been found");
}
示例10: test1OLINGO1102
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void test1OLINGO1102() throws Exception {
ODataClient odataClient = ODataClientFactory.getClient();
InputStream entity = getClass().getResourceAsStream("500error." + getSuffix(ContentType.JSON));
StatusLine statusLine = mock(StatusLine.class);
when(statusLine.getStatusCode()).thenReturn(500);
when(statusLine.toString()).thenReturn("Internal Server Error");
ODataClientErrorException exp = (ODataClientErrorException) ODataErrorResponseChecker.
checkResponse(odataClient, statusLine, entity, "Json");
assertTrue(exp.getMessage().contains("(500) Internal Server Error"));
ODataError error = exp.getODataError();
assertTrue(error.getMessage().startsWith("Internal Server Error"));
assertEquals(500, Integer.parseInt(error.getCode()));
assertEquals(2, error.getInnerError().size());
assertEquals("\"Method does not support entities of specific type\"", error.getInnerError().get("message"));
assertEquals("\"FaultException\"", error.getInnerError().get("type"));
assertNull(error.getDetails());
}
示例11: setupMock
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ODataClient setupMock(Exception e) {
ODataInvokeRequest<ClientEntity> functionInvokeRequest = createMock(ODataInvokeRequest.class);
expect(functionInvokeRequest.setAccept(capture(contentType))).andReturn(functionInvokeRequest);
if(e != null) {
expect(functionInvokeRequest.execute())
.andThrow(e);
} else {
ODataInvokeResponse<ClientEntity> responseMock = createMock(ODataInvokeResponse.class);
expect(responseMock.getStatusCode()).andReturn(200);
responseMock.close(); expectLastCall();
replay(responseMock);
expect(functionInvokeRequest.execute()).andReturn(responseMock);
}
InvokeRequestFactory invokeRequestFactoryMock = createMock(InvokeRequestFactory.class);
expect(invokeRequestFactoryMock.getFunctionInvokeRequest(capture(address), eq(ClientEntity.class))).andReturn(functionInvokeRequest);
ODataClient clientMock = createMockBuilder(ODataClientImpl.class)
.addMockedMethod("getInvokeRequestFactory")
.addMockedMethod("getConfiguration").createMock();
expect(clientMock.getInvokeRequestFactory()).andReturn(invokeRequestFactoryMock);
expect(clientMock.getConfiguration()).andReturn(getConfiguration());
replay(functionInvokeRequest, invokeRequestFactoryMock, clientMock);
return clientMock;
}
示例12: setupMock
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ODataClient setupMock(Exception e) {
ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> responseMock = createMock(ODataRetrieveResponse.class);
if(e != null) {
expect(responseMock.getBody()).andThrow(e);
} else {
ClientEntitySetIterator<ClientEntitySet, ClientEntity> iteratorMock = createMock(ClientEntitySetIterator.class);
expect(iteratorMock.hasNext()).andReturn(true);
expect(iteratorMock.next()).andReturn(setupTransportMock("L21K90002N", false));
expect(iteratorMock.hasNext()).andReturn(true);
expect(iteratorMock.next()).andReturn(setupTransportMock("L21K90002L", false));
expect(iteratorMock.hasNext()).andReturn(true);
expect(iteratorMock.next()).andReturn(setupTransportMock("L21K90002J", true));
expect(iteratorMock.hasNext()).andReturn(false);
expect(responseMock.getBody()).andReturn(iteratorMock);
replay(iteratorMock);
}
responseMock.close();
expectLastCall();
ODataEntitySetIteratorRequest<ClientEntitySet, ClientEntity> oDataEntityRequestMock = createMock(ODataEntitySetIteratorRequest.class);
expect(oDataEntityRequestMock.setAccept(capture(contentType))).andReturn(oDataEntityRequestMock);
expect(oDataEntityRequestMock.execute()).andReturn(responseMock);
RetrieveRequestFactory retrieveRequestFactoryMock = createMock(RetrieveRequestFactory.class);
expect(retrieveRequestFactoryMock.getEntitySetIteratorRequest(capture(address))).andReturn(oDataEntityRequestMock);
ODataClient clientMock = createMockBuilder(ODataClientImpl.class)
.addMockedMethod("getRetrieveRequestFactory")
.addMockedMethod("getConfiguration").createMock();
expect(clientMock.getRetrieveRequestFactory()).andReturn(retrieveRequestFactoryMock);
expect(clientMock.getConfiguration()).andReturn(getConfiguration());
replay(responseMock, oDataEntityRequestMock, retrieveRequestFactoryMock, clientMock);
return clientMock;
}
示例13: read
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void read(final ODataClient client, final ContentType contentType) throws EdmPrimitiveTypeException {
final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
final ODataEntityRequest<ClientSingleton> singleton =
client.getRetrieveRequestFactory().getSingletonRequest(builder.build());
singleton.setFormat(contentType);
final ClientSingleton company = singleton.execute().getBody();
assertNotNull(company);
assertEquals(0, company.getProperty("CompanyID").getPrimitiveValue().toCastValue(Integer.class), 0);
// cast to workaround JDK 6 bug, fixed in JDK 7
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.CompanyCategory",
((ClientValuable) company.getProperty("CompanyCategory")).getValue().getTypeName());
assertTrue(company.getProperty("CompanyCategory").hasEnumValue());
}
示例14: readWithAnnotations
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void readWithAnnotations(final ODataClient client, final ContentType contentType)
throws EdmPrimitiveTypeException {
final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Boss");
final ODataEntityRequest<ClientSingleton> singleton =
client.getRetrieveRequestFactory().getSingletonRequest(builder.build());
singleton.setFormat(contentType);
singleton.setPrefer(client.newPreferences().includeAnnotations("*"));
final ClientSingleton boss = singleton.execute().getBody();
assertNotNull(boss);
assertFalse(boss.getAnnotations().isEmpty());
final ClientAnnotation isBoss = boss.getAnnotations().get(0);
assertTrue(isBoss.getPrimitiveValue().toCastValue(Boolean.class));
}
示例15: entitySetNavigationLink
import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void entitySetNavigationLink(final ODataClient client, final ContentType contentType) {
final URI uri = client.newURIBuilder(testStaticServiceRootURL).
appendEntitySetSegment("Accounts").appendKeySegment(101).build();
final ODataEntityRequest<ClientEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uri);
req.setFormat(contentType);
final ClientEntity entity = req.execute().getBody();
assertNotNull(entity);
// With JSON, entity set navigation links are only recognizable via Edm
if (contentType.equals(ContentType.APPLICATION_ATOM_XML) || client instanceof EdmEnabledODataClient) {
assertEquals(ClientLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("MyPaymentInstruments").getType());
assertEquals(ClientLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("ActiveSubscriptions").getType());
}
}