Announcement Announcement Module
Collapse
No announcement yet.
need help on Spring WS() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • need help on Spring WS()

    I'am new to Spring and Spring-WS.

    I have next code:

    Client.java
    Code:
    public class Client extends WebServiceGatewaySupport {
        
        private Resource request;
        private String action;
        
        public void setRequest(Resource request) {
            this.request = request;
        }
        
        public void setAction(String action) {
            this.action = action;
        }
        
        public void quotes() throws IOException {
            Source requestSource = new ResourceSource(request);
            StringResult result = new StringResult();
            getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource, new SoapActionCallback(action), result);
            FileWriter writer = new FileWriter("settings.xml");
            writer.write(result.toString()
                        .replace("&lt;", "<")
                        .replace("&gt;", ">"));
            writer.close();
            System.out.println(result);
        }
        public static void main(String[] args) throws IOException {
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml", Client.class);
            Client stockClient = (Client) applicationContext.getBean("stockClient");
            stockClient.quotes();
        }
        
    }


    applicationContext.xml

    Code:
    <beans xmlns="springframework.org/schema/beans"
            xmlns:xsi="w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="springframework.org/schema/beans
                                springframework.org/schema/beans/spring-beans-2.5.xsd">
                
        <bean id="stockClient" class="service.Client">
            <property name="defaultUri" value="webserviceX.NET/stockquote.asmx"/>
            <property name="request" value="classpath:quotesRequest.xml"/>
            <property name="action" value="webserviceX.NET/GetQuote"/>
            
        </bean>
    </beans>

    quotesRequest.xml
    Code:
    <GetQuote xmlns="webserviceX.NET/">
        <symbol>GOOG</symbol>
    </GetQuote>
    I receive next response:
    Code:
    <GetQuoteResponse xmlns="webserviceX.NET/">
        <GetQuoteResult>
            <StockQuotes>
                <Stock>
                    <Symbol>GOOG</Symbol>
                    <Last>479.85</Last>
                    <Date>8/5/2008</Date>
                    <Time>4:00pm</Time>
                    <Change>+16.85</Change>
                    <Open>467.89</Open>
                    <High>480.08</High>
                    <Low>466.33</Low>
                    <Volume>3584321</Volume>
                    <MktCap>150.6B</MktCap>
                    <PreviousClose>463.00</PreviousClose>
                    <PercentageChange>+3.64%</PercentageChange>
                    <AnnRange>412.11 - 747.24</AnnRange>
                    <Earns>15.216</Earns>
                    <P-E>30.43</P-E>
                    <Name>GOOGLE</Name>
                </Stock>
            </StockQuotes>
        </GetQuoteResult>
    </GetQuoteResponse>

    But I want just get value from <Last/> tag from above code. How can I do so?

  • #2
    As I understand instead method getWebServiceTemplate().sendSourceAndReceiveToResu lt(requestSource, new SoapActionCallback(action), result), I have to use method getWebServiceTemplate().marshalSendAndReceive(). Is it right? If it is right can someone explane or give some examples how to use this?

    Comment

    Working...
    X