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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main(final String[] args) throws Exception {

new SpringApplicationBuilder().sources(SpringmvcClient.class).web(WebApplicationType.SERVLET).build().run(args);

org.apache.servicecomb.demo.springmvc.client.SpringmvcClient.run();
org.apache.servicecomb.demo.springmvc.SpringmvcClient.run();

TestMgr.summary();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
import org.slf4j.LoggerFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;

import com.netflix.config.DynamicPropertyFactory;

@SpringBootApplication
@SpringBootApplication(exclude = {WebMvcAutoConfiguration.class})
@EnableServiceComb
public class SpringmvcServer {
private static final Logger LOGGER = LoggerFactory.getLogger(SpringmvcServer.class);
Expand Down
2 changes: 1 addition & 1 deletion demo/demo-springmvc/springmvc-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</dependencies>

<properties>
<demo.main>org.apache.servicecomb.demo.springmvc.client.SpringmvcClient</demo.main>
<demo.main>org.apache.servicecomb.demo.springmvc.SpringmvcClient</demo.main>
</properties>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.servicecomb.demo.springmvc.client;
package org.apache.servicecomb.demo.springmvc;

import java.util.Date;
import java.util.HashMap;
Expand All @@ -27,6 +27,7 @@
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.demo.controller.Controller;
import org.apache.servicecomb.demo.controller.Person;
import org.apache.servicecomb.demo.springmvc.client.CodeFirstRestTemplateSpringmvc;
import org.apache.servicecomb.demo.springmvc.client.ThirdSvc.ThirdSvcClient;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.junit.Assert.assertThat;

import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.demo.springmvc.client.SpringmvcClient;
import org.junit.Before;
import org.junit.Test;

Expand Down
6 changes: 5 additions & 1 deletion demo/demo-springmvc/springmvc-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>provider-springmvc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>provider-pojo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
Expand All @@ -58,7 +62,7 @@
</dependencies>

<properties>
<demo.main>org.apache.servicecomb.demo.springmvc.server.SpringmvcServer</demo.main>
<demo.main>org.apache.servicecomb.demo.springmvc.SpringmvcServer</demo.main>
</properties>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.servicecomb.demo.springmvc.server;
package org.apache.servicecomb.demo.springmvc;

import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public void testSchemaNotChange(SCBEngine scbEngine) {

public void testRegisteredBasePath() {
if (DynamicPropertyFactory.getInstance().getBooleanProperty("servicecomb.test.vert.transport", true).get()) {
TestMgr.check(19, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
} else {
TestMgr.check(20, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
} else {
TestMgr.check(21, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.servicecomb.demo.springmvc.third;

import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* see: https://github.com/apache/servicecomb-java-chassis/issues/2534
*/
@Component
public class EarlyConsumer implements BootListener {
private static final Logger LOGGER = LoggerFactory.getLogger(EarlyConsumer.class);

@RpcReference(microserviceName = "third", schemaId = "heartbeat")
private HealthSchema healthSchema;

private volatile boolean stopped = false;

public EarlyConsumer() {
new Thread() {
public void run() {
while (!stopped) {
LOGGER.info("calling service");
try {
healthSchema.heartbeat();
} catch (Throwable e) {
// ignore error
}
try {
Thread.sleep(100);
} catch (Throwable e) {
// ignore error
}
}
}
}.start();
}

@Override
public void onAfterRegistry(BootEvent event) {
stopped = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.servicecomb.demo.springmvc.third;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/v1")
public interface HealthSchema {
@GetMapping(value = "/heartbeat")
void heartbeat();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.servicecomb.demo.springmvc.third;

import org.apache.servicecomb.provider.rest.common.RestSchema;

@RestSchema(schemaId = "health", schemaInterface = HealthSchema.class)
public class HeartBeatService implements HealthSchema {
@Override
public void heartbeat() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.servicecomb.demo.springmvc.third;

import org.apache.servicecomb.core.BootListener;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* see: https://github.com/apache/servicecomb-java-chassis/issues/2534
*/
@Component
public class NormalConsumer implements BootListener {
private static final Logger LOGGER = LoggerFactory.getLogger(NormalConsumer.class);

@RpcReference(microserviceName = "third", schemaId = "heartbeat")
private HealthSchema healthSchema;

@Override
public void onAfterRegistry(BootListener.BootEvent event) {
try {
LOGGER.info("calling service after register");

healthSchema.heartbeat();
LOGGER.info("heartbeat succ");
} catch (Throwable e) {
TestMgr.failed("3rd invoke failed", e);
throw e;
}
}


@Override
public int getOrder() {
// 比ThirdServiceRegister晚
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.servicecomb.demo.springmvc.third;

import java.util.Arrays;

import org.apache.servicecomb.provider.pojo.registry.ThirdServiceWithInvokerRegister;
import org.springframework.stereotype.Component;

/**
* see: https://github.com/apache/servicecomb-java-chassis/issues/2534
*/
@Component
public class Register extends ThirdServiceWithInvokerRegister {
public Register() {
super("third");
addSchema("heartbeat", HealthSchema.class);
setUrls("", Arrays.asList("rest://localhost:8080?sslEnabled=false"));
}
}