Announcement Announcement Module
Collapse
No announcement yet.
Spring WS requestElement vs HTTP request Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring WS requestElement vs HTTP request

    Hello there,

    We use Spring WS as poor as it can be. We have a simple configuration calling an xsdBuilder and an endpoint object. (class: WsEndpoint).

    The xsdBuilder class is used for generating a wsdl dynamically and the endpoint object is used for creating dynamicaly a response.

    In fact, we only use the spring WS framework to get things up and running so clients can get a wsdl and do a service call.

    The dynamic generated response message depends on the url which is called to get to the webservice. I.e. http://localhost:8080/services/test

    the first part (http://localhost:8080/services) is mapped in the configuration to an endpoint class (WsEndpoint). The last part of the url (test) is used to call different methods which generate a response for a specific request.
    The question is: How can i get the url within the endpoint (class: WsEndpoint) object?

    I use the following endpoint construction:

    public class WsEndpoint extends AbstractDomPayloadEndpoint {
    protected Element invokeInternal(Element requestElement, Document incomingDocument) throws Exception {
    }
    etc.
    }

    The nearest we can get is an (empty) attribute list in the requestElement and some specific variables like localname/nameSpaceUri etc. etc. and a nearly clean incomingDocument object.

    How can i retrieve the called url i.e. "http://localhost:8080/services/test"
    so i can determine 'test' and call the correct method to generate a response.



    The configuration file is:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
    	<bean id="wsEndpoint"
    		class="nl.company.services.springws.endpoint.WsEndpoint">
    	</bean>
    
    	<bean id="payloadMapping"
    		class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    		<property name="defaultEndpoint" ref="wsEndpoint" />
    	</bean>
    
    	<bean id="xsdBuilder"
    		class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition">
    		<property name="builder">
    			<bean
    				class="nl.company.services.springws.xsdbuilder.XSDBuilder">
    			</bean>
    		</property>
    	</bean>
    </beans>
    Greets,

    Herbert te Lintelo
    Last edited by Herbert; Mar 6th, 2008, 05:14 AM.

  • #2
    Solved...

    Hi,

    Someone at work had a great idea. Don't search this in the WS context, use other Spring possibilities ..

    Solution:
    Code:
    		TransportContext context = TransportContextHolder.getTransportContext();
    		HttpServletConnection conn = (HttpServletConnection)context.getConnection();
    		HttpServletRequest httpServletRequest = conn.getHttpServletRequest();
    Cheers..

    However... these lines of code cannot be used in the xsdBuilder (bean) class:
    Code:
    <bean id="xsdBuilder"
    		class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition">
    		<property name="builder">
    			<bean
    				class="nl.company.services.springws.xsdbuilder.XSDBuilder">
    			</bean>
    		</property>
    	</bean>
    anyone suggestions? We need to generate a dynamic WSDL reading the url and calling depending on the url the correct XSD/WSDL generator..
    Last edited by Herbert; Mar 10th, 2008, 08:07 AM.

    Comment


    • #3
      Here's an idea (I haven't tested it, so YMMV):

      Declare a Spring RequestContextFilter in your web.xml. This exposes the request to the current thread. In your WSDL builder, you can get a reference to the request by doing:

      Code:
      ServletWebRequest request = (ServletWebRequest )RequestContextHolder. currentRequestAttributes();
      HttpServletRequest httpRequest = (HttpServletRequest)request.getNativeRequest();
      It should work [TM].

      Comment


      • #4
        Arjen,

        Thanks for the answer..

        I've posted another thread about the same issue, maybe that one can be closed. http://forum.springframework.org/showthread.php?t=50991

        I'm not sure if i can use this solution, because the JEE application i work on uses OSGi as a framework. I've no control to edit the web.xml (i think).. i just created a 'servlet' within a plugin which is loaded in the framework.

        How it works:
        Everything loaded from http://localhost:8080/CompanyName/services. is steered to the spring webservice context. Without the 'services' part a cocoon webapp is shown.

        Question:
        Is there a way to get this working without use of the web.xml or other configuration files? just bij creating beans or spring support classes within the same configuration file where the endpoint and builder are configured?

        Another problem:
        I was debugging yesterday in the Spring source code. The conclusion was that the only class usable is the MessageDispatcher. I can't extend from it because the variables needed are private... ;-(..
        Another thing which i was wondering.. there seems to be a sort of cache mechanism.. Only the first call is calling my wsdl builder bean/class..

        What do i want:
        What i want is that everytime a call for the wsdl is made (http://localhost:8080/CompanyName/services/extraUrlPart/xsdBuilder.wsdl) i can 'catch' the url part: extraUrlPart, and create (by hand) a custom wsdl for the client depending on the 'cathed' url part.
        Last edited by Herbert; Mar 12th, 2008, 12:04 PM.

        Comment

        Working...
        X