Announcement Announcement Module
Collapse
No announcement yet.
Advice on choosing best approach for xml over http Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advice on choosing best approach for xml over http

    Hi,

    I need to build a client that exchanges xml messages directly over http to a server process. The remoting api options I have considered for this are:
    • Commons HttpClient
    • Apache XML-RPC

    I am looking for a remoting option that has nice spring integration. Can anyone suggest alternatives?

    I intend using xmlbeans or castor to provide schema to object mapping. What other options are there?

    Thanks in advance,

    Colin

  • #3
    I've used HttpClient a lot and its a very good tool for initiating http communication with remote clients.

    If you have a system that just listens and responds to http calls then a servlet that reads the request input stream and puts any result into the servlet response works very well.

    I've used this very successfully for an XML messaging system.

    Comment


    • #4
      I made an HttpClient template that makes using HttpClient a little easier. It converts HttpException to a runtime exception so you don't have to catch errors if you don't want to and the template reduces code a little. It also makes setting up authentication a little easier (beans have no param constructors).

      Below are a couple of simple examples and there is more info if you follow the links.

      HttpClientTemplate

      Code:
      <bean id="httpClient" class="org.springbyexample.httpclient.HttpClientTemplate">
          <property name="defaultUri">
              <value><![CDATA[http://localhost:8093/test]]></value>
          </property>
      </bean>
      The built in callbacks are for String, InputStream, and a byte array (below String callback).

      Code:
      template.executeGetMethod(new ResponseStringCallback() {
          public void doWithResponse(String response) throws IOException {
              ...
              
              logger.debug("HTTP Get string response. '{}'", response);
          }
      });
      HttpClientOxmTemplate can also marshall and unmarshall responses using Spring Web Service's OXM Framework for marshalling and unmarshalling.

      Code:
      <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
          <property name="contextPath" value="org.springbyexample.schema.beans"/>
      </bean>
          
      <bean id="httpClient" class="org.springbyexample.httpclient.HttpClientOxmTemplate">
          <property name="defaultUri">
              <value><![CDATA[http://localhost:8093/test]]></value>
          </property>
          <property name="marshaller" ref="jaxbMarshaller" />
          <property name="unmarshaller" ref="jaxbMarshaller" />
      </bean>
      Code:
      template.executePostMethod(persons, new ResponseCallback<Persons>() {
          public void doWithResponse(Persons persons) throws IOException {
              ...
              
              Person result = persons.getPerson().get(0);
              
              ...
      
              logger.debug("id={}  firstName={}  lastName={}", 
                           new Object[] { result.getId(), 
                                          result.getFirstName(), 
                                          result.getLastName()});
          }
      });
      Last edited by David Winterfeldt; Apr 8th, 2008, 01:31 AM.

      Comment

      Working...
      X