forked from apache/dubbo-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add consumer for integration test (apache#632)
- Loading branch information
Showing
10 changed files
with
360 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
dubbo-admin-test/src/main/java/org/apache/dubbo/admin/ConsumerBootstrap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* | ||
* 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.dubbo.admin; | ||
|
||
|
||
import com.sun.jersey.spi.container.servlet.ServletContainer; | ||
import org.apache.dubbo.admin.impl.consumer.RestApiService; | ||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
import org.eclipse.jetty.servlet.ServletHolder; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
|
||
public class ConsumerBootstrap { | ||
public static void main(String[] args) throws Exception { | ||
int port = 8282; | ||
try { | ||
port = Integer.parseInt(System.getenv("rest.api.port")); | ||
} catch (Exception ex) { | ||
//ignore | ||
} | ||
|
||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerBootstrap.ConsumerConfiguration.class); | ||
context.start(); | ||
|
||
|
||
RestApiService.applicationContext = context; | ||
|
||
Server server = new Server(port); | ||
ServletHolder servlet = new ServletHolder(ServletContainer.class); | ||
|
||
servlet.setInitParameter("com.sun.jersey.config.property.packages", "org.apache.dubbo.admin.impl.consumer"); | ||
servlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true"); | ||
|
||
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS); | ||
handler.setContextPath("/"); | ||
handler.addServlet(servlet, "/*"); | ||
server.setHandler(handler); | ||
server.start(); | ||
|
||
System.out.println("dubbo service init finish"); | ||
} | ||
|
||
|
||
@Configuration | ||
@EnableDubbo(scanBasePackages = "org.apache.dubbo.admin.impl.consumer") | ||
@ComponentScan(basePackages = "org.apache.dubbo.admin.impl.consumer") | ||
@PropertySource("classpath:/spring/dubbo-consumer.properties") | ||
public static class ConsumerConfiguration { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...min-test/src/main/java/org/apache/dubbo/admin/impl/consumer/AnnotatedGreetingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* | ||
* 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.dubbo.admin.impl.consumer; | ||
|
||
import org.apache.dubbo.admin.api.GreetingService; | ||
import org.apache.dubbo.config.annotation.DubboReference; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AnnotatedGreetingService { | ||
@DubboReference(version = "1.0.0") | ||
private GreetingService greetingService; | ||
|
||
public String sayHello(String name) { | ||
return greetingService.sayHello(name); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
dubbo-admin-test/src/main/java/org/apache/dubbo/admin/impl/consumer/RestApiService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* | ||
* 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.dubbo.admin.impl.consumer; | ||
|
||
import org.springframework.context.ApplicationContext; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path("/") | ||
public class RestApiService { | ||
public static ApplicationContext applicationContext; | ||
|
||
@Path("/checkAlive") | ||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public CommonResult alive() { | ||
return CommonResult.success("OK"); | ||
} | ||
|
||
@Path("/hello") | ||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) // 声明这个接口将以json格式返回 | ||
public CommonResult hello(@QueryParam("name") String name) { | ||
return CommonResult.success(applicationContext.getBean(AnnotatedGreetingService.class).sayHello(name)); | ||
} | ||
|
||
public static class CommonResult { | ||
private Object data; | ||
private int code; | ||
|
||
public static CommonResult success(Object object) { | ||
CommonResult result = new CommonResult(); | ||
result.data = object; | ||
result.code = 1; | ||
return result; | ||
} | ||
|
||
public Object getData() { | ||
return data; | ||
} | ||
|
||
public void setData(Object data) { | ||
this.data = data; | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(int code) { | ||
this.code = code; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
dubbo-admin-test/src/main/resources/spring/dubbo-consumer.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# | ||
# 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. | ||
# | ||
# | ||
|
||
dubbo.application.name=dubbo-admin-integration-consumer | ||
dubbo.config-center.address=zookeeper://localhost:2181 |
Oops, something went wrong.