Request & Response in NIO SocketChannel

Hi
I just reading NIO, SocketChannel.
Here I found short tutorial with examples:
http://developer.java.sun.com/developer/technicalArticles/releases/nio/
in ReadURL.java says about send some request
<Socket Channels>
String request = "GET / \r\n\r\n";
channel.write(encoder.encode(CharBuffer.wrap(request)));
Q?: What is response to this request and how generate this request?
<Non-Blocking Servers>
in Server.java is sending back a canned text message for each request
Q?: How I can read request that send client (ReadURL) then hence send response?
any suggestions or other tutorial links,
Thanks,
~Hill

http://www.javaworld.com/javaworld/jw-09-2001/jw-0907-merlin.html

Similar Messages

  • Sender adapter request response bean not working for calling a webservice

    Hi All,
    In PI 7.31, My scenario :  SOAP sender Asynch-> PI -> HTTP Receiver Sync ->take response to call another webservice  (SOAP)
    I have configured request response bean and response one way bean in the sender adapter to make this work.
    Attached the screenshot of the module config in  the sender soap adapter. The final response from HTTP has to be used to call another webservice (not sender webservice)
    This giving an error "couldn't retrieve binding values for sender to receiver etc etc ----------"
    Has anyone configured response one way bean to call a webservice to submit? If so, please share the configuration details. And let me know if I am doing anything wrong
    thx
    mike

    Hi Michael,
    I think the adapter type is for the receiver channel looking at the documentation SAP Library - SAP Exchange Infrastructure
    Have you checked your receiver channel doesn't belong to a party?
    I havent tried this bridge with the http_aae but looks to be problematic according with Michal comment here http://scn.sap.com/community/pi-and-soa-middleware/blog/2014/01/28/generic-pi-async-sync-bridge-configuration-for-any-adapters#comment-454463
    Regards.

  • Using Request Response Bean Module in FILE Adapter

    Hi Experts,
    Can we use Request Response Bean Module in FILE Adapter in reverse way. That is can we configure thses adapter modules in Reciever file channel and call a sender file channel in it?
    My case is RFC to File synchronous case? How do we do this?
    Thanks & Regards,
    priyanka

    Can we use Request Response Bean Module in FILE Adapter in reverse way. That is can we configure thses adapter
    modules in Reciever file channel and call a sender file channel in it?
    My case is RFC to File synchronous case? How do we do this?
    The above is not possible....Bean works only for Sender channel and not for Receiver.....requirement not possible using even a BPM as FILE does not support SYNC communication in receiver end......max you can do is split the scenario into SYNC-ASYNC bridge.
    Regards,
    Abhishek.

  • ESB Console turns Request/Response message into One Way message

    Hi folks,
    have come across a strange situation and wondered if anyone else had come across this. Maybe it's fixed as part of a patch set.
    I'm running SOA Suite 10.1.3.1.0 on Windows.
    After I've created and deployed a Request/Response service (either RS or SOAP Invocation Service) if I go to the ESB Console and click on "Apply" in say the Definition tab, my service turns into a One Way service.
    This then causes null pointer exceptions when I run my process, as you might expect.
    If I redeploy from JDev and leave the "Apply" button alone I'm back in business.
    Is this something that anyone else has had a problem with?

    Hi.
    I would recommend you to install version 10.1.3.3 of SOA Suite
    http://download.oracle.com/otn/nt/ias/10133/ias_windows_x86_101330.zip
    http://download.oracle.com/otn/linux/ias/10133/ias_linux_x86_101330.zip
    Also, use the JDev 10.1.3.3
    http://www.oracle.com/technology/software/products/jdev/htdocs/soft10133.html
    They are supposed to be much more stable.
    After using the new release, let us know if you still run into this problem.
    Denis

  • How to implement request/response domain in JMS

    hi friends,
    I need help regarding implementing request/response domain
    in jms.please help me.

    See the TopicRequestor and QueueRequestor helper classes in the JMS API.
    FWIW there's a POJO based request/response implementation using JMS here...
    http://lingo.codehaus.org
    you might find the source code useful as it does efficient request/response in a highly concurrent way using JMS under the covers.
    James
    http://logicblaze.com/

  • Request Response Bean for SOAP Sender Adapter

    Hi Friends,
    Is it possible to use  Request Response Bean Module described (FIle to RFC to File here) for SOAP(sender) and JDBC(receiver) adapter?
    I want to configure SOAP to JDBC to JDBC scenario.
    http://wiki.sdn.sap.com/wiki/display/HOME/UsingRequestResponseBeanModuleinFILE+Adapter
    Scenario:
    I will do SOAP adapter call Asynchronously and JDBC receiver adapter will select data from database. This response will go back to SOAP adapter and then SOAP will divert this response to another JDBC adapter. This JDBC adapter will insert data into another database.
    I do not want to use ccBPM. Is there any design approach to implement this scenario?
    Thanks,
    Sandeep Maurya

    Hi Sandeep,
    SAP says SOAP sender adapter does not support Modules. You can serch Help.sap (for SOAP sender channel) to find the same.
    I would suggest to use AXIS adapter (provides all the functionality of SOAP) and supports the Modules as well.
    I have used the Module beans that you mentioned in the past... but it is not consistent with its processing.. sometimes it stucks with Message ID issue... I have seen same issue faced some other friends as well .. search on SDN you will find the issue with these modules...
    Using BPM would be another option...
    Thanks,
    Sunil Singh

  • XML Namespace in WebService Request/Response

    Hi all,
    I have a question regarding xml namespace usage in wsdl and the corresponding request/response messages.
    I have already browsed quite some articles about xml namespaces as well as some forum threads, but I am still not sure.
    I have the following part of a wsdl document (generated by Integration Directory), defining a targetnamespace.
    u2026
    <wsdl:types>
        <xsd:schema targetNamespace="http://www.dorma.com/sap/xi/finance"
                             xmlns="http://www.dorma.com/sap/xi/finance"
                             xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:element name="DebtorGetDetailResponse" type="Z_BAPI_DEBTOR_GETDETAIL_Response"></xsd:element>
            u2026
            <xsd:complexType name="Z_BAPI_DEBTOR_GETDETAIL_Response">
                <xsd:sequence>
                    <xsd:element name="DEBITOR_COMPANY_DETAIL" type="BAPI1007_5" minOccurs="0">
                    </xsd:element> u2026
                </xsd:sequence>
            </xsd:complexType>
            u2026
        </xsd:schema>
        u2026
    </wsdl:types>
    u2026
    In my understanding, all types defined in the schema section of a wsdl document will be in the targetnamespace, if defined.
    Therefore the element DEBITOR_COMPANY_DETAIL would be in the namesapce
    http://www.dorma.com/sap/xi/finance
    However, the ABAP proxy generates a response message like follows,
    where only the root element is in this namespace and the child elements are in the global namespace:
    <?xml version="1.0" encoding="utf-8"?>
    <ns1:DebtorGetDetailResponse xmlns:ns1="http://www.dorma.com/sap/xi/finance"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <DEBITOR_COMPANY_DETAIL>
            u2026
        </DEBITOR_COMPANY_DETAIL>
        u2026
    </ns1:DebtorGetDetailResponse>
    Do I have a wrong understand of the wsdl (xml schema) or is this an erroneous behavior?
    The problem is that some 3rd-party software web service module does not accept
    the response message as not complient with the respective wsdl document.
    Any input is appreciated.
    Thanks
    Hans
    Edited by: Hans-Jürgen Schwippert on Oct 1, 2008 12:02 PM

    I have the same problem. I am trying to connect to a webservice running on IBM websphere but it doesn't accept the xml in my request. It appears to be the same namespace issue.
    Did you ever find a solution for this?
    Is it a valid webservice call if you omit the namespace for an element or is this a bug in the Adaptive WS implementation?
    Web Dynpro web service model generated request:
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Header>
    <sapsess:Session xmlns:sapsess="http://www.sap.com/webas/630/soap/features/session/">
    <enableSession>true</enableSession>
    </sapsess:Session>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
    look between these lines -
    <ns1:tamKontrolleraKontoLastAnrop xmlns:ns1="http://schemas.fora.se/modell/tam/1.0/TAM_Data">
    <AnvandarNamn>30039647</AnvandarNamn>
    </ns1:tamKontrolleraKontoLastAnrop>
    look between these lines -
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    As you can see the tag
    <AnvandarNamn>30039647</AnvandarNamn>
    is missing a namespace.
    It should be
    <ns1:AnvandarNamn>30039647</ns1:AnvandarNamn>
    Using a third part tool called Soapui i generate this request that works:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tam="http://schemas.fora.se/modell/tam/1.0/TAM_Data">
       <soapenv:Header/>
       <soapenv:Body>
          <tam:tamKontrolleraKontoLastAnrop>
             <tam:AnvandarNamn>30039647</tam:AnvandarNamn>
          </tam:tamKontrolleraKontoLastAnrop>
       </soapenv:Body>
    </soapenv:Envelope>

  • HTTP request/response object not thread safe.

    According to the serlvet spec. Http Request/Response
    are not thread safe. Quoting from the Spec:
    " Implementations of the request and response objects are not guaranteed to be thread safe. This means that they should only be used within the scope of the request handling thread. References to the request and response objects must not be given to objects executing in other threads as the resulting behavior may be nondeterministic."
    This has prompt me to ask the following question.
    For Example I have a servlet which does the following
    request.setAttribute("myVar","Hello");
    The request and response is dispatched(using RequestDispatch.include(request,response)) to another
    servlet which retrieve this attribute i.e request.getAttribute("myVar");
    Is this safe?
    The Spec only said "The Container Provider must ensure that the dispatch of the request to a target
    servlet occurs in the same thread of the same VM as the original request." I take this meaning that the targeting servlet does not have to run in the same thread(only dispatch), otherwise it would be safe.

    To put it another way, you can only have onle thing working on a request at a time. For instance, the ServletContext is available to all servlets running on a server. If you tried to save a particular request to the ServletContext, it would potentially be available to many concurrently running servlets. They could all change whatever in it at the same time. Each servlet is in its own running thread. Hope that helps some.

  • Is there a way to attach request/response handlers in BEA Weblogic Workshop similar to Axis?

    Apache Axis allows developers to attach Request/Response handlers to do
    stuff like logging, authorization check etc.
    Something like...
    public class MyHandler extends org.apache.axis.handlers.BasicHandler {
    public void invoke(org.apache.axis.MessageContext msgContext) throws
    AxisFault
    Does BEA Weblogic Workshop has a similar capability?
    Thanks.
    Best Regards
    Hitesh

    Hi Hitesh,
    The logging in Workshop user log4j and is configured in the
    <WL-HOME>/weblogic700/server/lib/workshopLogConfig.xml file.
    To log the SOAP responses, add the following lines in the xml file:
    <category name="knex.SoapJwsReq"> <priority value="debug" /> <appender-ref
    ref="MYLOGFILE" /> </category>
    <category name="knex.SoapJwsResp"> <priority value="debug" /> <appender-ref
    ref="MYLOGFILE" /> </category>
    The MYLOGFILE can be configured by copying from the already defined
    appenders. The file location is relative to the domain directory.
    <appender name="MYLOGFILE" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="mylog.log" />
    <param name="Append" value="true" />
    <param name="MaxFileSize" value="3000KB" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d{DATE} %-5p %-15c{1}: %m%n"/>
    </layout>
    </appender>
    As of now, the SOAP request message is not logged, only the responses are
    getting logged. This will be corrected within the next few days. Please also
    note that if you are using the Test View for running the web service, you
    should use the 'Test XML' tab for seeing the SOAP requests/responses. The
    'Test Form' tab uses HTTP GET, and hence you will not see any SOAP messages.
    Do let me know if you have any further queries.
    Regards,
    Anurag
    Workshop Support
    "Hitesh Seth" <[email protected]> wrote in message
    news:[email protected]...
    Thanks Anurag. What is the best recommended way in BEA Weblogic Workshop
    today to implement a logger which will log all SOAP Requests & Responses
    into a custom logging system.
    Best Regards
    Hitesh
    "Anurag Pareek" <[email protected]> wrote in message
    news:[email protected]...
    Hitesh,
    You can modify the SOAP request and response payload by using ECMA
    Script
    and XMLMaps.
    In the current release, Workshop does not support 'handlers' for SOAP
    messages.
    Regards,
    Anurag
    Workshop Support
    "Hitesh Seth" <[email protected]> wrote in message
    news:[email protected]...
    Apache Axis allows developers to attach Request/Response handlers to
    do
    stuff like logging, authorization check etc.
    Something like...
    public class MyHandler extends org.apache.axis.handlers.BasicHandler {
    public void invoke(org.apache.axis.MessageContext msgContext)throws
    AxisFault
    Does BEA Weblogic Workshop has a similar capability?
    Thanks.
    Best Regards
    Hitesh

  • WEB SERVICE + REQUEST RESPONSE TRACK

    Hello Friends,
    I have a issue, I have to consume the webservice made in .NET environment. The web service uses oasis security. so I have to set the SOAP HEADER with user name and passwrod. Unfortunately its not working. My question is , is there any way that one can track the request response... Can I see, how my request packet looks like when it reaches to server ?
    Any help will be gr8.
    Regards,

    Hi Raja,
    Okey, now I will first paste the request formate which web service is expecting, and then I will paste my code, might be you have hint for me.....
    POST /alertservice.asmx HTTP/1.1
            Host: desktopalert
            Content-Type: text/xml; charset=utf-8
            Content-Length: length
            SOAPAction: "http://service.desktopalert.net/AlertService.asmx/CreateAlert"
            <?xml version="1.0" encoding="utf-8"?>
            <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
              <soapenv:Header>
                <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                  <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-386451">
                    <wsse:Username>someuser</wsse:Username>
                    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">ILReFb7Uz57eNwgJXjj9S086aAw=</wsse:Password>
                    <wsse:Nonce>jHgxoLOr9RzHpALQRark7Q==</wsse:Nonce>
                    <wsu:Created>2007-02-11T23:34:23.027Z</wsu:Created>
                  </wsse:UsernameToken>
                  <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-24470798">
                    <wsu:Created>2007-02-11T23:34:22.996Z</wsu:Created>
                    <wsu:Expires>2007-02-11T23:39:22.996Z</wsu:Expires>
                  </wsu:Timestamp>
                </wsse:Security>
              </soapenv:Header>
              <soap:Body>
                <CreateAlert xmlns="http://service.desktopalert.net/AlertService.asmx">
                  <content>string</content>
                  <title>string</title>
                  <height>int</height>
                  <width>int</width>
                  <PublishDate>dateTime</PublishDate>
                  <ExpireDate>dateTime</ExpireDate>
                  <groupids>
                    <int>int</int>
                    <int>int</int>
                  </groupids>
                </CreateAlert>
              </soap:Body>
            </soap:Envelope>
            HTTP/1.1 200 OK
            Content-Type: text/xml; charset=utf-8
            Content-Length: length
    My code ( SOAP HEADER AND SOAP BODY ):
    CONCATENATE
    '<?xml version="1.0" encoding="UTF-8"?>'
    '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
    '  <soapenv:Header>'
    '    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'
    '      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-11072909">'
    '        <wsse:Username>admin</wsse:Username>'
    '        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">ISMvKXpXpadDiUoOSoAfww==</wsse:Password>'
    '        <wsse:Nonce>WL4S/89uFlsVZ+Ys73fTNQ==</wsse:Nonce>'
    '        <wsu:Created>2007-03-27T14:34:23.199Z</wsu:Created>'
    '      </wsse:UsernameToken>'
    '      <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-12203633">'
    '        <wsu:Created>2007-03-27T14:34:23.184Z</wsu:Created>'
    '        <wsu:Expires>2007-03-27T14:39:23.184Z</wsu:Expires>'
    '      </wsu:Timestamp>'
    '    </wsse:Security>'
    '  </soapenv:Header>'
    '<soap:Body>'
    '   <CreateAlert xmlns="http://service.desktopalert.net/AlertService.asmx" /> '
    '    <content>teststring</content>'
    '    <title>teststring</title>'
    '    <height>300</height>'
    '    <width>300</width>'
    '    <PublishDate> 27.03.2007 16:08:18</PublishDate>'
    '    <ExpireDate>30.03.2007 10:00:18</ExpireDate>'
    '    <groupids>'
    '      <int>1</int>'
    '      <int>1</int>'
    '    </groupids>'
    '    </CreateAlert>'
    '    </soap:Body>'
    '</soapenv:Envelope>'
    INTO WF_STRING.
    And if any one of the parameter is wrong, still I am expecting that, my data reached till database, or if I am doing something wrong, then some exception, error, has to come ? right...
    Regards,

  • OSB with request response MQ business service

    Hi,
    We have OSB webservice whice interacts with MQ via business service. We need to send the request to MQ request queue and get the response from the response queue.
    For this, we have configured a business with MQ transport, request-response is enabled, message id is set for the correlation, auto generate correlation value is chosen.
    The business service sends the message but unable receive the response from the response queue. Failing with the error message like
    The invocation resulted in an error: [WliSbTransports:381918]Failed to receive response, within the configured timeout, for request message with id 42454BD3E5F7647914544E793F9F0000013EC9DF03918057 and correlation id 42454BD3E5F7647914544E793F9F0000013EC9DF03918057.
    But we checked with the end system, the response is sent tot he response queue in no time. We also increased the time out but still same issue.
    We noticed that if we dont send the message id, we are getting the response but not response of the request sent but some other response.
    Please suggest what needs to be done to fix the issue.

    Open your business service and navigate to HTTP Transport configuration page and check what is the http type is enabled.
    Look to me its with GET method, change it to POST and re-try.
    If the above solution is not helping, try to check the Follow HTTP redirects check box below the Advanced Setting in same page.
    Thanks,
    Vijay

  • Best way to implement request-response and still reliability

              HI,
              what is the best way to implement a request -response paradigm and still have
              the reliability that message will be 100% processed and give response...do i need
              to create the permanant queues with storage..
              anybody gives suggestions..
              Akhil
              

    Hi Akhil,
              Temporary destinations can only store non-persistent messages
              as per JMS spec - so they are not useful for reliable for holding
              responses that must survive longer than the life of the
              interested client. For persistence, you will need to use configured
              queues or durable subscriptions. For detailed
              discussion of request/response, I suggest reading the "WebLogic JMS
              Performance Guide" white-paper on dev2dev.bea.com. If you
              have many clients, or expect large message back-logs,
              there can be a performance impact when using selectors...
              FYI: There is a new pub/sub subscriber index enhancement
              that is available in 8.1 and
              in the latest service-packs for 6.1, 7.0.
              "Indexing Topic Subscriber Message Selectors To Optimize Performance"
              http://edocs.bea.com/wls/docs81/jms/implement.html#1294809
              This may be useful.
              Tom, BEA
              Akhil Nagpal wrote:
              > HI,
              > what is the best way to implement a request -response paradigm and still have
              > the reliability that message will be 100% processed and give response...do i need
              > to create the permanant queues with storage..
              >
              > anybody gives suggestions..
              > Akhil
              

  • Workbench freezes on call to BAPI_PRODORDCONF_GETLIST Request/Response XML

    I have created a simple transaction in MII 12.0.6 with three JRA actions: Start Session, Function Call, and End Session.  From the configuration dialog of the Function Call action, I confirmed the existance of BAPI_PRODORDCONF_GETLIST via a BAPI search. I attempted to select this BAPI only to have the Workbench freeze up.  This BAPI works flawlessly in SE37. I checked the logs and saw that the following error message was thrown:
    com.sap.mw.jco.jra.JRA$ResourceException: Couldn't execute interaction. Transaction rolledback due to connection interruption...
    I am using the same JRA connection to call BAPIs in other transactions without any issues.
    Has someone ran into a similar issue before that could assist me in resolving this?
    FYI...my objective is to obtain a list of confirmations, including the confirmation number and confirmation counters, from the output of this BAPI which will be inputted into BAPI_PROCORDCONF_GETDETAIL to maintain a count of the yield and scrap already confirmed for that particular operation/phase.
    Thanks,
    Michael Teti
    Senior Solutions Consultant
    SeeIT Solutions, LLC

    Michael,
    It was my understanding (via customer confirmation) that the returned Yield and Scrap located in the Phase tables of the BAPI_PROCORD_GET_DETAIL Bapi are the Planned Operation Yield and Scrap for that operation and not the Yield and Scrap already confirmed.  The Help documentation in the BAPI Explorer does not verify this one way or another.
    Also, after numerous attempts of trying to pull down the BAPI_PROCORDCONF_GETLIST Request/Response XML, the configuration dialog actually closed.  It tooke quite a long time to complete.  My guess is that it timed out because when I look at the BAPI structure, there was none.
    I did see the other thread prior to my submission but since that thread was referring to a JCO connection and a timeout wasn't actually confirmed on my end, I decided to creat a new one.
    Thanks,
    Michael Teti

  • Blocking Request/Response model

    Hi everyone !
    I'm starting to write a JMS application and I'm having some doubt about the request/response model enabled by the replyTo() method and CorrelationID field. As far is I know JMS is intended to let the client be free from the server's response by posting it's message on the queue and start doing some other work. But supposing the client needs a response from the server(a MDB) after the processing of the message I wonder how would him receive this response, assuming there is a second queue for posting the response messages. Simply using the MessageConsumer.receive() the client will be blocked, killing all the purpose of the model(even with timeout). So I wonder, should I create a second MDB just to handle the response queue ? This would left me with an RPC message producer, a MDB Message consumer (of the request message), and a MDB Message consumer (on the response queue). Is this a normal approach or is there something better ???

    Simply using the MessageConsumer.receive() the client will be blocked, killing all the purpose of the model(even with timeout).
    You have to send the message and wait for the response in two separate transactions. For example:
    // Start create and send transaction  
    ctx.getUserTransaction().begin();
    connection = connectionFactory.createQueueConnection();
    connection.start();
    session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    final Message request = // create message
    final Queue tempQueue = session.createTemporaryQueue();
    request.setJMSReplyTo(tempQueue);
    final QueueSender sender = session.createSender(destination);
    sender.send(request);
    ctx.getUserTransaction().commit();
    // End create and send transaction
    // Start receive transaction
    ctx.getUserTransaction().begin();
    final QueueReceiver receiver = session.createReceiver(tempQueue);
    final Message response = receiver.receive(TIMEOUT);
    ctx.getUserTransaction().commit();
    // End receive transaction
    // process response

  • Blocking Request/Response JMS model

    Hi everyone !
    I'm starting to write a JMS application and I'm having some doubt about the request/response model enabled by the replyTo() method and CorrelationID field. As far is I know JMS is intended to let the client be free from the server's response by posting it's message on the queue and start doing some other work. But supposing the client needs a response from the server(a MDB) after the processing of the message I wonder how would him receive this response, assuming there is a second queue for posting the response messages. Simply using the MessageConsumer.receive() the client will be blocked, killing all the purpose of the model(even with timeout). So I wonder, should I create a second MDB just to handle the response queue ? This would left me with an RPC message producer, a MDB Message consumer (of the request message), and a MDB Message consumer (on the response queue). Is this a normal approach or is there something better ?
    Thank you !

    Simply using the MessageConsumer.receive() the client will be blocked, killing all the purpose of the model(even with timeout).
    You have to send the message and wait for the response in two separate transactions. For example:
    // Start create and send transaction  
    ctx.getUserTransaction().begin();
    connection = connectionFactory.createQueueConnection();
    connection.start();
    session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    final Message request = // create message
    final Queue tempQueue = session.createTemporaryQueue();
    request.setJMSReplyTo(tempQueue);
    final QueueSender sender = session.createSender(destination);
    sender.send(request);
    ctx.getUserTransaction().commit();
    // End create and send transaction
    // Start receive transaction
    ctx.getUserTransaction().begin();
    final QueueReceiver receiver = session.createReceiver(tempQueue);
    final Message response = receiver.receive(TIMEOUT);
    ctx.getUserTransaction().commit();
    // End receive transaction
    // process response

Maybe you are looking for