[OLINGO-832] Removed actual not supported/wanted methods
This commit is contained in:
parent
dc2c972c46
commit
5174f70897
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
import org.apache.olingo.commons.api.ex.ODataNotSupportedException;
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
|
@ -35,7 +36,7 @@ public abstract class EntityIterator extends AbstractEntityCollection implements
|
|||
@Override
|
||||
public void remove() {
|
||||
//"Remove is not supported for iteration over Entities."
|
||||
throw new NotImplementedException();
|
||||
throw new ODataNotSupportedException("Entity Iterator does not support remove()");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,15 +45,14 @@ public abstract class EntityIterator extends AbstractEntityCollection implements
|
|||
}
|
||||
|
||||
public Integer getCount() {
|
||||
throw new ODataRuntimeException("getCount() not supported for " + getClass().getSimpleName());
|
||||
throw new ODataNotSupportedException("Entity Iterator does not support getCount()");
|
||||
}
|
||||
|
||||
public URI getNext() {
|
||||
throw new ODataRuntimeException("getNext() not supported for " + getClass().getSimpleName());
|
||||
|
||||
throw new ODataNotSupportedException("Entity Iterator does not support getNext()");
|
||||
}
|
||||
|
||||
public URI getDeltaLink() {
|
||||
throw new ODataRuntimeException("getDeltaLink() not supported for " + getClass().getSimpleName());
|
||||
throw new ODataNotSupportedException("Entity Iterator does not support getDeltaLink()");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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.olingo.commons.api.ex;
|
||||
|
||||
/**
|
||||
* Core runtime exception for OData.
|
||||
*/
|
||||
public class ODataNotSupportedException extends ODataRuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 42L;
|
||||
|
||||
/**
|
||||
* Create with <code>message</code>.
|
||||
*
|
||||
* @param msg message text for exception
|
||||
*/
|
||||
public ODataNotSupportedException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create with <code>message</code> for and <code>cause</code> of exception.
|
||||
*
|
||||
* @param msg message text for exception
|
||||
* @param cause cause of exception
|
||||
*/
|
||||
public ODataNotSupportedException(final String msg, final Exception cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create with <code>cause</code> of exception.
|
||||
*
|
||||
* @param cause cause of exception
|
||||
*/
|
||||
public ODataNotSupportedException(final Exception cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,15 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.server.api;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
public interface ODataContent {
|
||||
ReadableByteChannel getChannel();
|
||||
|
||||
void write(WritableByteChannel channel);
|
||||
|
||||
void write(WritableByteChannel channel, WriteContentErrorCallback callback);
|
||||
|
||||
boolean isWriteSupported();
|
||||
void write(OutputStream stream);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.olingo.server.api.serializer;
|
||||
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.server.api.WriteContentErrorCallback;
|
||||
import org.apache.olingo.server.api.uri.queryoption.CountOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||
|
@ -32,6 +33,7 @@ public class EntityCollectionSerializerOptions {
|
|||
private SelectOption select;
|
||||
private boolean writeOnlyReferences;
|
||||
private String id;
|
||||
private WriteContentErrorCallback writeContentErrorCallback;
|
||||
|
||||
/** Gets the {@link ContextURL}. */
|
||||
public ContextURL getContextURL() {
|
||||
|
@ -63,6 +65,18 @@ public class EntityCollectionSerializerOptions {
|
|||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the callback which is used in case of an exception during
|
||||
* write of the content (in case the content will be written/streamed
|
||||
* in the future)
|
||||
* @return callback which is used in case of an exception during
|
||||
* write of the content
|
||||
*
|
||||
*/
|
||||
public WriteContentErrorCallback getWriteContentErrorCallback() {
|
||||
return writeContentErrorCallback;
|
||||
}
|
||||
|
||||
/** Initializes the options builder. */
|
||||
public static Builder with() {
|
||||
return new Builder();
|
||||
|
@ -113,6 +127,18 @@ public class EntityCollectionSerializerOptions {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the callback which is used in case of an exception during
|
||||
* write of the content.
|
||||
*
|
||||
* @param writeContentErrorCallback the callback
|
||||
* @return the builder
|
||||
*/
|
||||
public Builder writeContentErrorCallback(WriteContentErrorCallback writeContentErrorCallback) {
|
||||
options.writeContentErrorCallback = writeContentErrorCallback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Builds the OData serializer options. */
|
||||
public EntityCollectionSerializerOptions build() {
|
||||
return options;
|
||||
|
|
|
@ -18,11 +18,7 @@
|
|||
*/
|
||||
package org.apache.olingo.server.api.serializer;
|
||||
|
||||
import org.apache.olingo.server.api.ODataContent;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
/**
|
||||
* Result type for {@link ODataSerializer} methods
|
||||
|
@ -33,6 +29,4 @@ public interface SerializerResult {
|
|||
* @return serialized content
|
||||
*/
|
||||
InputStream getContent();
|
||||
|
||||
ODataContent getODataContent();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.olingo.server.api.ODataContent;
|
|||
|
||||
/**
|
||||
* Result type for {@link ODataSerializer} methods
|
||||
* which supports stream/write in the future
|
||||
*/
|
||||
public interface SerializerStreamResult {
|
||||
/**
|
||||
|
|
|
@ -1,59 +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 org.apache.olingo.server.core;
|
||||
|
||||
import org.apache.olingo.server.api.ODataContent;
|
||||
import org.apache.olingo.server.api.WriteContentErrorCallback;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
public class ODataBasicContent implements ODataContent {
|
||||
private final ReadableByteChannel channel;
|
||||
|
||||
public ODataBasicContent(ReadableByteChannel channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public ODataBasicContent(InputStream stream) {
|
||||
this(Channels.newChannel(stream));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableByteChannel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(WritableByteChannel channel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(WritableByteChannel channel, WriteContentErrorCallback callback) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWriteSupported() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -161,11 +161,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
|||
static void writeContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
|
||||
try {
|
||||
ODataContent res = odataResponse.getODataContent();
|
||||
if(res.isWriteSupported()) {
|
||||
res.write(Channels.newChannel(servletResponse.getOutputStream()));
|
||||
} else {
|
||||
copyContent(res.getChannel(), servletResponse);
|
||||
}
|
||||
res.write(Channels.newChannel(servletResponse.getOutputStream()));
|
||||
} catch (IOException e) {
|
||||
throw new ODataRuntimeException("Error on reading request content", e);
|
||||
}
|
||||
|
|
|
@ -18,22 +18,6 @@
|
|||
*/
|
||||
package org.apache.olingo.server.core;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntityIterator;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.server.api.ODataContent;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.WriteContentErrorCallback;
|
||||
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.apache.olingo.server.api.serializer.SerializerStreamResult;
|
||||
import org.apache.olingo.server.core.serializer.SerializerStreamResultImpl;
|
||||
import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
|
||||
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -42,6 +26,22 @@ import java.nio.channels.ReadableByteChannel;
|
|||
import java.nio.channels.WritableByteChannel;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntityIterator;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.server.api.ODataContent;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.apache.olingo.server.api.serializer.SerializerStreamResult;
|
||||
import org.apache.olingo.server.core.serializer.SerializerStreamResultImpl;
|
||||
import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
|
||||
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
public class ODataWritableContent implements ODataContent {
|
||||
private StreamChannel channel;
|
||||
|
||||
|
@ -184,17 +184,10 @@ public class ODataWritableContent implements ODataContent {
|
|||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public InputStream getContent() {
|
||||
// return Channels.newInputStream(this.channel);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public ReadableByteChannel getChannel() {
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWriteSupported() {
|
||||
return true;
|
||||
}
|
||||
|
@ -212,9 +205,8 @@ public class ODataWritableContent implements ODataContent {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(WritableByteChannel channel, WriteContentErrorCallback callback) {
|
||||
// TODO: implement error handling
|
||||
throw new ODataRuntimeException("error handling not yet supported");
|
||||
public void write(OutputStream stream) {
|
||||
write(Channels.newChannel(stream));
|
||||
}
|
||||
|
||||
private ODataWritableContent(StreamChannel channel) {
|
||||
|
|
|
@ -18,34 +18,19 @@
|
|||
*/
|
||||
package org.apache.olingo.server.core.serializer;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.olingo.server.api.ODataContent;
|
||||
import org.apache.olingo.server.api.serializer.SerializerResult;
|
||||
import org.apache.olingo.server.api.serializer.SerializerStreamResult;
|
||||
import org.apache.olingo.server.core.ODataBasicContent;
|
||||
import org.apache.olingo.server.core.serializer.utils.ResultHelper;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
public class SerializerResultImpl implements SerializerResult {
|
||||
private InputStream content;
|
||||
private ODataContent oDataContent;
|
||||
|
||||
@Override
|
||||
public InputStream getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataContent getODataContent() {
|
||||
if(oDataContent == null && content != null) {
|
||||
return new ODataBasicContent(content);
|
||||
}
|
||||
return oDataContent;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public ReadableByteChannel getChannel() {
|
||||
// return Channels.newChannel(getContent());
|
||||
|
@ -73,11 +58,6 @@ public class SerializerResultImpl implements SerializerResult {
|
|||
return this;
|
||||
}
|
||||
|
||||
public SerializerResultBuilder content(final ODataContent input) {
|
||||
result.oDataContent = input;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SerializerResult build() {
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
*/
|
||||
package org.apache.olingo.server.tecsvc.processor;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -44,6 +49,7 @@ import org.apache.olingo.server.api.ODataLibraryException;
|
|||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.WriteContentErrorCallback;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerResult;
|
||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
||||
import org.apache.olingo.server.api.prefer.Preferences.Return;
|
||||
|
@ -531,7 +537,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
|||
if(isReference) {
|
||||
final SerializerResult serializerResult =
|
||||
serializeReferenceCollection(entitySetSerialization, edmEntitySet, requestedContentType, countOption);
|
||||
response.setODataContent(serializerResult.getODataContent());
|
||||
response.setContent(serializerResult.getContent());
|
||||
} else {
|
||||
final SerializerStreamResult serializerResult =
|
||||
serializeEntityStreamCollectionFixed(request,
|
||||
|
@ -540,6 +546,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
|||
|
||||
response.setODataContent(serializerResult.getODataContent());
|
||||
}
|
||||
|
||||
//
|
||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
|
||||
|
|
Loading…
Reference in New Issue