Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions samples/bmi/calculator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,34 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>flowcontrol</id>
<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>handler-flowcontrol-qps</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>bizkeeper</id>
<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>handler-bizkeeper</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>tracing</id>
<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>handler-tracing-zipkin</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

@Profile("!v2")
@Service
public class CalculatorServiceImpl implements CalculatorService {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed 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 io.servicecomb.samples.bmi;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

@Profile("v2")
@Service
public class HalfCalculatorServiceImpl extends CalculatorServiceImpl {

/**
* calculate half of BMI value
*/
@Override
public double calculate(double height, double weight) {
return super.calculate(height, weight) / 2;
}
}
25 changes: 25 additions & 0 deletions samples/bmi/webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,29 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>loadbalance</id>
<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>handler-loadbalance</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>tracing</id>
<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>handler-tracing-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>spring-cloud-zuul-zipkin</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed 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 io.servicecomb.samples.bmi.filters;

import static io.servicecomb.core.Const.CSE_CONTEXT;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

import io.servicecomb.config.ConfigUtil;
import io.servicecomb.config.archaius.sources.MicroserviceConfigLoader;
import io.servicecomb.foundation.common.utils.JsonUtils;
import io.servicecomb.serviceregistry.definition.MicroserviceDefinition;

@Component
public class CseHeaderFilter extends ZuulFilter {
@Override
public String filterType() {
return "pre";
}

@Override
public int filterOrder() {
return 0;
}

@Override
public boolean shouldFilter() {
return true;
}

@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
MicroserviceConfigLoader loader = ConfigUtil.getMicroserviceConfigLoader();
MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(loader.getConfigModels());
ctx.addZuulRequestHeader("x-cse-src-microservice", microserviceDefinition.getMicroserviceName());

try {
ctx.addZuulRequestHeader(CSE_CONTEXT, JsonUtils.writeValueAsString(ctx.getZuulRequestHeaders()));
} catch (JsonProcessingException e) {
throw new IllegalStateException("Unable to write request headers as json to " + CSE_CONTEXT, e);
}
return null;
}
}
13 changes: 9 additions & 4 deletions samples/bmi/webapp/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ <h3>Your BMI result is: <span id="bmi_result"></span></h3>
</div>
</div>

<script>
</body>
<script>
$("#error").hide();
$("#submit").click(function () {
if ( !$("#height").val() || !$("#weight").val() ) {
Expand Down Expand Up @@ -83,12 +84,16 @@ <h3>Your BMI result is: <span id="bmi_result"></span></h3>
return;
}
var resp = JSON.parse(xhr.responseText);
$("#error_message").text(resp.error + ": " + resp.exception)
$("#error").removeClass().addClass("alert").addClass("alert-danger").show();
if (xhr.status == 429) {
$("#error_message").text(resp.message);
$("#error").removeClass().addClass("alert").addClass("alert-danger").show();
} else {
$("#error_message").text(resp.error + ": " + resp.exception)
$("#error").removeClass().addClass("alert").addClass("alert-danger").show();
}
}
});
});
</script>
</body>

</html>