[OLINGO-936] fix sonar issues
This commit is contained in:
parent
ff87212deb
commit
f18a489f97
|
@ -20,6 +20,7 @@ package org.apache.olingo.server.core.debug;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -39,6 +40,7 @@ import org.apache.olingo.server.api.uri.UriInfo;
|
|||
|
||||
public class ServerCoreDebugger {
|
||||
|
||||
private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
|
||||
private final List<RuntimeMeasurement> runtimeInformation = new ArrayList<RuntimeMeasurement>();
|
||||
private final OData odata;
|
||||
|
||||
|
@ -82,7 +84,8 @@ public class ServerCoreDebugger {
|
|||
ODataResponse odResponse = new ODataResponse();
|
||||
odResponse.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||
odResponse.setHeader(HttpHeader.CONTENT_TYPE, ContentType.TEXT_PLAIN.toContentTypeString());
|
||||
InputStream content = new ByteArrayInputStream("ODataLibrary: Could not assemble debug response.".getBytes());
|
||||
InputStream content = new ByteArrayInputStream("ODataLibrary: Could not assemble debug response."
|
||||
.getBytes(DEFAULT_ENCODING));
|
||||
odResponse.setContent(content);
|
||||
return odResponse;
|
||||
}
|
||||
|
|
|
@ -44,17 +44,11 @@ public class BatchParser {
|
|||
|
||||
private List<BatchRequestPart> parse(final InputStream in, final String boundary,
|
||||
final BatchRequestTransformator transformator)
|
||||
throws BatchDeserializerException {
|
||||
throws BatchDeserializerException {
|
||||
try {
|
||||
return parseBatch(in, boundary, transformator);
|
||||
} catch (IOException e) {
|
||||
throw new ODataRuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
throw new ODataRuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +66,7 @@ public class BatchParser {
|
|||
}
|
||||
|
||||
private List<List<Line>> splitBodyParts(final InputStream in, final String boundary) throws IOException,
|
||||
BatchDeserializerException {
|
||||
BatchDeserializerException {
|
||||
final BatchLineReader reader = new BatchLineReader(in);
|
||||
final List<Line> message = reader.toLineList();
|
||||
reader.close();
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
|
||||
public class Header implements Iterable<HeaderField>, Cloneable {
|
||||
private final Map<String, HeaderField> headers = new HashMap<String, HeaderField>();
|
||||
private Map<String, HeaderField> headers = new HashMap<String, HeaderField>();
|
||||
private int lineNumber;
|
||||
|
||||
public Header(final int lineNumer) {
|
||||
|
@ -111,7 +111,6 @@ public class Header implements Iterable<HeaderField>, Cloneable {
|
|||
|
||||
private HeaderField getHeaderFieldOrDefault(final String name, final int lineNumber) {
|
||||
HeaderField headerField = headers.get(name.toLowerCase(Locale.ENGLISH));
|
||||
|
||||
if (headerField == null) {
|
||||
headerField = new HeaderField(name, lineNumber);
|
||||
headers.put(name.toLowerCase(Locale.ENGLISH), headerField);
|
||||
|
@ -121,14 +120,15 @@ public class Header implements Iterable<HeaderField>, Cloneable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Header clone() {
|
||||
final Header newInstance = new Header(lineNumber);
|
||||
|
||||
public Header clone() throws CloneNotSupportedException{
|
||||
Header clone = (Header) super.clone();
|
||||
clone.lineNumber = lineNumber;
|
||||
clone.headers = new HashMap<String, HeaderField>();
|
||||
for (final Map.Entry<String, HeaderField> entries : headers.entrySet()) {
|
||||
newInstance.headers.put(entries.getKey(), entries.getValue().clone());
|
||||
clone.headers.put(entries.getKey(), entries.getValue().clone());
|
||||
}
|
||||
|
||||
return newInstance;
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,8 +23,8 @@ import java.util.List;
|
|||
|
||||
public class HeaderField implements Cloneable {
|
||||
private final String fieldName;
|
||||
private final List<String> values;
|
||||
private final int lineNumber;
|
||||
private List<String> values;
|
||||
|
||||
public HeaderField(final String fieldName, final int lineNumber) {
|
||||
this(fieldName, new ArrayList<String>(), lineNumber);
|
||||
|
@ -60,11 +60,11 @@ public class HeaderField implements Cloneable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HeaderField clone() {
|
||||
List<String> newValues = new ArrayList<String>(values.size());
|
||||
newValues.addAll(values);
|
||||
|
||||
return new HeaderField(fieldName, newValues, lineNumber);
|
||||
public HeaderField clone() throws CloneNotSupportedException{
|
||||
HeaderField clone = (HeaderField) super.clone();
|
||||
clone.values = new ArrayList<String>(values.size());
|
||||
clone.values.addAll(values);
|
||||
return clone;
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
|
|
|
@ -110,19 +110,19 @@ public class BatchResponseSerializer {
|
|||
|
||||
private void appendHeader(final String name, final String value, final BodyBuilder builder) {
|
||||
builder.append(name)
|
||||
.append(COLON)
|
||||
.append(SP)
|
||||
.append(value)
|
||||
.append(CRLF);
|
||||
.append(COLON)
|
||||
.append(SP)
|
||||
.append(value)
|
||||
.append(CRLF);
|
||||
}
|
||||
|
||||
private void appendStatusLine(final ODataResponse response, final BodyBuilder builder) {
|
||||
builder.append("HTTP/1.1")
|
||||
.append(SP)
|
||||
.append(response.getStatusCode())
|
||||
.append(SP)
|
||||
.append(getStatusCodeInfo(response))
|
||||
.append(CRLF);
|
||||
.append(SP)
|
||||
.append(response.getStatusCode())
|
||||
.append(SP)
|
||||
.append(getStatusCodeInfo(response))
|
||||
.append(CRLF);
|
||||
}
|
||||
|
||||
private String getStatusCodeInfo(final ODataResponse response) {
|
||||
|
@ -234,11 +234,11 @@ public class BatchResponseSerializer {
|
|||
content = getBody(response);
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
private int getLength() {
|
||||
return content.length;
|
||||
}
|
||||
|
||||
public byte[] getContent() {
|
||||
private byte[] getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -86,7 +87,7 @@ public class HeaderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void deepCopy() {
|
||||
public void deepCopy() throws Exception {
|
||||
Header header = new Header(1);
|
||||
header.addHeader(HttpHeader.CONTENT_TYPE, ContentType.MULTIPART_MIXED + ";boundary=123", 1);
|
||||
|
||||
|
@ -99,6 +100,21 @@ public class HeaderTest {
|
|||
assertTrue(header.getHeaderField(HttpHeader.CONTENT_TYPE) != copy.getHeaderField(HttpHeader.CONTENT_TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deepCopyHeaderField() throws Exception {
|
||||
List<String> values = new ArrayList<String>();
|
||||
values.add("abc");
|
||||
values.add("def");
|
||||
HeaderField field = new HeaderField("name", values, 17);
|
||||
|
||||
HeaderField clone = field.clone();
|
||||
assertEquals(field.getFieldName(), clone.getFieldName());
|
||||
assertEquals(field.getLineNumber(), clone.getLineNumber());
|
||||
assertEquals(field.getValues(), clone.getValues());
|
||||
|
||||
assertTrue(field.getValues() != clone.getValues());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicatedAddList() {
|
||||
Header header = new Header(1);
|
||||
|
|
Loading…
Reference in New Issue