2017-08-21 29 views
0

this exampleを使用して、HEXデータを使用して通信するメインフレームマシンとの間でデータを送受信しようとしています。だから私は、私の構成では、次のしている:Spring TCPソケットクライアントがメインフレームからデータを受信して​​いません

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

    <context:property-placeholder /> 

    <!-- Client side --> 

    <int:gateway id="gw" 
       service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway" 
       default-request-channel="input"/> 

    <int-ip:tcp-connection-factory id="client" 
            type="client" 
            host="<ip>" 
            serializer="CustomSerializerDeserializer" 
            deserializer="CustomSerializerDeserializer" 
            port="${availableServerSocket}" 
            single-use="false" 
            so-timeout="1800000" 
            using-nio="false" /> 

    <bean id="CustomSerializerDeserializer" class="org.springframework.integration.samples.tcpclientserver.CustomSerializerDeserializer" /> 


    <int:channel id="input" /> 

    <int-ip:tcp-outbound-gateway id="outGateway" 
           request-channel="input" 
           connection-factory="client" 
           request-timeout="1800000" 
           reply-timeout="1800000"/> 

    <!-- Server side --> 

    <int-ip:tcp-connection-factory id="crLfServer" 
            type="server" 
            port="${availableServerSocket}"/> 

    <int-ip:tcp-inbound-gateway id="gatewayCrLf" 
           connection-factory="crLfServer" 
           request-channel="serverBytes2StringChannel" 
           error-channel="errorChannel"/> 

    <int:channel id="toSA" /> 

    <int:service-activator input-channel="toSA" 
          ref="echoService" 
          method="test"/> 

    <bean id="echoService" 
      class="org.springframework.integration.samples.tcpclientserver.EchoService" /> 

    <int:object-to-string-transformer id="serverBytes2String" 
             input-channel="serverBytes2StringChannel" 
             output-channel="toSA"/> 

</beans> 

そして、私のシリアライザ/デシリアライザで、私は以下の内容が含まれています。自分自身で

public void serialize(String input, OutputStream outputStream) throws IOException { 
    outputStream.write(buildmsg(input)); 
    outputStream.flush(); 
} 

public String deserialize(InputStream inputStream) throws IOException { 
    String data = ""; 
    logger.info("inside deserialize"); 
    DataInputStream dis = new DataInputStream(inputStream); 
    int len = dis.readInt(); 
    if (len > 0) { 
     logger.info("len: " + decimaltohex(len)); 
     logger.info("data: " + data); 
     byte[] b = new byte[dis.available()]; 
     dis.readFully(b); 
     data += decimaltohex(len); 
     data += byteArrayToHex(b); 
    } 
    logger.info("full data:" + data); 
    return data; 
} 

public byte[] buildmsg(String body) throws UnsupportedEncodingException { 
    String header = "00000000"; 
    String totMsg = header + body; 
    header = massageheader(decimaltohex(totMsg.length()/2)); 
    totMsg = header + body; 
    logger.info("sending data : " + totMsg); 
    return hexStringToByteArray(totMsg); 
} 

public String decimaltohex(int data) { 
    return Integer.toHexString(data); 
} 

public static String massageheader(String data) { 
    String str = String.format("%8s", data).replace(' ', '0').toUpperCase(); 
    return str; 
} 

public static byte[] hexStringToByteArray(String s) { 
    int len = s.length(); 
    byte[] data = new byte[len/2]; 
    for (int i = 0; i < len; i += 2) { 
     data[i/2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) 
       + Character.digit(s.charAt(i + 1), 16)); 
    } 
    return data; 
} 

public static String byteArrayToHex(byte[] a) { 
    StringBuilder sb = new StringBuilder(a.length * 2); 
    for (byte b : a) { 
     sb.append(String.format("%02x", b)); 
    } 
    return sb.toString(); 
} 

入力は16進文字列(そうと仮定)です。したがって、メッセージは送信されており、応答も正しく受信されていますが、出力はエコーサービスに戻されていません。なぜそれは起こっていないのですか?私の設定に何か問題はありますか?

答えて

2

これはDEBUGログではなく、INFOのみです。 log4j構成が間違っていなければなりません。

デシリアライズ内部

これは、単にデータを待って受信スレッドです。メインフレームが接続を閉じるのを待っているあなたのforループに詰まっています - あなたはループ内にいくつかのデバッグを追加することをお勧めします。

EDIT

コモンズ・ロギングは

<dependency> 
    <groupId>commons-logging</groupId> 
    <artifactId>commons-logging</artifactId> 
    <version>1.2</version> 
</dependency> 

または

<dependency> 
    <groupId>org.apache.logging.log4j</groupId> 
    <artifactId>log4j-core</artifactId> 
    <version>2.7</version> 
</dependency> 

をlog4j2とlog4j2設定ファイルを作成するために切り替える...あなたのPOMから欠落しています。

春Frameworkの5は今のlog4j 1.xのをサポートしていませんコモンズ・ログの独自の実装を使用しています

+0

私は訂正を追加しました。これは、データを待っているデシリアライザに座っている読者スレッドです。 –

+0

あなたの権利、それは論理に私のせいでした。それを指摘してくれてありがとう。私は今それを修正し、バイトは文字列に変換されています。私はそれらを私のログに印刷することができますが、何らかの理由でechoserviceクラスに渡されません。なぜ私を助けることができますか? – JackSlayer94

+0

DEBUGログを見る必要があります。あなたがまだそれを理解できないならば。どこかのログを投稿してください。 –

0

応答の最後にメインフレームが接続を終了しない場合、おそらくそうではないため、読み取りループは決して終了しません。ループは、何らかの形で応答の予想長さまたは実際の長さを認識する必要があります。

シリアライザも確かにEBCDIC変換を行う必要がありますか?

+0

ええ - すでに、元の質問(https://stackoverflow.com/questions/45367943/spring-tcp-client-without-transformer/45373462#45373462)でEBCDIC変換について説明しました。 –

関連する問題