Java Code Examples for javax.xml.ws.WebServiceException#getCause()

The following examples show how to use javax.xml.ws.WebServiceException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static TechnicalConnectorException handleWebServiceException(WebServiceException e) {
   if (e.getCause() instanceof FolderDecryptionRuntimeException) {
      FolderDecryptionRuntimeException decryptException = (FolderDecryptionRuntimeException)e.getCause();
      return decryptException.getCause() instanceof TechnicalConnectorException ? (TechnicalConnectorException)decryptException.getCause() : new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e, new Object[]{""});
   } else {
      return new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e.getCause(), new Object[]{e.getMessage()});
   }
}
 
Example 2
Source File: ServiceHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static TechnicalConnectorException handleWebServiceException(WebServiceException e) {
   if (e.getCause() instanceof FolderDecryptionRuntimeException) {
      FolderDecryptionRuntimeException decryptException = (FolderDecryptionRuntimeException)e.getCause();
      return decryptException.getCause() instanceof TechnicalConnectorException ? (TechnicalConnectorException)decryptException.getCause() : new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e, new Object[]{""});
   } else {
      return new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e.getCause(), new Object[]{e.getMessage()});
   }
}
 
Example 3
Source File: ServiceHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static TechnicalConnectorException handleWebServiceException(WebServiceException e) {
   if (e.getCause() instanceof FolderDecryptionRuntimeException) {
      FolderDecryptionRuntimeException decryptException = (FolderDecryptionRuntimeException)e.getCause();
      return decryptException.getCause() instanceof TechnicalConnectorException ? (TechnicalConnectorException)decryptException.getCause() : new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e, new Object[]{""});
   } else {
      return new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e.getCause(), new Object[]{e.getMessage()});
   }
}
 
Example 4
Source File: IntraHubServiceImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private TechnicalConnectorException handleWebServiceException(WebServiceException e) {
   if (e.getCause() instanceof FolderDecryptionRuntimeException) {
      FolderDecryptionRuntimeException decryptException = (FolderDecryptionRuntimeException)e.getCause();
      return decryptException.getCause() instanceof TechnicalConnectorException ? (TechnicalConnectorException)decryptException.getCause() : new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e, new Object[]{""});
   } else {
      return new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e.getCause(), new Object[]{e.getMessage()});
   }
}
 
Example 5
Source File: ServiceHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static TechnicalConnectorException handleWebServiceException(WebServiceException e) {
   if (e.getCause() instanceof FolderDecryptionRuntimeException) {
      FolderDecryptionRuntimeException decryptException = (FolderDecryptionRuntimeException)e.getCause();
      return decryptException.getCause() instanceof TechnicalConnectorException ? (TechnicalConnectorException)decryptException.getCause() : new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e, new Object[]{""});
   } else {
      return new TechnicalConnectorException(TechnicalConnectorExceptionValues.UNKNOWN_ERROR, e.getCause(), new Object[]{e.getMessage()});
   }
}
 
Example 6
Source File: SequenceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnknownSequence() throws Exception {
    init("org/apache/cxf/systest/ws/rm/rminterceptors.xml");

    class SequenceIdInterceptor extends AbstractPhaseInterceptor<Message> {
        SequenceIdInterceptor() {
            super(Phase.PRE_STREAM);
        }

        public void handleMessage(Message m) {
            RMProperties rmps = RMContextUtils.retrieveRMProperties(m, true);
            if (null != rmps && null != rmps.getSequence()) {
                rmps.getSequence().getIdentifier().setValue("UNKNOWN");
            }
        }
    }
    greeterBus.getOutInterceptors().add(new SequenceIdInterceptor());
    RMManager manager = greeterBus.getExtension(RMManager.class);
    manager.getConfiguration().setBaseRetransmissionInterval(Long.valueOf(2000));

    try {
        greeter.greetMe("one");
        fail("Expected fault.");
    } catch (WebServiceException ex) {
        SoapFault sf = (SoapFault)ex.getCause();
        assertEquals("Unexpected fault code.", Soap11.getInstance().getSender(), sf.getFaultCode());
        assertNull("Unexpected sub code.", sf.getSubCode());
        assertTrue("Unexpected reason.", sf.getReason().endsWith("is not a known Sequence identifier."));
    }

    // the third inbound message has a SequenceFault header
    MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(),
        inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
    mf.verifySequenceFault(RM10Constants.UNKNOWN_SEQUENCE_FAULT_QNAME, false, 1);
    String[] expectedActions = new String[3];
    expectedActions = new String[] {RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION,
                                    RM10_GENERIC_FAULT_ACTION};
    mf.verifyActions(expectedActions, false);
}
 
Example 7
Source File: ProductPortalServlet.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private String sendWsReq(HttpServletRequest req, String productId, boolean secured) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(Product.class);
    factory.setAddress("http://localhost:8282/ProductServiceCF");

    Product simpleClient = (Product)factory.create();
    java.lang.String _getProduct_productIdVal = productId;
    javax.xml.ws.Holder<java.lang.String> _getProduct_productId = new javax.xml.ws.Holder<java.lang.String>(_getProduct_productIdVal);
    javax.xml.ws.Holder<java.lang.String> _getProduct_name = new javax.xml.ws.Holder<java.lang.String>();

    // Attach Authorization header
    if (secured) {
        Client clientProxy = ClientProxy.getClient(simpleClient);

        KeycloakSecurityContext session = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName());
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("Authorization", Arrays.asList("Bearer " + session.getTokenString()));

        clientProxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);
    }

    try {
        simpleClient.getProduct(_getProduct_productId, _getProduct_name);
        return String.format("Product received: id=%s, name=%s", _getProduct_productId.value, _getProduct_name.value);
    } catch (UnknownProductFault upf) {
        return "UnknownProductFault has occurred. Details: " + upf.toString();
    } catch (WebServiceException wse) {
        String error = "Can't receive product. Reason: " + wse.getMessage();
        if (wse.getCause() != null) {
            Throwable cause = wse.getCause();
            error = error + " Details: " + cause.getClass().getName() + ": " + cause.getMessage();
        }
        return error;
    }
}
 
Example 8
Source File: ManagerWsNodeServiceImpl.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void broadcast(final Message message) {

    final ContextRspMessage wsMessage = (ContextRspMessage) message;
    final AsyncContext context = wsMessage.getAsyncContext();

    if (AsyncContext.NO_BROADCAST.equals(context.getAttribute(AsyncContext.NO_BROADCAST))) {
        log.debug("Broadcasting switched off for context of message {}", message.getSubject());
        return;
    }

    if (reloadClusterTopics.contains(message.getSubject())) {
        log.info("Reloading cluster information before {}", message.getSubject());
        reloadClusterConfiguration();
    }

    final List<String> targets = message.getTargets();

    final List<Node> cluster = new ArrayList<>(getSfNodes());
    if (CollectionUtils.isNotEmpty(targets)) {
        cluster.removeIf(node -> !targets.contains(node.getId()));
    }


    for (final Node yesNode : cluster) {
        try {
            final WsClientFactory<WebServiceInboundChannel> factory =
                    getWebServiceInboundChannel(context, yesNode.getChannel(),
                            context.getAttribute(AsyncContext.TIMEOUT_KEY));

            WebServiceInboundChannel service = factory.getService();
            try {
                final WsMessage rsp = service.accept(new WsMessage(wsMessage));
                if (rsp != null) {
                    wsMessage.addResponse(
                            new BasicMessageImpl(
                                    rsp.getSource(),
                                    rsp.getTargets(),
                                    rsp.getSubject(),
                                    rsp.getPayloadObject()
                            ));
                }
            } finally {
                factory.release(service);
                service = null;
            }

        } catch (WebServiceException wse) {

            if (wse.getCause() instanceof ConnectException) {

                blacklist(yesNode.getId());

                if (log.isErrorEnabled()) {
                    log.error(Markers.alert(), "Node message failure [" + message + "] to channel ["
                            + yesNode.getId() + ":" + yesNode.getChannel() + "] . Blacklisting this node due to connection exception.");
                }

            } else if (wse.getCause() instanceof XMLStreamException) {

                blacklist(yesNode.getId());

                if (log.isErrorEnabled()) {
                    log.error(Markers.alert(), "Node message failure [" + message + "] to channel ["
                            + yesNode.getId() + ":" + yesNode.getChannel() + "] . Blacklisting this node due to malformed message.");
                }

            } else {

                if (log.isErrorEnabled()) {
                    log.error(Markers.alert(), "Node message failure [" + message + "] to channel ["
                            + yesNode.getId() + ":" + yesNode.getChannel() + "] . Exception occurred during ws call",
                            wse);
                }

            }

        } catch (Exception e) {

            if (log.isErrorEnabled()) {
                log.error(Markers.alert(), "Node message failure [" + message + "] to channel ["
                        + yesNode.getId() + ":" + yesNode.getChannel() + "] . Exception occurred during ws call",
                        e);
            }

        }
    }

}
 
Example 9
Source File: SequenceTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void doTestTwowayNoDuplicates(String cfg) throws Exception {

        init(cfg);

        class MessageNumberInterceptor extends AbstractPhaseInterceptor<Message> {
            MessageNumberInterceptor() {
                super(Phase.PRE_STREAM);
            }

            public void handleMessage(Message m) {
                RMProperties rmps = RMContextUtils.retrieveRMProperties(m, true);
                if (null != rmps && null != rmps.getSequence()) {
                    rmps.getSequence().setMessageNumber(Long.valueOf(1));
                }
            }
        }
        greeterBus.getOutInterceptors().add(new MessageNumberInterceptor());
        RMManager manager = greeterBus.getExtension(RMManager.class);
        manager.getConfiguration().setBaseRetransmissionInterval(Long.valueOf(2000));

        greeter.greetMe("one");
        try {
            ((BindingProvider)greeter).getRequestContext().put("cxf.synchronous.timeout", 5000);
            String s = greeter.greetMe("two");
            fail("Expected timeout. Received response: " + s);
        } catch (WebServiceException ex) {
            assertTrue("Unexpected exception cause", ex.getCause() instanceof IOException);
            IOException ie = (IOException)ex.getCause();
            assertTrue("Unexpected IOException message", ie.getMessage().startsWith("Timed out"));
        }

        // wait for resend to occur

        awaitMessages(4, 3, 5000);

        MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(),
            inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);

        // Expected outbound:
        // CreateSequence
        // + two requests
        // + acknowledgement

        String[] expectedActions = new String[4];
        expectedActions[0] = RM10Constants.CREATE_SEQUENCE_ACTION;
        expectedActions[1] = GREETME_ACTION;
        expectedActions[2] = GREETME_ACTION;
        expectedActions[3] = RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION;
        mf.verifyActions(expectedActions, true);
        mf.verifyMessageNumbers(new String[] {null, "1", "1", null}, true);
        mf.verifyLastMessage(new boolean[expectedActions.length], true);
        mf.verifyAcknowledgements(new boolean[] {false, false, false, true}, true);

        // Expected inbound:
        // createSequenceResponse
        // + 1 response without acknowledgement
        // + 1 acknowledgement/last message

        mf.verifyMessages(3, false);
        expectedActions = new String[] {RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION,
                                        GREETME_RESPONSE_ACTION,
                                        RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION};
        mf.verifyActions(expectedActions, false);
        mf.verifyMessageNumbers(new String[] {null, "1", null}, false);
        mf.verifyAcknowledgements(new boolean[] {false, false, true}, false);
    }
 
Example 10
Source File: HTTPServerPolicyTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testUsingHTTPServerPolicies() throws Exception {

    // use a plain client

    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus();

    BasicGreeterService gs = new BasicGreeterService();
    final Greeter greeter = gs.getGreeterPort();

    updateAddressPort(greeter, PORT);
    LoggingInInterceptor in = new LoggingInInterceptor();
    LoggingOutInterceptor out = new LoggingOutInterceptor();

    bus.getInInterceptors().add(in);
    bus.getOutInterceptors().add(out);

    LOG.fine("Created greeter client.");

    // sayHi - this operation has message policies that are incompatible with
    // the endpoint policies

    try {
        greeter.sayHi();
        fail("Did not receive expected Exception.");
    } catch (WebServiceException wse) {
        SoapFault sf = (SoapFault)wse.getCause();
        assertEquals("Server", sf.getFaultCode().getLocalPart());

        String text = sf.getMessage();
        assertTrue(text.contains("{http://cxf.apache.org/transports/http/configuration}server"));

        // assertEquals("INCOMPATIBLE_HTTPSERVERPOLICY_ASSERTIONS", ex.getCode());
    }

    // greetMe - no operation or message specific policies

    assertEquals("CXF", greeter.greetMe("cxf"));

    // pingMe - policy attached to binding operation fault should have no effect

    try {
        greeter.pingMe();
        fail("Expected PingMeFault not thrown.");
    } catch (PingMeFault ex) {
        assertEquals(2, ex.getFaultInfo().getMajor());
        assertEquals(1, ex.getFaultInfo().getMinor());
    }
    ((Closeable)greeter).close();
}
 
Example 11
Source File: ProductPortalServlet.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private String sendWsReq(HttpServletRequest req, String productId, boolean secured) {
        Product simpleClient = null;
//        try {
            JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
            factory.setServiceClass(Product.class);
            factory.setAddress("http://localhost:8282/ProductServiceCF");

            simpleClient = (Product)factory.create();
/*        } catch (Exception ex) {
            ex.printStackTrace();
            String error = "Cannot create WS client: " + ex;
            return error;
        }*/
        java.lang.String _getProduct_productIdVal = productId;
        javax.xml.ws.Holder<java.lang.String> _getProduct_productId = new javax.xml.ws.Holder<java.lang.String>(_getProduct_productIdVal);
        javax.xml.ws.Holder<java.lang.String> _getProduct_name = new javax.xml.ws.Holder<java.lang.String>();

        // Attach Authorization header
        if (secured) {
            Client clientProxy = ClientProxy.getClient(simpleClient);

            KeycloakSecurityContext session = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName());
            Map<String, List<String>> headers = new HashMap<String, List<String>>();
            headers.put("Authorization", Arrays.asList("Bearer " + session.getTokenString()));

            clientProxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);
        }

        try {
            simpleClient.getProduct(_getProduct_productId, _getProduct_name);
            return String.format("Product received: id=%s, name=%s", _getProduct_productId.value, _getProduct_name.value);
        } catch (UnknownProductFault upf) {
            return "UnknownProductFault has occurred. Details: " + upf.toString();
        } catch (WebServiceException wse) {
            String error = "Can't receive product. Reason: " + wse.getMessage();
            if (wse.getCause() != null) {
                Throwable cause = wse.getCause();
                error = error + " Details: " + cause.getClass().getName() + ": " + cause.getMessage();
            }
            return error;
        }
    }
 
Example 12
Source File: ApplicationServiceBean.java    From development with Apache License 2.0 2 votes vote down vote up
/**
 * Checks if the cause of the webexception is a timeout.
 * 
 * @param e
 *            the webexception.
 * @return true if a timeout was the cause of the exception.
 */
private boolean isTimeoutOccured(WebServiceException e) {
    return (e.getCause() instanceof SocketTimeoutException) ? true : false;
}