Merge branch 'github_dev' into ctrip_module_dev

This commit is contained in:
fanqq 2015-04-23 17:02:28 +08:00
commit e7b26a0570
4 changed files with 35 additions and 23 deletions

View file

@ -39,16 +39,18 @@ public class DefaultResponseHandler implements ResponseHandler {
@Override
public Response handle(Object object, MediaType mediaType) throws Exception {
if (mediaType == null) {
mediaType = defaultMediaType;
}
if (acceptedMediaTypes.contains(mediaType)) {
if (mediaType != null && acceptedMediaTypes.contains(mediaType)) {
Message response = generateMessage(object, mediaType.toString());
return Response.status(response.getStatus()).entity(response.getResponse())
.type(mediaType).build();
}
throw new ValidationException("Unaccepted media type: " + mediaType.toString());
try {
Message response = generateMessage(object, defaultMediaType.toString());
return Response.status(response.getStatus()).entity(response.getResponse())
.type(defaultMediaType).build();
} catch (Exception ex) {
throw new ValidationException("Unaccepted media type.");
}
}
private static Set<MediaType> getDefault() {

View file

@ -76,10 +76,12 @@ public class AppResource {
App a;
if (hh.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)) {
a = DefaultSaxParser.parseEntity(App.class, app);
} else if (hh.getMediaType().equals(MediaType.APPLICATION_JSON_TYPE)) {
a = DefaultJsonParser.parse(App.class, app);
} else {
throw new Exception("Unacceptable type.");
try {
a = DefaultJsonParser.parse(App.class, app);
} catch (Exception ex) {
throw new Exception("Unacceptable type.");
}
}
appRepository.add(a);
return Response.ok().build();
@ -92,10 +94,12 @@ public class AppResource {
App a;
if (hh.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)) {
a = DefaultSaxParser.parseEntity(App.class, app);
} else if (hh.getMediaType().equals(MediaType.APPLICATION_JSON_TYPE)) {
a = DefaultJsonParser.parse(App.class, app);
} else {
throw new Exception("Unacceptable type.");
try {
a = DefaultJsonParser.parse(App.class, app);
} catch (Exception e) {
throw new Exception("Unacceptable type.");
}
}
appRepository.update(a);
return Response.ok().build();

View file

@ -26,11 +26,11 @@ public class HealthCheckConf {
.append(" fall=").append(h.getFails())
.append(" timeout=").append(1000)
.append(" type=http").append(";\n")
.append(" check_keepalive_requests 100").append(";\n")
.append(" check_http_send \"")
.append("GET ").append(h.getUri()).append(" HTTP/1.0\r")
.append(" Connection: keep-alive\r")
.append(" Host: ").append(vs.getDomains().get(0).getName()).append("\r\"").append(";\n")
.append("check_keepalive_requests 100").append(";\n")
.append("check_http_send \"")
.append("GET ").append(h.getUri()).append(" HTTP/1.0\\r\\n")
.append(" Connection: keep-alive\\r\\n")
.append(" Host: ").append(vs.getDomains().get(0).getName()).append("\\r\\n\\r\\n\"").append(";\n")
.append("check_http_expect_alive http_2xx http_3xx").append(";\n");
return b.toString();
}

View file

@ -4,6 +4,7 @@ import com.ctrip.zeus.model.entity.Slb;
import com.ctrip.zeus.util.StringFormat;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
/**
* @author:xingchaowang
@ -11,7 +12,14 @@ import com.netflix.config.DynamicPropertyFactory;
*/
public class NginxConf {
private static DynamicIntProperty nginxStatusPort = DynamicPropertyFactory.getInstance().getIntProperty("slb.nginx.status-port", 10001);
// private static final int DEFAULT_WORKERS = 4;
private static DynamicStringProperty logFormat = DynamicPropertyFactory.getInstance().getStringProperty("slb.nginx.log-format",
"log_format main '[$time_local] $host $hostname $server_addr $request_method $uri '\n" +
"'\"$query_string\" $server_port $remote_user $remote_addr $http_x_forwarded_for '\n" +
"'$server_protocol \"$http_user_agent\" \"$cookie_COOKIE\" \"$http_referer\" '\n" +
"'$host $status $body_bytes_sent $request_time $upstream_response_time '\n" +
"'$upstream_addr $upstream_status';\n"
);
public static String generate(Slb slb) {
StringBuilder b = new StringBuilder(1024);
@ -35,12 +43,10 @@ public class NginxConf {
b.append("include mime.types;\n");
b.append("default_type application/octet-stream;\n");
b.append("keepalive_timeout 65;\n");
b.append("log_format main '[$time_local] $host $hostname $server_addr $request_method \"$uri\" ' " +
"'\"$query_string\" $server_port $remote_user $remote_addr $http_x_forwarded_for ' " +
"'$server_protocol \"$http_user_agent\" \"$cookie_COOKIE\" \"$http_referer\" ' " +
"'$host $status $body_bytes_sent $request_time $upstream_response_time ' " +
"'$upstream_addr $upstream_status';\n");
b.append(logFormat.get());
b.append("access_log /opt/logs/nginx/access.log main;\n");
b.append(statusConf());
b.append("include upstreams/*.conf;\n");
b.append("include vhosts/*.conf;\n");