Skip to content

Commit

Permalink
CAMEL-8358: Refactored Olingo2 component to avoid using classes from …
Browse files Browse the repository at this point in the history
…Olingo2 core package
  • Loading branch information
dhirajsb committed Feb 16, 2015
1 parent 1b21156 commit 21795ee
Show file tree
Hide file tree
Showing 11 changed files with 607 additions and 94 deletions.
23 changes: 12 additions & 11 deletions components/camel-olingo2/camel-olingo2-api/pom.xml
Expand Up @@ -40,17 +40,6 @@
<artifactId>olingo-odata2-api</artifactId>
<version>${olingo2-version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-core</artifactId>
<version>${olingo2-version}</version>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
Expand All @@ -74,6 +63,18 @@
</dependency>

<!-- testing -->
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-core</artifactId>
<version>${olingo2-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
Expand Down
Expand Up @@ -17,26 +17,28 @@
package org.apache.camel.component.olingo2.api.impl;

import java.io.IOException;
import java.util.regex.Pattern;

import org.apache.camel.component.olingo2.api.Olingo2ResponseHandler;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ContentType;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.ep.EntityProvider;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.api.exception.ODataApplicationException;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.processor.ODataErrorContext;
import org.apache.olingo.odata2.core.commons.ContentType;

/**
* Helper implementation of {@link org.apache.http.concurrent.FutureCallback}
* for {@link org.apache.camel.component.olingo2.api.impl.Olingo2AppImpl}
*/
public abstract class AbstractFutureCallback<T> implements FutureCallback<HttpResponse> {

public static final Pattern ODATA_MIME_TYPE = Pattern.compile("application/((atom)|(json)|(xml)).*");
private final Olingo2ResponseHandler<T> responseHandler;

AbstractFutureCallback(Olingo2ResponseHandler<T> responseHandler) {
Expand All @@ -49,21 +51,17 @@ public static HttpStatusCodes checkStatus(HttpResponse response) throws ODataApp
if (400 <= httpStatusCode.getStatusCode() && httpStatusCode.getStatusCode() <= 599) {
if (response.getEntity() != null) {
try {
final ContentType responseContentType = ContentType.create(
final ContentType responseContentType = ContentType.parse(
response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());

switch (responseContentType.getODataFormat()) {
case ATOM:
case XML:
case JSON:
final String mimeType = responseContentType.getMimeType();
if (ODATA_MIME_TYPE.matcher(mimeType).matches()) {
final ODataErrorContext errorContext = EntityProvider.readErrorDocument(
response.getEntity().getContent(),
responseContentType.toString());
throw new ODataApplicationException(errorContext.getMessage(),
errorContext.getLocale(), httpStatusCode, errorContext.getErrorCode(),
errorContext.getException());
default:
// fall through to default exception with status line information
}
} catch (EntityProviderException e) {
throw new ODataApplicationException(e.getMessage(), response.getLocale(), httpStatusCode, e);
Expand Down
@@ -0,0 +1,58 @@
/**
* 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 org.apache.camel.component.olingo2.api.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.olingo.odata2.api.uri.PathSegment;

/**
* Copied from Olingo2 library, since URI parsing wasn't made a part of it's public API.
*/
public class ODataPathSegmentImpl implements PathSegment {

private String path;
private Map<String, List<String>> matrixParameter;

public ODataPathSegmentImpl(final String path, final Map<String, List<String>> matrixParameters) {
this.path = path;

Map<String, List<String>> unmodifiableMap = new HashMap<String, List<String>>();
if (matrixParameters != null) {
for (String key : matrixParameters.keySet()) {
List<String> values = Collections.unmodifiableList(matrixParameters.get(key));
unmodifiableMap.put(key, values);
}
}

matrixParameter = Collections.unmodifiableMap(unmodifiableMap);
}

@Override
public String getPath() {
return path;
}

@Override
public Map<String, List<String>> getMatrixParameters() {
return matrixParameter;
}

}

0 comments on commit 21795ee

Please sign in to comment.