Java Code Examples for org.apache.olingo.odata2.api.ep.EntityProvider#readMetadata()

The following examples show how to use org.apache.olingo.odata2.api.ep.EntityProvider#readMetadata() . 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: ServiceTicketODataConsumer.java    From C4CODATAAPIDEVGUIDE with Apache License 2.0 6 votes vote down vote up
private Edm readEdm() throws EntityProviderException,
		IllegalStateException, IOException {

	// This is used for both setting the Edm and CSRF Token :)
	if (m_edm != null) {
		return m_edm;
	}

	String serviceUrl = new StringBuilder(getODataServiceUrl())
			.append(SEPARATOR).append(METADATA).toString();

	logger.info("Metadata url => " + serviceUrl);

	final HttpGet get = new HttpGet(serviceUrl);
	get.setHeader(AUTHORIZATION_HEADER, getAuthorizationHeader());
	get.setHeader(CSRF_TOKEN_HEADER, CSRF_TOKEN_FETCH);

	HttpResponse response = getHttpClient().execute(get);

	m_csrfToken = response.getFirstHeader(CSRF_TOKEN_HEADER).getValue();
	logger.info("CSRF token => " + m_csrfToken);

	m_edm = EntityProvider.readMetadata(response.getEntity().getContent(),
			false);
	return m_edm;
}
 
Example 2
Source File: CMODataAbapClient.java    From devops-cm-client with Apache License 2.0 5 votes vote down vote up
private synchronized Edm getEntityDataModel() throws IOException, EntityProviderException, UnexpectedHttpResponseException {

        if(dataModel == null) {
            try (CloseableHttpClient edmClient = clientFactory.createClient()) {
                try (CloseableHttpResponse response = edmClient.execute(new HttpGet(endpoint.toASCIIString() + "/" + "$metadata"))) {
                    hasStatusOrFail(response, SC_OK);
                    dataModel = EntityProvider.readMetadata(response.getEntity().getContent(), false);
                }
            }
        }

        return dataModel;
    }
 
Example 3
Source File: AccountAttachmentODataConsumer.java    From C4CODATAAPIDEVGUIDE with Apache License 2.0 5 votes vote down vote up
private Edm readEdm() throws EntityProviderException,
		IllegalStateException, IOException {

	// This is used for both setting the Edm and CSRF Token :)
	if (m_edm != null) {
		return m_edm;
	}

	String serviceUrl = new StringBuilder(getODataServiceURL())
			.append(SEPARATOR).append(METADATA).toString();

	logger.info("Metadata url => " + serviceUrl);

	final HttpGet get = new HttpGet(serviceUrl);
	get.setHeader(AUTHORIZATION_HEADER, getAuthorizationHeader());
	get.setHeader(CSRF_TOKEN_HEADER, CSRF_TOKEN_FETCH);

	HttpResponse response = getHttpClient().execute(get);
	if(response.getStatusLine().getStatusCode() != 200) {
		logger.severe(response.getStatusLine().toString());
	}

	m_csrfToken = response.getFirstHeader(CSRF_TOKEN_HEADER).getValue();
	logger.info("CSRF token => " + m_csrfToken);

	m_edm = EntityProvider.readMetadata(response.getEntity().getContent(),
			false);
	return m_edm;
}
 
Example 4
Source File: ODataFilterExpressionParserTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
  InputStream metadataStream =
      ODataFilterExpressionParserTest.class.getClassLoader().getResourceAsStream("metadata.xml");
  try {
    edm = EntityProvider.readMetadata(metadataStream, true);
  } catch (EntityProviderException e) {
    fail("Not expected");
  }
}
 
Example 5
Source File: ODataSelectExpressionParserTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
  InputStream metadataStream =
      ODataFilterExpressionParserTest.class.getClassLoader().getResourceAsStream("metadata.xml");
  try {
    edm = EntityProvider.readMetadata(metadataStream, true);
  } catch (EntityProviderException e) {
    fail("Not expected");
  }
}
 
Example 6
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void edmxReferences() throws Exception {
  DataServices serviceMetadata = new DataServices();
  List<AnnotationElement> annoElements = new ArrayList<AnnotationElement>();
  annoElements.add(createElementWithoutInclude());
  annoElements.add(createElementWithInclude());
  serviceMetadata.setAnnotationElements(annoElements);
  serviceMetadata.setDataServiceVersion(ODataServiceVersion.V20);
  ODataResponse response = EntityProvider.writeMetadata(serviceMetadata, null);

  EntityProvider.readMetadata(response.getEntityAsStream(), false);
}
 
Example 7
Source File: EdmxProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Edm createEdm() throws Exception {
  EdmProvider testProvider = new EdmTestProvider();
  ODataResponse response = EntityProvider.writeMetadata(testProvider.getSchemas(), null);
  InputStream in = (InputStream) response.getEntity();
  return EntityProvider.readMetadata(in, true);

}
 
Example 8
Source File: GenericODataClient.java    From lemonaid with MIT License 4 votes vote down vote up
private Edm readEdm(String serviceUrl) throws IOException, ODataException {
	InputStream content = execute(serviceUrl + SEPARATOR + METADATA, APPLICATION_XML, GET);
	return EntityProvider.readMetadata(content, false);
}
 
Example 9
Source File: JPALinkTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void loadEdm() throws EntityProviderException {
  edm = EntityProvider.readMetadata(JPALinkTest.class.getClassLoader().getResourceAsStream(
      "metadata.xml"), false);
}
 
Example 10
Source File: Client.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private Edm getEdmInternal() throws IOException, ODataException, HttpException {
  HttpURLConnection connection = connect(METADATA, null, APPLICATION_XML, "GET");
  edm = EntityProvider.readMetadata((InputStream) connection.getContent(), false);
  return edm;
}