iaik.xkms.transport
Class TransportUtil

Object
  extended by TransportUtil

public class TransportUtil
extends Object

Various XKMS transport medium utility functions.


Method Summary
static void appendHTTPResponseHeader(StringBuffer buffer)
          Appends HTTP response header to message.
static String discardHTTPResponseHeader(String response)
          Discards HTTP response header from String.
static String prependHTTPRequestHeader(String message, URI uri)
          Prepends HTTP request header to message.
static String prependHTTPResponseHeader(String message)
          Prepends HTTP response header to message.
static XMessageAbstractType responseStringToMessage(String response, XKMSContext context)
          Converts a response String into a Message and removes the SOAP header, if present.
static Element unwrapSOAP(Element messageElement, TransportModeEncapsulator transportation)
          Checks for SOAP enveloped XKMS Message and returns root element of contained message.
static String wrapMessage(String message, TransportMethod transportationMethod)
          Wraps message in envelope according to a transportation method.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

unwrapSOAP

public static Element unwrapSOAP(Element messageElement,
                                 TransportModeEncapsulator transportation)
                          throws InvalidRequestException
Checks for SOAP enveloped XKMS Message and returns root element of contained message. In addition the given transportation variable is set accordingly, if present (=not null)

Parameters:
transportation - the transportation method will be stored to this variable, if provided (= not null).
messageElement - root message element. If there is only one message in DOM this is Document.getDocumentElement().
Returns:
root element of the enveloped request, or null if this was not a SOAP enveloped request. If null is returned the transportation will not be changed.
Throws:
InvalidRequestException - if the message seems to be enveloped in SOAP at first but a contradiction to this assumption is found later on. E.g. the first element is a correct SOAP "Envelope" but no SOAP-body is present. The transportation will not be changed in this case.

wrapMessage

public static String wrapMessage(String message,
                                 TransportMethod transportationMethod)
Wraps message in envelope according to a transportation method. If transportation method is still UNKNOWN then PLAIN_HTTP is assumed.

SOAP 1.1 wrapping:

 <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
   ....
  </env:Body>
 </env:Envelope>
 
 

SOAP 1.2 wrapping:

 <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <env:Body>
   ....
  </env:Body>
 </env:Envelope>
 
 

Parameters:
message - message to wrap
Returns:
wrapped message.

prependHTTPResponseHeader

public static String prependHTTPResponseHeader(String message)
Prepends HTTP response header to message.

Prepends:

 HTTP/1.0 200 OK
 Connection: Close
 Content-Type: text/xml; charset=UTF-8
 Content-Length: ....
 \n
 
to message.

Parameters:
message - message to prepend header to
Returns:
message with prepended HTTP protocol header
Throws:
UnsupportedEncodingException - if the calculation of the output length fails due to an unsupported character encoding in transformation to bytes. (however, should NEVER happen...).

appendHTTPResponseHeader

public static void appendHTTPResponseHeader(StringBuffer buffer)
Appends HTTP response header to message.

See prependHTTPResponseHeader


prependHTTPRequestHeader

public static String prependHTTPRequestHeader(String message,
                                              URI uri)
Prepends HTTP request header to message.

Prepends:

 POST /path HTTP/1.0
 Content-Type: text/xml; charset=UTF-8
 Host: host.name
 Connection: Close
 Cache-Control: no-cache
 Content-Length: ...
 \n
 
to message.

Parameters:
message - message to prepend header to
uri - destination to connect to
Returns:
message with prepended HTTP protocol header

discardHTTPResponseHeader

public static String discardHTTPResponseHeader(String response)
                                        throws XKMSException
Discards HTTP response header from String.

Parameters:
response - a response String from the server, inclusive HTTP header
Returns:
the contained message
Throws:
XKMSException - if the header-body separation is not found. If HTTP response was not '200 OK'. If message has no XML declaration and also no or wrong HTTP 'Content-Type' header.

responseStringToMessage

public static XMessageAbstractType responseStringToMessage(String response,
                                                           XKMSContext context)
                                                    throws XKMSException
Converts a response String into a Message and removes the SOAP header, if present.

Call this method only if you don't know the wrapping status of the message. If there is no SOAP wrapping, directly call XKMSContext.StringToMessage instead, which is more efficient.

Parameters:
response - a response String
Returns:
the contained message
Throws:
XKMSException - if something goes wrong