Announcement Announcement Module
Collapse
No announcement yet.
Problem in getting Database connection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem in getting Database connection

    I am trying to develop a webservice using Spring...

    In the server side I am using interceptors for logging the header information:

    In the class that is implementing the Endpoint Interceptor, we have three methods namely

    1.public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception
    2.public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception
    3.public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception

    At the end of handleRequest method we are instantiating the EndPoint like this:
    MyViewEP myViewEPObj = new MyViewEP();
    myViewEPObj = (MyViewEP)endpoint;

    And in the servlet.xml the mapping is as follows:

    <bean class="org.springframework.ws.server.endpoint.mapp ing.PayloadRootQNameEndpointMapping">
    <property name="interceptors">
    <list>
    <bean class="org.springframework.ws.server.endpoint.inte rceptor.PayloadLoggingInterceptor"/>
    <ref bean="loggingHeader"/>
    </list>
    </property>
    <property name="mappings">
    <props>
    <prop key="{http://www.boo.com/schemas}MyViewRequest">MyViewEP</prop>
    </props>
    </property>
    </bean>

    <bean id="loggingHeader" class="com.boo.webservices.endpoint.interceptors.H eaderLogger">

    Here in the servlet when we are explicitly mapping the endpoint, then what is the need of instantiating the EndPoint from handleRequest().
    My problem is I have to pass databaseconnection, which needs to be passed to both the interceptor and EndPoint. But it gives some error in doing so. Now if I can pass the database connection like this:
    MyViewEP myViewEPObj = new MyViewEP(databaseconnection);

    If I can do this, the problem is solved. Can anyone suggest a way so that we can remove the mapping to Endpoint(ie <property name="mappings"> ) and directly instantiate the endpoint from interceptor…

  • #2
    Well, you probably want Spring to instantiate the endpoints, so creating it in the interceptor is not a good idea.

    The question is whether the database connection changes per request. If it does, it makes sense to pass it to the endpoint. Typically, however, connections are rather static, so you can wire it up like any other bean, and inject it into your components.

    If you need the dynamic connection, you can use a ThreadLocal to store the database connection, or put it in the MessageContext. The MessageContext has properties you can use to store stuff in. SInce one context is created per incoming request, you are safe to put stuff in there with setProperty("connection", connection), and get it out again with getProperty("connection")

    Comment


    • #3
      Thank You Arjen Poutsma..The problem is solved

      Comment

      Working...
      X