Search in sources :

Example 11 with SOAPBinding

use of jakarta.xml.ws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class HttpTransportPipe method createResponsePacket.

private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
    // throws IOE
    con.readResponseCodeAndMessage();
    recordCookies(request, con);
    InputStream responseStream = con.getInput();
    if (dump || LOGGER.isLoggable(Level.FINER)) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        if (responseStream != null) {
            buf.write(responseStream);
            responseStream.close();
        }
        dump(buf, "HTTP response - " + request.endpointAddress + " - " + con.statusCode, con.getHeaders());
        responseStream = buf.newInputStream();
    }
    // Check if stream contains any data
    int cl = con.contentLength;
    InputStream tempIn = null;
    if (cl == -1) {
        // No Content-Length header
        tempIn = StreamUtils.hasSomeData(responseStream);
        if (tempIn != null) {
            responseStream = tempIn;
        }
    }
    if (cl == 0 || (cl == -1 && tempIn == null)) {
        if (responseStream != null) {
            // No data, so close the stream
            responseStream.close();
            responseStream = null;
        }
    }
    // Allows only certain http status codes for a binding. For all
    // other status codes, throws exception
    // throws ClientTransportException
    checkStatusCode(responseStream, con);
    // To avoid zero-length chunk for One-Way
    if (cl == -1 && con.statusCode == 202 && "Accepted".equals(con.statusMessage) && responseStream != null) {
        ByteArrayBuffer buf = new ByteArrayBuffer();
        // What is within the responseStream?
        buf.write(responseStream);
        responseStream.close();
        responseStream = (buf.size() == 0) ? null : buf.newInputStream();
        buf.close();
    }
    Packet reply = request.createClientResponse(null);
    reply.wasTransportSecure = con.isSecure();
    if (responseStream != null) {
        String contentType = con.getContentType();
        if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
            throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
        }
        codec.decode(responseStream, contentType, reply);
    }
    return reply;
}
Also used : ClientTransportException(com.sun.xml.ws.client.ClientTransportException) Packet(com.sun.xml.ws.api.message.Packet) InputStream(java.io.InputStream) SOAPBinding(jakarta.xml.ws.soap.SOAPBinding) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 12 with SOAPBinding

use of jakarta.xml.ws.soap.SOAPBinding 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 13 with SOAPBinding

use of jakarta.xml.ws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class EndToEndTest method testAllRoles.

/*
     * Test the allRoles boolean argument of getHeaders()
     * method in SOAPMessageContext.
     */
public void testAllRoles() throws Exception {
    TestService_Service service = getService();
    TestService testStub = getTestStub(service);
    ReportService reportStub = getReportStub(service);
    HandlerTracker tracker = HandlerTracker.getClientInstance();
    // these lines make calls to the server
    reportStub.clearHandlerTracker();
    reportStub.setInstruction(SERVER_PREFIX + 4, HA_ADD_HEADER_OUTBOUND_CLIENT_ROLE1);
    // so we clear out the client handlers afterwards
    tracker.clearAll();
    tracker.setHandlerAction(CLIENT_PREFIX + 7, HA_CHECK_SMC_ALL_ROLES);
    // first check with the client1 role
    int result = testStub.testInt(5);
    // now check without the known role (should get no headers in handler)
    SOAPBinding sBinding = (SOAPBinding) ((BindingProvider) testStub).getBinding();
    sBinding.setRoles(new HashSet<String>());
    result = testStub.testInt(5);
}
Also used : HandlerTracker(handler.handler_processing.common.HandlerTracker) SOAPBinding(jakarta.xml.ws.soap.SOAPBinding)

Example 14 with SOAPBinding

use of jakarta.xml.ws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class MtomCidTest method setUp.

@Override
public void setUp() throws Exception {
    HelloService helloService = new HelloService();
    Object obj = helloService.getHelloPort();
    assertTrue(obj != null);
    // set Mtom optimization.
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) obj).getBinding();
    binding.setMTOMEnabled(true);
    port = (Hello) obj;
    address = (String) ((BindingProvider) obj).getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
}
Also used : SOAPBinding(jakarta.xml.ws.soap.SOAPBinding)

Aggregations

SOAPBinding (jakarta.xml.ws.soap.SOAPBinding)14 WebServiceException (jakarta.xml.ws.WebServiceException)3 ClientTransportException (com.sun.xml.ws.client.ClientTransportException)2 HandlerTube (com.sun.xml.ws.handler.HandlerTube)2 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)2 Binding (jakarta.xml.ws.Binding)2 BindingProvider (jakarta.xml.ws.BindingProvider)2 HashSet (java.util.HashSet)2 NotNull (com.sun.istack.NotNull)1 Packet (com.sun.xml.ws.api.message.Packet)1 ClientLogicalHandlerTube (com.sun.xml.ws.handler.ClientLogicalHandlerTube)1 ClientMessageHandlerTube (com.sun.xml.ws.handler.ClientMessageHandlerTube)1 ClientSOAPHandlerTube (com.sun.xml.ws.handler.ClientSOAPHandlerTube)1 ServerLogicalHandlerTube (com.sun.xml.ws.handler.ServerLogicalHandlerTube)1 ServerMessageHandlerTube (com.sun.xml.ws.handler.ServerMessageHandlerTube)1 ServerSOAPHandlerTube (com.sun.xml.ws.handler.ServerSOAPHandlerTube)1 Headers (com.sun.xml.ws.transport.Headers)1 HandlerAnnotationInfo (com.sun.xml.ws.util.HandlerAnnotationInfo)1 HandlerTracker (fromwsdl.handler.common.HandlerTracker)1 HandlerTracker (handler.handler_processing.common.HandlerTracker)1