XFire

Add support for custom HTTP headers

Details

  • Type: New Feature New Feature
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.2.5
  • Component/s: Core
  • Labels:
    None
  • Number of attachments :
    1

Description

It would be good to have a way to specify custom http headers

Activity

Hide
Scott MacKenzie added a comment -

This change is important for the project I am currently working on so I took a stab at a patch for it.

This patch will allow custom HTTP headers to be added as contextual properties. For example, the developer could set the header(s) like this:

Client client = Client.getInstance(soap)
Map m = new HashMap();
m.put("routing.key", "target");
m.put("test-header", new String[]{"test1", "test2"} );
client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m );

this would produce the following headers:

routing.key: target
test-header: test1
test-header: test2

The map can have either (String, String) or (String, String[]) since we are allowed to have headers with the same name.

Show
Scott MacKenzie added a comment - This change is important for the project I am currently working on so I took a stab at a patch for it. This patch will allow custom HTTP headers to be added as contextual properties. For example, the developer could set the header(s) like this:
Client client = Client.getInstance(soap)
Map m = new HashMap();
m.put("routing.key", "target");
m.put("test-header", new String[]{"test1", "test2"} );
client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m );
this would produce the following headers:
routing.key: target
test-header: test1
test-header: test2
The map can have either (String, String) or (String, String[]) since we are allowed to have headers with the same name.
Hide
Tomasz Sztelak added a comment -

Fixed in svn

Show
Tomasz Sztelak added a comment - Fixed in svn
Hide
Julius Davies added a comment -

I see this committed to SVN:

Map headersMap = (Map) context.getContextualProperty(HTTP_HEADERS);
if (headersMap != null) {
for (Iterator iter = headersMap.entrySet().iterator(); iter.hasNext() { Map.Entry entry = (Entry) iter.next(); postMethod.addRequestHeader(entry.getKey().toString(), entry.getValue().toString()); }
}

I like the Object.toString()! That could come in handy.

Is the support for several headers (so checking for instanceof Object[]) with the same name not desirable?

Just curious if the String[] idea was a bad one.

Show
Julius Davies added a comment - I see this committed to SVN: Map headersMap = (Map) context.getContextualProperty(HTTP_HEADERS); if (headersMap != null) { for (Iterator iter = headersMap.entrySet().iterator(); iter.hasNext() { Map.Entry entry = (Entry) iter.next(); postMethod.addRequestHeader(entry.getKey().toString(), entry.getValue().toString()); } } I like the Object.toString()! That could come in handy. Is the support for several headers (so checking for instanceof Object[]) with the same name not desirable? Just curious if the String[] idea was a bad one.
Hide
Tomasz Sztelak added a comment -

I fixed this before you attached your patch, so i couldn't see the idea with multiple values for one header. But still i don't see any potential situation when you must send many headers with the same name. If you show me any requirement of that kind i'll add such functionality.

Show
Tomasz Sztelak added a comment - I fixed this before you attached your patch, so i couldn't see the idea with multiple values for one header. But still i don't see any potential situation when you must send many headers with the same name. If you show me any requirement of that kind i'll add such functionality.

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: