当前位置: 代码迷 >> Web前端 >> SpringDM札记8-开发SpringDM Web Bundle
  详细解决方案

SpringDM札记8-开发SpringDM Web Bundle

热度:956   发布时间:2012-08-19 21:09:48.0
SpringDM笔记8-开发SpringDM Web Bundle

1. 创建工程

?? mvn archetype:create -DgroupId=com.manning.sdmia? -DartifactId=SpringDM-Web-Sample

?? 文件目录结构:

?? SpringDM-Web-Sample\
?????? src/
?????????? main/
????????????? java/
????????????? webapp/
????????????????? WEB-INF/
???????????????????? web.xml
????????????????? index.html
????????????????? index.jsp
????????????? test/
??? pom.xml:

??? ...

??? <plugin>
??? ??? ??? <groupId>org.apache.felix</groupId>
??? ??? ??? <artifactId>maven-bundle-plugin</artifactId>
??? ??? ??? <version>2.3.4</version>
??? ??? ??? <extensions>true</extensions>
??? ??? ??? <configuration>
??? ??? ??????? <instructions>
??? ??? ??????? ??? <Include-Resource>
??? ??? ????? ??? ??? ??? src/main/webapp
??? ??? ??????? ??? </Include-Resource>
??? ??? ??????? ??? <Web-ContextPath>
??? ??? ??? ? ??? ??? ??? SpringDM-Web-Sample
??? ??? ??? ??? ??? </Web-ContextPath>
??? ??? ??? ??? </instructions>
??? ??? ??? </configuration>
??? </plugin>

??? ...

2. 工程打包

??? The bundle will be deployed in two steps: it will be deployed as a bundle in the OSGi container,

??? then the Spring DM web extender will react to its registration with OSGi by deploying it to the

??? web container. To be deployed by the web extender, a bundle needs to meet one of two???

??? conditions:
??? ■ Its filename ends with .war.
??? ■ It contains a WEB-INF directory at its root.

3. 部署测试

??? install file:///D:/sts_workspace/SpringDM-Web-Sample/target/SpringDM-Web-Sample-1.0.0.jar

??? 访问地址路径:

??? ■ http://localhost:8080/SpringDM-Web-Sample/
??? ■ http://localhost:8080/SpringDM-Web-Sample/index.jsp

??? 测试代码:

??? public class SpringDmWebSampleTest extends AbstractConfigurableBundleCreatorTests {

????? public void testIntegration() throws Exception{
??? ???? boolean bundleIsHereAndStarted = false;
??? ???? for(Bundle bundle : bundleContext.getBundles()){
??? ??? ??? if("com.manning.sdmia.SpringDM-Web-Sample".equals(bundle.getSymbolicName())

??????????????? &&bundle.getState() == Bundle.ACTIVE){
??? ??? ??? ??? bundleIsHereAndStarted = true;
??? ??? ??? ??? break;
??? ??? ??? }
??? ???? }
??? ???? assertEquals("SpringDM-Web-Bundle is not installed or activated!", bundleIsHereAndStarted);
??? ???
??? ???? Thread.sleep(10*1000);
??? ???? testConnection("http://localhost:8080/SpringDM-Web-Sample/index.html");
??? ???? testConnection("http://localhost:8080/SpringDM-Web-Sample/index.jsp");??? ???
???? }

???? private void testConnection(String address) throws Exception {
??? ??? URL url = new URL(address);
??? ??? HttpURLConnection con = (HttpURLConnection) url.openConnection();
??? ??? con.setUseCaches(false);
??? ???
??? ??? try {
??? ??? ??? con.connect();
??? ??? ??? assertEquals(HttpURLConnection.HTTP_OK, con.getResponseCode());
??? ??? } finally {
??? ??? ??? con.disconnect();
??? ??? }
???? }
???
???? @Override
???? protected String[] getTestBundlesNames() {
??? ??? return new String[] {
??? ??? ??? ??? "org.springframework.osgi, spring-osgi-web,"
??? ??? ??? ??? ??? ??? + getSpringDMVersion(),
??? ??? ??? ??? "org.springframework.osgi, spring-osgi-web-extender,"
??? ??? ??? ??? ??? ??? + getSpringDMVersion(),
??? ??? ??? ??? "javax.servlet, com.springsource.javax.servlet, 2.4.0",
??? ??? ??? ??? "org.springframework.osgi, catalina.osgi, 5.5.23-SNAPSHOT",
??? ??? ??? ??? "org.springframework.osgi, catalina.start.osgi, 1.0.0",
??? ??? ??? ??? "org.springframework.osgi, jsp-api.osgi, 2.0-SNAPSHOT",
??? ??? ??? ??? "org.springframework.osgi, jasper.osgi, 5.5.23-SNAPSHOT",
??? ??? ??? ??? "org.springframework.osgi, commons-el.osgi, 1.0-SNAPSHOT",
??? ??? ??? ??? "org.springframework.osgi, jstl.osgi, 1.1.2-SNAPSHOT",
??? ??? ??? ??? "com.manning.sdmia, SpringDM-Web-Sample, 1.0.0" };
???? }
???
???? @Override
???? protected Resource getTestingFrameworkBundlesConfiguration() {
??? ??? return new InputStreamResource(SpringDmWebSampleTest.class

?????????? .getResourceAsStream("boot-bundles.properties"));
???? }???
?? }

?? 其中文件boot-bundles.properties:

4.启动容器

??? java -jar org.eclipse.osgi-3.5.1.R35x_v20090827.jar -console

5.案例代码

?? 将附件SpringDM-Web-Sample.rar

?

?

1 楼 41082468 2011-12-03  
老大 压缩包 没给阿
2 楼 linyan803 2012-03-27  
楼主,你看的那本书学习的SpringDM,我参考下是否 manning spring dm in action?
3 楼 SpringsFeng 2012-03-28  
SpringDM项目现在已经捐给Eclipse了,叫做Gemini项目,建议关注该项目。
  相关解决方案