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);
}
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)));
}
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);
}
}
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();
}
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();
}
}
}
Aggregations