Announcement Announcement Module
Collapse
No announcement yet.
How to write a service bundle and make the service work? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to write a service bundle and make the service work?

    Now I try to write a service bundle and some problem trouble me so long. I write a service bundle to get the system time:
    package timeservice;

    public interface LocalTime {
    public String GetTime();
    }
    .....................
    package timeservice.impl;
    import timeservice.LocalTime;
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;

    public class LocalTimeImpl implements LocalTime {
    public String GetTime() {
    Date dt = new Date();
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    String nowTime = "";
    nowTime = df.format(dt);
    return nowTime;
    }
    }

    and in the META-INFspring folder there are tow .xml files:
    module-context.xml:

    <bean id="localTime" class="timeservice.impl.LocalTimeImpl"/>

    osgi-context.xml:

    <service ref="localTime" interface="timeservice.LocalTime" />

    MANIFEST.MF file is:

    Manifest-Version: 1.0
    Bundle-Name: TimeService Bundle
    Bundle-ManifestVersion: 2
    Bundle-SymbolicName: TimeService
    Bundle-Version: 1.0.0
    Export-Package: timeservice;version="1.0.0"

    Now my question is are these work enough to publish services ???

    and in another bundle I want to share the service,I did the works below:

    the MANIFEST.MF file is:
    Manifest-Version: 1.0
    Bundle-Name: springapp Bundle
    Bundle-ManifestVersion: 2
    Bundle-SymbolicName: springapp
    Bundle-Version: 1.0.0
    Import-Package: timeservice;version="[1.0.0,1.0.0]"

    in the WEB-INF there are 3 .xml files:

    web.xml:
    <?xml version="1.0" encoding="ISO-8859-1"?>

    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <description>
    Spring App Examples.
    </description>
    <display-name>Spring App Examples</display-name>
    <servlet>
    <servlet-name>hello</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    hello-servlet.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/hellouser.do">helloUserAction</prop>
    </props>
    </property>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass">
    <value>org.springframework.web.servlet.view.Intern alResourceView</value>
    </property>
    </bean>

    <bean id="helloUserAction" class="onlyfun.caterpillar.HelloUserAction">
    <property name="helloWord">
    <value>Hello!</value>
    </property>
    <property name="localTime" ref="localTime">
    </property>
    <property name="viewPage">
    <value>/WEB-INF/jsp/hellouser.jsp</value>
    </property>
    </bean>
    </beans>

    applicationContext.xml is:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/osgi"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <reference id="localTime" interface="timeservice.LocalTime" />

    </beans:beans>

    and in the HelloUserAction.java I define :
    public LocalTime localTime;
    public void setLocalTime(LocalTime localTime) {
    this.localTime = localTime;
    }

    until now can I make this.localTime.GetTime() to work here? can some one give me the details,I will feel so thankful for that,thank you!!!!!

  • #2
    How to write a service bundle and make the service work?

    Hi Yang Qi,

    > Now my question is are these work enough to publish services ???

    Yes, at a quick glance your configuration for your service bundle looks fine.

    > and in another bundle I want to share the service,I did the works below:

    When you say "bundle" here, do you mean Web Module?
    Or are you attempting to build a Shared Services WAR?

    If you're building a Web Module, you will need to use the "Module-Type: Web" manifest header declaration. In addition, you will likely not even need to configure web.xml. Instead you can make use of the Web-* manifest headers. Alternatively, you may need to configure a web.xml fragment. For details, please consult the Programmer Guide:

    http://static.springsource.com/projects/dm-server/1.0.x/programmer-guide/htmlsingle/programmer-guide.html#developing-applications-packaging-web-modules

    On the other hand, if you are developing a Shared Services WAR, you'll need to explicitly set the contextClass for your configured DispatcherServlet to ServerOsgiBundleXmlWebApplicationContext. This is also explained in the Programmer Guide:

    http://static.springsource.com/projects/dm-server/1.0.x/programmer-guide/htmlsingle/programmer-guide.html#developing-applications-packaging-war

    You might also find the Form Tags case study useful:

    http://static.springsource.com/projects/dm-server/1.0.x/programmer-guide/htmlsingle/programmer-guide.html#formtags-case-study

    Regards,

    Sam

    Comment


    • #3
      How to write a service bundle and make the service work?

      FYI: please note that this forum is no longer active. Thus, for future questions and comments, you should instead follow up on the official SpringSource dm Server forum here:

      http://forum.springframework.org/forumdisplay.php?f=53

      Thanks,

      Sam

      Comment


      • #4
        How to write a service bundle and make the service work?

        Thank you Sam!

        Comment

        Working...
        X