Announcement Announcement Module
Collapse
No announcement yet.
tcp inbound socket Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • tcp inbound socket

    Hi,

    I am new to spring-integration. I am trying to create tcp inbound socket, which will just receive string, and invoke a spring bean. I tried search on google, and looking into forum. But didn't find any working example. I found couple of blogs and used knowledge I gained from the example provided by the spring-integration. But it seems like that its not working. The simplest thing I want is, start the inbound server, and send a string using telnet to see if its calling my bean. Then later on I will put an outbound socket, and make it bidirectional.

    My context looks like this -

    Code:
    <int-ip:inbound-channel-adapter protocol="tcp"
                                        channel="helloInputChannel"
                                        close="false"
                                        id="inbound"
                                        local-address="192.168.1.3"
                                        port="8081"/>
    
        <int:channel id="helloInputChannel"/>
        <int:service-activator input-channel="helloInputChannel" ref="tcpHelloService" method="sayHello"/>
        <!--output-channel="deliveries"/>-->
    
        <beans:bean id="tcpHelloService" class="org.edu.springintegration.tcpip.impl.TCPHelloServiceImpl"/>
        <stream:stdout-channel-adapter id="deliveries"/>

    And when I ran is, I get an exception which looks like this -



    Code:
    Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 1 in XML document from class path resource [org/edu/springintegration/tcpip/impl/tcpContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:122)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:197)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
    	at org.edu.springintegration.tcpip.impl.TCPHelloServiceEntryPoint.main(TCPHelloServiceEntryPoint.java:8)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
    Caused by: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
    	at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1414)
    	at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanExternalID(XMLScanner.java:1026)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.scanDoctypeDecl(XMLDocumentScannerImpl.java:688)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:968)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    	at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:435)
    	at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:491)
    	at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOMParser.parse(SchemaDOMParser.java:510)
    	at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:1802)
    	at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:531)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2436)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1781)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:725)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
    	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
    	at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    	... 17 more

    Any kind of help will be highly appreciated. If anyone can give a link of working code, then it will even be more then I expected.

    Thanks in advance.

    Jahid

  • #2
    That error indicates a general problem in the top of your XML file. Can you post the entire config, or at least the XML header and initial root element?

    Comment


    • #3
      Thanks Fisher,

      here it goes-

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans:beans xmlns="http://www.springframework.org/schema/integration"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:beans="http://www.springframework.org/schema/beans"
                   xmlns:int="http://www.springframework.org/schema/integration"
                   xmlns:stream="http://www.springframework.org/schema/integration/stream"
                   xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
                   xsi:schemaLocation="http://www.springframework.org/schema/beans
      			http://www.springframework.org/schema/beans/spring-beans.xsd
      			http://www.springframework.org/schema/integration
      			http://www.springframework.org/schema/integration/spring-integration.xsd
      			http://www.springframework.org/schema/integration/stream
      			http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
      			http://www.springframework.org/schema/integration/ip
      			http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
      			">
      
          <!--<int-ip:tcp-inbound-channel-adapter channel="helloInputChannel" id="inbound"/>-->
      
      
          <int-ip:inbound-channel-adapter protocol="tcp"
                                          channel="helloInputChannel"
                                          close="false"
                                          id="inbound"
                                          local-address="192.168.1.3"
                                          port="8081"/>
      
      
      
          <int:channel id="helloInputChannel"/>
          <int:service-activator input-channel="helloInputChannel" ref="tcpHelloService" method="sayHello"/>
      
      
          <beans:bean id="tcpHelloService" class="org.edu.springintegration.tcpip.impl.TCPHelloServiceImpl"/>
          <stream:stdout-channel-adapter id="deliveries"/>
      </beans:beans>

      Comment


      • #4
        I have not looked into your problem yet, but what you are trying to do (connect to SI using telnet) is demonstrated by the tcp-client-server sample application.

        How to get the samples is described here...

        http://blog.springsource.com/2010/09...ation-samples/

        ...but you can browse this particular sample here...

        http://git.springsource.org/spring-i...-client-server

        The readme talks about using telnet; the inbound gateway sends messages to a simple echo service.

        Here is the salient part of the configuration...

        Code:
        	<!-- Server side -->
        	
        	<ip:tcp-connection-factory id="crLfServer"
        		type="server"
        		port="11111"/>
        			
        	<ip:tcp-inbound-gateway id="gatewayCrLf"
        		connection-factory="crLfServer"
        		request-channel="toSA" />
        		
        	<channel id="toSA" />
        
        	<service-activator input-channel="toSA"
        		   ref="echoService"
        		   method="test"
        	/>
        
        	<beans:bean id="echoService" 
        		  class="org.springframework.integration.samples.tcpclientserver.EchoService" />
        Notice that the connection properties are on a connection factory; from your example, it looks like you might be using a very old milestone. Please upgrade to the release candidate.

        Code:
        $ telnet localhost 11111
        Trying 127.0.0.1...
        Connected to localhost.
        Escape character is '^]'.
        Hello world!
        echo:Hello world!
        Test
        echo:Test
        ^]
        
        telnet> quit
        Connection closed.

        Comment


        • #5
          Regarding your configuration, your schemalocation attribute is incorrect.

          Code:
                       xsi:schemaLocation="http://www.springframework.org/schema/beans
          			http://www.springframework.org/schema/beans/spring-beans.xsd
          			http://www.springframework.org/schema/integration
          			http://www.springframework.org/schema/integration/spring-integration.xsd
          			http://www.springframework.org/schema/integration/stream
          			http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
          			http://www.springframework.org/schema/integration/ip
          			http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
          You have two entries for the ip namespace, and only one maps to a schema - remove the first...

          Code:
                       xsi:schemaLocation="http://www.springframework.org/schema/beans
          			http://www.springframework.org/schema/beans/spring-beans.xsd
          			http://www.springframework.org/schema/integration
          			http://www.springframework.org/schema/integration/spring-integration.xsd
          			http://www.springframework.org/schema/integration/stream
          			http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
          			http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
          If you don't want the output to go back to the telnet client, use an inbound channel adapter - I just modified the sample application as follows, and it works fine...

          Code:
          	<int-ip:tcp-connection-factory id="crLfServer"
          		type="server"
          		port="11111"/>
          			
          	<int-ip:tcp-inbound-channel-adapter id="inbound" 
          		connection-factory="crLfServer"
          		channel="toSA" />
          		
          	<channel id="toSA" />
          
          	<service-activator input-channel="toSA"
          			   ref="echoService"
          			   method="test"
          			   output-channel="deliveries"
          	/>
          
          	<beans:bean id="echoService" 
          		  class="org.springframework.integration.samples.tcpclientserver.EchoService" />
          
                  <stream:stdout-channel-adapter id="deliveries"/>

          Comment


          • #6
            Also, since you are using "integration" as the base namespace, you do not need to define "xmlns:int" as a prefix, and you do not need to use the "int" prefix on any of the elements defined in the integration core namespace.

            Comment


            • #7
              Fisher and Russell,

              Thanks a lot for excellent help.

              HTML Code:
              If you don't want the output to go back to the telnet client, use an inbound channel adapter - I just modified the sample application as follows, and it works fine...
              Russell, my bean is returning nothing (i mean its a void type). thats why i didnt connect it to any output channel or to stdout adapter. i mean, its uni-directional.

              Comment

              Working...
              X