Search in sources :

Example 1 with Headers

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);
    }
}
Also used : Headers(com.sun.xml.ws.transport.Headers) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Headers

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;
}
Also used : Enumeration(java.util.Enumeration) Headers(com.sun.xml.ws.transport.Headers) NotNull(com.sun.istack.NotNull)

Example 3 with Headers

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;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Headers(com.sun.xml.ws.transport.Headers) MimeHeader(jakarta.xml.soap.MimeHeader) Iterator(java.util.Iterator)

Example 4 with Headers

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);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) Headers(com.sun.xml.ws.transport.Headers) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SOAPBinding(jakarta.xml.ws.soap.SOAPBinding) IOException(java.io.IOException) WebServiceException(jakarta.xml.ws.WebServiceException) ClientTransportException(com.sun.xml.ws.client.ClientTransportException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with Headers

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;
}
Also used : Headers(com.sun.xml.ws.transport.Headers)

Aggregations

Headers (com.sun.xml.ws.transport.Headers)5 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 NotNull (com.sun.istack.NotNull)1 Packet (com.sun.xml.ws.api.message.Packet)1 ClientTransportException (com.sun.xml.ws.client.ClientTransportException)1 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)1 MimeHeader (jakarta.xml.soap.MimeHeader)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 SOAPBinding (jakarta.xml.ws.soap.SOAPBinding)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1