Example usage for javax.xml.ws WebServiceException WebServiceException

List of usage examples for javax.xml.ws WebServiceException WebServiceException

Introduction

In this page you can find the example usage for javax.xml.ws WebServiceException WebServiceException.

Prototype

public WebServiceException(Throwable cause) 

Source Link

Document

Constructs a new WebServiceException with the specified cause and a detail message of (cause==null ?

Usage

From source file:com.omertron.thetvdbapi.tools.DOMHelper.java

private static String getValidWebpage(String url) {
    // Count the number of times we download the web page
    int retryCount = 0;
    // Is the web page valid
    boolean valid = false;
    String webPage;/*from  ww w .jav  a  2  s. co  m*/

    try {
        while (!valid && (retryCount < RETRY_COUNT)) {
            retryCount++;
            webPage = requestWebPage(url);
            if (StringUtils.isNotBlank(webPage)) {
                // See if the ID is null
                if (!webPage.contains("<id>") || webPage.contains("<id></id>")) {
                    // Wait an increasing amount of time the more retries that happen
                    waiting(retryCount * RETRY_TIME);
                    continue;
                } else {
                    valid = true;
                }
            }

            // Couldn't get a valid webPage so, quit.
            if (!valid) {
                throw new WebServiceException("Failed to download data from " + url);
            }

            return webPage;
        }
    } catch (UnsupportedEncodingException ex) {
        throw new WebServiceException(ERROR_UNABLE_TO_ENCODE_URL + url, ex);
    } catch (IOException ex) {
        throw new WebServiceException("Unable to download URL: " + url, ex);
    }

    return null;
}

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

public SOAPMessage invoke(SOAPMessage request) {
    try {//from   ww w .  j a va  2  s  .  c  o  m
        SOAPBody body = request.getSOAPBody();
        RequestType type = determineRequestType(body);
        if (type == RequestType.IMPORT_STUDY) {
            return processStudyImportRequest(body);
        } else {
            return processStudyExportRequest(body);
        }
    } catch (Exception e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
        throw new WebServiceException(createSOAPFaultException(e.getMessage()));
    }
}

From source file:com.arpnetworking.tsdcore.sinks.circonus.CirconusClient.java

private static BrokerListResponse handleBrokerListResponse(final WSRequest request, final WSResponse response)
        throws java.io.IOException {
    final String body = response.getBody();
    LOGGER.trace().setMessage("Response from get brokers").addData("response", response).addData("body", body)
            .log();/*from  www .  j a  v  a2 s  .  c o m*/
    if (response.getStatus() / 100 == 2) {
        final List<BrokerListResponse.Broker> brokers = OBJECT_MAPPER.readValue(body,
                BROKER_LIST_TYPE_REFERENCE);
        return new BrokerListResponse(brokers);
    }
    throw new WebServiceException(String.format(
            "Received non 200 response getting broker list; request=%s, response=%s, responseBody=%s", request,
            response, response.getBody()));
}

From source file:com.arpnetworking.tsdcore.sinks.circonus.CirconusClient.java

private static WSResponse handleMetricResponse(final WSRequest request, final WSResponse response) {
    final String body = response.getBody();
    LOGGER.trace().setMessage("Response from posting metric data").addData("response", response)
            .addData("body", body).log();
    if (response.getStatus() / 100 == 2) {
        return response;
    }/*from  w  w  w .j av a  2 s  . c o m*/
    throw new WebServiceException(String.format(
            "Received non 200 response posting metric data; request=%s, response=%s, responseBody=%s", request,
            response, response.getBody()));
}

From source file:edu.kit.dama.rest.util.RestClientUtils.java

/**
 * Deserializes an entity from a stream provided by a ClientResponse.
 * <b>Attention:</b>May throw a DeserializationException if the
 * deserialization fails for some reason. In some cases, pEntityClass might
 * be 'null', e.g. if no deserializable output is expected. In this cases it
 * is possible, to obtain the response object by setting the return type C
 * to ClientResponse. If this is the case and pEntityClass is null,
 * pResponse will be returned./*from  w ww. j  a  va 2s . c  o m*/
 *
 * @param <C> entity class of ClientResponse if pResponse should be
 * returned.
 * @param pEntityClass The class of the entity to deserialize or null if no
 * deserializable result is expected.
 * @param pResponse The response which provides the entity input stream and
 * the HTTP result.
 *
 * @return The deserialized object or pResponse.
 */
public static <C> C createObjectFromStream(final Class<C> pEntityClass, final ClientResponse pResponse) {
    C returnValue = null;
    if (pResponse == null) {
        throw new WebServiceException(
                "Failed to create object from stream. No response availabe! (response == null)");
    }
    if (pResponse.getStatus() != 200) {
        //error ... do not try to deserialize the result.
        try {
            String data = new String(IOUtils.toByteArray(pResponse.getEntityInputStream()));
            String tmp = FileUtils.getTempDirectoryPath();
            String extension = ".html";
            if (!data.contains("<html>")) {
                extension = ".log";
            }
            String outputFile = FilenameUtils.concat(tmp,
                    "kitdm_rest_" + System.currentTimeMillis() + extension);

            try (FileOutputStream fout = new FileOutputStream(outputFile)) {
                fout.write(data.getBytes());
                fout.flush();
            }

            throw new WebServiceException("Failed to create object from stream. Service call returned status "
                    + pResponse.getStatus() + ". More information available at: " + outputFile);
        } catch (IOException ex) {
            throw new WebServiceException("Failed to create object from stream. Service call returned status "
                    + pResponse.getStatus() + ". Cause: See server log.");
        }
    } else if (pEntityClass != null) {
        return pResponse.getEntity(pEntityClass);
        /* try {
        Unmarshaller unmarshaller = org.eclipse.persistence.jaxb.JAXBContext.newInstance(pEntityClass).createUnmarshaller();
        returnValue = (C) unmarshaller.unmarshal(getInputStream(pResponse.getEntityInputStream()));
        if (LOGGER.isDebugEnabled()) {
            Marshaller marshaller = org.eclipse.persistence.jaxb.JAXBContext.newInstance(pEntityClass).createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            StringWriter sw = new StringWriter();
            marshaller.marshal(returnValue, sw);
            LOGGER.debug("createObjectFromStream: " + sw.toString());
        }
        } catch (JAXBException ex) {
        throw new DeserializationException("Failed to deserialize object of type " + pEntityClass + " from response " + pResponse, ex);
        }*/
    } else {
        try {
            //check if the ClientResponse is expected as result...
            returnValue = (C) pResponse;
        } catch (ClassCastException e) {
            LOGGER.debug("No response expected!");
            returnValue = null;
        }
    }
    return returnValue;
}

From source file:de.drv.dsrv.spoc.web.webservice.jax.ExtraSchemaValidationHandler.java

private boolean handleException(final SOAPBody soapBody, final String errorText,
        final ExtraErrorReasonType reason) {

    try {/*  ww w  .j a v  a 2  s.  c  o  m*/
        // Bisherigen Inhalt des SOAP-Bodys entfernen
        soapBody.removeContents();

        // SOAP-Fault erzeugen
        final SOAPFault fault = soapBody.addFault();
        fault.setFaultString(this.soapFaultString);
        fault.setFaultCode(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, SOAP_FAULT_CODE));

        final ExtraJaxbMarshaller extraJaxbMarshaller = new ExtraJaxbMarshaller();
        final ExtraErrorType extraError = ExtraHelper.generateError(reason, this.extraErrorCode, errorText);
        extraJaxbMarshaller.marshalExtraError(extraError, fault.addDetail());

        return false;
    } catch (final Exception e) {
        LOG.error("Fehler bei Exception-Behandlung.", e);
        throw new WebServiceException(resourceBundle.getString(Messages.ERROR_NON_EXTRA_TEXT));
    }
}

From source file:eu.domibus.ebms3.receiver.MSHWebservice.java

@Override
@Transactional//  w  ww .j a va 2  s .c  o m
public SOAPMessage invoke(final SOAPMessage request) {
    SOAPMessage responseMessage = null;

    String pmodeKey = null;
    try {
        //FIXME: use a consistent way of property exchange between JAXWS and CXF message model. This: PropertyExchangeInterceptor
        pmodeKey = (String) request.getProperty(MSHDispatcher.PMODE_KEY_CONTEXT_PROPERTY);
    } catch (SOAPException e) {
        //this error should never occur because pmode handling is done inside the in-interceptorchain
        LOG.error("Cannot find PModeKey property for incoming Message");
        assert false;
    }

    LegConfiguration legConfiguration = pModeProvider.getLegConfiguration(pmodeKey);
    String messageId = "";
    try (StringWriter sw = new StringWriter()) {
        if (MSHWebservice.LOG.isDebugEnabled()) {

            this.transformerFactory.newTransformer().transform(new DOMSource(request.getSOAPPart()),
                    new StreamResult(sw));

            MSHWebservice.LOG.debug(sw.toString());
            MSHWebservice.LOG.debug("received attachments:");
            Iterator i = request.getAttachments();
            while (i.hasNext()) {
                MSHWebservice.LOG.debug(i.next());
            }
        }
        Messaging messaging = this.getMessaging(request);
        checkCharset(messaging);

        boolean messageExists = legConfiguration.getReceptionAwareness().getDuplicateDetection()
                && this.checkDuplicate(messaging);
        if (!messageExists && !(eu.domibus.common.configuration.model.Service.PING_SERVICE
                .equals(legConfiguration.getService().getValue())
                && Action.PING_ACTION.equals(legConfiguration.getAction().getValue()))) { // ping messages are not stored/delivered
            messageId = this.persistReceivedMessage(request, legConfiguration, pmodeKey, messaging);
        }
        responseMessage = this.generateReceipt(request, legConfiguration, messageExists);

        if (!messageExists) {
            this.notifyBackends(messageId, legConfiguration);
        }

    } catch (TransformerException | SOAPException | JAXBException | IOException e) {
        throw new RuntimeException(e);
    } catch (EbMS3Exception e) {
        throw new WebServiceException(e);
    }

    return responseMessage;
}

From source file:com.arpnetworking.tsdcore.sinks.circonus.CirconusClient.java

private static CheckBundle handleCheckBundleResponse(final WSRequest request, final WSResponse response,
        final String operation) throws java.io.IOException {
    final String body = response.getBody();
    LOGGER.trace().setMessage("Response from " + operation + " checkbundle").addData("response", response)
            .addData("body", body).log();
    if (response.getStatus() / 100 == 2) {
        return OBJECT_MAPPER.readValue(body, CheckBundle.class);
    }//from  ww w  .  j a  v a2s  .  com
    throw new WebServiceException(String.format(
            "Received non 200 response " + operation + " checkbundle; request=%s, response=%s, responseBody=%s",
            request, response, response.getBody()));
}

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

/**
 * Creates the soap fault./*from w  w  w. j  av  a2 s.c o  m*/
 *
 * @param msg the msg
 * @return the sOAP fault
 */
private SOAPFault createSOAPFault(String msg) {
    try {
        SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault fault = factory.createFault();
        fault.setFaultString(msg);
        fault.setFaultCode(new QName(SOAP_NS, SOAP_FAULT_CODE));
        Detail detail = fault.addDetail();
        final Element detailEntry = detail.getOwnerDocument().createElementNS(SERVICE_NS, STUDY_IMPORT_FAULT);
        detail.appendChild(detailEntry);

        final Element detailMsg = detail.getOwnerDocument().createElementNS(SERVICE_NS, FAULT_MESSAGE);
        detailMsg.setTextContent(msg);
        detailEntry.appendChild(detailMsg);
        return fault;
    } catch (SOAPException e) {
        log.error(ExceptionUtils.getFullStackTrace(e));
        throw new WebServiceException(e);
    }

}

From source file:com.jaeksoft.searchlib.webservice.crawler.webcrawler.WebCrawlerImpl.java

@Override
public CommonResult crawl(String use, String login, String key, String url, Boolean returnData) {
    try {//from   w ww .  j  ava  2s . com
        Client client = getLoggedClient(use, login, key, Role.WEB_CRAWLER_START_STOP);
        ClientFactory.INSTANCE.properties.checkApi();
        WebCrawlThread webCrawlThread = client.getWebCrawlMaster().manualCrawl(LinkUtils.newEncodedURL(url),
                HostUrlList.ListType.MANUAL);
        if (!webCrawlThread.waitForStart(120))
            throw new WebServiceException("Time out reached (120 seconds)");
        if (!webCrawlThread.waitForEnd(3600))
            throw new WebServiceException("Time out reached (3600 seconds)");
        UrlItem urlItem = webCrawlThread.getCurrentUrlItem();
        CommonResult cr = null;
        if (BooleanUtils.isTrue(returnData)) {
            Crawl crawl = webCrawlThread.getCurrentCrawl();
            if (crawl != null) {
                List<IndexDocument> indexDocuments = crawl.getTargetIndexDocuments();
                if (CollectionUtils.isNotEmpty(indexDocuments)) {
                    CommonListResult<List<FieldValueList>> clr = new CommonListResult<List<FieldValueList>>(
                            indexDocuments.size());
                    for (IndexDocument indexDocument : indexDocuments) {
                        List<FieldValueList> list = FieldValueList.getNewList(indexDocument);
                        if (list != null)
                            clr.items.add(list);
                    }
                    cr = clr;
                }
            }
        }

        String message = urlItem != null
                ? "Result: " + urlItem.getFetchStatus() + " - " + urlItem.getParserStatus() + " - "
                        + urlItem.getIndexStatus()
                : null;
        if (cr == null)
            cr = new CommonResult(true, message);
        cr.addDetail("URL", urlItem.getUrl());
        cr.addDetail("HttpResponseCode", urlItem.getResponseCode());
        cr.addDetail("RobotsTxtStatus", urlItem.getRobotsTxtStatus());
        cr.addDetail("FetchStatus", urlItem.getFetchStatus());
        cr.addDetail("ParserStatus", urlItem.getParserStatus());
        cr.addDetail("IndexStatus", urlItem.getIndexStatus());
        cr.addDetail("RedirectionURL", urlItem.getRedirectionUrl());
        cr.addDetail("ContentBaseType", urlItem.getContentBaseType());
        cr.addDetail("ContentTypeCharset", urlItem.getContentTypeCharset());
        cr.addDetail("ContentLength", urlItem.getContentLength());
        return cr;
    } catch (MalformedURLException e) {
        throw new CommonServiceException(e);
    } catch (SearchLibException e) {
        throw new CommonServiceException(e);
    } catch (ParseException e) {
        throw new CommonServiceException(e);
    } catch (IOException e) {
        throw new CommonServiceException(e);
    } catch (SyntaxError e) {
        throw new CommonServiceException(e);
    } catch (URISyntaxException e) {
        throw new CommonServiceException(e);
    } catch (ClassNotFoundException e) {
        throw new CommonServiceException(e);
    } catch (InterruptedException e) {
        throw new CommonServiceException(e);
    } catch (InstantiationException e) {
        throw new CommonServiceException(e);
    } catch (IllegalAccessException e) {
        throw new CommonServiceException(e);
    }
}