Skip to content

Commit

Permalink
Update Hprose for Java
Browse files Browse the repository at this point in the history
Add addAccessControlAllowOrigin & removeAccessControlAllowOrigin for
HproseHttpService.
  • Loading branch information
andot committed Apr 17, 2014
1 parent 52bdf25 commit eb8d75a
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 26 deletions.
Binary file modified java5/dist/hprose_client_for_java_5.jar
Binary file not shown.
Binary file modified java5/dist/hprose_client_for_java_6.jar
Binary file not shown.
Binary file modified java5/dist/hprose_client_for_java_7.jar
Binary file not shown.
Binary file modified java5/dist/hprose_client_for_java_8.jar
Binary file not shown.
Binary file modified java5/dist/hprose_for_java_5.jar
Binary file not shown.
Binary file modified java5/dist/hprose_for_java_6.jar
Binary file not shown.
Binary file modified java5/dist/hprose_for_java_7.jar
Binary file not shown.
Binary file modified java5/dist/hprose_for_java_8.jar
Binary file not shown.
23 changes: 0 additions & 23 deletions java5/make

This file was deleted.

18 changes: 15 additions & 3 deletions java5/src/hprose/server/HproseHttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* *
* hprose http service class for Java. *
* *
* LastModified: Apr 13, 2014 *
* LastModified: Apr 17, 2014 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand All @@ -23,6 +23,7 @@
import hprose.io.ByteBufferStream;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -33,6 +34,7 @@ public class HproseHttpService extends HproseService {
private boolean crossDomainEnabled = false;
private boolean p3pEnabled = false;
private boolean getEnabled = true;
private final HashMap<String, Boolean> origins = new HashMap<String, Boolean>();
private static final ThreadLocal<HttpContext> currentContext = new ThreadLocal<HttpContext>();

public static HttpContext getCurrentContext() {
Expand Down Expand Up @@ -81,6 +83,14 @@ public void setGetEnabled(boolean enabled) {
getEnabled = enabled;
}

public void addAccessControlAllowOrigin(String origin) {
origins.put(origin, true);
}

public void removeAccessControlAllowOrigin(String origin) {
origins.remove(origin);
}

@Override
protected Object[] fixArguments(Type[] argumentTypes, Object[] arguments, int count, Object context) {
HttpContext httpContext = (HttpContext)context;
Expand Down Expand Up @@ -127,8 +137,10 @@ protected void sendHeader(HttpContext httpContext) throws IOException {
if (crossDomainEnabled) {
String origin = request.getHeader("Origin");
if (origin != null && !origin.equals("null")) {
response.setHeader("Access-Control-Allow-Origin", origin);
response.setHeader("Access-Control-Allow-Credentials", "true");
if (origins.isEmpty() || origins.containsKey(origin)) {
response.setHeader("Access-Control-Allow-Origin", origin);
response.setHeader("Access-Control-Allow-Credentials", "true");
}
}
else {
response.setHeader("Access-Control-Allow-Origin", "*");
Expand Down

0 comments on commit eb8d75a

Please sign in to comment.