Announcement Announcement Module
Collapse
No announcement yet.
Modifying/Adding HTTP Headers? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Modifying/Adding HTTP Headers?

    Hi everyone, may your weeks be going well.

    At my workplace I'm trying to consume a web service hosted on a CICS Transaction Server mainframe. Everything was going well until a recent system patch caused a failure. We're having little luck tracking down the cause, but suspect it has something to do with the content-type and/or charset.

    I've used TCPMon to "peek in" at what's being sent and everything looks good to me (i.e. "text/html; charset=utf-8"). However, the server people want to try to use iso-8859-1 instead of Unicode.

    I've tried setting the charset via a HttpClient in my bean (see below) but to no avail. How do I modify HTTP headers in Spring WS? Also, how could I send custom headers (I'm guessing it's the same mechanism).

    Here's my bean definition:
    Code:
    <bean
      class="webservices.clients.FooClient"
      p:defaultUri="${FooClientUrl}"
    >
      <property name="messageSenders">
        <list>
          <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
            <constructor-arg>
              <bean class="org.apache.commons.httpclient.HttpClient">
                <property name="params">
                  <!--
                    this does NOT seem to work ...
                  -->
                  <bean
                    class="org.apache.commons.httpclient.params.HttpClientParams"
                    p:contentCharset="ISO-8859-1"
                  />
                </property>
              </bean>
            </constructor-arg>
          </bean>
        </list>
      </property>
    </bean>
    Thanks in advance!

  • #2
    More Information.

    After using TCPMon to proxy the request the HTTP Header for content-type looks like this: "Content-type: text/xml". Note the lack of charset being added.

    Of course the server SHOULD just use a sensible default in the case of no charset being reported ...

    Comment


    • #3
      If using SAAJ, you can set the content type of the message by setting a property. Something like:

      Code:
      WebServiceMessage message = ...
      SOAPMessage saajMessage = ((SaajSoapMessage)message).getSaajMessage();
      saajMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "iso-8559-1");
      You could do this in an interceptor or callback.

      Comment


      • #4
        Thank you very much. I figured this out yesterday afternoon but forgot to post back to the forum regarding my solution. Hours of sifting through Spring WS source code and a few lucky hits on Google found me my solution.

        I ended up making a single class that implements WebServiceMessageCallback that inspects the message to see if it is a SaajSoapMessage and adds the headers (that are then exposed as bean properties). My client classes (which extend WebServiceGatewaySupport) now just instantiate my callback class in afterPropertiesSet if there is no other callback set via an exposed bean property.

        I still haven't figured out why Saaj wasn't adding headers on one server, yet was on other servers.

        Thanks for getting back to me, I apologize for not updating the forum of my findings yesterday.

        Comment

        Working...
        X