This commit is contained in:
fmartelli 2014-05-22 17:04:16 +02:00
commit f57c9f041c
1234 changed files with 1979 additions and 117367 deletions

View File

@ -1,3 +0,0 @@
target/
yworks-uml-doclet-3.0_02-jdk1.5/
*/nb-configuration.xml

View File

@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,95 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.msopentech.odatajclient</groupId>
<artifactId>odatajclient</artifactId>
<version>0.10.0-SNAPSHOT</version>
</parent>
<name>Client OData library for Java: Engine XML parser</name>
<description>Java client API for OData 3.0 services: Engine XML parser</description>
<groupId>com.msopentech.odatajclient</groupId>
<artifactId>odatajclient-engine-xml</artifactId>
<packaging>jar</packaging>
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>aalto-xml</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>jarjar-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jarjar</goal>
</goals>
<configuration>
<includes>
<include>javax.xml.stream:stax-api</include>
<include>org.codehaus.woodstox:stax2-api</include>
<include>com.fasterxml.jackson.dataformat:jackson-dataformat-xml</include>
<include>com.fasterxml:aalto-xml</include>
</includes>
<rules>
<rule>
<pattern>javax.xml.stream.**</pattern>
<result>com.msopentech.javax.xml.stream.@1</result>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>..</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE</include>
</includes>
</resource>
</resources>
</build>
</project>

View File

@ -1,2 +0,0 @@
nb-configuration.xml
nbactions-debugTest.xml

View File

@ -1,275 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.msopentech.odatajclient</groupId>
<artifactId>odatajclient</artifactId>
<version>0.10.0-SNAPSHOT</version>
</parent>
<name>Client OData library for Java: Engine</name>
<description>Java client API for OData 3.0 services: Engine</description>
<groupId>com.msopentech.odatajclient</groupId>
<artifactId>odatajclient-engine</artifactId>
<packaging>jar</packaging>
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>com.msopentech.odatajclient</groupId>
<artifactId>odatajclient-engine-xml</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml</groupId>
<artifactId>aalto-xml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>junit-benchmarks</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
<systemPropertyVariables>
<propertyName>org.slf4j.simpleLogger.defaultLogLevel</propertyName>
<org.slf4j.simpleLogger.defaultLogLevel>ERROR</org.slf4j.simpleLogger.defaultLogLevel>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*PerfTest.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<inherited>true</inherited>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>..</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
<profiles>
<profile>
<id>it</id>
<dependencies>
<dependency>
<groupId>com.msopentech.odatajclient</groupId>
<artifactId>odatajclient-test-service</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
<testResource>
<directory>${basedir}/../test-service/src/main/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>perf</id>
<build>
<defaultGoal>clean test exec:exec</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
<execution>
<id>perf-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/*PerfTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<classpathScope>test</classpathScope>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>com.msopentech.odatajclient.engine.performance.PerfTestReporter</argument>
<argument>${project.basedir}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,208 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
import com.msopentech.odatajclient.engine.client.http.DefaultHttpClientFactory;
import com.msopentech.odatajclient.engine.client.http.DefaultHttpUriRequestFactory;
import com.msopentech.odatajclient.engine.client.http.HttpClientFactory;
import com.msopentech.odatajclient.engine.client.http.HttpUriRequestFactory;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import com.msopentech.odatajclient.engine.format.ODataMediaFormat;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import com.msopentech.odatajclient.engine.format.ODataValueFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public abstract class AbstractConfiguration implements Configuration {
private static final String DEFAULT_PUB_FORMAT = "pubFormat";
private static final String DEFAULT_VALUE_FORMAT = "valueFormat";
private static final String DEFAULT_MEDIA_FORMAT = "valueFormat";
private static final String HTTP_CLIENT_FACTORY = "httpClientFactory";
private static final String HTTP_URI_REQUEST_FACTORY = "httpUriRequestFactory";
private static final String USE_XHTTP_METHOD = "useHTTPMethod";
private static final String KEY_AS_SEGMENT = "keyAsSegment";
private static final String GZIP_COMPRESSION = "gzipCompression";
private static final String CHUNKING = "chunking";
private final Map<String, Object> CONF = new HashMap<String, Object>();
private transient ExecutorService executor = Executors.newFixedThreadPool(10);
/**
* Gets given configuration property.
*
* @param key key value of the property to be retrieved.
* @param defaultValue default value to be used in case of the given key doesn't exist.
* @return property value if exists; default value if does not exist.
*/
private Object getProperty(final String key, final Object defaultValue) {
return CONF.containsKey(key) ? CONF.get(key) : defaultValue;
}
/**
* Sets new configuration property.
*
* @param key configuration property key.
* @param value configuration property value.
* @return given value.
*/
private Object setProperty(final String key, final Object value) {
return CONF.put(key, value);
}
@Override
public ODataPubFormat getDefaultPubFormat() {
return ODataPubFormat.valueOf(
getProperty(DEFAULT_PUB_FORMAT, ODataPubFormat.JSON_FULL_METADATA.name()).toString());
}
@Override
public void setDefaultPubFormat(final ODataPubFormat format) {
setProperty(DEFAULT_PUB_FORMAT, format.name());
}
@Override
public ODataFormat getDefaultFormat() {
ODataFormat format;
switch (getDefaultPubFormat()) {
case ATOM:
format = ODataFormat.XML;
break;
case JSON_FULL_METADATA:
format = ODataFormat.JSON_FULL_METADATA;
break;
case JSON_NO_METADATA:
format = ODataFormat.JSON_NO_METADATA;
break;
case JSON:
default:
format = ODataFormat.JSON;
}
return format;
}
@Override
public ODataValueFormat getDefaultValueFormat() {
return ODataValueFormat.valueOf(
getProperty(DEFAULT_VALUE_FORMAT, ODataValueFormat.TEXT.name()).toString());
}
@Override
public void setDefaultValueFormat(final ODataValueFormat format) {
setProperty(DEFAULT_VALUE_FORMAT, format.name());
}
@Override
public ODataMediaFormat getDefaultMediaFormat() {
return ODataMediaFormat.valueOf(
getProperty(DEFAULT_VALUE_FORMAT, ODataMediaFormat.APPLICATION_OCTET_STREAM.name()).toString());
}
@Override
public void setDefaultMediaFormat(final ODataMediaFormat format) {
setProperty(DEFAULT_MEDIA_FORMAT, format.name());
}
@Override
public HttpClientFactory getHttpClientFactory() {
return (HttpClientFactory) getProperty(HTTP_CLIENT_FACTORY, new DefaultHttpClientFactory());
}
@Override
public void setHttpClientFactory(final HttpClientFactory factory) {
setProperty(HTTP_CLIENT_FACTORY, factory);
}
@Override
public HttpUriRequestFactory getHttpUriRequestFactory() {
return (HttpUriRequestFactory) getProperty(HTTP_URI_REQUEST_FACTORY, new DefaultHttpUriRequestFactory());
}
@Override
public void setHttpUriRequestFactory(final HttpUriRequestFactory factory) {
setProperty(HTTP_URI_REQUEST_FACTORY, factory);
}
@Override
public boolean isUseXHTTPMethod() {
return (Boolean) getProperty(USE_XHTTP_METHOD, false);
}
@Override
public void setUseXHTTPMethod(final boolean value) {
setProperty(USE_XHTTP_METHOD, value);
}
@Override
public boolean isKeyAsSegment() {
return (Boolean) getProperty(KEY_AS_SEGMENT, false);
}
@Override
public void setKeyAsSegment(final boolean value) {
setProperty(KEY_AS_SEGMENT, value);
}
@Override
public boolean isGzipCompression() {
return (Boolean) getProperty(GZIP_COMPRESSION, false);
}
@Override
public void setGzipCompression(final boolean value) {
setProperty(GZIP_COMPRESSION, value);
}
@Override
public boolean isUseChuncked() {
return (Boolean) getProperty(CHUNKING, true);
}
@Override
public void setUseChuncked(final boolean value) {
setProperty(CHUNKING, value);
}
@Override
public ExecutorService getExecutor() {
return executor;
}
@Override
public void setExecutor(final ExecutorService executorService) {
executor = executorService;
}
}

View File

@ -1,38 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
import com.msopentech.odatajclient.engine.data.ODataGeospatialValue;
import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
abstract class AbstractODataClient implements ODataClient {
private static final long serialVersionUID = 7269096702397630265L;
@Override
public ODataPrimitiveValue.Builder getPrimitiveValueBuilder() {
return new ODataPrimitiveValue.Builder(this);
}
@Override
public ODataGeospatialValue.Builder getGeospatialValueBuilder() {
return new ODataGeospatialValue.Builder(this);
}
}

View File

@ -1,206 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
import com.msopentech.odatajclient.engine.client.http.DefaultHttpClientFactory;
import com.msopentech.odatajclient.engine.client.http.DefaultHttpUriRequestFactory;
import com.msopentech.odatajclient.engine.client.http.HttpClientFactory;
import com.msopentech.odatajclient.engine.client.http.HttpUriRequestFactory;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import com.msopentech.odatajclient.engine.format.ODataMediaFormat;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import com.msopentech.odatajclient.engine.format.ODataValueFormat;
import java.io.Serializable;
import java.util.concurrent.ExecutorService;
/**
* Configuration wrapper.
*/
public interface Configuration extends Serializable {
/**
* Gets the configured OData format for AtomPub exchanges.
* If this configuration parameter doesn't exist the JSON_FULL_METADATA format will be used as default.
*
* @return configured OData format for AtomPub if specified; JSON_FULL_METADATA format otherwise.
* @see ODataPubFormat#JSON_FULL_METADATA
*/
ODataPubFormat getDefaultPubFormat();
/**
* Sets the default OData format for AtomPub exchanges.
*
* @param format default format.
*/
void setDefaultPubFormat(ODataPubFormat format);
/**
* Gets the configured OData format.
* This value depends on what is returned from <tt>getDefaultPubFormat()</tt>.
*
* @return configured OData format
* @see #getDefaultPubFormat()
*/
ODataFormat getDefaultFormat();
/**
* Gets the configured OData value format.
* If this configuration parameter doesn't exist the TEXT format will be used as default.
*
* @return configured OData value format if specified; TEXT format otherwise.
* @see ODataValueFormat#TEXT
*/
ODataValueFormat getDefaultValueFormat();
/**
* Sets the default OData value format.
*
* @param format default format.
*/
void setDefaultValueFormat(ODataValueFormat format);
/**
* Gets the configured OData media format.
* If this configuration parameter doesn't exist the APPLICATION_OCTET_STREAM format will be used as default.
*
* @return configured OData media format if specified; APPLICATION_OCTET_STREAM format otherwise.
* @see ODataMediaFormat#WILDCARD
*/
ODataMediaFormat getDefaultMediaFormat();
/**
* Sets the default OData media format.
*
* @param format default format.
*/
void setDefaultMediaFormat(ODataMediaFormat format);
/**
* Gets the HttpClient factory to be used for executing requests.
*
* @return provided implementation (if configured via <tt>setHttpClientFactory</tt> or default.
* @see DefaultHttpClientFactory
*/
HttpClientFactory getHttpClientFactory();
/**
* Sets the HttpClient factory to be used for executing requests.
*
* @param factory implementation of <tt>HttpClientFactory</tt>.
* @see HttpClientFactory
*/
void setHttpClientFactory(HttpClientFactory factory);
/**
* Gets the HttpUriRequest factory for generating requests to be executed.
*
* @return provided implementation (if configured via <tt>setHttpUriRequestFactory</tt> or default.
* @see DefaultHttpUriRequestFactory
*/
HttpUriRequestFactory getHttpUriRequestFactory();
/**
* Sets the HttpUriRequest factory generating requests to be executed.
*
* @param factory implementation of <tt>HttpUriRequestFactory</tt>.
* @see HttpUriRequestFactory
*/
void setHttpUriRequestFactory(HttpUriRequestFactory factory);
/**
* Gets whether <tt>PUT</tt>, <tt>MERGE</tt>, <tt>PATCH</tt>, <tt>DELETE</tt> HTTP methods need to be translated to
* <tt>POST</tt> with additional <tt>X-HTTTP-Method</tt> header.
*
* @return whether <tt>X-HTTTP-Method</tt> header is to be used
*/
boolean isUseXHTTPMethod();
/**
* Sets whether <tt>PUT</tt>, <tt>MERGE</tt>, <tt>PATCH</tt>, <tt>DELETE</tt> HTTP methods need to be translated to
* <tt>POST</tt> with additional <tt>X-HTTTP-Method</tt> header.
*
* @param value 'TRUE' to use tunneling.
*/
void setUseXHTTPMethod(boolean value);
/**
* Checks whether URIs contain entity key between parentheses (standard) or instead as additional segment.
* Example: http://services.odata.org/V4/OData/OData.svc/Products(0) or
* http://services.odata.org/V4/OData/OData.svc/Products/0
*
* @return
*/
boolean isKeyAsSegment();
/**
* Sets whether URIs shall be built with entity key between parentheses (standard) or instead as additional
* segment.
* Example: http://services.odata.org/V4/OData/OData.svc/Products(0) or
* http://services.odata.org/V4/OData/OData.svc/Products/0
*
* @return whether URIs shall be built with entity key between parentheses (standard) or instead as additional
* segment.
*/
void setKeyAsSegment(boolean value);
/**
* Checks whether Gzip compression (e.g. support for <tt>Accept-Encoding: gzip</tt> and
* <tt>Content-Encoding: gzip</tt> HTTP headers) is enabled.
*
* @return whether HTTP Gzip compression is enabled
*/
boolean isGzipCompression();
/**
* Sets Gzip compression (e.g. support for <tt>Accept-Encoding: gzip</tt> and
* <tt>Content-Encoding: gzip</tt> HTTP headers) enabled or disabled.
*
* @param value whether to use Gzip compression.
*/
void setGzipCompression(boolean value);
/**
* Checks whether chunk HTTP encoding is being used.
*
* @return whether chunk HTTP encoding is being used
*/
boolean isUseChuncked();
/**
* Sets chunk HTTP encoding enabled or disabled.
*
* @param value whether to use chunk HTTP encoding.
*/
void setUseChuncked(boolean value);
/**
* Retrieves request executor service.
*
* @return request executor service.
*/
ExecutorService getExecutor();
/**
* Sets request executor service.
*
* @param executorService new executor services.
*/
void setExecutor(ExecutorService executorService);
}

View File

@ -1,77 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaders;
import com.msopentech.odatajclient.engine.communication.request.batch.BatchRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.cud.CUDRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.invoke.InvokeRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.retrieve.RetrieveRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.streamed.StreamedRequestFactory;
import com.msopentech.odatajclient.engine.data.ODataDeserializer;
import com.msopentech.odatajclient.engine.data.ODataBinder;
import com.msopentech.odatajclient.engine.data.ODataGeospatialValue;
import com.msopentech.odatajclient.engine.data.ODataObjectFactory;
import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
import com.msopentech.odatajclient.engine.data.ODataReader;
import com.msopentech.odatajclient.engine.data.ODataWriter;
import com.msopentech.odatajclient.engine.data.ODataSerializer;
import com.msopentech.odatajclient.engine.uri.URIBuilder;
import com.msopentech.odatajclient.engine.uri.filter.FilterFactory;
import com.msopentech.odatajclient.engine.utils.ODataVersion;
import java.io.Serializable;
public interface ODataClient extends Serializable {
ODataVersion getWorkingVersion();
ODataHeaders getVersionHeaders();
Configuration getConfiguration();
URIBuilder getURIBuilder(String serviceRoot);
FilterFactory getFilterFactory();
ODataPrimitiveValue.Builder getPrimitiveValueBuilder();
ODataGeospatialValue.Builder getGeospatialValueBuilder();
ODataSerializer getSerializer();
ODataDeserializer getDeserializer();
ODataReader getReader();
ODataWriter getWriter();
ODataBinder getBinder();
ODataObjectFactory getObjectFactory();
RetrieveRequestFactory getRetrieveRequestFactory();
CUDRequestFactory getCUDRequestFactory();
StreamedRequestFactory getStreamedRequestFactory();
InvokeRequestFactory<?, ?, ?, ?, ?, ?, ?, ?> getInvokeRequestFactory();
BatchRequestFactory getBatchRequestFactory();
}

View File

@ -1,34 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
public final class ODataClientFactory {
public static ODataV3Client getV3() {
return new ODataV3Client();
}
public static ODataV4Client getV4() {
return new ODataV4Client();
}
private ODataClientFactory() {
// empty constructory for static utility class
}
}

View File

@ -1,150 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaders;
import com.msopentech.odatajclient.engine.communication.request.batch.V3BatchRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.cud.V3CUDRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.invoke.V3InvokeRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.retrieve.V3RetrieveRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.streamed.V3StreamedRequestFactory;
import com.msopentech.odatajclient.engine.data.impl.v3.ODataBinderImpl;
import com.msopentech.odatajclient.engine.data.impl.v3.ODataReaderImpl;
import com.msopentech.odatajclient.engine.data.impl.v3.ODataWriterImpl;
import com.msopentech.odatajclient.engine.data.impl.v3.ODataDeserializerImpl;
import com.msopentech.odatajclient.engine.data.impl.v3.ODataObjectFactoryImpl;
import com.msopentech.odatajclient.engine.data.impl.v3.ODataSerializerImpl;
import com.msopentech.odatajclient.engine.uri.V3URIBuilder;
import com.msopentech.odatajclient.engine.uri.filter.V3FilterFactory;
import com.msopentech.odatajclient.engine.utils.ODataVersion;
public class ODataV3Client extends AbstractODataClient {
private static final long serialVersionUID = -1655712193243609209L;
private final V3Configuration configuration = new V3Configuration();
private final V3FilterFactory filterFactory = new V3FilterFactory();
private final ODataDeserializerImpl deserializer = new ODataDeserializerImpl(this);
private final ODataSerializerImpl serializer = new ODataSerializerImpl(this);
private final ODataReaderImpl reader = new ODataReaderImpl(this);
private final ODataWriterImpl writer = new ODataWriterImpl(this);
private final ODataBinderImpl binder = new ODataBinderImpl(this);
private final ODataObjectFactoryImpl objectFactory = new ODataObjectFactoryImpl(this);
private final V3RetrieveRequestFactory retrieveReqFact = new V3RetrieveRequestFactory(this);
private final V3CUDRequestFactory cudReqFact = new V3CUDRequestFactory(this);
private final V3StreamedRequestFactory streamedReqFact = new V3StreamedRequestFactory(this);
private final V3InvokeRequestFactory invokeReqFact = new V3InvokeRequestFactory(this);
private final V3BatchRequestFactory batchReqFact = new V3BatchRequestFactory(this);
@Override
public ODataVersion getWorkingVersion() {
return ODataVersion.V3;
}
@Override
public ODataHeaders getVersionHeaders() {
final ODataHeaders odataHeaders = new ODataHeaders();
odataHeaders.setHeader(ODataHeaders.HeaderName.minDataServiceVersion, ODataVersion.V3.toString());
odataHeaders.setHeader(ODataHeaders.HeaderName.maxDataServiceVersion, ODataVersion.V3.toString());
odataHeaders.setHeader(ODataHeaders.HeaderName.dataServiceVersion, ODataVersion.V3.toString());
return odataHeaders;
}
@Override
public V3Configuration getConfiguration() {
return configuration;
}
@Override
public V3URIBuilder getURIBuilder(final String serviceRoot) {
return new V3URIBuilder(configuration, serviceRoot);
}
@Override
public V3FilterFactory getFilterFactory() {
return filterFactory;
}
@Override
public ODataDeserializerImpl getDeserializer() {
return deserializer;
}
@Override
public ODataSerializerImpl getSerializer() {
return serializer;
}
@Override
public ODataReaderImpl getReader() {
return reader;
}
@Override
public ODataWriterImpl getWriter() {
return writer;
}
@Override
public ODataBinderImpl getBinder() {
return binder;
}
@Override
public ODataObjectFactoryImpl getObjectFactory() {
return objectFactory;
}
@Override
public V3RetrieveRequestFactory getRetrieveRequestFactory() {
return retrieveReqFact;
}
@Override
public V3CUDRequestFactory getCUDRequestFactory() {
return cudReqFact;
}
@Override
public V3StreamedRequestFactory getStreamedRequestFactory() {
return streamedReqFact;
}
@Override
public V3InvokeRequestFactory getInvokeRequestFactory() {
return invokeReqFact;
}
@Override
public V3BatchRequestFactory getBatchRequestFactory() {
return batchReqFact;
}
}

View File

@ -1,150 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaders;
import com.msopentech.odatajclient.engine.communication.request.batch.V4BatchRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.cud.V4CUDRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.invoke.V4InvokeRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.retrieve.V4RetrieveRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.streamed.V4StreamedRequestFactory;
import com.msopentech.odatajclient.engine.data.impl.v4.ODataBinderImpl;
import com.msopentech.odatajclient.engine.data.impl.v4.ODataReaderImpl;
import com.msopentech.odatajclient.engine.data.impl.v4.ODataWriterImpl;
import com.msopentech.odatajclient.engine.data.impl.v4.ODataDeserializerImpl;
import com.msopentech.odatajclient.engine.data.impl.v4.ODataObjectFactoryImpl;
import com.msopentech.odatajclient.engine.data.impl.v4.ODataSerializerImpl;
import com.msopentech.odatajclient.engine.uri.URIBuilder;
import com.msopentech.odatajclient.engine.uri.V4URIBuilder;
import com.msopentech.odatajclient.engine.uri.filter.V4FilterFactory;
import com.msopentech.odatajclient.engine.utils.ODataVersion;
public class ODataV4Client extends AbstractODataClient {
private static final long serialVersionUID = -6653176125573631964L;
private final V4Configuration configuration = new V4Configuration();
private final V4FilterFactory filterFactory = new V4FilterFactory();
private final ODataDeserializerImpl deserializer = new ODataDeserializerImpl(this);
private final ODataSerializerImpl serializer = new ODataSerializerImpl(this);
private final ODataReaderImpl reader = new ODataReaderImpl(this);
private final ODataWriterImpl writer = new ODataWriterImpl(this);
private final ODataBinderImpl binder = new ODataBinderImpl(this);
private final ODataObjectFactoryImpl objectFactory = new ODataObjectFactoryImpl(this);
private final V4RetrieveRequestFactory retrieveReqFact = new V4RetrieveRequestFactory(this);
private final V4CUDRequestFactory cudReqFact = new V4CUDRequestFactory(this);
private final V4StreamedRequestFactory streamedReqFact = new V4StreamedRequestFactory(this);
private final V4InvokeRequestFactory invokeReqFact = new V4InvokeRequestFactory(this);
private final V4BatchRequestFactory batchReqFact = new V4BatchRequestFactory(this);
@Override
public ODataVersion getWorkingVersion() {
return ODataVersion.V4;
}
@Override
public ODataHeaders getVersionHeaders() {
final ODataHeaders odataHeaders = new ODataHeaders();
odataHeaders.setHeader(ODataHeaders.HeaderName.maxDataServiceVersion, ODataVersion.V4.toString());
odataHeaders.setHeader(ODataHeaders.HeaderName.dataServiceVersion, ODataVersion.V4.toString());
return odataHeaders;
}
@Override
public V4Configuration getConfiguration() {
return configuration;
}
@Override
public URIBuilder getURIBuilder(final String serviceRoot) {
return new V4URIBuilder(configuration, serviceRoot);
}
@Override
public V4FilterFactory getFilterFactory() {
return filterFactory;
}
@Override
public ODataDeserializerImpl getDeserializer() {
return deserializer;
}
@Override
public ODataSerializerImpl getSerializer() {
return serializer;
}
@Override
public ODataReaderImpl getReader() {
return reader;
}
@Override
public ODataWriterImpl getWriter() {
return writer;
}
@Override
public ODataBinderImpl getBinder() {
return binder;
}
@Override
public ODataObjectFactoryImpl getObjectFactory() {
return objectFactory;
}
@Override
public V4RetrieveRequestFactory getRetrieveRequestFactory() {
return retrieveReqFact;
}
@Override
public V4CUDRequestFactory getCUDRequestFactory() {
return cudReqFact;
}
@Override
public V4StreamedRequestFactory getStreamedRequestFactory() {
return streamedReqFact;
}
@Override
public V4InvokeRequestFactory getInvokeRequestFactory() {
return invokeReqFact;
}
@Override
public V4BatchRequestFactory getBatchRequestFactory() {
return batchReqFact;
}
}

View File

@ -1,29 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
public class V3Configuration extends AbstractConfiguration {
private static final long serialVersionUID = -8719958537946884777L;
protected V3Configuration() {
super();
}
}

View File

@ -1,29 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client;
public class V4Configuration extends AbstractConfiguration {
private static final long serialVersionUID = -1134213707190176857L;
protected V4Configuration() {
super();
}
}

View File

@ -1,49 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import java.net.URI;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* Base implementation for working with Basic Authentication: needs to be subclassed in order to provide actual username
* and password.
*/
public abstract class AbstractBasicAuthHttpClientFactory extends DefaultHttpClientFactory {
private static final long serialVersionUID = 7985626503125490244L;
protected abstract String getUsername();
protected abstract String getPassword();
@Override
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {
final DefaultHttpClient httpclient = (DefaultHttpClient) super.createHttpClient(method, uri);
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(uri.getHost(), uri.getPort()),
new UsernamePasswordCredentials(getUsername(), getPassword()));
return httpclient;
}
}

View File

@ -1,61 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import java.net.URI;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* Base implementation for working with NTLM Authentication via embedded HttpClient features: needs to be subclassed
* in order to provide all needed login information.
* <br/>
* External NTLM engine such as <a href="http://jcifs.samba.org/">JCIFS</a> library developed by the
* <a href="http://www.samba.org/">Samba</a> project as a part of their Windows interoperability suite of programs.
*
* @see NTCredentials
* @see http://hc.apache.org/httpcomponents-client-ga/ntlm.html#Using_Samba_JCIFS_as_an_alternative_NTLM_engine
*/
public abstract class AbstractNTLMAuthHttpClientFactory extends DefaultHttpClientFactory {
protected abstract String getUsername();
protected abstract String getPassword();
protected abstract String getWorkstation();
protected abstract String getDomain();
@Override
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {
final DefaultHttpClient httpclient = (DefaultHttpClient) super.createHttpClient(method, uri);
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials(getUsername(), getPassword(), getWorkstation(), getDomain()));
httpclient.setCredentialsProvider(credsProvider);
return httpclient;
}
}

View File

@ -1,37 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import java.io.Serializable;
import java.net.URI;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* Default implementation returning HttpClients with default parameters.
*/
public class DefaultHttpClientFactory implements HttpClientFactory, Serializable {
private static final long serialVersionUID = -2461355444507227332L;
@Override
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {
return new DefaultHttpClient();
}
}

View File

@ -1,66 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import java.net.URI;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
/**
* Default implementation returning default HttpUriRequest implementations.
*/
public class DefaultHttpUriRequestFactory implements HttpUriRequestFactory {
@Override
public HttpUriRequest createHttpUriRequest(final HttpMethod method, final URI uri) {
HttpUriRequest result;
switch (method) {
case POST:
result = new HttpPost(uri);
break;
case PUT:
result = new HttpPut(uri);
break;
case PATCH:
result = new HttpPatch(uri);
break;
case MERGE:
result = new HttpMerge(uri);
break;
case DELETE:
result = new HttpDelete(uri);
break;
case GET:
default:
result = new HttpGet(uri);
break;
}
return result;
}
}

View File

@ -1,76 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
/**
* A client-side processing runtime exception.
*
* The exception is thrown during HTTP request invocation processing,
* to signal a failure to process the HTTP request or response. The exception
* message or nested {@link Throwable} cause SHOULD contain additional information
* about the reason of the processing failure.
*/
public class HttpClientException extends RuntimeException {
private static final long serialVersionUID = -4232431597816056514L;
/**
* Constructs a new client-side runtime exception with the specified cause
* and a detail message of {@code (cause==null ? null : cause.toString())}
* (which typically contains the class and detail message of {@code cause}).
* This constructor is useful for runtime exceptions that are little more
* than wrappers for other throwables.
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is permitted,
* and indicates that the cause is nonexistent or unknown.)
*/
public HttpClientException(final Throwable cause) {
super(cause);
}
/**
* Constructs a new client-side runtime exception with the specified detail
* message and cause.
* <p/>
* Note that the detail message associated with {@code cause} is <i>not</i>
* automatically incorporated in this runtime exception's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is permitted,
* and indicates that the cause is nonexistent or unknown.)
*/
public HttpClientException(final String message, final Throwable cause) {
super(message, cause);
}
/**
* Constructs a new client-side runtime exception with the specified detail
* message. The cause is not initialized, and may subsequently be initialized
* by a call to {@link #initCause}.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
*/
public HttpClientException(final String message) {
super(message);
}
}

View File

@ -1,30 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import java.net.URI;
import org.apache.http.client.HttpClient;
/**
* Interface used by ODataRequest implementations to instantiate HttpClient.
*/
public interface HttpClientFactory {
HttpClient createHttpClient(HttpMethod method, URI uri);
}

View File

@ -1,70 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import java.net.URI;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
/**
* Class identifying MERGE HTTP method.
*/
@NotThreadSafe
public class HttpMerge extends HttpEntityEnclosingRequestBase {
public final static String METHOD_NAME = "MERGE";
/**
* Constructor.
*/
public HttpMerge() {
super();
}
/**
* Constructor.
*
* @param uri request URI.
*/
public HttpMerge(final URI uri) {
super();
setURI(uri);
}
/**
* Constructor.
*
* @param uri request URI.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpMerge(final String uri) {
super();
setURI(URI.create(uri));
}
/**
* Gets HTTP method name.
*
* @return HTTP method name.
*/
@Override
public String getMethod() {
return METHOD_NAME;
}
}

View File

@ -1,33 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
/**
* Supported HTTP methods.
*/
public enum HttpMethod {
GET,
POST,
PUT,
PATCH,
MERGE,
DELETE;
}

View File

@ -1,70 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import java.net.URI;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
/**
* Class identifying PATCH HTTP method.
*/
@NotThreadSafe
public class HttpPatch extends HttpEntityEnclosingRequestBase {
public final static String METHOD_NAME = "PATCH";
/**
* Constructor.
*/
public HttpPatch() {
super();
}
/**
* Constructor.
*
* @param uri request URI.
*/
public HttpPatch(final URI uri) {
super();
setURI(uri);
}
/**
* Constructor.
*
* @param uri request URI.
* @throws IllegalArgumentException if the uri is invalid.
*/
public HttpPatch(final String uri) {
super();
setURI(URI.create(uri));
}
/**
* Gets HTTP method name.
*
* @return HTTP method name.
*/
@Override
public String getMethod() {
return METHOD_NAME;
}
}

View File

@ -1,30 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import java.net.URI;
import org.apache.http.client.methods.HttpUriRequest;
/**
* Interface used by ODataRequest implementations to create the HttpUriRequest.
*/
public interface HttpUriRequestFactory {
HttpUriRequest createHttpUriRequest(HttpMethod method, URI uri);
}

View File

@ -1,36 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.client.http;
import org.apache.http.HttpStatus;
/**
* Exception to be thrown when trying to read content with HTTP status 204.
*/
public class NoContentException extends HttpClientException {
private static final long serialVersionUID = 7947066635285809192L;
/**
* Constructs a new client-side runtime exception, with fixed message.
*/
public NoContentException() {
super("No content found when HTTP status is " + HttpStatus.SC_NO_CONTENT);
}
}

View File

@ -1,110 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication;
import com.msopentech.odatajclient.engine.data.ODataError;
import java.io.IOException;
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.StatusLine;
/**
* Represents a client error in OData.
*
* @see ODataError
*/
public class ODataClientErrorException extends RuntimeException {
private static final long serialVersionUID = -2551523202755268162L;
private final StatusLine statusLine;
private final ODataError error;
/**
* Constructor.
*
* @param statusLine request status info.
*/
public ODataClientErrorException(final StatusLine statusLine) {
super(statusLine.toString());
this.statusLine = statusLine;
this.error = null;
}
/**
* Constructor.
*
* @param statusLine request status info.
* @param error OData error to be wrapped.
*/
public ODataClientErrorException(final StatusLine statusLine, final ODataError error) {
super((StringUtils.isBlank(error.getCode()) ? StringUtils.EMPTY : "(" + error.getCode() + ") ")
+ error.getMessageValue() + " [" + statusLine.toString() + "]");
this.statusLine = statusLine;
this.error = error;
if (this.error.getInnerErrorType() != null && this.error.getInnerErrorMessage() != null) {
final RuntimeException cause =
new RuntimeException(this.error.getInnerErrorType() + ": " + this.error.getInnerErrorMessage());
if (this.error.getInnerErrorStacktrace() != null) {
List<String> stLines;
try {
stLines = IOUtils.readLines(new StringReader(this.error.getInnerErrorStacktrace()));
} catch (IOException e) {
stLines = Collections.<String>emptyList();
}
StackTraceElement[] stElements = new StackTraceElement[stLines.size()];
for (int i = 0; i < stLines.size(); i++) {
final String stLine = stLines.get(i).substring(stLines.get(i).indexOf("at ") + 3);
final int lastDotPos = stLine.lastIndexOf('.');
stElements[i] = new StackTraceElement(
stLine.substring(0, lastDotPos), stLine.substring(lastDotPos + 1), null, 0);
}
cause.setStackTrace(stElements);
}
initCause(cause);
}
}
/**
* Gets request status info.
*
* @return request status info.
*/
public StatusLine getStatusLine() {
return statusLine;
}
/**
* Gets OData error.
*
* @return OData error.
*/
public ODataError getODataError() {
return error;
}
}

View File

@ -1,38 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication;
import org.apache.http.StatusLine;
/**
* Represents a server error in OData.
*/
public class ODataServerErrorException extends RuntimeException {
private static final long serialVersionUID = -6423014532618680135L;
/**
* Constructor.
*
* @param statusLine request status info.
*/
public ODataServerErrorException(final StatusLine statusLine) {
super(statusLine.toString());
}
}

View File

@ -1,45 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.header;
/**
* Constant header values class.
*/
public class ODataHeaderValues {
/**
* <code>Prefer</code> header, return content.
*
* @see ODataHeaders.HeaderName#prefer
*/
public static final String preferReturnContent = "return-content";
/**
* <code>Prefer</code> header, return no content.
*
* @see ODataHeaders.HeaderName#prefer
*/
public static final String preferReturnNoContent = "return-no-content";
/**
* @see ODataHeaders.HeaderName#dataServiceUrlConventions
*/
public static final String keyAsSegment = "KeyAsSegment";
}

View File

@ -1,253 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.header;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
/**
* ODataHeaders wraps OData request/response headers.
*
* @see com.msopentech.odatajclient.engine.communication.request.ODataRequest
* @see com.msopentech.odatajclient.engine.communication.response.ODataResponse
*/
public class ODataHeaders {
/**
* Major OData request/response header names.
*/
public enum HeaderName {
/**
* The OData protocol uses the Accept request-header field, as specified in [RFC2616].
*/
accept("Accept"),
/**
* The Content-Type header is used as specified in [RFC2616].
* <br/>
* OData request/response supports the following types:
* <ul>
* <li>application/atom+xml</li>
* <li>application/atom+xml;type=entry</li>
* <li>application/atom+xml;type=feed</li>
* <li>application/json; odata=verbose</li>
* <li>application/json</li>
* <li>application/xml</li>
* <li>text/plain</li>
* <li>text/xml</li>
* <li>octet/stream</li>
* <li>multipart/mixed</li>
* </ul>
*/
contentType("Content-Type"),
/**
* This header is a custom HTTP header defined for protocol versioning purposes.
* This header MAY be present on any request or response message.
*/
dataServiceVersion("DataServiceVersion"),
/**
* An ETag (entity tag) is an HTTP response header returned by an HTTP/1.1 compliant web server
* used to determine change in content of a resource at a given URL. The value of the header is an
* opaque string representing the state of the resource at the time the response was generated.
*/
etag("ETag"),
/**
* The If-Match request-header field is used with a method to make it conditional. As specified in
* [RFC2616], "the purpose of this feature is to allow efficient updates of cached information with a
* minimum amount of transaction overhead. It is also used, on updating requests, to prevent
* inadvertent modification of the wrong version of a resource".
*/
ifMatch("If-Match"),
/**
* The If-None-Match request header is used with a method to make it conditional. As specified in
* [RFC2616], "The purpose of this feature is to allow efficient updates of cached information with a
* minimum amount of transaction overhead. It is also used to prevent a method (for example, PUT)
* from inadvertently modifying an existing resource when the client believes that the resource does
* not exist."
*/
ifNoneMatch("If-None-Match"),
/**
* This header is a custom HTTP request only header defined for protocol versioning purposes.
* This header MAY be present on any request message from client to server.
*/
maxDataServiceVersion("MaxDataServiceVersion"),
/**
* This header is a custom HTTP request only header defined for protocol versioning purposes.
* This header MAY be present on any request message from client to server.
*/
minDataServiceVersion("MinDataServiceVersion"),
/**
* A Prefer header is included in a request to state the clients preferred, but not required, server
* behavior (that is, a hint to the server). The Prefer header MAY be included on any request type
* (within a standalone or batch request), and a server MAY honor the header for HTTP POST, PUT,
* PATCH, and MERGE requests. A Prefer header with a value of return-content MUST NOT be
* specified on a DELETE request, a batch request as a whole, or a PUT request to update a named
* stream.
*/
prefer("Prefer"),
/**
* When a Prefer header value is successfully honored by the server, it MAY include a
* Preference-Applied response header that states which preference values were honored by the
* server.
*/
preferenceApplied("Preference-Applied"),
/**
* The DataServiceId response header is returned by the server when the response payload for an
* HTTP PUT, POST, PATCH, or MERGE request is empty.
* The value of the header is the identifier of the entity that was acted on by the PUT, POST, PATCH, or
* MERGE request. The identifier, in this case, is the same identifier that would have been returned in
* the response payload (for example, as the value of the atom:id element for Atom responses)
*/
dataServiceId("DataServiceId"),
/**
* Location header is used to specify the URL of an entity modified through a Data Modification request, or the
* request URL to check on the status of an asynchronous operation as described in
* <code>202 Accepted</code>.
*/
location("Location"),
/**
* A service must include a
* <code>Retry-After</code> header in a
* <code>202 Accepted</code>.
*/
retryAfter("Retry-After"),
dataServiceUrlConventions("DataServiceUrlConventions"),
slug("Slug"),
/**
* This header is a custom HTTP request header.
* <br/>
* It is possible to instruct network intermediaries (proxies, firewalls, and so on) inspecting traffic at
* the application protocol layer (for example, HTTP) to block requests that contain certain HTTP verbs.
* In practice, GET and POST verbs are rarely blocked (traditional web pages rely heavily on these
* HTTP methods), while, for a variety of reasons (such as security vulnerabilities in prior protocols),
* other HTTP methods (PUT, DELETE, and so on) are at times blocked by intermediaries. Additionally,
* some existing HTTP libraries do not allow creation of requests using verbs other than GET or POST.
* Therefore, an alternative way of specifying request types which use verbs other than GET and POST
* is needed to ensure that this document works well in a wide range of environments.
* <br/>
* To address this need, the X-HTTP-Method header can be added to a POST request that signals that
* the server MUST process the request not as a POST, but as if the HTTP verb specified as the value of
* the header was used as the method on the HTTP request's request line, as specified in [RFC2616]
* section 5.1. This technique is often referred to as "verb tunneling".
* <br/>
* This header is only valid when on POST requests.
*/
xHttpMethod("X-HTTP-METHOD");
private final String headerName;
private HeaderName(final String headerName) {
this.headerName = headerName;
}
@Override
public String toString() {
return headerName;
}
}
/**
* OData request/response header key/value pairs.
*/
private final Map<String, String> headers = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
/**
* Add the specified (custom) header (header name is case-insensitive).
*
* @param name header key.
* @param value header value.
* @return the current updated header instance.
*/
public ODataHeaders setHeader(final String name, final String value) {
headers.put(name, value);
return this;
}
/**
* Add the specified header.
*
* @param name header key.
* @param value header value.
* @return the current updated header instance.
*/
public ODataHeaders setHeader(final HeaderName name, final String value) {
headers.put(name.toString(), value);
return this;
}
/**
* Gets the value of the header identified by the given name.
* <br/>
* Please note that header name is case-insensitive.
*
* @param name name of the header to be retrieved.
* @return header value.
*/
public String getHeader(final HeaderName name) {
return headers.get(name.toString());
}
/**
* Gets the value of the header identified by the given name.
* <br/>
* Please note that header name is case-insensitive.
*
* @param name name of the header to be retrieved.
* @return header value.
*/
public String getHeader(final String name) {
return headers.get(name);
}
/**
* Removes the header identified by the given name.
* <br/>
* Please note that header name is case-insensitive.
*
* @param name name of the header to be retrieved.
* @return header name (if found).
*/
public String removeHeader(final HeaderName name) {
return headers.remove(name.toString());
}
/**
* Removes the header identified by the given name.
* <br/>
* Please note that header name is case-insensitive.
*
* @param name name of the header to be retrieved.
* @return header name (if found).
*/
public String removeHeader(final String name) {
return headers.remove(name);
}
/**
* Gets header names.
* <br/>
* Please note that header name is case-insensitive.
*
* @return header names.
*/
public Collection<String> getHeaderNames() {
return headers.keySet();
}
}

View File

@ -1,124 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import com.msopentech.odatajclient.engine.utils.ODataBatchConstants;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
/**
* Basic request abstract implementation.
*
* @param <V> OData response type corresponding to the request implementation.
* @param <T> OData format being used.
*/
public abstract class AbstractODataBasicRequestImpl<V extends ODataResponse, T extends Enum<T>>
extends ODataRequestImpl<T>
implements ODataBasicRequest<V, T> {
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param formatRef reference class for the format being used
* @param method request method.
* @param uri OData request URI.
*/
public AbstractODataBasicRequestImpl(final ODataClient odataClient,
final Class<T> formatRef, final HttpMethod method, final URI uri) {
super(odataClient, formatRef, method, uri);
}
/**
* {@inheritDoc}
*/
@Override
public void setFormat(final T format) {
if (format != null) {
setAccept(format.toString());
setContentType(format.toString());
}
}
/**
* {@inheritDoc}
*/
@Override
public final Future<V> asyncExecute() {
return odataClient.getConfiguration().getExecutor().submit(new Callable<V>() {
@Override
public V call() throws Exception {
return execute();
}
});
}
/**
* Gets payload as an InputStream.
*
* @return InputStream for entire payload.
*/
protected abstract InputStream getPayload();
/**
* Serializes the full request into the given batch request.
*
* @param req destination batch request.
*/
public void batch(final ODataBatchRequest req) {
batch(req, null);
}
/**
* Serializes the full request into the given batch request.
* <p>
* This method have to be used to serialize a changeset item with the specified contentId.
*
* @param req destination batch request.
* @param contentId contentId of the changeset item.
*/
public void batch(final ODataBatchRequest req, final String contentId) {
try {
req.rawAppend(toByteArray());
if (StringUtils.isNotBlank(contentId)) {
req.rawAppend((ODataBatchConstants.CHANGESET_CONTENT_ID_NAME + ": " + contentId).getBytes());
req.rawAppend(ODataStreamer.CRLF);
}
req.rawAppend(ODataStreamer.CRLF);
final InputStream payload = getPayload();
if (payload != null) {
req.rawAppend(IOUtils.toByteArray(getPayload()));
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}

View File

@ -1,54 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import java.util.concurrent.Future;
/**
* Basic OData request.
*
* @param <V> OData response type corresponding to the request implementation.
* @param <T> Accepted content-type formats by the request in object.
*/
public interface ODataBasicRequest<V extends ODataResponse, T extends Enum<T>> extends ODataRequest {
/**
* Request execute.
*
* @return return an OData response.
*/
V execute();
/**
* Async request execute.
*
* @return <code>Future&lt;ODataResponse&gt;</code> about the executed request.
*/
Future<V> asyncExecute();
/**
* Override configured request format.
*
* @param format request format.
* @see com.msopentech.odatajclient.engine.format.ODataFormat
* @see com.msopentech.odatajclient.engine.format.ODataPubFormat
*/
void setFormat(T format);
}

View File

@ -1,197 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.batch.BatchRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.cud.CUDRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.invoke.InvokeRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.retrieve.RetrieveRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.streamed.StreamedRequestFactory;
import java.io.InputStream;
import java.net.URI;
import java.util.Collection;
/**
* Abstract representation of an OData request.
* Get instance by using factories.
*
* @see CUDRequestFactory
* @see RetrieveRequestFactory
* @see BatchRequestFactory
* @see InvokeRequestFactory
* @see StreamedRequestFactory
*/
public interface ODataRequest {
/**
* Returns OData request target URI.
*
* @return OData request target URI.
*/
URI getURI();
/**
* Returns HTTP request method.
*
* @return HTTP request method.
*/
HttpMethod getMethod();
/**
* Gets all OData request header names.
*
* @return all request header names.
*/
Collection<String> getHeaderNames();
/**
* Gets the value of the OData request header identified by the given name.
*
* @param name name of the OData request header to be retrieved.
* @return header value.
*/
String getHeader(final String name);
/**
* Adds <tt>Accept</tt> OData request header.
*
* @param value header value.
* @return current object
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#accept
*/
ODataRequest setAccept(final String value);
/**
* Gets <tt>Accept</tt> OData request header.
*
* @return header value.
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#accept
*/
String getAccept();
/**
* Adds <tt>If-Match</tt> OData request header.
*
* @param value header value.
* @return current object
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#ifMatch
*/
ODataRequest setIfMatch(final String value);
/**
* Gets <tt>If-Match</tt> OData request header.
*
* @return header value.
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#ifMatch
*/
String getIfMatch();
/**
* Adds <tt>If-None-Match</tt> OData request header.
*
* @param value header value.
* @return current object
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#ifNoneMatch
*/
ODataRequest setIfNoneMatch(final String value);
/**
* Gets <tt>If-None-Match</tt> OData request header.
*
* @return header value.
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#ifNoneMatch
*/
String getIfNoneMatch();
/**
* Adds <tt>Prefer</tt> OData request header.
*
* @param value header value.
* @return current object
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#prefer
*/
ODataRequest setPrefer(final String value);
/**
* Gets <tt>Prefer</tt> OData request header.
*
* @return header value.
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#prefer
*/
String getPrefer();
/**
* Adds <tt>contentType</tt> OData request header.
*
* @param value header value.
* @return current object
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#contentType
*/
ODataRequest setContentType(final String value);
/**
* Gets <tt>contentType</tt> OData request header.
*
* @return header value.
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#contentType
*/
String getContentType();
/**
* Adds <tt>Slug</tt> OData request header.
*
* @param value header value.
* @return current object
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#slug
*/
ODataRequest setSlug(final String value);
/**
* Adds <tt>X-HTTP-METHOD</tt> OData request header.
*
* @param value header value.
* @return current object
* @see com.msopentech.odatajclient.engine.communication.header.ODataHeaders.HeaderName#xHttpMethod
*/
ODataRequest setXHTTPMethod(final String value);
/**
* Adds a custom OData request header.
*
* @param name header name.
* @param value header value.
* @return current object
*/
ODataRequest addCustomHeader(final String name, final String value);
/**
* Gets byte array representation of the full request header.
*
* @return full request header.
*/
byte[] toByteArray();
/**
* Request raw execute.
*
* @return raw input stream response.
*/
InputStream rawExecute();
}

View File

@ -1,481 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpClientException;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.ODataClientErrorException;
import com.msopentech.odatajclient.engine.communication.ODataServerErrorException;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaderValues;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaders;
import com.msopentech.odatajclient.engine.communication.request.batch.BatchRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.cud.CUDRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.invoke.InvokeRequestFactory;
import com.msopentech.odatajclient.engine.communication.request.streamed.StreamedRequestFactory;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import com.msopentech.odatajclient.engine.data.ODataError;
import com.msopentech.odatajclient.engine.data.impl.v3.JSONODataError;
import com.msopentech.odatajclient.engine.data.impl.v3.XMLODataError;
import com.msopentech.odatajclient.engine.format.ODataMediaFormat;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import com.msopentech.odatajclient.engine.format.ODataValueFormat;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DecompressingHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Abstract representation of an OData request.
* Get instance by using factories.
*
* @param <T> Accepted content-type formats by the request in object.
*
* @see CUDRequestFactory
* @see BatchRequestFactory
* @see InvokeRequestFactory
* @see StreamedRequestFactory
*/
public class ODataRequestImpl<T extends Enum<T>> implements ODataRequest {
/**
* Logger.
*/
protected static final Logger LOG = LoggerFactory.getLogger(ODataRequest.class);
protected final ODataClient odataClient;
protected final Class<T> formatRef;
/**
* OData request method.
*/
protected final HttpMethod method;
/**
* OData request header.
*/
protected final ODataHeaders odataHeaders;
/**
* Target URI.
*/
protected final URI uri;
/**
* HTTP client.
*/
protected final HttpClient httpClient;
/**
* HTTP request.
*/
protected final HttpUriRequest request;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param formatRef reference class for the format being used
* @param method HTTP request method. If configured X-HTTP-METHOD header will be used.
* @param uri OData request URI.
*/
protected ODataRequestImpl(final ODataClient odataClient,
final Class<T> formatRef, final HttpMethod method, final URI uri) {
this.odataClient = odataClient;
this.formatRef = formatRef;
this.method = method;
// initialize default headers
this.odataHeaders = odataClient.getVersionHeaders();
// target uri
this.uri = uri;
HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().
createHttpClient(this.method, this.uri);
if (odataClient.getConfiguration().isGzipCompression()) {
_httpClient = new DecompressingHttpClient(_httpClient);
}
this.httpClient = _httpClient;
this.request = odataClient.getConfiguration().getHttpUriRequestFactory().
createHttpUriRequest(this.method, this.uri);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public T getDefaultFormat() {
return (T) (formatRef.equals(ODataPubFormat.class)
? odataClient.getConfiguration().getDefaultPubFormat()
: (formatRef.equals(ODataValueFormat.class)
? odataClient.getConfiguration().getDefaultValueFormat()
: (formatRef.equals(ODataMediaFormat.class)
? odataClient.getConfiguration().getDefaultMediaFormat()
: odataClient.getConfiguration().getDefaultFormat())));
}
/**
* {@inheritDoc}
*/
@Override
public URI getURI() {
return uri;
}
/**
* {@inheritDoc}
*/
@Override
public Collection<String> getHeaderNames() {
return odataHeaders.getHeaderNames();
}
/**
* {@inheritDoc}
*/
@Override
public String getHeader(final String name) {
return odataHeaders.getHeader(name);
}
/**
* {@inheritDoc}
*/
@Override
public ODataRequest setAccept(final String value) {
odataHeaders.setHeader(ODataHeaders.HeaderName.accept, value);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataRequest setIfMatch(final String value) {
odataHeaders.setHeader(ODataHeaders.HeaderName.ifMatch, value);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataRequest setIfNoneMatch(final String value) {
odataHeaders.setHeader(ODataHeaders.HeaderName.ifNoneMatch, value);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataRequest setPrefer(final String value) {
odataHeaders.setHeader(ODataHeaders.HeaderName.prefer, value);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataRequest setXHTTPMethod(final String value) {
odataHeaders.setHeader(ODataHeaders.HeaderName.xHttpMethod, value);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataRequest setContentType(final String value) {
odataHeaders.setHeader(ODataHeaders.HeaderName.contentType, value);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataRequest setSlug(final String value) {
odataHeaders.setHeader(ODataHeaders.HeaderName.slug, value);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataRequest addCustomHeader(final String name, final String value) {
odataHeaders.setHeader(name, value);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public String getAccept() {
final String acceptHead = odataHeaders.getHeader(ODataHeaders.HeaderName.accept);
return StringUtils.isBlank(acceptHead) ? getDefaultFormat().toString() : acceptHead;
}
/**
* {@inheritDoc}
*/
@Override
public String getIfMatch() {
return odataHeaders.getHeader(ODataHeaders.HeaderName.ifMatch);
}
/**
* {@inheritDoc}
*/
@Override
public String getIfNoneMatch() {
return odataHeaders.getHeader(ODataHeaders.HeaderName.ifNoneMatch);
}
/**
* {@inheritDoc}
*/
@Override
public String getPrefer() {
return odataHeaders.getHeader(ODataHeaders.HeaderName.prefer);
}
/**
* {@inheritDoc}
*/
@Override
public String getContentType() {
final String contentTypeHead = odataHeaders.getHeader(ODataHeaders.HeaderName.contentType);
return StringUtils.isBlank(contentTypeHead) ? getDefaultFormat().toString() : contentTypeHead;
}
/**
* ${@inheritDoc }
*/
@Override
public HttpMethod getMethod() {
return method;
}
/**
* Gets request headers.
*
* @return request headers.
*/
public ODataHeaders getHeader() {
return odataHeaders;
}
/**
* {@inheritDoc }
*/
@Override
public byte[] toByteArray() {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
final StringBuilder requestBuilder = new StringBuilder();
requestBuilder.append(getMethod().toString()).append(" ").
append(uri.toString()).append(" ").append("HTTP/1.1");
baos.write(requestBuilder.toString().getBytes());
baos.write(ODataStreamer.CRLF);
// Set Content-Type and Accept headers with default values, if not yet set
if (StringUtils.isBlank(odataHeaders.getHeader(ODataHeaders.HeaderName.contentType))) {
setContentType(getContentType());
}
if (StringUtils.isBlank(odataHeaders.getHeader(ODataHeaders.HeaderName.accept))) {
setAccept(getAccept());
}
for (String name : getHeaderNames()) {
final String value = getHeader(name);
if (StringUtils.isNotBlank(value)) {
baos.write((name + ": " + value).getBytes());
baos.write(ODataStreamer.CRLF);
}
}
return baos.toByteArray();
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
IOUtils.closeQuietly(baos);
}
}
/**
* {@inheritDoc }
*/
@Override
public InputStream rawExecute() {
try {
final HttpEntity httpEntity = doExecute().getEntity();
return httpEntity == null ? null : httpEntity.getContent();
} catch (IOException e) {
throw new HttpClientException(e);
} catch (RuntimeException e) {
this.request.abort();
throw new HttpClientException(e);
}
}
/**
* Builds the request and execute it.
*
* @return HttpReponse object.
*/
protected HttpResponse doExecute() {
// Set Content-Type and Accept headers with default values, if not yet set
if (StringUtils.isBlank(odataHeaders.getHeader(ODataHeaders.HeaderName.contentType))) {
setContentType(getContentType());
}
if (StringUtils.isBlank(odataHeaders.getHeader(ODataHeaders.HeaderName.accept))) {
setAccept(getAccept());
}
// Add header for KeyAsSegment management
if (odataClient.getConfiguration().isKeyAsSegment()) {
addCustomHeader(
ODataHeaders.HeaderName.dataServiceUrlConventions.toString(), ODataHeaderValues.keyAsSegment);
}
// Add all available headers
for (String key : getHeaderNames()) {
this.request.addHeader(key, odataHeaders.getHeader(key));
}
if (LOG.isDebugEnabled()) {
for (Header header : this.request.getAllHeaders()) {
LOG.debug("HTTP header being sent: " + header);
}
}
final HttpResponse response;
try {
response = this.httpClient.execute(this.request);
} catch (IOException e) {
throw new HttpClientException(e);
} catch (RuntimeException e) {
this.request.abort();
throw new HttpClientException(e);
}
if (response.getStatusLine().getStatusCode() >= 500) {
throw new ODataServerErrorException(response.getStatusLine());
} else if (response.getStatusLine().getStatusCode() >= 400) {
try {
final HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
throw new ODataClientErrorException(response.getStatusLine());
} else {
final boolean isXML = getAccept().indexOf("json") == -1;
ODataError error;
try {
error = odataClient.getReader().readError(httpEntity.getContent(), isXML);
} catch (IllegalArgumentException e) {
LOG.warn("Error deserializing error response", e);
error = getGenericError(
response.getStatusLine().getStatusCode(),
response.getStatusLine().getReasonPhrase(),
isXML);
}
throw new ODataClientErrorException(response.getStatusLine(), error);
}
} catch (IOException e) {
throw new HttpClientException(
"Received '" + response.getStatusLine() + "' but could not extract error body", e);
}
}
return response;
}
/**
* Gets an empty response that can be initialized by a stream.
* <p>
* This method has to be used to build response items about a batch request.
*
* @param <V> ODataResppnse 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());
constructor.setAccessible(true);
return (V) constructor.newInstance(this);
} catch (Exception e) {
LOG.error("Error retrieving response class template instance", e);
}
}
}
throw new IllegalStateException("No response class template has been found");
}
private ODataError getGenericError(final int code, final String errorMsg, final boolean isXML) {
final ODataError error;
if (isXML) {
error = new XMLODataError();
final XMLODataError.Message msg = new XMLODataError.Message(
Collections.singletonMap("", (Object) errorMsg));
((XMLODataError) error).setMessage(msg);
((XMLODataError) error).setCode(String.valueOf(code));
} else {
error = new JSONODataError();
final JSONODataError.Message msg = new JSONODataError.Message();
msg.setValue(errorMsg);
((JSONODataError) error).setMessage(msg);
((JSONODataError) error).setCode(String.valueOf(code));
}
return error;
}
}

View File

@ -1,184 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request;
import com.msopentech.odatajclient.engine.client.http.HttpClientException;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import com.msopentech.odatajclient.engine.utils.Wrapper;
import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
/**
* OData request payload management abstract class.
*
* @param <T> OData response type corresponding to the request implementation.
*/
public abstract class ODataStreamManager<T extends ODataResponse> extends ODataStreamer {
/**
* Body input stream.
*/
private final PipedInputStream body;
/**
* Default body input stream.
*/
private final InputStream defaultBody;
/**
* Wrapper for actual streamed request's future.
*/
private final Wrapper<Future<HttpResponse>> futureWrap;
/**
* Constructor.
*
* @param futureWrap wrapper of the Future object of the HttpResponse.
*/
public ODataStreamManager(final Wrapper<Future<HttpResponse>> futureWrap) {
this(futureWrap, new PipedOutputStream());
}
/**
* Constructor.
*
* @param futureWrap wrapper of the Future object of the HttpResponse.
* @param output stream to be piped to retrieve the payload.
*/
public ODataStreamManager(final Wrapper<Future<HttpResponse>> futureWrap, final PipedOutputStream output) {
super(output);
this.futureWrap = futureWrap;
try {
this.body = new PipedInputStream(getBodyStreamWriter());
} catch (IOException e) {
throw new IllegalStateException(e);
}
this.defaultBody = this.body;
}
/**
* Constructor.
*
* @param futureWrap wrapper of the Future object of the HttpResponse.
* @param input stream to be used to retrieve the content.
*/
public ODataStreamManager(final Wrapper<Future<HttpResponse>> futureWrap, final InputStream input) {
super(null);
this.futureWrap = futureWrap;
this.body = null;
this.defaultBody = input;
}
/**
* Gets payload stream.
*
* @return payload stream.
*/
public InputStream getBody() {
return this.body == null ? this.defaultBody : this.body;
}
/**
* Closes piped output stream.
*/
public void finalizeBody() {
IOUtils.closeQuietly(getBodyStreamWriter());
}
/**
* Gets HttpResponse.
*
* @param timeout maximum delay after which the request must be aborted.
* @param unit time unit.
* @return HttpResponse.
*/
protected HttpResponse getHttpResponse(final long timeout, final TimeUnit unit) {
try {
return futureWrap.getWrapped().get(timeout, unit);
} catch (Exception e) {
LOG.error("Failure executing request");
throw new HttpClientException(e);
}
}
/**
* Gets OData response.
*
* @param timeout maximum delay after which the request must be aborted.
* @param unit time unit.
* @return ODataResponse instance.
*/
protected abstract T getResponse(long timeout, TimeUnit unit);
/**
* Closes the payload input stream and gets the OData response back.
*
* @return OData response.
*/
public final T getResponse() {
return getResponse(30, TimeUnit.SECONDS);
}
/**
* Closes the payload input stream and ask for an asynchronous response.
*
* @return <code>Future&lt;ODataResponse&gt;</code> about the executed request.
*/
public final Future<T> getAsyncResponse() {
return new Future<T>() {
@Override
public boolean cancel(final boolean mayInterruptIfRunning) {
return futureWrap.getWrapped().cancel(mayInterruptIfRunning);
}
@Override
public boolean isCancelled() {
return futureWrap.getWrapped().isCancelled();
}
@Override
public boolean isDone() {
return futureWrap.getWrapped().isDone();
}
@Override
public T get() throws InterruptedException, ExecutionException {
return getResponse(0, TimeUnit.SECONDS);
}
@Override
public T get(final long timeout, final TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return getResponse(timeout, unit);
}
};
}
}

View File

@ -1,104 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PipedOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Streamer utility object.
*/
public abstract class ODataStreamer {
/**
* Logger.
*/
protected static final Logger LOG = LoggerFactory.getLogger(ODataStreamer.class);
/**
* CR/LF.
*/
public static final byte[] CRLF = {13, 10};
/**
* OutputStream to be used to write objects to the stream.
*/
private final PipedOutputStream bodyStreamWriter;
/**
* Constructor.
*
* @param bodyStreamWriter piped stream to be used to retrieve the payload.
*/
public ODataStreamer(final PipedOutputStream bodyStreamWriter) {
this.bodyStreamWriter = bodyStreamWriter;
}
/**
* Writes the gibe byte array onto the output stream provided at instantiation time.
*
* @param src byte array to be written.
*/
protected void stream(final byte[] src) {
new Writer(src, bodyStreamWriter).run();
}
/**
* Stream CR/LF.
*/
protected void newLine() {
stream(CRLF);
}
/**
* Gets the piped stream to be used to stream the payload.
*
* @return piped stream.
*/
public PipedOutputStream getBodyStreamWriter() {
return bodyStreamWriter;
}
/**
* Writer thread.
*/
private class Writer implements Runnable {
final OutputStream os;
final byte[] src;
public Writer(final byte[] src, final OutputStream os) {
this.os = os;
this.src = src;
}
@Override
public void run() {
try {
os.write(src);
} catch (IOException e) {
LOG.error("Error streaming object", e);
}
}
}
}

View File

@ -1,56 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
/**
* Update type.
*/
public enum UpdateType {
/**
* Replace all and remove missing attributes.
*/
REPLACE(HttpMethod.PUT),
/**
* Differential update with whole entity as input (non-standard).
* Differences will be retrieved by the server itself.
*/
MERGE(HttpMethod.MERGE),
/**
* Differential update with only specified input property values to be replaced.
*/
PATCH(HttpMethod.PATCH);
private final HttpMethod method;
private UpdateType(final HttpMethod method) {
this.method = method;
}
/**
* Gets HTTP request method.
*
* @return HTTP request method.
*/
public HttpMethod getMethod() {
return method;
}
}

View File

@ -1,40 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.client.ODataClient;
/**
* OData batch request factory class.
*/
public abstract class AbstractBatchRequestFactory implements BatchRequestFactory {
private static final long serialVersionUID = -3875283254713404483L;
protected final ODataClient client;
protected AbstractBatchRequestFactory(final ODataClient client) {
this.client = client;
}
@Override
public ODataBatchRequest getBatchRequest(final String serviceRoot) {
return new ODataBatchRequest(client, client.getURIBuilder(serviceRoot).appendBatchSegment().build());
}
}

View File

@ -1,35 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import java.io.Serializable;
/**
* OData batch request factory class.
*/
public interface BatchRequestFactory extends Serializable {
/**
* Gets a batch request object instance.
*
* @param serviceRoot service root.
* @return new ODataBatchRequest instance.
*/
ODataBatchRequest getBatchRequest(String serviceRoot);
}

View File

@ -1,87 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
/**
* Utility class used to communicate batch info.
*/
public class ODataBatchController {
/**
* Batch validity.
*/
private boolean validBatch = true;
/**
* Batch boundary.
*/
private final String boundary;
/**
* Batch line iterator.
*/
private final ODataBatchLineIterator batchLineIterator;
/**
* Constructor.
*
* @param batchLineIterator batch line iterator.
* @param boundary batch boundary.
*/
public ODataBatchController(final ODataBatchLineIterator batchLineIterator, final String boundary) {
this.batchLineIterator = batchLineIterator;
this.boundary = boundary;
}
/**
* Checks if batch is valid.
*
* @return batch validity.
*/
public boolean isValidBatch() {
return validBatch;
}
/**
* Sets batch validity.
*
* @param validBatch validity.
*/
public void setValidBatch(final boolean validBatch) {
this.validBatch = validBatch;
}
/**
* Gest batch boundary.
*
* @return batch boundary.
*/
public String getBoundary() {
return boundary;
}
/**
* Gest batch line iterator.
*
* @return batch line iterator.
*/
public ODataBatchLineIterator getBatchLineIterator() {
return batchLineIterator;
}
}

View File

@ -1,95 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import java.util.Iterator;
import org.apache.commons.io.LineIterator;
/**
* Batch line iterator class.
*/
public class ODataBatchLineIterator implements Iterator<String> {
/**
* Stream line iterator.
*/
private final LineIterator batchLineIterator;
/**
* Last cached line.
*/
private String current;
/**
* Constructor.
*
* @param batchLineIterator stream line iterator.
*/
public ODataBatchLineIterator(final LineIterator batchLineIterator) {
this.batchLineIterator = batchLineIterator;
this.current = null;
}
/**
* Checks if batch has next line.
*
* @return 'TRUE' if has next line; 'FALSE' otherwise.
*/
@Override
public boolean hasNext() {
return batchLineIterator.hasNext();
}
/**
* Gets next line.
*
* @return next line.
*/
@Override
public String next() {
return nextLine();
}
/**
* Gets next line.
*
* @return next line.
*/
public String nextLine() {
current = batchLineIterator.nextLine();
return current;
}
/**
* Unsupported operation.
*/
@Override
public void remove() {
throw new UnsupportedOperationException("Unsupported operation");
}
/**
* Gets last cached line (the current one).
*
* @return last cached line; null if <code>next()</code> method never called
*/
public String getCurrent() {
return current;
}
}

View File

@ -1,259 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamManager;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchRequest.BatchStreamManager;
import com.msopentech.odatajclient.engine.communication.request.streamed.AbstractODataStreamedRequestImpl;
import com.msopentech.odatajclient.engine.communication.response.ODataBatchResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.utils.ODataBatchConstants;
import java.io.IOException;
import java.io.PipedOutputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements a batch request.
*/
public class ODataBatchRequest extends AbstractODataStreamedRequestImpl<ODataBatchResponse, BatchStreamManager> {
/**
* Batch request boundary.
*/
private final String boundary;
/**
* Expected batch response items.
*/
private final List<ODataBatchResponseItem> expectedResItems = new ArrayList<ODataBatchResponseItem>();
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param uri batch request URI (http://serviceRoot/$batch)
*/
ODataBatchRequest(final ODataClient odataClient, final URI uri) {
super(odataClient, HttpMethod.POST, uri);
// create a random UUID value for boundary
boundary = "batch_" + UUID.randomUUID().toString();
// specify the contentType header
setContentType(ODataBatchConstants.MULTIPART_CONTENT_TYPE + ";" + ODataBatchConstants.BOUNDARY + "=" + boundary);
}
/**
* {@inheritDoc }
*/
@Override
protected BatchStreamManager getStreamManager() {
if (streamManager == null) {
streamManager = new BatchStreamManager(this);
}
return (BatchStreamManager) streamManager;
}
/**
* Gets piped stream to be used to stream batch items.
*
* @return piped stream for the payload.
*/
PipedOutputStream getOutputStream() {
return getStreamManager().getBodyStreamWriter();
}
/**
* Appends the given byte array to the payload.
*
* @param toBeStreamed byte array to be appended.
* @return the current batch request.
* @throws IOException in case of write errors.
*/
public ODataBatchRequest rawAppend(final byte[] toBeStreamed) throws IOException {
getStreamManager().getBodyStreamWriter().write(toBeStreamed);
return this;
}
/**
* Appends the given byte array to the payload.
*
* @param toBeStreamed byte array to be appended.
* @param off byte array offset.
* @param len number of byte to be streamed.
* @return the current batch request.
* @throws IOException in case of write errors.
*/
public ODataBatchRequest rawAppend(final byte[] toBeStreamed, int off, int len) throws IOException {
getStreamManager().getBodyStreamWriter().write(toBeStreamed, off, len);
return this;
}
/**
* Batch request payload management.
*/
public class BatchStreamManager extends ODataStreamManager<ODataBatchResponse> {
/**
* Batch request current item.
*/
private ODataBatchRequestItem currentItem = null;
/**
* batch request reference.
*/
private final ODataBatchRequest req;
/**
* Private constructor.
*
* @param req batch request reference.
*/
private BatchStreamManager(final ODataBatchRequest req) {
super(ODataBatchRequest.this.futureWrapper);
this.req = req;
}
/**
* Gets a changeset batch item instance.
* A changeset can be submitted embedded into a batch request only.
*
* @return ODataChangeset instance.
*/
public ODataChangeset addChangeset() {
closeCurrentItem();
// stream dash boundary
streamDashBoundary();
final ODataChangesetResponseItem expectedResItem = new ODataChangesetResponseItem();
expectedResItems.add(expectedResItem);
currentItem = new ODataChangeset(req, expectedResItem);
return (ODataChangeset) currentItem;
}
/**
* Gets a retrieve batch item instance.
* A retrieve item can be submitted embedded into a batch request only.
*
* @return ODataRetrieve instance.
*/
public ODataRetrieve addRetrieve() {
closeCurrentItem();
// stream dash boundary
streamDashBoundary();
final ODataRetrieveResponseItem expectedResItem = new ODataRetrieveResponseItem();
currentItem = new ODataRetrieve(req, expectedResItem);
expectedResItems.add(expectedResItem);
return (ODataRetrieve) currentItem;
}
/**
* Close the current streamed item.
*/
private void closeCurrentItem() {
if (currentItem != null) {
currentItem.close();
}
}
/**
* {@inheritDoc }
*/
@Override
protected ODataBatchResponse getResponse(final long timeout, final TimeUnit unit) {
closeCurrentItem();
streamCloseDelimiter();
finalizeBody();
return new ODataBatchResponseImpl(httpClient, getHttpResponse(timeout, unit));
}
/**
* Streams dash boundary.
*/
private void streamDashBoundary() {
// preamble
newLine();
// stream batch-boundary
stream(("--" + boundary).getBytes());
newLine();
}
/**
* Streams close delimiter.
*/
private void streamCloseDelimiter() {
// stream close-delimiter
newLine();
stream(("--" + boundary + "--").getBytes());
}
}
/**
* {@inheritDoc}
* <p>
* This operation is unsupported by a batch request.
*/
@Override
public void batch(ODataBatchRequest req) {
throw new UnsupportedOperationException("A batch request is not batchable");
}
/**
* This class implements a response to a batch request.
*
* @see com.msopentech.odatajclient.engine.communication.request.ODataBatchRequest
*/
private class ODataBatchResponseImpl extends ODataResponseImpl implements ODataBatchResponse {
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataBatchResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc}
*/
@Override
public Iterator<ODataBatchResponseItem> getBody() {
return new ODataBatchResponseManager(this, expectedResItems);
}
}
}

View File

@ -1,121 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamer;
import com.msopentech.odatajclient.engine.utils.ODataBatchConstants;
/**
* Abstract representation of a batch request item.
*/
public abstract class ODataBatchRequestItem extends ODataStreamer {
/**
* Stream started check.
*/
protected boolean hasStreamedSomething = false;
/**
* Stream open check.
*/
private boolean open = false;
/**
* OData batch request.
*/
protected ODataBatchRequest req;
/**
* Constructor.
*
* @param req OData batch request.
*/
public ODataBatchRequestItem(final ODataBatchRequest req) {
super(req.getOutputStream());
this.open = true;
this.req = req;
}
/**
* Checks if the current item is still opened.
*
* @return 'TRUE' if opened; 'FALSE' otherwise.
*/
public boolean isOpen() {
return open;
}
/**
* Closes the item.
*/
public void close() {
closeItem();
open = false;
}
/**
* Stream the given request header.
* <p>
* Use this method to stream changeset items.
*
* @param request request to be batched.
* @param contentId changeset item id.
*/
protected void streamRequestHeader(final ODataBatchableRequest request, final int contentId) {
//stream batch content type
stream(ODataBatchConstants.ITEM_CONTENT_TYPE_LINE.getBytes());
newLine();
stream(ODataBatchConstants.ITEM_TRANSFER_ENCODING_LINE.getBytes());
newLine();
stream((ODataBatchConstants.CHANGESET_CONTENT_ID_NAME + ":" + contentId).getBytes());
newLine();
newLine();
}
/**
* Stream the given request header.
*
* @param request request to be batched.
*/
protected void streamRequestHeader(final ODataBatchableRequest request) {
//stream batch content type
stream(ODataBatchConstants.ITEM_CONTENT_TYPE_LINE.getBytes());
newLine();
stream(ODataBatchConstants.ITEM_TRANSFER_ENCODING_LINE.getBytes());
newLine();
newLine();
stream(request.toByteArray());
newLine();
}
/**
* Checks if the streaming of the current item is started yet.
*
* @return 'TRUE' if started; 'FALSE' otherwise.
*/
public boolean hasStreamedSomething() {
return hasStreamedSomething;
}
/**
* Closes the current item.
*/
protected abstract void closeItem();
}

View File

@ -1,149 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Abstract representation of a response item about a batch request.
*/
public abstract class ODataBatchResponseItem implements Iterator<ODataResponse> {
/**
* Logger.
*/
protected static final Logger LOG = LoggerFactory.getLogger(ODataBatchResponseItem.class);
/**
* Expected OData responses for the current batch response item.
*/
protected final Map<String, ODataResponse> responses = new HashMap<String, ODataResponse>();
/**
* Expected OData responses iterator.
*/
protected Iterator<ODataResponse> expectedItemsIterator;
/**
* Changeset controller.
* Gives more information about the type of batch item.
*/
private final boolean changeset;
/**
* Batch response line iterator.
*/
protected ODataBatchLineIterator batchLineIterator;
/**
* Batch boundary.
*/
protected String boundary;
/**
* Gives information about the batch response item status.
*/
protected boolean closed = false;
/**
* Constructor.
*
* @param isChangeset 'TRUE' if the current batch response item is a changeset.
*/
public ODataBatchResponseItem(boolean isChangeset) {
this.changeset = isChangeset;
}
/**
* Adds the given OData response template to the current OData batch response item.
*
* @param contentId changeset contentId in case of changeset; '__RETRIEVE__' in case of retrieve item.
* @param res OData response template to be added.
*/
void addResponse(final String contentId, final ODataResponse res) {
if (closed) {
throw new IllegalStateException("Invalid batch item because explicitely closed");
}
responses.put(contentId, res);
}
/**
* Initializes ODataResponse template from batch response item part.
*
* @param batchLineIterator batch response line iterator.
* @param boundary batch response boundary.
*/
void initFromBatch(final ODataBatchLineIterator batchLineIterator, final String boundary) {
if (closed) {
throw new IllegalStateException("Invalid batch item because explicitely closed");
}
LOG.debug("Init from batch - boundary '{}'", boundary);
this.batchLineIterator = batchLineIterator;
this.boundary = boundary;
}
/**
* Gets response about the given contentId.
*
* @param contentId response identifier (a specific contentId in case of changeset item).
* @return ODataResponse corresponding to the given contentId.
*/
protected ODataResponse getResponse(final String contentId) {
if (closed) {
throw new IllegalStateException("Invalid batch item because explicitely closed");
}
return responses.get(contentId);
}
/**
* Gets OData responses iterator.
*
* @return OData responses iterator.
*/
protected Iterator<ODataResponse> getResponseIterator() {
if (closed) {
throw new IllegalStateException("Invalid batch item because explicitely closed");
}
return responses.values().iterator();
}
/**
* Checks if the current batch response item is a changeset.
*
* @return 'TRUE' if the item is a changeset; 'FALSE' otherwise.
*/
public final boolean isChangeset() {
return changeset;
}
/**
* Closes the current batch responses item including all wrapped OData responses.
*/
public void close() {
for (ODataResponse response : responses.values()) {
response.close();
}
closed = true;
}
}

View File

@ -1,147 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaders;
import com.msopentech.odatajclient.engine.communication.response.ODataBatchResponse;
import com.msopentech.odatajclient.engine.utils.ODataConstants;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Batch response manager class.
*/
public class ODataBatchResponseManager implements Iterator<ODataBatchResponseItem> {
/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(ODataBatchResponseManager.class);
/**
* Batch response line iterator.
*/
private final ODataBatchLineIterator batchLineIterator;
/**
* Batch boundary.
*/
private final String batchBoundary;
/**
* Expected batch response items iterator.
*/
private final Iterator<ODataBatchResponseItem> expectedItemsIterator;
/**
* Last retrieved batch response item.
*/
private ODataBatchResponseItem current = null;
/**
* Constructor.
*
* @param res OData batch response.
* @param expectedItems expected batch response items.
*/
public ODataBatchResponseManager(final ODataBatchResponse res, final List<ODataBatchResponseItem> expectedItems) {
try {
this.expectedItemsIterator = expectedItems.iterator();
this.batchLineIterator = new ODataBatchLineIterator(
IOUtils.lineIterator(res.getRawResponse(), ODataConstants.UTF8));
// search for boundary
batchBoundary = ODataBatchUtilities.getBoundaryFromHeader(
res.getHeader(ODataHeaders.HeaderName.contentType));
LOG.debug("Retrieved batch response bondary '{}'", batchBoundary);
} catch (IOException e) {
LOG.error("Error parsing batch response", e);
throw new IllegalStateException(e);
}
}
/**
* {@inheritDoc }
*/
@Override
public boolean hasNext() {
return expectedItemsIterator.hasNext();
}
/**
* {@inheritDoc }
*/
@Override
public ODataBatchResponseItem next() {
if (current != null) {
current.close();
}
if (!hasNext()) {
throw new NoSuchElementException("No item found");
}
current = expectedItemsIterator.next();
final Map<String, Collection<String>> nextItemHeaders =
ODataBatchUtilities.nextItemHeaders(batchLineIterator, batchBoundary);
switch (ODataBatchUtilities.getItemType(nextItemHeaders)) {
case CHANGESET:
if (!current.isChangeset()) {
throw new IllegalStateException("Unexpected batch item");
}
current.initFromBatch(
batchLineIterator,
ODataBatchUtilities.getBoundaryFromHeader(
nextItemHeaders.get(ODataHeaders.HeaderName.contentType.toString())));
break;
case RETRIEVE:
if (current.isChangeset()) {
throw new IllegalStateException("Unexpected batch item");
}
current.initFromBatch(
batchLineIterator,
batchBoundary);
break;
default:
throw new IllegalStateException("Expected item not found");
}
return current;
}
/**
* Unsupported operation.
*/
@Override
public void remove() {
throw new UnsupportedOperationException("Remove operation is not supported");
}
}

View File

@ -1,330 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaders;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamer;
import com.msopentech.odatajclient.engine.utils.ODataBatchConstants;
import com.msopentech.odatajclient.engine.utils.ODataConstants;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utility class for batch requests and responses.
*/
public class ODataBatchUtilities {
public static enum BatchItemType {
NONE,
CHANGESET,
RETRIEVE
}
/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(ODataBatchUtilities.class);
/**
* Response line syntax.
*/
private static final Pattern RESPONSE_PATTERN =
Pattern.compile("HTTP/\\d\\.\\d (\\d+) (.*)", Pattern.CASE_INSENSITIVE);
/**
* Reads batch part taking source and delimiter (boundary) from given batch controller.
* <p>
* Usually used to consume/discard useless lines.
*
* @param batchController batch controller.
* @param checkCurrent if 'TRUE' the current line will be included into the delimiter verification.
* @return latest read line.
*/
public static String readBatchPart(final ODataBatchController batchController, final boolean checkCurrent) {
return readBatchPart(batchController, null, -1, checkCurrent);
}
/**
* Reads the given number of line from the given batch wrapped into the batch controller.
* <p>
* Usually used to consume/discard useless lines.
*
* @param batchController batch controller.
* @param count number of batch line to be read.
* @return latest read line.
*/
public static String readBatchPart(final ODataBatchController batchController, final int count) {
return readBatchPart(batchController, null, count, true);
}
/**
* Reads batch part taking source and delimiter (boundary) from given batch controller.
* <p>
* Usually used to read an entire batch part.
*
* @param batchController batch controller.
* @param os destination stream of batch part (null to discard).
* @param checkCurrent if 'TRUE' the current line will be included into the delimiter verification.
* @return latest read line.
*/
public static String readBatchPart(
final ODataBatchController controller, final OutputStream os, final boolean checkCurrent) {
return readBatchPart(controller, os, -1, checkCurrent);
}
/**
* Reads batch part taking source and delimiter (boundary) from given batch controller.
* <p>
* Usually used to read an entire batch part.
*
* @param batchController batch controller.
* @param os destination stream of batch part (null to discard).
* @param count number of batch line to be read.
* @param checkCurrent if 'TRUE' the current line will be included into the delimiter verification.
* @return latest read line.
*/
public static String readBatchPart(
final ODataBatchController controller, final OutputStream os, final int count, final boolean checkCurrent) {
String currentLine;
synchronized (controller.getBatchLineIterator()) {
currentLine = checkCurrent ? controller.getBatchLineIterator().getCurrent() : null;
if (count < 0) {
try {
boolean notEndLine = isNotEndLine(controller, currentLine);
while (controller.isValidBatch() && notEndLine && controller.getBatchLineIterator().hasNext()) {
currentLine = controller.getBatchLineIterator().nextLine();
LOG.debug("Read line '{}' (end-line '{}')", currentLine, controller.getBoundary());
notEndLine = isNotEndLine(controller, currentLine);
if (notEndLine && os != null) {
os.write(currentLine.getBytes(ODataConstants.UTF8));
os.write(ODataStreamer.CRLF);
}
}
} catch (IOException e) {
LOG.error("Error reading batch part", e);
throw new IllegalStateException(e);
}
} else {
for (int i = 0;
controller.isValidBatch() && controller.getBatchLineIterator().hasNext() && i < count; i++) {
currentLine = controller.getBatchLineIterator().nextLine();
}
}
}
return currentLine;
}
/**
* Reads headers from the batch starting from the given position.
*
* @param iterator batch iterator.
* @return Map of header name in header values.
*/
public static Map<String, Collection<String>> readHeaders(final ODataBatchLineIterator iterator) {
final Map<String, Collection<String>> target =
new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
readHeaders(iterator, target);
return target;
}
/**
* Reads headers from the batch starting from the given position.
* <p>
* Retrieved headers will be added to the map given by target parameter.
*
* @param iterator batch iterator.
* @param target destination of the retrieved headers.
*/
public static void readHeaders(
final ODataBatchLineIterator iterator, final Map<String, Collection<String>> target) {
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
readBatchPart(new ODataBatchController(iterator, null), baos, true);
final LineIterator headers = IOUtils.lineIterator(new ByteArrayInputStream(baos.toByteArray()),
ODataConstants.UTF8);
while (headers.hasNext()) {
final String line = headers.nextLine().trim();
if (StringUtils.isNotBlank(line)) {
addHeaderLine(line, target);
}
}
} catch (Exception e) {
LOG.error("Error retrieving headers", e);
throw new IllegalStateException(e);
}
}
/**
* Parses and adds the given header line to the given target map.
*
* @param headerLine header line to be added.
* @param targetMap target map.
*/
public static void addHeaderLine(final String headerLine, final Map<String, Collection<String>> targetMap) {
final int sep = headerLine.indexOf(':');
if (sep > 0 && sep < headerLine.length() - 1) {
final String key = headerLine.substring(0, sep).trim();
final Collection<String> value;
if (targetMap.containsKey(key)) {
value = targetMap.get(key);
} else {
value = new HashSet<String>();
targetMap.put(key, value);
}
value.add(headerLine.substring(sep + 1, headerLine.length()).trim());
}
}
/**
* Retrieved batch boundary from the given content-type header values.
*
* @param contentType content-types.
* @return batch boundary.
*/
public static String getBoundaryFromHeader(final Collection<String> contentType) {
final String boundaryKey = ODataBatchConstants.BOUNDARY + "=";
if (contentType == null || contentType.isEmpty() || !contentType.toString().contains(boundaryKey)) {
throw new IllegalArgumentException("Invalid content type");
}
final String headerValue = contentType.toString();
final int start = headerValue.indexOf(boundaryKey) + boundaryKey.length();
int end = headerValue.indexOf(';', start);
if (end < 0) {
end = headerValue.indexOf(']', start);
}
final String res = headerValue.substring(start, end);
return res.startsWith("--") ? res : "--" + res;
}
/**
* Retrieves response line from the given position.
*
* @param iterator batch iterator.
* @return retrieved response line.
*/
public static Map.Entry<Integer, String> readResponseLine(final ODataBatchLineIterator iterator) {
final String line = readBatchPart(new ODataBatchController(iterator, null), 1);
LOG.debug("Response line '{}'", line);
final Matcher matcher = RESPONSE_PATTERN.matcher(line.trim());
if (matcher.matches()) {
return new AbstractMap.SimpleEntry<Integer, String>(Integer.valueOf(matcher.group(1)), matcher.group(2));
}
throw new IllegalArgumentException("Invalid response line '" + line + "'");
}
/**
* Retrieves headers of the next batch item.
*
* @param iterator batch line iterator.
* @param boundary batch boundary.
* @return batch item headers.
*/
public static Map<String, Collection<String>> nextItemHeaders(
final ODataBatchLineIterator iterator, final String boundary) {
final Map<String, Collection<String>> headers =
new TreeMap<String, Collection<String>>(String.CASE_INSENSITIVE_ORDER);
final String line = ODataBatchUtilities.readBatchPart(new ODataBatchController(iterator, boundary), true);
if (line != null && line.trim().equals(boundary)) {
ODataBatchUtilities.readHeaders(iterator, headers);
}
LOG.debug("Retrieved batch item headers {}", headers);
return headers;
}
/**
* Retrieves item type from item headers.
*
* @param headers batch item headers.
* @return batch item type.
*/
public static BatchItemType getItemType(final Map<String, Collection<String>> headers) {
final BatchItemType nextItemType;
final String contentType = headers.containsKey(ODataHeaders.HeaderName.contentType.toString())
? headers.get(ODataHeaders.HeaderName.contentType.toString()).toString() : StringUtils.EMPTY;
if (contentType.contains(ODataBatchConstants.MULTIPART_CONTENT_TYPE)) {
nextItemType = BatchItemType.CHANGESET;
} else if (contentType.contains(ODataBatchConstants.ITEM_CONTENT_TYPE)) {
nextItemType = BatchItemType.RETRIEVE;
} else {
nextItemType = BatchItemType.NONE;
}
LOG.debug("Retrieved next item type {}", nextItemType);
return nextItemType;
}
/**
* Checks if the given line is the expected end-line.
*
* @param controller batch controller.
* @param line line to be checked.
* @return 'TRUE' if the line is not the end-line; 'FALSE' otherwise.
*/
private static boolean isNotEndLine(final ODataBatchController controller, final String line) {
return line == null
|| (StringUtils.isBlank(controller.getBoundary()) && StringUtils.isNotBlank(line))
|| (StringUtils.isNotBlank(controller.getBoundary()) && !line.startsWith(controller.getBoundary()));
}
}

View File

@ -1,47 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.communication.request.ODataRequest;
/**
* Object request that can be sent embedded into a batch request.
*/
public interface ODataBatchableRequest extends ODataRequest {
/**
* Writes (and consume) the request onto the given batch stream.
* <p>
* Please note that this method will consume the request (execution won't be possible anymore).
*
* @param req destination batch request.
*/
void batch(final ODataBatchRequest req);
/**
* Writes (and consume) the request onto the given batch stream.
* <p>
* Please note that this method will consume the request (execution won't be possible anymore).
*
* @param req destination batch request.
* @param contentId ContentId header value to be added to the serialization.
* Use this in case of changeset items.
*/
void batch(final ODataBatchRequest req, final String contentId);
}

View File

@ -1,124 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaders;
import com.msopentech.odatajclient.engine.communication.request.ODataRequestImpl;
import com.msopentech.odatajclient.engine.utils.ODataBatchConstants;
import java.util.UUID;
/**
* Changeset wrapper for the corresponding batch item.
*/
public class ODataChangeset extends ODataBatchRequestItem {
/**
* ContentId.
*/
private int contentId = 0;
/**
* Changeset boundary.
*/
private final String boundary;
/**
* Expected changeset response items.
*/
private final ODataChangesetResponseItem expectedResItem;
/**
* Constructor.
*
* @param req batch request.
* @param expectedResItem expected OData response items.
*/
ODataChangeset(final ODataBatchRequest req, final ODataChangesetResponseItem expectedResItem) {
super(req);
this.expectedResItem = expectedResItem;
// create a random UUID value for boundary
boundary = "changeset_" + UUID.randomUUID().toString();
}
public int getLastContentId() {
return contentId;
}
/**
* Close changeset item an send changeset request footer.
*/
@Override
protected void closeItem() {
// stream close-delimiter
if (hasStreamedSomething) {
newLine();
stream(("--" + boundary + "--").getBytes());
newLine();
newLine();
}
}
/**
* Serialize and send the given request.
* <p>
* An IllegalArgumentException is thrown in case of GET request.
*
* @param request request to be serialized.
* @return current item instance.
*/
public ODataChangeset addRequest(final ODataBatchableRequest request) {
if (!isOpen()) {
throw new IllegalStateException("Current batch item is closed");
}
if (request.getMethod() == HttpMethod.GET) {
throw new IllegalArgumentException("Invalid request. GET method not allowed in changeset");
}
if (!hasStreamedSomething) {
stream((ODataHeaders.HeaderName.contentType.toString() + ": "
+ ODataBatchConstants.MULTIPART_CONTENT_TYPE + ";boundary=" + boundary).getBytes());
newLine();
newLine();
hasStreamedSomething = true;
}
contentId++;
// preamble
newLine();
// stream batch-boundary
stream(("--" + boundary).getBytes());
newLine();
// stream the request
streamRequestHeader(request, contentId);
request.batch(req, String.valueOf(contentId));
// add request to the list
expectedResItem.addResponse(String.valueOf(contentId), ((ODataRequestImpl) request).getResponseTemplate());
return this;
}
}

View File

@ -1,131 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import static com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchResponseItem.LOG;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import com.msopentech.odatajclient.engine.utils.ODataBatchConstants;
import java.util.Collection;
import java.util.Map;
import java.util.NoSuchElementException;
/**
* Changeset wrapper for the corresponding batch item.
*/
public class ODataChangesetResponseItem extends ODataBatchResponseItem {
/**
* Last cached OData response.
*/
private ODataResponse current = null;
/**
* Constructor.
*/
public ODataChangesetResponseItem() {
super(true);
}
/**
* {@inheritDoc }
*/
@Override
public boolean hasNext() {
if (closed) {
throw new IllegalStateException("Invalid request - the item has been closed");
}
if (expectedItemsIterator == null) {
expectedItemsIterator = responses.values().iterator();
}
return expectedItemsIterator.hasNext();
}
/**
* {@inheritDoc }
*/
@Override
public ODataResponse next() {
if (current != null) {
current.close();
}
if (closed) {
throw new IllegalStateException("Invalid request - the item has been closed");
}
if (hasNext()) {
// consume item for condition above (like a counter ...)
expectedItemsIterator.next();
} else {
throw new NoSuchElementException("No item found");
}
final Map<String, Collection<String>> nextItemHeaders =
ODataBatchUtilities.nextItemHeaders(batchLineIterator, boundary);
if (nextItemHeaders.isEmpty()) {
throw new IllegalStateException("Expected item not found");
}
final Map.Entry<Integer, String> responseLine = ODataBatchUtilities.readResponseLine(batchLineIterator);
LOG.debug("Retrieved item response {}", responseLine);
final Map<String, Collection<String>> headers = ODataBatchUtilities.readHeaders(batchLineIterator);
LOG.debug("Retrieved item headers {}", headers);
Collection<String> contentId = nextItemHeaders.get(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME);
if (contentId == null || contentId.isEmpty()) {
contentId = headers.get(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME);
if (contentId == null || contentId.isEmpty()) {
throw new IllegalStateException("Content-ID is missing");
}
}
current = getResponse(contentId.iterator().next());
if (current == null) {
throw new IllegalStateException("Unexpected '" + contentId + "' item found");
}
current.initFromBatch(responseLine, headers, batchLineIterator, boundary);
if (current.getStatusCode() >= 400) {
// found error .... consume expeted items
while (expectedItemsIterator.hasNext()) {
expectedItemsIterator.next();
}
}
return current;
}
/**
* Unsupported operation.
*/
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported operation.");
}
}

View File

@ -1,81 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.ODataRequestImpl;
/**
* Retrieve request wrapper for the corresponding batch item.
*/
public class ODataRetrieve extends ODataBatchRequestItem {
private final ODataRetrieveResponseItem expectedResItem;
/**
* Constructor.
*
* @param req batch request.
* @param expectedResItem expected batch response item.
*/
ODataRetrieve(final ODataBatchRequest req, final ODataRetrieveResponseItem expectedResItem) {
super(req);
this.expectedResItem = expectedResItem;
}
/**
* Close item.
*/
@Override
protected void closeItem() {
// nop
}
/**
* Serialize and send the given request.
* <p>
* An IllegalArgumentException is thrown in case of no GET request.
*
* @param request request to be serialized.
* @return current item instance.
*/
public ODataRetrieve setRequest(final ODataBatchableRequest request) {
if (!isOpen()) {
throw new IllegalStateException("Current batch item is closed");
}
if (((ODataRequestImpl) request).getMethod() != HttpMethod.GET) {
throw new IllegalArgumentException("Invalid request. Only GET method is allowed");
}
hasStreamedSomething = true;
// stream the request
streamRequestHeader(request);
// close before in order to avoid any further setRequest calls.
close();
// add request to the list
expectedResItem.addResponse(
ODataRetrieveResponseItem.RETRIEVE_CONTENT_ID, ((ODataRequestImpl) request).getResponseTemplate());
return this;
}
}

View File

@ -1,86 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import static com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchResponseItem.LOG;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import java.util.Collection;
import java.util.Map;
import java.util.NoSuchElementException;
/**
* Retrieve response wrapper for the corresponding batch item.
*/
public class ODataRetrieveResponseItem extends ODataBatchResponseItem {
public static final String RETRIEVE_CONTENT_ID = "__RETRIEVE__";
/**
* Constructor.
*/
public ODataRetrieveResponseItem() {
super(false);
}
/**
* {@inheritDoc }
*/
@Override
public boolean hasNext() {
if (closed) {
throw new IllegalStateException("Invalid request - the item has been closed");
}
if (expectedItemsIterator == null) {
expectedItemsIterator = responses.values().iterator();
}
return expectedItemsIterator.hasNext();
}
/**
* {@inheritDoc }
*/
@Override
public ODataResponse next() {
if (closed) {
throw new IllegalStateException("Invalid request - the item has been closed");
}
if (!hasNext()) {
throw new NoSuchElementException("No item found");
}
final Map.Entry<Integer, String> responseLine = ODataBatchUtilities.readResponseLine(batchLineIterator);
LOG.debug("Retrieved item response {}", responseLine);
final Map<String, Collection<String>> headers = ODataBatchUtilities.readHeaders(batchLineIterator);
LOG.debug("Retrieved item headers {}", headers);
return expectedItemsIterator.next().initFromBatch(responseLine, headers, batchLineIterator, boundary);
}
/**
* Unsupported operation.
*/
@Override
public void remove() {
throw new UnsupportedOperationException("Operation not supported.");
}
}

View File

@ -1,31 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.client.ODataV3Client;
public class V3BatchRequestFactory extends AbstractBatchRequestFactory {
private static final long serialVersionUID = -6271567229804128570L;
public V3BatchRequestFactory(final ODataV3Client client) {
super(client);
}
}

View File

@ -1,31 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.batch;
import com.msopentech.odatajclient.engine.client.ODataV4Client;
public class V4BatchRequestFactory extends AbstractBatchRequestFactory {
private static final long serialVersionUID = 788349446729208639L;
public V4BatchRequestFactory(final ODataV4Client client) {
super(client);
}
}

View File

@ -1,189 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.UpdateType;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import com.msopentech.odatajclient.engine.data.ODataLink;
import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
import com.msopentech.odatajclient.engine.data.ODataProperty;
import java.net.URI;
public abstract class AbstractCUDRequestFactory implements CUDRequestFactory {
private static final long serialVersionUID = -2723641791198745990L;
protected final ODataClient client;
protected AbstractCUDRequestFactory(final ODataClient client) {
this.client = client;
}
@Override
public ODataEntityCreateRequest getEntityCreateRequest(final URI targetURI, final ODataEntity entity) {
return new ODataEntityCreateRequest(client, targetURI, entity);
}
@Override
public ODataEntityUpdateRequest getEntityUpdateRequest(
final URI targetURI, final UpdateType type, final ODataEntity changes) {
final ODataEntityUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataEntityUpdateRequest(client, HttpMethod.POST, targetURI, changes);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataEntityUpdateRequest(client, type.getMethod(), targetURI, changes);
}
return req;
}
@Override
public ODataEntityUpdateRequest getEntityUpdateRequest(final UpdateType type, final ODataEntity entity) {
if (entity.getEditLink() == null) {
throw new IllegalArgumentException("No edit link found");
}
final ODataEntityUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataEntityUpdateRequest(client, HttpMethod.POST, entity.getEditLink(), entity);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataEntityUpdateRequest(client, type.getMethod(), entity.getEditLink(), entity);
}
return req;
}
@Override
public ODataValueUpdateRequest getValueUpdateRequest(
final URI targetURI, final UpdateType type, final ODataPrimitiveValue value) {
final ODataValueUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataValueUpdateRequest(client, HttpMethod.POST, targetURI, value);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataValueUpdateRequest(client, type.getMethod(), targetURI, value);
}
return req;
}
@Override
public ODataPropertyUpdateRequest getPropertyPrimitiveValueUpdateRequest(
final URI targetURI, final ODataProperty property) {
if (!property.hasPrimitiveValue()) {
throw new IllegalArgumentException("A primitive value is required");
}
final ODataPropertyUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataPropertyUpdateRequest(client, HttpMethod.POST, targetURI, property);
req.setXHTTPMethod(HttpMethod.PUT.name());
} else {
req = new ODataPropertyUpdateRequest(client, HttpMethod.PUT, targetURI, property);
}
return req;
}
@Override
public ODataPropertyUpdateRequest getPropertyComplexValueUpdateRequest(
final URI targetURI, final UpdateType type, final ODataProperty property) {
if (!property.hasComplexValue()) {
throw new IllegalArgumentException("A complex value is required");
}
final ODataPropertyUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataPropertyUpdateRequest(client, HttpMethod.POST, targetURI, property);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataPropertyUpdateRequest(client, type.getMethod(), targetURI, property);
}
return req;
}
@Override
public ODataPropertyUpdateRequest getPropertyCollectionValueUpdateRequest(
final URI targetURI, final ODataProperty property) {
if (!property.hasCollectionValue()) {
throw new IllegalArgumentException("A collection value is required");
}
final ODataPropertyUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataPropertyUpdateRequest(client, HttpMethod.POST, targetURI, property);
req.setXHTTPMethod(HttpMethod.PUT.name());
} else {
req = new ODataPropertyUpdateRequest(client, HttpMethod.PUT, targetURI, property);
}
return req;
}
@Override
public ODataLinkCreateRequest getLinkCreateRequest(final URI targetURI, final ODataLink link) {
return new ODataLinkCreateRequest(client, targetURI, link);
}
@Override
public ODataLinkUpdateRequest getLinkUpdateRequest(
final URI targetURI, final UpdateType type, final ODataLink link) {
final ODataLinkUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataLinkUpdateRequest(client, HttpMethod.POST, targetURI, link);
req.setXHTTPMethod(type.getMethod().name());
} else {
req = new ODataLinkUpdateRequest(client, type.getMethod(), targetURI, link);
}
return req;
}
@Override
public ODataDeleteRequest getDeleteRequest(final URI targetURI) {
final ODataDeleteRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataDeleteRequest(client, HttpMethod.POST, targetURI);
req.setXHTTPMethod(HttpMethod.DELETE.name());
} else {
req = new ODataDeleteRequest(client, HttpMethod.DELETE, targetURI);
}
return req;
}
}

View File

@ -1,145 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.communication.request.UpdateType;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import com.msopentech.odatajclient.engine.data.ODataLink;
import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
import com.msopentech.odatajclient.engine.data.ODataProperty;
import java.io.Serializable;
import java.net.URI;
/**
* OData request factory class.
*/
public interface CUDRequestFactory extends Serializable {
/**
* Gets a create request object instance.
* <br/>
* Use this kind of request to create a new entity.
*
* @param targetURI entity set URI.
* @param entity entity to be created.
* @return new ODataEntityCreateRequest instance.
*/
ODataEntityCreateRequest getEntityCreateRequest(URI targetURI, ODataEntity entity);
/**
* Gets an update request object instance.
*
* @param targetURI edit link of the object to be updated.
* @param type type of update to be performed.
* @param changes changes to be applied.
* @return new ODataEntityUpdateRequest instance.
*/
ODataEntityUpdateRequest getEntityUpdateRequest(URI targetURI, UpdateType type, ODataEntity changes);
/**
* Gets an update request object instance; uses entity's edit link as endpoint.
*
* @param type type of update to be performed.
* @param entity changes to be applied.
* @return new ODataEntityUpdateRequest instance.
*/
ODataEntityUpdateRequest getEntityUpdateRequest(UpdateType type, ODataEntity entity);
/**
* Gets a create request object instance.
* <br/>
* Use this kind of request to create a new value (e.g. http://Northwind.svc/Customer(1)/Picture/$value).
*
* @param targetURI entity set or entity or entity property URI.
* @param type type of update to be performed.
* @param value value to be created.
* @return new ODataValueUpdateRequest instance.
*/
ODataValueUpdateRequest getValueUpdateRequest(URI targetURI, UpdateType type, ODataPrimitiveValue value);
/**
* Gets an update request object instance.
* <br/>
* Use this kind of request to update a primitive property value.
*
* @param targetURI entity set or entity or entity property URI.
* @param property value to be update.
* @return new ODataPropertyUpdateRequest instance.
*/
ODataPropertyUpdateRequest getPropertyPrimitiveValueUpdateRequest(URI targetURI, ODataProperty property);
/**
* Gets an update request object instance.
* <br/>
* Use this kind of request to update a complex property value.
*
* @param targetURI entity set or entity or entity property URI.
* @param type type of update to be performed.
* @param property value to be update.
* @return new ODataPropertyUpdateRequest instance.
*/
ODataPropertyUpdateRequest getPropertyComplexValueUpdateRequest(
URI targetURI, UpdateType type, ODataProperty property);
/**
* Gets an update request object instance.
* <br/>
* Use this kind of request to update a collection property value.
*
* @param targetURI entity set or entity or entity property URI.
* @param property value to be update.
* @return new ODataPropertyUpdateRequest instance.
*/
ODataPropertyUpdateRequest getPropertyCollectionValueUpdateRequest(URI targetURI, ODataProperty property);
/**
* Gets an add link request object instance.
* <br/>
* Use this kind of request to create a navigation link between existing entities.
*
* @param targetURI navigation property's link collection.
* @param link navigation link to be added.
* @return new ODataLinkCreateRequest instance.
*/
ODataLinkCreateRequest getLinkCreateRequest(URI targetURI, ODataLink link);
/**
* Gets a link update request object instance.
* <br/>
* Use this kind of request to update a navigation link between existing entities.
* <br/>
* In case of the old navigation link doesn't exist the new one will be added as well.
*
* @param targetURI navigation property's link collection.
* @param type type of update to be performed.
* @param link URL that identifies the entity to be linked.
* @return new ODataLinkUpdateRequest instance.
*/
ODataLinkUpdateRequest getLinkUpdateRequest(URI targetURI, UpdateType type, ODataLink link);
/**
* Gets a delete request object instance.
* <br/>
* Use this kind of request to delete an entity and media entity as well.
*
* @param targetURI edit link of the object to be removed.
* @return new ODataDeleteRequest instance.
*/
ODataDeleteRequest getDeleteRequest(URI targetURI);
}

View File

@ -1,92 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataDeleteResponse;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import java.io.InputStream;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData delete request.
*/
public class ODataDeleteRequest extends AbstractODataBasicRequestImpl<ODataDeleteResponse, ODataPubFormat>
implements ODataBatchableRequest {
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method HTTP method to be used
* @param uri URI of the entity to be deleted.
*/
ODataDeleteRequest(final ODataClient odataClient, final HttpMethod method, final URI uri) {
super(odataClient, ODataPubFormat.class, method, uri);
}
/**
* {@inheritDoc }
* <p>
* No payload: null will be returned.
*/
@Override
protected InputStream getPayload() {
return null;
}
/**
* {@inheritDoc }
*/
@Override
public ODataDeleteResponse execute() {
return new ODataDeleteResponseImpl(httpClient, doExecute());
}
/**
* Response class about an ODataDeleteRequest.
*/
private class ODataDeleteResponseImpl extends ODataResponseImpl implements ODataDeleteResponse {
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataDeleteResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataDeleteResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
this.close();
}
}
}

View File

@ -1,124 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataEntityCreateResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import com.msopentech.odatajclient.engine.utils.URIUtils;
import java.io.InputStream;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
/**
* This class implements an OData create request.
*/
public class ODataEntityCreateRequest extends AbstractODataBasicRequestImpl<ODataEntityCreateResponse, ODataPubFormat>
implements ODataBatchableRequest {
/**
* Entity to be created.
*/
private final ODataEntity entity;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param targetURI entity set URI.
* @param entity entity to be created.
*/
ODataEntityCreateRequest(final ODataClient odataClient, final URI targetURI, final ODataEntity entity) {
super(odataClient, ODataPubFormat.class, HttpMethod.POST, targetURI);
this.entity = entity;
}
/**
* {@inheritDoc }
*/
@Override
protected InputStream getPayload() {
return odataClient.getWriter().writeEntity(entity, ODataPubFormat.fromString(getContentType()));
}
/**
* {@inheritDoc }
*/
@Override
public ODataEntityCreateResponse execute() {
final InputStream input = getPayload();
((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try {
return new ODataEntityCreateResponseImpl(httpClient, doExecute());
} finally {
IOUtils.closeQuietly(input);
}
}
/**
* Response class about an ODataEntityCreateRequest.
*/
private class ODataEntityCreateResponseImpl extends ODataResponseImpl implements ODataEntityCreateResponse {
private ODataEntity entity = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataEntityCreateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntityCreateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataEntity getBody() {
if (entity == null) {
try {
entity = odataClient.getReader().
readEntity(getRawResponse(), ODataPubFormat.fromString(getAccept()));
} finally {
this.close();
}
}
return entity;
}
}
}

View File

@ -1,130 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataEntityUpdateResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import com.msopentech.odatajclient.engine.utils.URIUtils;
import java.io.InputStream;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
/**
* This class implements an OData update request.
*/
public class ODataEntityUpdateRequest extends AbstractODataBasicRequestImpl<ODataEntityUpdateResponse, ODataPubFormat>
implements ODataBatchableRequest {
/**
* Changes to be applied.
*/
private final ODataEntity changes;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method request method.
* @param uri URI of the entity to be updated.
* @param changes changes to be applied.
*/
ODataEntityUpdateRequest(final ODataClient odataClient,
final HttpMethod method, final URI uri, final ODataEntity changes) {
super(odataClient, ODataPubFormat.class, method, uri);
this.changes = changes;
}
/**
* {@inheritDoc }
*/
@Override
public ODataEntityUpdateResponse execute() {
final InputStream input = getPayload();
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try {
return new ODataEntityUpdateResponseImpl(httpClient, doExecute());
} finally {
IOUtils.closeQuietly(input);
}
}
/**
* {@inheritDoc }
*/
@Override
protected InputStream getPayload() {
return odataClient.getWriter().writeEntity(changes, ODataPubFormat.fromString(getContentType()));
}
/**
* Response class about an ODataEntityUpdateRequest.
*/
private class ODataEntityUpdateResponseImpl extends ODataResponseImpl implements ODataEntityUpdateResponse {
/**
* Changes.
*/
private ODataEntity entity = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataEntityUpdateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntityUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc ]
*/
@Override
public ODataEntity getBody() {
if (entity == null) {
try {
entity = odataClient.getReader().
readEntity(getRawResponse(), ODataPubFormat.fromString(getAccept()));
} finally {
this.close();
}
}
return entity;
}
}
}

View File

@ -1,107 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataLinkOperationResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.data.ODataLink;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import com.msopentech.odatajclient.engine.utils.URIUtils;
import java.io.InputStream;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
/**
* This class implements an insert link OData request.
*/
public class ODataLinkCreateRequest extends AbstractODataBasicRequestImpl<ODataLinkOperationResponse, ODataFormat>
implements ODataBatchableRequest {
/**
* OData entity to be linked.
*/
private final ODataLink link;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param targetURI entity set URI.
* @param link entity to be linked.
*/
ODataLinkCreateRequest(final ODataClient odataClient, final URI targetURI, final ODataLink link) {
super(odataClient, ODataFormat.class, HttpMethod.POST, targetURI);
// set request body
this.link = link;
}
/**
* {@inheritDoc}
*/
@Override
public ODataLinkOperationResponse execute() {
final InputStream input = getPayload();
((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try {
return new ODataLinkCreateResponseImpl(httpClient, doExecute());
} finally {
IOUtils.closeQuietly(input);
}
}
/**
* {@inheritDoc}
*/
@Override
protected InputStream getPayload() {
return odataClient.getWriter().writeLink(link, ODataFormat.fromString(getContentType()));
}
/**
* This class implements the response to an OData link operation request.
*/
private class ODataLinkCreateResponseImpl extends ODataResponseImpl implements ODataLinkOperationResponse {
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataLinkCreateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataLinkCreateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
}
}

View File

@ -1,110 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataLinkOperationResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.data.ODataLink;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import com.msopentech.odatajclient.engine.utils.URIUtils;
import java.io.InputStream;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
/**
* This class implements an update link OData request.
*/
public class ODataLinkUpdateRequest extends AbstractODataBasicRequestImpl<ODataLinkOperationResponse, ODataFormat>
implements ODataBatchableRequest {
/**
* Entity to be linked.
*/
private final ODataLink link;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method request method.
* @param targetURI entity URI.
* @param link entity to be linked.
*/
ODataLinkUpdateRequest(final ODataClient odataClient,
final HttpMethod method, final URI targetURI, final ODataLink link) {
super(odataClient, ODataFormat.class, method, targetURI);
// set request body
this.link = link;
}
/**
* {@inheritDoc }
*/
@Override
public ODataLinkOperationResponse execute() {
final InputStream input = getPayload();
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try {
return new ODataLinkUpdateResponseImpl(httpClient, doExecute());
} finally {
IOUtils.closeQuietly(input);
}
}
/**
* {@inheritDoc }
*/
@Override
protected InputStream getPayload() {
return odataClient.getWriter().writeLink(link, ODataFormat.fromString(getContentType()));
}
/**
* This class implements the response to an OData link operation request.
*/
public class ODataLinkUpdateResponseImpl extends ODataResponseImpl implements ODataLinkOperationResponse {
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataLinkUpdateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
public ODataLinkUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
}
}

View File

@ -1,129 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataPropertyUpdateResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.data.ODataProperty;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import com.msopentech.odatajclient.engine.utils.URIUtils;
import java.io.InputStream;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.entity.InputStreamEntity;
/**
* This class implements an OData update entity property request.
*/
public class ODataPropertyUpdateRequest extends AbstractODataBasicRequestImpl<ODataPropertyUpdateResponse, ODataFormat>
implements ODataBatchableRequest {
/**
* Value to be created.
*/
private final ODataProperty property;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method request method.
* @param targetURI entity set or entity or entity property URI.
* @param property value to be created.
*/
ODataPropertyUpdateRequest(final ODataClient odataClient,
final HttpMethod method, final URI targetURI, final ODataProperty property) {
super(odataClient, ODataFormat.class, method, targetURI);
// set request body
this.property = property;
}
/**
* {@inheritDoc }
*/
@Override
public ODataPropertyUpdateResponse execute() {
final InputStream input = getPayload();
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try {
return new ODataPropertyUpdateResponseImpl(httpClient, doExecute());
} finally {
IOUtils.closeQuietly(input);
}
}
/**
* {@inheritDoc }
*/
@Override
protected InputStream getPayload() {
return odataClient.getWriter().writeProperty(property, ODataFormat.fromString(getContentType()));
}
/**
* Response class about an ODataPropertyUpdateRequest.
*/
private class ODataPropertyUpdateResponseImpl extends ODataResponseImpl implements ODataPropertyUpdateResponse {
private ODataProperty property = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataPropertyUpdateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataPropertyUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataProperty getBody() {
if (property == null) {
try {
property = odataClient.getReader().
readProperty(getRawResponse(), ODataFormat.fromString(getAccept()));
} finally {
this.close();
}
}
return property;
}
}
}

View File

@ -1,138 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpClientException;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataValueUpdateResponse;
import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
import com.msopentech.odatajclient.engine.data.ODataValue;
import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
import com.msopentech.odatajclient.engine.format.ODataValueFormat;
import com.msopentech.odatajclient.engine.utils.URIUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
/**
* This class implements an OData update entity property value request.
*/
public class ODataValueUpdateRequest extends AbstractODataBasicRequestImpl<ODataValueUpdateResponse, ODataValueFormat>
implements ODataBatchableRequest {
/**
* Value to be created.
*/
private final ODataValue value;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method request method.
* @param targetURI entity set or entity or entity property URI.
* @param value value to be created.
*/
ODataValueUpdateRequest(final ODataClient odataClient,
final HttpMethod method, final URI targetURI, final ODataValue value) {
super(odataClient, ODataValueFormat.class, method, targetURI);
// set request body
this.value = value;
}
/**
* {@inheritDoc }
*/
@Override
public ODataValueUpdateResponseImpl execute() {
final InputStream input = getPayload();
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try {
return new ODataValueUpdateResponseImpl(httpClient, doExecute());
} finally {
IOUtils.closeQuietly(input);
}
}
/**
* {@inheritDoc }
*/
@Override
protected InputStream getPayload() {
return IOUtils.toInputStream(value.toString());
}
/**
* Response class about an ODataValueUpdateRequest.
*/
private class ODataValueUpdateResponseImpl extends ODataResponseImpl implements ODataValueUpdateResponse {
private ODataValue value = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataValueUpdateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataValueUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataValue getBody() {
if (value == null) {
final ODataValueFormat format = ODataValueFormat.fromString(getAccept());
try {
value = new ODataPrimitiveValue.Builder(odataClient).
setType(format == ODataValueFormat.TEXT ? EdmSimpleType.String : EdmSimpleType.Stream).
setText(IOUtils.toString(getRawResponse())).
build();
} catch (IOException e) {
throw new HttpClientException(e);
} finally {
this.close();
}
}
return value;
}
}
}

View File

@ -1,31 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataV3Client;
public class V3CUDRequestFactory extends AbstractCUDRequestFactory {
private static final long serialVersionUID = 109196636064983035L;
public V3CUDRequestFactory(final ODataV3Client client) {
super(client);
}
}

View File

@ -1,31 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.cud;
import com.msopentech.odatajclient.engine.client.ODataV4Client;
public class V4CUDRequestFactory extends AbstractCUDRequestFactory {
private static final long serialVersionUID = 3080623853913380425L;
public V4CUDRequestFactory(final ODataV4Client client) {
super(client);
}
}

View File

@ -1,58 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.invoke;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.data.ODataInvokeResult;
import com.msopentech.odatajclient.engine.data.ODataValue;
import com.msopentech.odatajclient.engine.metadata.AbstractEdmMetadata;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractComplexType;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractDataServices;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEdmx;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEntityContainer;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEntityType;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractFunctionImport;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractSchema;
import java.net.URI;
import java.util.Map;
abstract class AbstractInvokeRequestFactory<META extends AbstractEdmMetadata<
EDMX, DS, S, EC, E, C, FI>, EDMX extends AbstractEdmx<DS, S, EC, E, C, FI>, DS extends AbstractDataServices<
S, EC, E, C, FI>, S extends AbstractSchema<EC, E, C, FI>, EC extends AbstractEntityContainer<
FI>, E extends AbstractEntityType, C extends AbstractComplexType, FI extends AbstractFunctionImport>
implements InvokeRequestFactory<META, EDMX, DS, S, EC, E, C, FI> {
private static final long serialVersionUID = -906760270085197249L;
protected final ODataClient client;
protected AbstractInvokeRequestFactory(final ODataClient client) {
this.client = client;
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getInvokeRequest(
final URI uri, final META metadata, final FI functionImport, final Map<String, ODataValue> parameters) {
final ODataInvokeRequest<RES> result = getInvokeRequest(uri, metadata, functionImport);
result.setParameters(parameters);
return result;
}
}

View File

@ -1,68 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.invoke;
import com.msopentech.odatajclient.engine.data.ODataInvokeResult;
import com.msopentech.odatajclient.engine.data.ODataValue;
import com.msopentech.odatajclient.engine.metadata.AbstractEdmMetadata;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractComplexType;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractDataServices;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEdmx;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEntityContainer;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEntityType;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractFunctionImport;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractSchema;
import java.io.Serializable;
import java.net.URI;
import java.util.Map;
/**
* OData request factory class.
*/
public interface InvokeRequestFactory<META extends AbstractEdmMetadata<
EDMX, DS, S, EC, E, C, FI>, EDMX extends AbstractEdmx<DS, S, EC, E, C, FI>, DS extends AbstractDataServices<
S, EC, E, C, FI>, S extends AbstractSchema<EC, E, C, FI>, EC extends AbstractEntityContainer<
FI>, E extends AbstractEntityType, C extends AbstractComplexType, FI extends AbstractFunctionImport>
extends Serializable {
/**
* Gets an invoke request instance.
*
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param uri URI that identifies the function import
* @param metadata Edm metadata
* @param functionImport function import to be invoked
* @return new ODataInvokeRequest instance.
*/
<RES extends ODataInvokeResult> ODataInvokeRequest<RES> getInvokeRequest(
URI uri, META metadata, FI functionImport);
/**
* Gets an invoke request instance.
*
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param uri URI that identifies the function import
* @param metadata Edm metadata
* @param functionImport function import to be invoked
* @param parameters parameters to pass to function import invocation
* @return new ODataInvokeRequest instance.
*/
<RES extends ODataInvokeResult> ODataInvokeRequest<RES> getInvokeRequest(
URI uri, META metadata, FI functionImport, Map<String, ODataValue> parameters);
}

View File

@ -1,235 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.invoke;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpClientException;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataInvokeResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import com.msopentech.odatajclient.engine.data.ODataEntitySet;
import com.msopentech.odatajclient.engine.data.ODataInvokeResult;
import com.msopentech.odatajclient.engine.data.ODataNoContent;
import com.msopentech.odatajclient.engine.data.ODataProperty;
import com.msopentech.odatajclient.engine.data.ODataValue;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import com.msopentech.odatajclient.engine.utils.URIUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
/**
* This class implements an OData invoke operation request.
*/
public class ODataInvokeRequest<T extends ODataInvokeResult>
extends AbstractODataBasicRequestImpl<ODataInvokeResponse<T>, ODataPubFormat>
implements ODataBatchableRequest {
private final Class<T> reference;
/**
* Function parameters.
*/
private Map<String, ODataValue> parameters;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param reference reference class for invoke result
* @param method HTTP method of the request.
* @param uri URI that identifies the operation.
*/
ODataInvokeRequest(
final ODataClient odataClient,
final Class<T> reference,
final HttpMethod method,
final URI uri) {
super(odataClient, ODataPubFormat.class, method, uri);
this.reference = reference;
this.parameters = new LinkedHashMap<String, ODataValue>();
}
/**
* Sets operation parameters.
*
* @param parameters operation parameters.
*/
public void setParameters(final Map<String, ODataValue> parameters) {
this.parameters.clear();
if (parameters != null && !parameters.isEmpty()) {
this.parameters.putAll(parameters);
}
}
/**
* {@inheritDoc }
*/
@Override
public void setFormat(final ODataPubFormat format) {
final String _format = (reference.isAssignableFrom(ODataProperty.class) && format == ODataPubFormat.ATOM)
? ODataFormat.XML.toString()
: format.toString();
setAccept(_format);
setContentType(_format);
}
/**
* {@inheritDoc }
*/
@Override
protected InputStream getPayload() {
if (!this.parameters.isEmpty() && this.method == HttpMethod.POST) {
// Additional, non-binding parameters MUST be sent as JSON
final ODataEntity tmp = odataClient.getObjectFactory().newEntity("");
for (Map.Entry<String, ODataValue> param : parameters.entrySet()) {
ODataProperty property = null;
if (param.getValue().isPrimitive()) {
property = odataClient.getObjectFactory().
newPrimitiveProperty(param.getKey(), param.getValue().asPrimitive());
} else if (param.getValue().isComplex()) {
property = odataClient.getObjectFactory().
newComplexProperty(param.getKey(), param.getValue().asComplex());
} else if (param.getValue().isCollection()) {
property = odataClient.getObjectFactory().
newCollectionProperty(param.getKey(), param.getValue().asCollection());
}
if (property != null) {
tmp.addProperty(property);
}
}
return odataClient.getWriter().writeEntity(tmp, ODataPubFormat.JSON, false);
}
return null;
}
/**
* {@inheritDoc }
*/
@Override
public ODataInvokeResponse<T> execute() {
final InputStream input = getPayload();
if (!this.parameters.isEmpty()) {
if (this.method == HttpMethod.GET) {
final URIBuilder uriBuilder = new URIBuilder(this.uri);
for (Map.Entry<String, ODataValue> param : parameters.entrySet()) {
if (!param.getValue().isPrimitive()) {
throw new IllegalArgumentException("Only primitive values can be passed via GET");
}
uriBuilder.addParameter(param.getKey(), param.getValue().toString());
}
try {
((HttpRequestBase) this.request).setURI(uriBuilder.build());
} catch (URISyntaxException e) {
throw new IllegalArgumentException("While adding GET parameters", e);
}
} else if (this.method == HttpMethod.POST) {
((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
setContentType(ODataPubFormat.JSON.toString());
}
}
try {
return new ODataInvokeResponseImpl(httpClient, doExecute());
} finally {
IOUtils.closeQuietly(input);
}
}
/**
* Response class about an ODataInvokeRequest.
*/
protected class ODataInvokeResponseImpl extends ODataResponseImpl implements ODataInvokeResponse<T> {
private T invokeResult = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataInvokeResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataInvokeResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
@SuppressWarnings("unchecked")
public T getBody() {
if (invokeResult == null) {
if (reference.isAssignableFrom(ODataNoContent.class)) {
invokeResult = (T) new ODataNoContent();
}
try {
if (reference.isAssignableFrom(ODataEntitySet.class)) {
invokeResult = (T) odataClient.getReader().readEntitySet(res.getEntity().getContent(),
ODataPubFormat.fromString(getContentType()));
}
if (reference.isAssignableFrom(ODataEntity.class)) {
invokeResult = (T) odataClient.getReader().readEntity(res.getEntity().getContent(),
ODataPubFormat.fromString(getContentType()));
}
if (reference.isAssignableFrom(ODataProperty.class)) {
invokeResult = (T) odataClient.getReader().readProperty(res.getEntity().getContent(),
ODataFormat.fromString(getContentType()));
}
} catch (IOException e) {
throw new HttpClientException(e);
} finally {
this.close();
}
}
return invokeResult;
}
}
}

View File

@ -1,88 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.invoke;
import com.msopentech.odatajclient.engine.client.ODataV3Client;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import com.msopentech.odatajclient.engine.data.ODataEntitySet;
import com.msopentech.odatajclient.engine.data.ODataInvokeResult;
import com.msopentech.odatajclient.engine.data.ODataNoContent;
import com.msopentech.odatajclient.engine.data.ODataProperty;
import com.msopentech.odatajclient.engine.metadata.EdmV3Metadata;
import com.msopentech.odatajclient.engine.metadata.EdmV3Type;
import com.msopentech.odatajclient.engine.metadata.edm.v3.ComplexType;
import com.msopentech.odatajclient.engine.metadata.edm.v3.DataServices;
import com.msopentech.odatajclient.engine.metadata.edm.v3.Edmx;
import com.msopentech.odatajclient.engine.metadata.edm.v3.EntityContainer;
import com.msopentech.odatajclient.engine.metadata.edm.v3.EntityType;
import com.msopentech.odatajclient.engine.metadata.edm.v3.FunctionImport;
import com.msopentech.odatajclient.engine.metadata.edm.v3.Schema;
import java.net.URI;
import org.apache.commons.lang3.StringUtils;
public class V3InvokeRequestFactory extends AbstractInvokeRequestFactory<
EdmV3Metadata, Edmx, DataServices, Schema, EntityContainer, EntityType, ComplexType, FunctionImport> {
private static final long serialVersionUID = -659256862901915496L;
public V3InvokeRequestFactory(final ODataV3Client client) {
super(client);
}
@Override
@SuppressWarnings("unchecked")
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getInvokeRequest(
final URI uri, final EdmV3Metadata metadata, final FunctionImport functionImport) {
HttpMethod method = null;
if (HttpMethod.GET.name().equals(functionImport.getHttpMethod())) {
method = HttpMethod.GET;
} else if (HttpMethod.POST.name().equals(functionImport.getHttpMethod())) {
method = HttpMethod.POST;
} else if (functionImport.getHttpMethod() == null) {
if (functionImport.isSideEffecting()) {
method = HttpMethod.POST;
} else {
method = HttpMethod.GET;
}
}
ODataInvokeRequest<RES> result;
if (StringUtils.isBlank(functionImport.getReturnType())) {
result = (ODataInvokeRequest<RES>) new ODataInvokeRequest<ODataNoContent>(
client, ODataNoContent.class, method, uri);
} else {
final EdmV3Type returnType = new EdmV3Type(metadata, functionImport.getReturnType());
if (returnType.isCollection() && returnType.isEntityType()) {
result = (ODataInvokeRequest<RES>) new ODataInvokeRequest<ODataEntitySet>(
client, ODataEntitySet.class, method, uri);
} else if (!returnType.isCollection() && returnType.isEntityType()) {
result = (ODataInvokeRequest<RES>) new ODataInvokeRequest<ODataEntity>(
client, ODataEntity.class, method, uri);
} else {
result = (ODataInvokeRequest<RES>) new ODataInvokeRequest<ODataProperty>(
client, ODataProperty.class, method, uri);
}
}
return result;
}
}

View File

@ -1,49 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.invoke;
import com.msopentech.odatajclient.engine.client.ODataV4Client;
import com.msopentech.odatajclient.engine.data.ODataInvokeResult;
import com.msopentech.odatajclient.engine.metadata.EdmV4Metadata;
import com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType;
import com.msopentech.odatajclient.engine.metadata.edm.v4.EntityContainer;
import com.msopentech.odatajclient.engine.metadata.edm.v4.EntityType;
import com.msopentech.odatajclient.engine.metadata.edm.v4.DataServices;
import com.msopentech.odatajclient.engine.metadata.edm.v4.Edmx;
import com.msopentech.odatajclient.engine.metadata.edm.v4.FunctionImport;
import com.msopentech.odatajclient.engine.metadata.edm.v4.Schema;
import java.net.URI;
public class V4InvokeRequestFactory extends AbstractInvokeRequestFactory<
EdmV4Metadata, Edmx, DataServices, Schema, EntityContainer, EntityType, ComplexType, FunctionImport> {
private static final long serialVersionUID = 8452737360003104372L;
public V4InvokeRequestFactory(final ODataV4Client client) {
super(client);
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getInvokeRequest(
final URI uri, final EdmV4Metadata metadata, final FunctionImport functionImport) {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View File

@ -1,97 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.communication.request.AbstractODataBasicRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import java.io.InputStream;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This is an abstract representation of an OData retrieve query request returning one or more result item.
* Get instance by using ODataRetrieveRequestFactory.
*/
abstract class AbstractODataRetrieveRequest<V, T extends Enum<T>>
extends AbstractODataBasicRequestImpl<ODataRetrieveResponse<V>, T>
implements ODataBatchableRequest {
/**
* Private constructor.
*
* @param odataClient client instance getting this request
* @param formatRef reference class for the format being used
* @param query query to be executed.
*/
AbstractODataRetrieveRequest(final ODataClient odataClient, final Class<T> formatRef, final URI query) {
super(odataClient, formatRef, HttpMethod.GET, query);
}
/**
* {@inheritDoc }
*/
@Override
public abstract ODataRetrieveResponse<V> execute();
/**
* {@inheritDoc }
* <p>
* This kind of request doesn't have any payload: null will be returned.
*/
@Override
protected InputStream getPayload() {
return null;
}
/**
* Response abstract class about an ODataRetrieveRequest.
*/
protected abstract class ODataRetrieveResponseImpl extends ODataResponseImpl implements ODataRetrieveResponse<V> {
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
protected ODataRetrieveResponseImpl() {
super();
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
protected ODataRetrieveResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public abstract V getBody();
}
}

View File

@ -1,78 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import java.net.URI;
public abstract class AbstractRetrieveRequestFactory implements RetrieveRequestFactory {
private static final long serialVersionUID = -111683263158803362L;
protected final ODataClient client;
protected AbstractRetrieveRequestFactory(final ODataClient client) {
this.client = client;
}
@Override
public ODataEntitySetRequest getEntitySetRequest(final URI query) {
return new ODataEntitySetRequest(client, query);
}
@Override
public ODataEntitySetIteratorRequest getEntitySetIteratorRequest(final URI query) {
return new ODataEntitySetIteratorRequest(client, query);
}
@Override
public ODataEntityRequest getEntityRequest(final URI query) {
return new ODataEntityRequest(client, query);
}
@Override
public ODataPropertyRequest getPropertyRequest(final URI query) {
return new ODataPropertyRequest(client, query);
}
@Override
public ODataValueRequest getValueRequest(final URI query) {
return new ODataValueRequest(client, query);
}
@Override
public ODataLinkCollectionRequest getLinkCollectionRequest(final URI targetURI, final String linkName) {
return new ODataLinkCollectionRequest(client, targetURI, linkName);
}
@Override
public ODataMediaRequest getMediaRequest(final URI query) {
return new ODataMediaRequest(client, query);
}
@Override
public ODataRawRequest getRawRequest(final URI uri) {
return new ODataRawRequest(client, uri);
}
@Override
public ODataGenericRetrieveRequest getGenericRetrieveRequest(final URI uri) {
return new ODataGenericRetrieveRequest(client, uri);
}
}

View File

@ -1,93 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData retrieve query request returning a single entity.
*/
public class ODataEntityRequest extends AbstractODataRetrieveRequest<ODataEntity, ODataPubFormat> {
/**
* Private constructor.
*
* @param odataClient client instance getting this request
* @param query query to be executed.
*/
ODataEntityRequest(final ODataClient odataClient, final URI query) {
super(odataClient, ODataPubFormat.class, query);
}
/**
* {@inheritDoc }
*/
@Override
public ODataRetrieveResponse<ODataEntity> execute() {
return new ODataEntityResponseImpl(httpClient, doExecute());
}
/**
* Response class about an ODataEntityRequest.
*/
public class ODataEntityResponseImpl extends ODataRetrieveResponseImpl {
private ODataEntity entity = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataEntityResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntityResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataEntity getBody() {
if (entity == null) {
try {
entity = odataClient.getReader().
readEntity(getRawResponse(), ODataPubFormat.fromString(getContentType()));
} finally {
this.close();
}
}
return entity;
}
}
}

View File

@ -1,83 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.data.ODataEntitySetIterator;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData EntitySet query request.
*/
public class ODataEntitySetIteratorRequest extends AbstractODataRetrieveRequest<ODataEntitySetIterator, ODataPubFormat> {
private ODataEntitySetIterator feedIterator = null;
/**
* Private constructor.
*
* @param odataClient client instance getting this request
* @param query query to be executed.
*/
ODataEntitySetIteratorRequest(final ODataClient odataClient, final URI query) {
super(odataClient, ODataPubFormat.class, query);
}
/**
* {@inheritDoc }
*/
@Override
public ODataRetrieveResponse<ODataEntitySetIterator> execute() {
final HttpResponse res = doExecute();
return new ODataEntitySetIteratorResponseImpl(httpClient, res);
}
/**
* Response class about an ODataEntitySetIteratorRequest.
*/
protected class ODataEntitySetIteratorResponseImpl extends ODataRetrieveResponseImpl {
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntitySetIteratorResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
@SuppressWarnings("unchecked")
public ODataEntitySetIterator getBody() {
if (feedIterator == null) {
feedIterator = new ODataEntitySetIterator(
odataClient, getRawResponse(), ODataPubFormat.fromString(getContentType()));
}
return feedIterator;
}
}
}

View File

@ -1,95 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.data.ODataEntitySet;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData EntitySet query request.
*/
public class ODataEntitySetRequest extends AbstractODataRetrieveRequest<ODataEntitySet, ODataPubFormat> {
private ODataEntitySet feed = null;
/**
* Private constructor.
*
* @param odataClient client instance getting this request
* @param query query to be executed.
*/
ODataEntitySetRequest(final ODataClient odataClient, final URI query) {
super(odataClient, ODataPubFormat.class, query);
}
/**
* {@inheritDoc }
*/
@Override
public ODataRetrieveResponse<ODataEntitySet> execute() {
final HttpResponse res = doExecute();
return new ODataEntitySetResponseImpl(httpClient, res);
}
/**
* Response class about an ODataEntitySetRequest.
*/
protected class ODataEntitySetResponseImpl extends ODataRetrieveResponseImpl {
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataEntitySetResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntitySetResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
@SuppressWarnings("unchecked")
public ODataEntitySet getBody() {
if (feed == null) {
try {
feed = odataClient.getReader().
readEntitySet(getRawResponse(), ODataPubFormat.fromString(getContentType()));
} finally {
this.close();
}
}
return feed;
}
}
}

View File

@ -1,107 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.data.ODataObjectWrapper;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements a generic OData retrieve query request.
*/
public class ODataGenericRetrieveRequest extends ODataRawRequest {
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param uri query request.
*/
public ODataGenericRetrieveRequest(final ODataClient odataClient, final URI uri) {
super(odataClient, uri);
}
/**
* Sets accepted format.
*
* @param format format.
*/
public void setFormat(final String format) {
setAccept(format);
setContentType(format);
}
/**
* Executes the query.
*
* @return query response.
*/
public ODataRetrieveResponse<ODataObjectWrapper> execute() {
return new ODataGenericResponseImpl(httpClient, doExecute());
}
/**
* Query response implementation about a generic query request.
*/
protected class ODataGenericResponseImpl extends ODataResponseImpl
implements ODataRetrieveResponse<ODataObjectWrapper> {
/**
* Retrieved object wrapper.
*/
private ODataObjectWrapper obj = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataGenericResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataGenericResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataObjectWrapper getBody() {
if (obj == null) {
try {
obj = new ODataObjectWrapper(odataClient.getReader(), getRawResponse(), getContentType());
} finally {
this.close();
}
}
return obj;
}
}
}

View File

@ -1,96 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpClientException;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.data.ODataLinkCollection;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import java.io.IOException;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData link query request.
*/
public class ODataLinkCollectionRequest extends AbstractODataRetrieveRequest<ODataLinkCollection, ODataFormat> {
/**
* Private constructor.
*
* @param odataClient client instance getting this request
* @param targetURI target URI.
* @param linkName link name.
*/
ODataLinkCollectionRequest(final ODataClient odataClient, final URI targetURI, final String linkName) {
super(odataClient, ODataFormat.class,
odataClient.getURIBuilder(targetURI.toASCIIString()).appendLinksSegment(linkName).build());
}
/**
* {@inheritDoc }
*/
@Override
public ODataRetrieveResponse<ODataLinkCollection> execute() {
return new ODataLinkCollectionResponseImpl(httpClient, doExecute());
}
protected class ODataLinkCollectionResponseImpl extends ODataRetrieveResponseImpl {
private ODataLinkCollection links = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataLinkCollectionResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataLinkCollectionResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataLinkCollection getBody() {
if (links == null) {
try {
links = odataClient.getReader().readLinks(
res.getEntity().getContent(), ODataFormat.fromString(getContentType()));
} catch (IOException e) {
throw new HttpClientException(e);
} finally {
this.close();
}
}
return links;
}
}
}

View File

@ -1,107 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpClientException;
import com.msopentech.odatajclient.engine.communication.header.ODataHeaders;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.format.ODataMediaFormat;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData media query request.
*/
public class ODataMediaRequest extends AbstractODataRetrieveRequest<InputStream, ODataMediaFormat> {
/**
* Private constructor.
*
* @param odataClient client instance getting this request
* @param query query to be executed.
*/
ODataMediaRequest(final ODataClient odataClient, final URI query) {
super(odataClient, ODataMediaFormat.class, query);
setAccept(ODataMediaFormat.APPLICATION_OCTET_STREAM.toString());
setContentType(ODataMediaFormat.APPLICATION_OCTET_STREAM.toString());
this.odataHeaders.removeHeader(ODataHeaders.HeaderName.minDataServiceVersion);
this.odataHeaders.removeHeader(ODataHeaders.HeaderName.maxDataServiceVersion);
this.odataHeaders.removeHeader(ODataHeaders.HeaderName.dataServiceVersion);
}
/**
* {@inheritDoc }
*/
@Override
public ODataRetrieveResponse<InputStream> execute() {
final HttpResponse res = doExecute();
return new ODataMediaResponseImpl(httpClient, res);
}
/**
* Response class about an ODataMediaRequest.
*/
protected class ODataMediaResponseImpl extends ODataRetrieveResponseImpl {
private InputStream input = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataMediaResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataMediaResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* Gets query result objects.
* <br/>
* <b>WARNING</b>: Closing this <tt>ODataResponse</tt> instance is left to the caller.
*
* @return query result objects as <tt>InputStream</tt>.
*/
@Override
public InputStream getBody() {
if (input == null) {
try {
input = res.getEntity().getContent();
} catch (IOException e) {
throw new HttpClientException(e);
}
}
return input;
}
}
}

View File

@ -1,118 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.communication.request.ODataRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.metadata.AbstractEdmMetadata;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractComplexType;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractDataServices;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEdmx;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEntityContainer;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractEntityType;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractFunctionImport;
import com.msopentech.odatajclient.engine.metadata.edm.AbstractSchema;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.entity.ContentType;
/**
* This class implements a metadata query request.
*/
class ODataMetadataRequest<META extends AbstractEdmMetadata<
EDMX, DS, S, EC, E, C, FI>, EDMX extends AbstractEdmx<DS, S, EC, E, C, FI>, DS extends AbstractDataServices<
S, EC, E, C, FI>, S extends AbstractSchema<EC, E, C, FI>, EC extends AbstractEntityContainer<
FI>, E extends AbstractEntityType, C extends AbstractComplexType, FI extends AbstractFunctionImport>
extends AbstractODataRetrieveRequest<META, ODataPubFormat> {
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param uri metadata URI.
*/
ODataMetadataRequest(final ODataClient odataClient, final URI uri) {
super(odataClient, ODataPubFormat.class, uri);
super.setAccept(ContentType.APPLICATION_XML.getMimeType());
super.setContentType(ContentType.APPLICATION_XML.getMimeType());
}
@Override
public ODataRequest setAccept(final String value) {
// do nothing: Accept is application/XML
return this;
}
@Override
public ODataRequest setContentType(final String value) {
// do nothing: Accept is application/XML
return this;
}
@Override
public ODataRetrieveResponse<META> execute() {
final HttpResponse res = doExecute();
return new ODataMetadataResponseImpl(httpClient, res);
}
/**
* Response class about an ODataMetadataRequest.
*/
protected class ODataMetadataResponseImpl extends ODataRetrieveResponseImpl {
private META metadata = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
public ODataMetadataResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataMetadataResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
@SuppressWarnings("unchecked")
public META getBody() {
if (metadata == null) {
try {
metadata = (META) odataClient.getReader().readMetadata(getRawResponse());
} finally {
this.close();
}
}
return metadata;
}
}
}

View File

@ -1,95 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpClientException;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.data.ODataProperty;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import java.io.IOException;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData entity property query request.
*/
public class ODataPropertyRequest extends AbstractODataRetrieveRequest<ODataProperty, ODataFormat> {
/**
* Private constructor.
*
* @param odataClient client instance getting this request
* @param query query to be executed.
*/
ODataPropertyRequest(final ODataClient odataClient, final URI query) {
super(odataClient, ODataFormat.class, query);
}
/**
* {@inheritDoc }
*/
@Override
public ODataRetrieveResponse<ODataProperty> execute() {
final HttpResponse res = doExecute();
return new ODataPropertyResponseImpl(httpClient, res);
}
protected class ODataPropertyResponseImpl extends ODataRetrieveResponseImpl {
private ODataProperty property = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataPropertyResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataPropertyResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataProperty getBody() {
if (property == null) {
try {
property = odataClient.getReader().readProperty(
res.getEntity().getContent(), ODataFormat.fromString(getContentType()));
} catch (IOException e) {
throw new HttpClientException(e);
} finally {
this.close();
}
}
return property;
}
}
}

View File

@ -1,41 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.ODataRequestImpl;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import java.net.URI;
/**
* This class implements a generic OData request.
*/
public class ODataRawRequest extends ODataRequestImpl<ODataPubFormat> {
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param uri request URI.
*/
ODataRawRequest(final ODataClient odataClient, final URI uri) {
super(odataClient, ODataPubFormat.class, HttpMethod.GET, uri);
}
}

View File

@ -1,91 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.data.ODataServiceDocument;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData service document request.
*/
public class ODataServiceDocumentRequest extends AbstractODataRetrieveRequest<ODataServiceDocument, ODataFormat> {
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param uri request URI.
*/
ODataServiceDocumentRequest(final ODataClient odataClient, final URI uri) {
super(odataClient, ODataFormat.class, uri);
}
/**
* {@inheritDoc }
*/
@Override
public ODataRetrieveResponse<ODataServiceDocument> execute() {
final HttpResponse res = doExecute();
return new ODataServiceResponseImpl(httpClient, res);
}
/**
* Response class about an ODataServiceDocumentRequest.
*/
protected class ODataServiceResponseImpl extends ODataRetrieveResponseImpl {
private ODataServiceDocument serviceDocument = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataServiceResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataServiceResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
@Override
public ODataServiceDocument getBody() {
if (serviceDocument == null) {
try {
serviceDocument = odataClient.getReader().readServiceDocument(
getRawResponse(), ODataFormat.fromString(getContentType()));
} finally {
this.close();
}
}
return serviceDocument;
}
}
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.metadata.EdmV3Metadata;
import com.msopentech.odatajclient.engine.metadata.edm.v3.ComplexType;
import com.msopentech.odatajclient.engine.metadata.edm.v3.DataServices;
import com.msopentech.odatajclient.engine.metadata.edm.v3.Edmx;
import com.msopentech.odatajclient.engine.metadata.edm.v3.EntityContainer;
import com.msopentech.odatajclient.engine.metadata.edm.v3.EntityType;
import com.msopentech.odatajclient.engine.metadata.edm.v3.FunctionImport;
import com.msopentech.odatajclient.engine.metadata.edm.v3.Schema;
import java.net.URI;
public class ODataV3MetadataRequest extends ODataMetadataRequest<
EdmV3Metadata, Edmx, DataServices, Schema, EntityContainer, EntityType, ComplexType, FunctionImport> {
public ODataV3MetadataRequest(final ODataClient odataClient, final URI uri) {
super(odataClient, uri);
}
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.metadata.EdmV4Metadata;
import com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType;
import com.msopentech.odatajclient.engine.metadata.edm.v4.DataServices;
import com.msopentech.odatajclient.engine.metadata.edm.v4.Edmx;
import com.msopentech.odatajclient.engine.metadata.edm.v4.EntityContainer;
import com.msopentech.odatajclient.engine.metadata.edm.v4.EntityType;
import com.msopentech.odatajclient.engine.metadata.edm.v4.FunctionImport;
import com.msopentech.odatajclient.engine.metadata.edm.v4.Schema;
import java.net.URI;
public class ODataV4MetadataRequest extends ODataMetadataRequest<
EdmV4Metadata, Edmx, DataServices, Schema, EntityContainer, EntityType, ComplexType, FunctionImport> {
public ODataV4MetadataRequest(final ODataClient odataClient, final URI uri) {
super(odataClient, uri);
}
}

View File

@ -1,105 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpClientException;
import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
import com.msopentech.odatajclient.engine.data.ODataValue;
import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
import com.msopentech.odatajclient.engine.format.ODataValueFormat;
import java.io.IOException;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData entity property value query request.
*/
public class ODataValueRequest extends AbstractODataRetrieveRequest<ODataValue, ODataValueFormat> {
/**
* Private constructor.
*
* @param odataClient client instance getting this request
* @param query query to be executed.
*/
ODataValueRequest(final ODataClient odataClient, final URI query) {
super(odataClient, ODataValueFormat.class, query);
}
/**
* {@inheritDoc }
*/
@Override
public ODataRetrieveResponse<ODataValue> execute() {
final HttpResponse res = doExecute();
return new ODataValueResponseImpl(httpClient, res);
}
/**
* Response class about an ODataDeleteReODataValueRequestquest.
*/
protected class ODataValueResponseImpl extends ODataRetrieveResponseImpl {
private ODataValue value = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataValueResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataValueResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataValue getBody() {
if (value == null) {
final ODataValueFormat format = ODataValueFormat.fromString(getContentType());
try {
value = new ODataPrimitiveValue.Builder(odataClient).
setType(format == ODataValueFormat.TEXT ? EdmSimpleType.String : EdmSimpleType.Stream).
setText(IOUtils.toString(getRawResponse())).
build();
} catch (IOException e) {
throw new HttpClientException(e);
} finally {
this.close();
}
}
return value;
}
}
}

View File

@ -1,122 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import java.io.Serializable;
import java.net.URI;
/**
* OData request factory class.
*/
public interface RetrieveRequestFactory extends Serializable {
/**
* Gets a service document request instance.
*
* @param serviceRoot absolute URL (schema, host and port included) representing the location of the root of the
* data service.
* @return new ODataServiceDocumentRequest instance.
*/
ODataServiceDocumentRequest getServiceDocumentRequest(String serviceRoot);
/**
* Gets a metadata request instance.
*
* @param serviceRoot absolute URL (schema, host and port included) representing the location of the root of the
* data service.
* @return new ODataMetadataRequest instance.
*/
ODataMetadataRequest getMetadataRequest(String serviceRoot);
/**
* Gets a query request returning a set of one or more OData entities.
*
* @param query query to be performed.
* @return new ODataEntitySetRequest instance.
*/
ODataEntitySetRequest getEntitySetRequest(URI query);
/**
* Gets a query request returning a set of one or more OData entities.
* <br/>
* Returned request gives the possibility to consume entities iterating on them without parsing and loading in
* memory the entire entity set.
*
* @param query query to be performed.
* @return new ODataEntitySetIteratorRequest instance.
*/
ODataEntitySetIteratorRequest getEntitySetIteratorRequest(URI query);
/**
* Gets a query request returning a single OData entity.
*
* @param query query to be performed.
* @return new ODataEntityRequest instance.
*/
ODataEntityRequest getEntityRequest(URI query);
/**
* Gets a query request returning a single OData entity property.
*
* @param query query to be performed.
* @return new ODataPropertyRequest instance.
*/
ODataPropertyRequest getPropertyRequest(URI query);
/**
* Gets a query request returning a single OData entity property value.
*
* @param query query to be performed.
* @return new ODataValueRequest instance.
*/
ODataValueRequest getValueRequest(URI query);
/**
* Gets a query request returning a single OData link.
*
* @param targetURI target URI.
* @param linkName link name.
* @return new ODataLinkRequest instance.
*/
ODataLinkCollectionRequest getLinkCollectionRequest(URI targetURI, String linkName);
/**
* Gets a query request returning a media stream.
*
* @param query query to be performed.
* @return new ODataMediaRequest instance.
*/
ODataMediaRequest getMediaRequest(URI query);
/**
* Implements a raw request returning a stream.
*
* @param uri query to be performed.
* @return new ODataRawRequest instance.
*/
ODataRawRequest getRawRequest(URI uri);
/**
* Implements a generic retrieve request without specifying any return type.
*
* @param uri query to be performed.
* @return new ODataGenericRerieveRequest instance.
*/
ODataGenericRetrieveRequest getGenericRetrieveRequest(URI uri);
}

View File

@ -1,45 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataV3Client;
import org.apache.commons.lang3.StringUtils;
public class V3RetrieveRequestFactory extends AbstractRetrieveRequestFactory {
private static final long serialVersionUID = 6602745001042802479L;
public V3RetrieveRequestFactory(final ODataV3Client client) {
super(client);
}
@Override
public ODataV3MetadataRequest getMetadataRequest(final String serviceRoot) {
return new ODataV3MetadataRequest(client, client.getURIBuilder(serviceRoot).appendMetadataSegment().build());
}
@Override
public ODataServiceDocumentRequest getServiceDocumentRequest(final String serviceRoot) {
return new ODataServiceDocumentRequest(client,
StringUtils.isNotBlank(serviceRoot) && serviceRoot.endsWith("/")
? client.getURIBuilder(serviceRoot).build()
: client.getURIBuilder(serviceRoot + "/").build());
}
}

View File

@ -1,44 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.retrieve;
import com.msopentech.odatajclient.engine.client.ODataV4Client;
import org.apache.commons.lang3.StringUtils;
public class V4RetrieveRequestFactory extends AbstractRetrieveRequestFactory {
private static final long serialVersionUID = 546577958047902917L;
public V4RetrieveRequestFactory(final ODataV4Client client) {
super(client);
}
@Override
public ODataV4MetadataRequest getMetadataRequest(final String serviceRoot) {
return new ODataV4MetadataRequest(client, client.getURIBuilder(serviceRoot).appendMetadataSegment().build());
}
@Override
public ODataServiceDocumentRequest getServiceDocumentRequest(final String serviceRoot) {
return new ODataServiceDocumentRequest(client,
StringUtils.isNotBlank(serviceRoot) && serviceRoot.endsWith("/")
? client.getURIBuilder(serviceRoot).build()
: client.getURIBuilder(serviceRoot + "/").build());
}
}

View File

@ -1,74 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamManager;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import com.msopentech.odatajclient.engine.format.ODataFormat;
import com.msopentech.odatajclient.engine.format.ODataPubFormat;
import java.net.URI;
import javax.security.auth.login.Configuration;
/**
* Abstract class representing a request concerning a streamed entity.
*
* @param <V> OData response type corresponding to the request implementation.
* @param <T> OData request payload type corresponding to the request implementation.
*/
public abstract class AbstractODataStreamedEntityRequestImpl<V extends ODataResponse, T extends ODataStreamManager<V>>
extends AbstractODataStreamedRequestImpl<V, T> {
private ODataPubFormat format;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method HTTP request method.
* @param uri request URI.
*/
public AbstractODataStreamedEntityRequestImpl(final ODataClient odataClient, final HttpMethod method,
URI uri) {
super(odataClient, method, uri);
setAccept(getFormat().toString());
}
/**
* Returns resource representation format.
*
* @return the configured format (or default if not specified).
* @see Configuration#getDefaultPubFormat()
*/
public final ODataPubFormat getFormat() {
return format == null ? odataClient.getConfiguration().getDefaultPubFormat() : format;
}
/**
* Override configured request format.
*
* @param format request format.
* @see ODataFormat
*/
public final void setFormat(final ODataPubFormat format) {
this.format = format;
setAccept(format.toString());
}
}

View File

@ -1,154 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.ODataRequestImpl;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamer;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamManager;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchRequest;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
import com.msopentech.odatajclient.engine.format.ODataMediaFormat;
import com.msopentech.odatajclient.engine.utils.ODataBatchConstants;
import com.msopentech.odatajclient.engine.utils.URIUtils;
import com.msopentech.odatajclient.engine.utils.Wrapper;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.entity.ContentType;
/**
* Streamed OData request abstract class.
*
* @param <V> OData response type corresponding to the request implementation.
* @param <T> OData request payload type corresponding to the request implementation.
*/
public abstract class AbstractODataStreamedRequestImpl<V extends ODataResponse, T extends ODataStreamManager<V>>
extends ODataRequestImpl<ODataMediaFormat> implements ODataStreamedRequest<V, T> {
/**
* OData payload stream manager.
*/
protected ODataStreamManager<V> streamManager;
/**
* Wrapper for actual streamed request's future.
* This holds information about the HTTP request / response currently open.
*/
protected final Wrapper<Future<HttpResponse>> futureWrapper = new Wrapper<Future<HttpResponse>>();
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method OData request HTTP method.
* @param uri OData request URI.
*/
public AbstractODataStreamedRequestImpl(final ODataClient odataClient,
final HttpMethod method, final URI uri) {
super(odataClient, ODataMediaFormat.class, method, uri);
setAccept(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
}
/**
* Gets OData request payload management object.
*
* @return OData request payload management object.
*/
protected abstract T getStreamManager();
/**
* {@inheritDoc }
*/
@Override
@SuppressWarnings("unchecked")
public T execute() {
streamManager = getStreamManager();
((HttpEntityEnclosingRequestBase) request).setEntity(
URIUtils.buildInputStreamEntity(odataClient, streamManager.getBody()));
futureWrapper.setWrapped(odataClient.getConfiguration().getExecutor().submit(new Callable<HttpResponse>() {
@Override
public HttpResponse call() throws Exception {
return doExecute();
}
}));
// returns the stream manager object
return (T) streamManager;
}
/**
* Writes (and consume) the request onto the given batch stream.
* <p>
* Please note that this method will consume the request (execution won't be possible anymore).
*
* @param req destination batch request.
*/
public void batch(final ODataBatchRequest req) {
batch(req, null);
}
/**
* Writes (and consume) the request onto the given batch stream.
* <p>
* Please note that this method will consume the request (execution won't be possible anymore).
*
* @param req destination batch request.
* @param contentId ContentId header value to be added to the serialization.
* Use this in case of changeset items.
*/
public void batch(final ODataBatchRequest req, final String contentId) {
final InputStream input = getStreamManager().getBody();
try {
// finalize the body
getStreamManager().finalizeBody();
req.rawAppend(toByteArray());
if (StringUtils.isNotBlank(contentId)) {
req.rawAppend((ODataBatchConstants.CHANGESET_CONTENT_ID_NAME + ": " + contentId).getBytes());
req.rawAppend(ODataStreamer.CRLF);
}
req.rawAppend(ODataStreamer.CRLF);
try {
req.rawAppend(IOUtils.toByteArray(input));
} catch (Exception e) {
LOG.debug("Invalid stream", e);
req.rawAppend(new byte[0]);
}
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
IOUtils.closeQuietly(input);
}
}
}

View File

@ -1,72 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import java.io.InputStream;
import java.net.URI;
public abstract class AbstractStreamedRequestFactory implements StreamedRequestFactory {
private static final long serialVersionUID = -2438839640443961168L;
protected final ODataClient client;
protected AbstractStreamedRequestFactory(final ODataClient client) {
this.client = client;
}
@Override
public ODataMediaEntityCreateRequest getMediaEntityCreateRequest(
final URI targetURI, final InputStream media) {
return new ODataMediaEntityCreateRequest(client, targetURI, media);
}
@Override
public ODataStreamUpdateRequest getStreamUpdateRequest(final URI targetURI, final InputStream stream) {
final ODataStreamUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataStreamUpdateRequest(client, HttpMethod.POST, targetURI, stream);
req.setXHTTPMethod(HttpMethod.PUT.name());
} else {
req = new ODataStreamUpdateRequest(client, HttpMethod.PUT, targetURI, stream);
}
return req;
}
@Override
public ODataMediaEntityUpdateRequest getMediaEntityUpdateRequest(
final URI editURI, final InputStream media) {
final ODataMediaEntityUpdateRequest req;
if (client.getConfiguration().isUseXHTTPMethod()) {
req = new ODataMediaEntityUpdateRequest(client, HttpMethod.POST, editURI, media);
req.setXHTTPMethod(HttpMethod.PUT.name());
} else {
req = new ODataMediaEntityUpdateRequest(client, HttpMethod.PUT, editURI, media);
}
return req;
}
}

View File

@ -1,133 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamManager;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.request.streamed.ODataMediaEntityCreateRequest.MediaEntityCreateStreamManager;
import com.msopentech.odatajclient.engine.communication.response.ODataMediaEntityCreateResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData Media Entity create request.
* Get instance by using ODataStreamedRequestFactory.
*/
public class ODataMediaEntityCreateRequest
extends AbstractODataStreamedEntityRequestImpl<ODataMediaEntityCreateResponse, MediaEntityCreateStreamManager>
implements ODataBatchableRequest {
private final InputStream media;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param targetURI target entity set.
* @param media media entity blob to be created.
*/
ODataMediaEntityCreateRequest(final ODataClient odataClient, final URI targetURI, final InputStream media) {
super(odataClient, HttpMethod.POST, targetURI);
this.media = media;
}
/**
* {@inheritDoc }
*/
@Override
protected MediaEntityCreateStreamManager getStreamManager() {
if (streamManager == null) {
streamManager = new MediaEntityCreateStreamManager(media);
}
return (MediaEntityCreateStreamManager) streamManager;
}
/**
* Media entity payload object.
*/
public class MediaEntityCreateStreamManager extends ODataStreamManager<ODataMediaEntityCreateResponse> {
/**
* Private constructor.
*
* @param input media stream.
*/
private MediaEntityCreateStreamManager(final InputStream input) {
super(ODataMediaEntityCreateRequest.this.futureWrapper, input);
}
/**
* {@inheritDoc }
*/
@Override
protected ODataMediaEntityCreateResponse getResponse(final long timeout, final TimeUnit unit) {
finalizeBody();
return new ODataMediaEntityCreateResponseImpl(httpClient, getHttpResponse(timeout, unit));
}
}
/**
* Response class about an ODataMediaEntityCreateRequest.
*/
private class ODataMediaEntityCreateResponseImpl extends ODataResponseImpl
implements ODataMediaEntityCreateResponse {
private ODataEntity entity = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataMediaEntityCreateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataMediaEntityCreateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataEntity getBody() {
if (entity == null) {
try {
entity = odataClient.getReader().readEntity(getRawResponse(), getFormat());
} finally {
this.close();
}
}
return entity;
}
}
}

View File

@ -1,136 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamManager;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.request.streamed.ODataMediaEntityUpdateRequest.MediaEntityUpdateStreamManager;
import com.msopentech.odatajclient.engine.communication.response.ODataMediaEntityUpdateResponse;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.data.ODataEntity;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData Media Entity create request.
* Get instance by using ODataStreamedRequestFactory.
*/
public class ODataMediaEntityUpdateRequest
extends AbstractODataStreamedEntityRequestImpl<ODataMediaEntityUpdateResponse, MediaEntityUpdateStreamManager>
implements ODataBatchableRequest {
private final InputStream media;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method request method.
* @param editURI edit URI of the entity to be updated.
* @param media media entity blob to be created.
*/
ODataMediaEntityUpdateRequest(final ODataClient odataClient,
final HttpMethod method, final URI editURI, final InputStream media) {
super(odataClient, method, editURI);
this.media = media;
}
/**
* {@inheritDoc }
*/
@Override
protected MediaEntityUpdateStreamManager getStreamManager() {
if (streamManager == null) {
streamManager = new MediaEntityUpdateStreamManager(media);
}
return (MediaEntityUpdateStreamManager) streamManager;
}
/**
* Media entity payload object.
*/
public class MediaEntityUpdateStreamManager extends ODataStreamManager<ODataMediaEntityUpdateResponse> {
/**
* Private constructor.
*
* @param input media stream.
*/
private MediaEntityUpdateStreamManager(final InputStream input) {
super(ODataMediaEntityUpdateRequest.this.futureWrapper, input);
}
/**
* {@inheritDoc }
*/
@Override
protected ODataMediaEntityUpdateResponse getResponse(final long timeout, final TimeUnit unit) {
finalizeBody();
return new ODataMediaEntityUpdateResponseImpl(httpClient, getHttpResponse(timeout, unit));
}
}
/**
* Response class about an ODataMediaEntityUpdateRequest.
*/
private class ODataMediaEntityUpdateResponseImpl extends ODataResponseImpl
implements ODataMediaEntityUpdateResponse {
private ODataEntity entity = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataMediaEntityUpdateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataMediaEntityUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* {@inheritDoc }
*/
@Override
public ODataEntity getBody() {
if (entity == null) {
try {
entity = odataClient.getReader().readEntity(getRawResponse(), getFormat());
} finally {
this.close();
}
}
return entity;
}
}
}

View File

@ -1,132 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.client.ODataClient;
import com.msopentech.odatajclient.engine.client.http.HttpMethod;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamManager;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchableRequest;
import com.msopentech.odatajclient.engine.communication.request.streamed.ODataStreamUpdateRequest.StreamUpdateStreamManager;
import com.msopentech.odatajclient.engine.communication.response.ODataResponseImpl;
import com.msopentech.odatajclient.engine.communication.response.ODataStreamUpdateResponse;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
/**
* This class implements an OData stream create/update request.
* Get instance by using ODataStreamedRequestFactory.
*/
public class ODataStreamUpdateRequest
extends AbstractODataStreamedRequestImpl<ODataStreamUpdateResponse, StreamUpdateStreamManager>
implements ODataBatchableRequest {
private final InputStream stream;
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param method request method.
* @param targetURI target URI.
* @param stream stream to be updated.
*/
ODataStreamUpdateRequest(final ODataClient odataClient,
final HttpMethod method, final URI targetURI, final InputStream stream) {
super(odataClient, method, targetURI);
this.stream = stream;
}
/**
* {@inheritDoc }
*/
@Override
protected StreamUpdateStreamManager getStreamManager() {
if (streamManager == null) {
streamManager = new StreamUpdateStreamManager(this.stream);
}
return (StreamUpdateStreamManager) streamManager;
}
public class StreamUpdateStreamManager extends ODataStreamManager<ODataStreamUpdateResponse> {
/**
* Private constructor.
*
* @param input payload input stream.
*/
private StreamUpdateStreamManager(final InputStream input) {
super(ODataStreamUpdateRequest.this.futureWrapper, input);
}
/**
* {@inheritDoc }
*/
@Override
protected ODataStreamUpdateResponse getResponse(final long timeout, final TimeUnit unit) {
finalizeBody();
return new ODataStreamUpdateResponseImpl(httpClient, getHttpResponse(timeout, unit));
}
}
/**
* Response class about an ODataStreamUpdateRequest.
*/
private class ODataStreamUpdateResponseImpl extends ODataResponseImpl implements ODataStreamUpdateResponse {
private InputStream input = null;
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataStreamUpdateResponseImpl() {
}
/**
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataStreamUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
}
/**
* Gets query result objects.
* <br/>
* <b>WARNING</b>: Closing this <tt>ODataResponse</tt> instance is left to the caller.
*
* @return query result objects as <tt>InputStream</tt>.
*/
@Override
public InputStream getBody() {
if (input == null) {
input = getRawResponse();
}
return input;
}
}
}

View File

@ -1,40 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.communication.request.ODataRequest;
import com.msopentech.odatajclient.engine.communication.request.ODataStreamManager;
import com.msopentech.odatajclient.engine.communication.response.ODataResponse;
/**
* Streamed OData request interface.
*
* @param <V> OData response type corresponding to the request implementation.
* @param <T> OData request payload type corresponding to the request implementation.
*/
public interface ODataStreamedRequest<V extends ODataResponse, T extends ODataStreamManager<V>>
extends ODataRequest {
/**
* Streamed request execute.
*
* @return OData request payload manager object.
*/
T execute();
}

View File

@ -1,62 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URI;
/**
* OData request factory class.
*/
public interface StreamedRequestFactory extends Serializable {
/**
* Gets a media entity create request object instance.
* <br/>
* Use this kind of request to create a new media entity.
*
* @param targetURI entity set URI.
* @param media entity blob to be created.
* @return new ODataMediaEntityCreateRequest instance.
*/
ODataMediaEntityCreateRequest getMediaEntityCreateRequest(URI targetURI, InputStream media);
/**
* Gets a stream update request object instance.
* <br/>
* Use this kind of request to update a named stream property.
*
* @param targetURI target URI.
* @param stream stream to be updated.
* @return new ODataStreamUpdateRequest instance.
*/
ODataStreamUpdateRequest getStreamUpdateRequest(URI targetURI, InputStream stream);
/**
* Gets a media entity update request object instance.
* <br/>
* Use this kind of request to update a media entity.
*
* @param editURI media entity edit link URI.
* @param media entity blob to be updated.
* @return new ODataMediaEntityUpdateRequest instance.
*/
ODataMediaEntityUpdateRequest getMediaEntityUpdateRequest(URI editURI, InputStream media);
}

View File

@ -1,31 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.client.ODataV3Client;
public class V3StreamedRequestFactory extends AbstractStreamedRequestFactory {
private static final long serialVersionUID = 2255688283995758441L;
public V3StreamedRequestFactory(final ODataV3Client client) {
super(client);
}
}

View File

@ -1,31 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.request.streamed;
import com.msopentech.odatajclient.engine.client.ODataV4Client;
public class V4StreamedRequestFactory extends AbstractStreamedRequestFactory {
private static final long serialVersionUID = 960862845654673053L;
public V4StreamedRequestFactory(final ODataV4Client client) {
super(client);
}
}

View File

@ -1,37 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.response;
import com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchResponseItem;
import java.util.Iterator;
/**
* This class implements a response to a batch request.
*
* @see com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchRequest
*/
public interface ODataBatchResponse extends ODataResponse {
/**
* Get all the batch response items.
*
* @return an iterator on batch response items.
*/
Iterator<ODataBatchResponseItem> getBody();
}

View File

@ -1,27 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.response;
/**
* This class implements the response to an OData delete request.
*
* @see com.msopentech.odatajclient.engine.communication.request.cud.ODataDeleteRequest
*/
public interface ODataDeleteResponse extends ODataResponse {
}

View File

@ -1,36 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.response;
import com.msopentech.odatajclient.engine.data.ODataEntity;
/**
* This class implements the response to an OData entity create request.
*
* @see com.msopentech.odatajclient.engine.communication.request.cud.ODataEntityCreateRequest
*/
public interface ODataEntityCreateResponse extends ODataResponse {
/**
* Gets created object.
*
* @return created object.
*/
ODataEntity getBody();
}

View File

@ -1,36 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.msopentech.odatajclient.engine.communication.response;
import com.msopentech.odatajclient.engine.data.ODataEntity;
/**
* This class implements the response to an OData update request.
*
* @see com.msopentech.odatajclient.engine.communication.request.cud.ODataEntityUpdateRequest
*/
public interface ODataEntityUpdateResponse extends ODataResponse {
/**
* Gets updated object.
*
* @return updated object.
*/
ODataEntity getBody();
}

Some files were not shown because too many files have changed in this diff Show More