Search in sources :

Example 6 with WebServiceException

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

the class FiberTest method testCancel.

public void testCancel() throws InterruptedException {
    final Semaphore atResponse = new Semaphore(0);
    final Semaphore mayProceed = new Semaphore(0);
    TestTube tubeC = new TestTube();
    FilterTestTube tubeB = new FilterTestTube(tubeC) {

        @Override
        @NotNull
        public NextAction processResponse(@NotNull Packet response) {
            try {
                atResponse.release();
                mayProceed.acquire();
            } catch (InterruptedException e) {
                throw new WebServiceException(e);
            }
            return super.processResponse(response);
        }
    };
    final FilterTestTube tubeA = new FilterTestTube(tubeB);
    final Packet request = new Packet();
    final SimpleCompletionCallback callback = new SimpleCompletionCallback();
    final Fiber fiber = engine.createFiber();
    assertNotNull(fiber);
    Thread testThread = new Thread(new Runnable() {

        @Override
        public void run() {
            fiber.start(tubeA, request, callback, true);
        }
    });
    testThread.start();
    if (!atResponse.tryAcquire(3, TimeUnit.MINUTES))
        fail("timeout");
    fiber.cancel(false);
    mayProceed.release();
    testThread.join(3 * 60 * 1000);
    assertNull(callback.response);
    assertNull(callback.error);
    List<TubeCall> calls = tubeA.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    TubeCall firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeB.getCalls();
    assertNotNull(calls);
    assertEquals(2, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    TubeCall secondCall = calls.get(1);
    assertNotNull(secondCall);
    assertEquals(TubeCallType.RESPONSE, secondCall.callType);
    assertEquals(testContainer, secondCall.container);
    calls = tubeC.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) WebServiceException(jakarta.xml.ws.WebServiceException) TubeCall(com.sun.xml.ws.api.pipe.EngineTest.TubeCall) Semaphore(java.util.concurrent.Semaphore) NotNull(com.sun.istack.NotNull) TestTube(com.sun.xml.ws.api.pipe.EngineTest.TestTube) SimpleCompletionCallback(com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback)

Example 7 with WebServiceException

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

the class Messages method createAddressingFaultMessage.

/**
 * Creates a fault {@link Message} that captures the code/subcode/subsubcode
 * defined by WS-Addressing if one of the expected WS-Addressing headers is
 * missing in the message
 *
 * @param binding WSBinding
 * @param p
 *      {@link Packet} that was missing a WS-Addressing header.
 * @param missingHeader The missing WS-Addressing Header
 * @return
 *      A message representing SOAPFault that contains the WS-Addressing code/subcode/subsubcode.
 */
public static Message createAddressingFaultMessage(WSBinding binding, Packet p, QName missingHeader) {
    AddressingVersion av = binding.getAddressingVersion();
    if (av == null) {
        // Addressing is not enabled.
        throw new WebServiceException(AddressingMessages.ADDRESSING_SHOULD_BE_ENABLED());
    }
    WsaTubeHelper helper = av.getWsaHelper(null, null, binding);
    return create(helper.newMapRequiredFault(new MissingAddressingHeaderException(missingHeader, p)));
}
Also used : AddressingVersion(com.sun.xml.ws.api.addressing.AddressingVersion) WebServiceException(jakarta.xml.ws.WebServiceException) WsaTubeHelper(com.sun.xml.ws.addressing.WsaTubeHelper) MissingAddressingHeaderException(com.sun.xml.ws.addressing.model.MissingAddressingHeaderException)

Example 8 with WebServiceException

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

the class Messages method create.

/**
 * Creates a {@link Message} from an {@link Element} that represents
 * the whole SOAP message.
 *
 * @param soapEnvelope
 *      The SOAP envelope element.
 */
public static Message create(Element soapEnvelope) {
    SOAPVersion ver = SOAPVersion.fromNsUri(soapEnvelope.getNamespaceURI());
    // find the headers
    Element header = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Header");
    HeaderList headers = null;
    if (header != null) {
        for (Node n = header.getFirstChild(); n != null; n = n.getNextSibling()) {
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                if (headers == null)
                    headers = new HeaderList(ver);
                headers.add(Headers.create((Element) n));
            }
        }
    }
    // find the payload
    Element body = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Body");
    if (body == null)
        throw new WebServiceException("Message doesn't have <S:Body> " + soapEnvelope);
    Element payload = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Body");
    if (payload == null) {
        return new EmptyMessageImpl(headers, new AttachmentSetImpl(), ver);
    } else {
        return new DOMMessage(ver, headers, payload);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) Element(org.w3c.dom.Element) XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) JAXBElement(jakarta.xml.bind.JAXBElement) Node(org.w3c.dom.Node) AttachmentSetImpl(com.sun.xml.ws.message.AttachmentSetImpl) DOMMessage(com.sun.xml.ws.message.DOMMessage) EmptyMessageImpl(com.sun.xml.ws.message.EmptyMessageImpl)

Example 9 with WebServiceException

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

the class Packet method toString.

// For use only in a debugger
@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    buf.append(super.toString());
    String content;
    try {
        Message msg = getMessage();
        if (msg != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter xmlWriter = XMLStreamWriterFactory.create(baos, "UTF-8");
            msg.copy().writeTo(xmlWriter);
            xmlWriter.flush();
            xmlWriter.close();
            baos.flush();
            XMLStreamWriterFactory.recycle(xmlWriter);
            byte[] bytes = baos.toByteArray();
            // message = Messages.create(XMLStreamReaderFactory.create(null, new ByteArrayInputStream(bytes), "UTF-8", true));
            content = new String(bytes, StandardCharsets.UTF_8);
        } else {
            content = "<none>";
        }
    } catch (Throwable t) {
        throw new WebServiceException(t);
    }
    buf.append(" Content: ").append(content);
    return buf.toString();
}
Also used : SOAPMessage(jakarta.xml.soap.SOAPMessage) WebServiceException(jakarta.xml.ws.WebServiceException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 10 with WebServiceException

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

the class Fiber method _doRun.

private boolean _doRun(Tube next) {
    // isRequireUnlock will contain Boolean.FALSE when lock has already been released in suspend
    Holder<Boolean> isRequireUnlock = new Holder<>(Boolean.TRUE);
    lock.lock();
    try {
        List<FiberContextSwitchInterceptor> ints;
        ClassLoader old;
        synchronized (this) {
            ints = interceptors;
            // currentThread is protected by the monitor for this fiber so
            // that it is accessible to cancel() even when the lock is held
            currentThread = Thread.currentThread();
            if (isTraceEnabled()) {
                LOGGER.log(Level.FINE, "Thread entering _doRun(): {0}", currentThread);
            }
            old = currentThread.getContextClassLoader();
            currentThread.setContextClassLoader(contextClassLoader);
        }
        try {
            boolean needsToReenter;
            do {
                // if interceptors are set, go through the interceptors.
                if (ints == null) {
                    this.next = next;
                    if (__doRun(isRequireUnlock, null)) {
                        return true;
                    }
                } else {
                    next = new InterceptorHandler(isRequireUnlock, ints).invoke(next);
                    if (next == PLACEHOLDER) {
                        return true;
                    }
                }
                synchronized (this) {
                    needsToReenter = (ints != interceptors);
                    if (needsToReenter)
                        ints = interceptors;
                }
            } while (needsToReenter);
        } catch (OnExitRunnableException o) {
            // catching this exception indicates onExitRunnable in suspend() threw.
            // we must still avoid double unlock
            Throwable t = o.target;
            if (t instanceof WebServiceException)
                throw (WebServiceException) t;
            throw new WebServiceException(t);
        } finally {
            // don't reference currentThread here because fiber processing
            // may already be running on a different thread (Note: isAlreadyExited
            // tracks this state
            Thread thread = Thread.currentThread();
            thread.setContextClassLoader(old);
            if (isTraceEnabled()) {
                LOGGER.log(Level.FINE, "Thread leaving _doRun(): {0}", thread);
            }
        }
        return false;
    } finally {
        if (isRequireUnlock.value) {
            synchronized (this) {
                currentThread = null;
            }
            lock.unlock();
        }
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) Holder(jakarta.xml.ws.Holder)

Aggregations

WebServiceException (jakarta.xml.ws.WebServiceException)386 QName (javax.xml.namespace.QName)49 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)36 SOAPException (jakarta.xml.soap.SOAPException)33 JAXBException (jakarta.xml.bind.JAXBException)30 Node (org.w3c.dom.Node)28 JAXBContext (jakarta.xml.bind.JAXBContext)27 IOException (java.io.IOException)26 SOAPMessage (jakarta.xml.soap.SOAPMessage)25 XMLStreamException (javax.xml.stream.XMLStreamException)25 Source (javax.xml.transform.Source)23 ProtocolException (jakarta.xml.ws.ProtocolException)20 Dispatch (jakarta.xml.ws.Dispatch)19 MalformedURLException (java.net.MalformedURLException)19 MessageContext (jakarta.xml.ws.handler.MessageContext)17 Map (java.util.Map)17 URL (java.net.URL)16 StreamSource (javax.xml.transform.stream.StreamSource)16 HandlerTracker (fromwsdl.handler.common.HandlerTracker)14 HandlerTracker (handler.handler_processing.common.HandlerTracker)14