use of javax.xml.ws.WebServiceException in project scout.rt by eclipse.
the class WsseUsernameTokenAuthenticationHandler method handleMessage.
@Override
public final boolean handleMessage(final SOAPMessageContext messageContext) {
if (MessageContexts.isInboundMessage(messageContext)) {
return true;
}
SOAPEnvelope envelope;
SOAPHeader header;
try {
envelope = messageContext.getMessage().getSOAPPart().getEnvelope();
header = envelope.getHeader();
if (header == null) {
header = envelope.addHeader();
}
final SOAPElement security = header.addChildElement(WS_SEC, WSSE, NAME_SPACE_URI);
final SOAPElement userToken = security.addChildElement(USERNAME_TOKEN, WSSE);
userToken.addChildElement(USERNAME, WSSE).addTextNode(StringUtility.valueOf(messageContext.get(InvocationContext.PROP_USERNAME)));
userToken.addChildElement(PASSWORD, WSSE).addTextNode(StringUtility.valueOf(messageContext.get(InvocationContext.PROP_PASSWORD)));
return true;
} catch (final SOAPException e) {
throw new WebServiceException("Failed to set SOAP header for WsseUsernameTokenAuthentication", e);
}
}
use of javax.xml.ws.WebServiceException in project scout.rt by eclipse.
the class ServicePool method createElement.
@Override
protected SERVICE createElement() {
try {
// Create the service
final Constructor<? extends Service> constructor = m_serviceClazz.getConstructor(URL.class, QName.class);
@SuppressWarnings("unchecked") final SERVICE service = (SERVICE) constructor.newInstance(m_wsdlLocation, new QName(m_targetNamespace, m_serviceName));
// Install the handler chain
service.setHandlerResolver(new HandlerResolver() {
@Override
public List<Handler> getHandlerChain(final PortInfo portInfo) {
final List<Handler<? extends MessageContext>> handlerChain = new ArrayList<>();
m_initializer.initHandlers(handlerChain);
for (int i = 0; i < handlerChain.size(); i++) {
handlerChain.set(i, proxyHandler(handlerChain.get(i)));
}
@SuppressWarnings("unchecked") final List<Handler> handlers = TypeCastUtility.castValue(handlerChain, List.class);
return handlers;
}
});
return service;
} catch (ReflectiveOperationException e) {
throw new WebServiceException("Failed to instantiate webservice stub.", e);
}
}
use of javax.xml.ws.WebServiceException in project scout.rt by eclipse.
the class AbstractValidationHandler method handleMessage.
@Override
public boolean handleMessage(LogicalMessageContext context) {
if (MessageContexts.isOutboundMessage(context)) {
return true;
}
LogicalMessage message = context.getMessage();
Source payload = message.getPayload();
Schema xsd = getXsd();
try {
xsd.newValidator().validate(payload);
} catch (SAXException e) {
throw new WebServiceException("Soap request message is not valid.", e);
} catch (IOException e) {
throw new WebServiceException(e);
}
return true;
}
use of javax.xml.ws.WebServiceException in project scout.rt by eclipse.
the class AbstractJaxWsClientTest method testSamePortMultipleTimesSleepWithReadTimeoutCheckResponseCode.
@Test
public void testSamePortMultipleTimesSleepWithReadTimeoutCheckResponseCode() {
final JaxWsConsumerTestServicePortType port = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().withReadTimeout(500, TimeUnit.MILLISECONDS).getPort();
// 1. invoke echo, response code 200 expected
EchoRequest echoReq = new EchoRequest();
echoReq.setMessage("test message");
port.echo(echoReq);
assertHttpResponseCode(port, 200);
// 2. invoke sleep
SleepRequest req = new SleepRequest();
req.setMillis(5000);
try {
port.sleep(req);
fail("invocation is expected to be cancelled");
} catch (WebServiceException e) {
if (!(e.getCause() instanceof SocketTimeoutException)) {
throw e;
}
}
assertHttpResponseCode(port, 0);
// 3. invoke echo again, response code 200 expected
port.echo(echoReq);
assertHttpResponseCode(port, 200);
}
use of javax.xml.ws.WebServiceException in project scout.rt by eclipse.
the class AbstractJaxWsClientTest method testAcquirePortInSameTransactionMultipleTimesSleepWithReadTimeoutCheckResponseHeaders.
@Test
public void testAcquirePortInSameTransactionMultipleTimesSleepWithReadTimeoutCheckResponseHeaders() {
// 1. invoke set header on port0
final JaxWsConsumerTestServicePortType port0 = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
final String testHeaderValue = "test header value";
SetHeaderRequest headerReq = new SetHeaderRequest();
headerReq.setHeaderName(X_SCOUT_JAX_WS_TEST_HEADER);
headerReq.setHeaderValue(testHeaderValue);
port0.setHeader(headerReq);
assertHttpResponseHeader(port0, X_SCOUT_JAX_WS_TEST_HEADER, testHeaderValue);
// 2. invoke sleep on port1
final JaxWsConsumerTestServicePortType port1 = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().withReadTimeout(500, TimeUnit.MILLISECONDS).getPort();
if (BEANS.get(JaxWsImplementorSpecifics.class).isPoolingSupported()) {
assertSamePort(port0, port1);
} else {
assertDifferentPort(port0, port1);
}
SleepRequest req = new SleepRequest();
req.setMillis(5000);
try {
port1.sleep(req);
fail("invocation is expected to be cancelled");
} catch (WebServiceException e) {
if (!(e.getCause() instanceof SocketTimeoutException)) {
throw e;
}
}
assertHttpResponseCode(port1, 0);
assertHttpResponseHeader(port1, X_SCOUT_JAX_WS_TEST_HEADER, null);
// 3. invoke echo on port1
EchoRequest echoReq = new EchoRequest();
echoReq.setMessage("test message");
port1.echo(echoReq);
assertHttpResponseCode(port1, 200);
assertHttpResponseHeader(port1, X_SCOUT_JAX_WS_TEST_HEADER, null);
}
Aggregations