use of com.sun.xml.ws.transport.Headers in project metro-jax-ws by eclipse-ee4j.
the class RequestContext method mergeRequestHeaders.
@SuppressWarnings("unchecked")
private void mergeRequestHeaders(Packet packet) {
// for bug 12883765
// retrieve headers which is set in soap message
Headers packetHeaders = (Headers) packet.invocationProperties.get(MessageContext.HTTP_REQUEST_HEADERS);
// retrieve headers from request context
Map<String, List<String>> myHeaders = (Map<String, List<String>>) asMap().get(MessageContext.HTTP_REQUEST_HEADERS);
if ((packetHeaders != null) && (myHeaders != null)) {
// update the headers set in soap message with those in request context
for (Entry<String, List<String>> entry : myHeaders.entrySet()) {
String key = entry.getKey();
if (key != null && key.trim().length() != 0) {
List<String> listFromPacket = packetHeaders.get(key);
// if the two headers contain the same key, combine the value
if (listFromPacket != null) {
listFromPacket.addAll(entry.getValue());
} else {
// add the headers in request context to those set in soap message
packetHeaders.put(key, myHeaders.get(key));
}
}
}
// update headers in request context with those set in soap message since it may contain other properties..
asMap().put(MessageContext.HTTP_REQUEST_HEADERS, packetHeaders);
}
}
use of com.sun.xml.ws.transport.Headers in project metro-jax-ws by eclipse-ee4j.
the class ServletConnectionImpl method getRequestHeaders.
@Override
@Property({ MessageContext.HTTP_REQUEST_HEADERS, Packet.INBOUND_TRANSPORT_HEADERS })
@NotNull
public Map<String, List<String>> getRequestHeaders() {
if (requestHeaders == null) {
requestHeaders = new Headers();
Enumeration enums = request.getHeaderNames();
while (enums.hasMoreElements()) {
String headerName = (String) enums.nextElement();
Enumeration e = request.getHeaders(headerName);
if (e != null) {
List<String> values = requestHeaders.get(headerName);
while (e.hasMoreElements()) {
String headerValue = (String) e.nextElement();
if (values == null) {
values = new ArrayList<>();
requestHeaders.put(headerName, values);
}
values.add(headerValue);
}
}
}
}
return requestHeaders;
}
use of com.sun.xml.ws.transport.Headers in project metro-jax-ws by eclipse-ee4j.
the class SOAPMessageDispatch method createPacket.
@Override
Packet createPacket(SOAPMessage arg) {
Iterator iter = arg.getMimeHeaders().getAllHeaders();
Headers ch = new Headers();
while (iter.hasNext()) {
MimeHeader mh = (MimeHeader) iter.next();
ch.add(mh.getName(), mh.getValue());
}
Packet packet = new Packet(SAAJFactory.create(arg));
packet.invocationProperties.put(MessageContext.HTTP_REQUEST_HEADERS, ch);
return packet;
}
use of com.sun.xml.ws.transport.Headers in project metro-jax-ws by eclipse-ee4j.
the class HttpTransportPipe method process.
@Override
public Packet process(Packet request) {
HttpClientTransport con;
try {
// get transport headers from message
Map<String, List<String>> reqHeaders = new Headers();
@SuppressWarnings("unchecked") Map<String, List<String>> userHeaders = (Map<String, List<String>>) request.invocationProperties.get(MessageContext.HTTP_REQUEST_HEADERS);
boolean addUserAgent = true;
if (userHeaders != null) {
// userHeaders may not be modifiable like SingletonMap, just copy them
reqHeaders.putAll(userHeaders);
// application wants to use its own User-Agent header
if (userHeaders.get("User-Agent") != null) {
addUserAgent = false;
}
}
if (addUserAgent) {
reqHeaders.put("User-Agent", USER_AGENT);
}
addBasicAuth(request, reqHeaders);
addCookies(request, reqHeaders);
con = getTransport(request, reqHeaders);
request.addSatellite(new HttpResponseProperties(con));
ContentType ct = codec.getStaticContentType(request);
if (ct == null) {
ByteArrayBuffer buf = new ByteArrayBuffer();
ct = codec.encode(request, buf);
// data size is available, set it as Content-Length
reqHeaders.put("Content-Length", Collections.singletonList(Integer.toString(buf.size())));
reqHeaders.put("Content-Type", Collections.singletonList(ct.getContentType()));
if (ct.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(ct.getAcceptHeader()));
}
if (binding instanceof SOAPBinding) {
writeSOAPAction(reqHeaders, ct.getSOAPActionHeader());
}
if (dump || LOGGER.isLoggable(Level.FINER)) {
dump(buf, "HTTP request", reqHeaders);
}
buf.writeTo(con.getOutput());
} else {
// Set static Content-Type
reqHeaders.put("Content-Type", Collections.singletonList(ct.getContentType()));
if (ct.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(ct.getAcceptHeader()));
}
if (binding instanceof SOAPBinding) {
writeSOAPAction(reqHeaders, ct.getSOAPActionHeader());
}
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
codec.encode(request, buf);
dump(buf, "HTTP request - " + request.endpointAddress, reqHeaders);
OutputStream out = con.getOutput();
if (out != null) {
buf.writeTo(out);
}
} else {
OutputStream os = con.getOutput();
if (os != null) {
codec.encode(request, os);
}
}
}
con.closeOutput();
return createResponsePacket(request, con);
} catch (WebServiceException wex) {
throw wex;
} catch (Exception ex) {
throw new WebServiceException(ex);
}
}
use of com.sun.xml.ws.transport.Headers in project metro-jax-ws by eclipse-ee4j.
the class HttpClientTransport method getHeaders.
public Map<String, List<String>> getHeaders() {
if (respHeaders != null) {
return respHeaders;
}
respHeaders = new Headers();
respHeaders.putAll(httpConnection.getHeaderFields());
return respHeaders;
}
Aggregations