Search in sources :

Example 41 with WebServiceException

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);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 42 with WebServiceException

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);
    }
}
Also used : PortInfo(javax.xml.ws.handler.PortInfo) HandlerResolver(javax.xml.ws.handler.HandlerResolver) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) List(java.util.List)

Example 43 with WebServiceException

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;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Schema(javax.xml.validation.Schema) LogicalMessage(javax.xml.ws.LogicalMessage) IOException(java.io.IOException) Source(javax.xml.transform.Source) SAXException(org.xml.sax.SAXException)

Example 44 with WebServiceException

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);
}
Also used : SleepRequest(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.SleepRequest) SocketTimeoutException(java.net.SocketTimeoutException) WebServiceException(javax.xml.ws.WebServiceException) EchoRequest(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.EchoRequest) JaxWsConsumerTestServicePortType(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.JaxWsConsumerTestServicePortType) Test(org.junit.Test)

Example 45 with WebServiceException

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);
}
Also used : SetHeaderRequest(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.SetHeaderRequest) SleepRequest(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.SleepRequest) SocketTimeoutException(java.net.SocketTimeoutException) WebServiceException(javax.xml.ws.WebServiceException) EchoRequest(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.EchoRequest) JaxWsConsumerTestServicePortType(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.JaxWsConsumerTestServicePortType) JaxWsImplementorSpecifics(org.eclipse.scout.rt.server.jaxws.implementor.JaxWsImplementorSpecifics) Test(org.junit.Test)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)378 Test (org.junit.Test)115 SOAPException (javax.xml.soap.SOAPException)59 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)59 SOAPMessage (javax.xml.soap.SOAPMessage)57 ConnectException (java.net.ConnectException)48 ErrorCode (org.olat.modules.vitero.model.ErrorCode)48 URL (java.net.URL)46 SOAPElement (javax.xml.soap.SOAPElement)46 IOException (java.io.IOException)43 SOAPBody (javax.xml.soap.SOAPBody)34 ArrayList (java.util.ArrayList)32 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)32 BindingProvider (javax.xml.ws.BindingProvider)31 Retry (io.github.resilience4j.retry.Retry)29 Service (javax.xml.ws.Service)29 QName (javax.xml.namespace.QName)27 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)21 DataHandler (javax.activation.DataHandler)17 RetryConfig (io.github.resilience4j.retry.RetryConfig)16