Skip to content

Commit

Permalink
Merge pull request #453 from personium/develop
Browse files Browse the repository at this point in the history
Release v1.7.16
  • Loading branch information
tochi-y authored Jul 26, 2019
2 parents 687ec88 + dab7ab7 commit cf46b1d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 42 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.7.16
BUG FIXES:
* Even if Depth:1 is specified in "Retrieve cell snapshot file setting" API, it is ignored. ([#439](https://github.com/personium/personium-core/issues/439))
* If Accept request header contains extra values, 409 is returned ([#435](https://github.com/personium/personium-core/issues/435))

IMPROVEMENTS:
* Fix crossdomain.xml error in Eclipse. ([#448](https://github.com/personium/personium-core/issues/444))

## 1.7.15
BUG FIXES:
* Implementation of log file deletion API([#270](https://github.com/personium/personium-core/issues/270))
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>io.personium</groupId>
<artifactId>personium-core</artifactId>
<packaging>war</packaging>
<version>1.7.15_es6.6.1</version>
<version>1.7.16_es6.6.1</version>
<name>personium-core Maven Webapp</name>
<url>http://maven.apache.org</url>
<licenses>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/personium/core/model/CellSnapshotCellRsCmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
package io.personium.core.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.wink.webdav.model.Propfind;

import io.personium.core.auth.AccessContext;

/**
Expand Down Expand Up @@ -49,4 +55,18 @@ public String getUrl() {
}
return cellUrl + "/" + SNAPSHOT_ENDPOINT;
}

/**
* {@inheritDoc}
*/
protected List<org.apache.wink.webdav.model.Response> createChildrenDavResponseList(String reqUri,
Propfind propfind, boolean canAclRead) {
List<org.apache.wink.webdav.model.Response> resList = new ArrayList<>();
Map<String, DavCmp> childrenMap = this.davCmp.getChildren();
for (String childName : childrenMap.keySet()) {
DavCmp child = childrenMap.get(childName);
resList.add(createDavResponse(childName, reqUri + "/" + child.getName(), child, propfind, canAclRead));
}
return resList;
}
}
48 changes: 23 additions & 25 deletions src/main/java/io/personium/core/rs/odata/AbstractODataResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.UriInfo;

import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
import org.odata4j.core.NamedValue;
import org.odata4j.core.NamespacedAnnotation;
Expand Down Expand Up @@ -147,15 +148,16 @@ public String getEntitySetName() {

/**
* Determine the ContentType to return.
* @param accept Content of the Accept header
* @param accept Content of the Accept header;
* Note that quality values like 'q=0.9' are ignored to determine.
* @param format $ format parameter
* @return Content-Type to return
*/
public final MediaType decideOutputFormat(final String accept, final String format) {
MediaType mediaType = null;
if (format != null) {
mediaType = decideOutputFormatFromQueryValue(format);
} else if (accept != null) {
} else if (!StringUtils.isEmpty(accept)) {
mediaType = decideOutputFormatFromHeaderValues(accept);
}
if (mediaType == null) {
Expand Down Expand Up @@ -191,21 +193,18 @@ private MediaType decideOutputFormatFromQueryValue(String format) {
* @return output format ("application / json" or "application / atom + xml")
*/
private MediaType decideOutputFormatFromHeaderValues(String acceptHeaderValue) {
MediaType mediaType = null;
StringTokenizer st = new StringTokenizer(acceptHeaderValue, ",");
while (st.hasMoreTokens()) {
String accept = truncateAfterSemicolon(st.nextToken());
if (isAcceptXml(accept)) {
mediaType = MediaType.APPLICATION_ATOM_XML_TYPE;
} else if (isAcceptJson(accept)) {
if (mediaType == null) {
mediaType = MediaType.APPLICATION_JSON_TYPE;
}
} else {
throw PersoniumCoreException.OData.UNSUPPORTED_MEDIA_TYPE.params(acceptHeaderValue);
}
String[] types = Stream.of(acceptHeaderValue.split("[ \t]*,[ \t]*"))
.map(this::truncateAfterSemicolon)
.toArray(String[]::new);
if (Stream.of(types).anyMatch(this::isAcceptXml)) {
return MediaType.APPLICATION_ATOM_XML_TYPE;
} else if (Stream.of(types).anyMatch(this::isAcceptJson)) {
return MediaType.APPLICATION_JSON_TYPE;
} else if (Stream.of(types).anyMatch(this::isAcceptWildcard)) {
return MediaType.APPLICATION_ATOM_XML_TYPE;
} else {
throw PersoniumCoreException.OData.UNSUPPORTED_MEDIA_TYPE.params(acceptHeaderValue);
}
return mediaType;
}

/**
Expand All @@ -214,24 +213,23 @@ private MediaType decideOutputFormatFromHeaderValues(String acceptHeaderValue) {
* @return String up to semicolon
*/
private String truncateAfterSemicolon(String source) {
String result = source;
int index = source.indexOf(";");
if (index >= 0) {
result = source.substring(0, index);
}
return result;
String[] splited = source.split("[ \t]*;", 2);
return splited[0];
}

private boolean isAcceptXml(String accept) {
return accept.equals(MediaType.APPLICATION_ATOM_XML)
|| accept.equals(MediaType.APPLICATION_XML)
|| accept.equals(MediaType.WILDCARD);
|| accept.equals(MediaType.APPLICATION_XML);
}

private boolean isAcceptJson(String accept) {
return accept.equals(MediaType.APPLICATION_JSON);
}

private boolean isAcceptWildcard(String accept) {
return accept.equals(MediaType.WILDCARD);
}

/**
* Ask Producer to create Entity.
* @param reader request body
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/crossdomain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
-->

<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<!DOCTYPE cross-domain-policy SYSTEM "https://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#################################################

# core version
io.personium.core.version=1.7.15
io.personium.core.version=1.7.16

# thread pool num.
io.personium.core.thread.pool.num.io.cell=10
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/personium/test/jersey/CrossDomainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public class CrossDomainTest extends PersoniumTest {
static final String TEST_CELL1 = "testcell1";
static final String ODATA_COL = "odatacol";
static final String CROSSDOMAIN_XML = "<?xml version=\"1.0\"?>"
+ "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">"
+ " <cross-domain-policy>"
+ " <site-control permitted-cross-domain-policies=\"all\"/>"
+ " <allow-access-from domain=\"*\"/>"
+ "<!DOCTYPE cross-domain-policy SYSTEM \"https://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">"
+ "<cross-domain-policy>"
+ " <site-control permitted-cross-domain-policies=\"all\"/>"
+ " <allow-access-from domain=\"*\"/>"
+ " <allow-http-request-headers-from domain=\"*\" headers=\"*\"/>"
+ "</cross-domain-policy>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ public class DecideOutputFormatTest {
assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, type);
}

/**
* format指定なしでacceptにJSONとATOM_XMLを空白ありで指定した場合XMLが返却されること.
*/
@Test
public final void format指定なしでacceptにJSONとATOM_XMLを空白ありで指定した場合XMLが返却されること() {
ODataEntityResource odataEntityResource = new ODataEntityResource();

MediaType type = odataEntityResource.decideOutputFormat(
MediaType.APPLICATION_JSON + " , " + MediaType.APPLICATION_ATOM_XML, null);
assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, type);
}

/**
* format指定なしでacceptにJSONとATOM_XMLをタブありで指定した場合XMLが返却されること.
*/
@Test
public final void format指定なしでacceptにJSONとATOM_XMLをタブありで指定した場合XMLが返却されること() {
ODataEntityResource odataEntityResource = new ODataEntityResource();

MediaType type = odataEntityResource.decideOutputFormat(
MediaType.APPLICATION_JSON + "\t,\t" + MediaType.APPLICATION_ATOM_XML, null);
assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, type);
}

/**
* acceptのセミコロン以降を無視すること.
*/
Expand All @@ -112,6 +136,30 @@ public class DecideOutputFormatTest {
assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, type);
}

/**
* acceptの空白とセミコロン以降を無視すること.
*/
@Test
public final void acceptの空白とセミコロン以降を無視すること() {
ODataEntityResource odataEntityResource = new ODataEntityResource();

MediaType type = odataEntityResource.decideOutputFormat(
"application/xml ;q=0.9,*/* ;q=0.8", null);
assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, type);
}

/**
* acceptのタブとセミコロン以降を無視すること.
*/
@Test
public final void acceptのタブとセミコロン以降を無視すること() {
ODataEntityResource odataEntityResource = new ODataEntityResource();

MediaType type = odataEntityResource.decideOutputFormat(
"application/xml\t;q=0.9,*/*\t;q=0.8", null);
assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, type);
}

/**
* format指定なしでacceptに未サポートの値を指定した場合415エラーが返却されること.
*/
Expand Down Expand Up @@ -157,18 +205,23 @@ public class DecideOutputFormatTest {
* format指定なしでacceptにxmlと未サポートの値を指定した場合415エラーが返却されること.
*/
@Test
public final void format指定なしでacceptにxmlと未サポートの値を指定した場合415エラーが返却されること() {
public final void format指定なしでacceptにxmlと未サポートの値を指定した場合xmlが返却されること() {
ODataEntityResource odataEntityResource = new ODataEntityResource();

try {
odataEntityResource.decideOutputFormat(
MediaType type = odataEntityResource.decideOutputFormat(
MediaType.APPLICATION_ATOM_XML + "," + "INVALID_VALUE", null);
fail();
} catch (PersoniumCoreException e) {
assertEquals("PR415-OD-0001", e.getCode());
} catch (Exception e) {
fail();
}
assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, type);
}

/**
* format指定なしでacceptにjsonとtext/plainと*を指定した場合jsonが返却されること.
*/
@Test
public final void format指定なしでacceptにjsonとtextとアスタリスクを指定した場合jsonが返却されること() {
ODataEntityResource odataEntityResource = new ODataEntityResource();
MediaType type = odataEntityResource.decideOutputFormat(
MediaType.APPLICATION_JSON + "," + MediaType.TEXT_PLAIN_TYPE + "," + MediaType.WILDCARD, null);
assertEquals(MediaType.APPLICATION_JSON_TYPE, type);
}

/**
Expand Down

0 comments on commit cf46b1d

Please sign in to comment.