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(String message, Throwable cause) 

Source Link

Document

Constructs a new exception with the specified detail message and cause.

Usage

From source file:ch.admin.vbs.cube.core.webservice.CubeSSLSocketFactory.java

/**
 * Create a new SSL socket factory.//from   w w w.  ja  v a 2  s. c  o  m
 * 
 * @param keyStoreBuilder
 *            the key store builder
 * @param trustStore
 *            the trust store
 * @param checkRevocation
 *            <code>true</code> if certificate revocations should be
 *            checked, else <code>false</code>
 * @throws WebServiceException
 *             if the creation failed
 */
public static SSLSocketFactory newSSLSocketFactory(KeyStore.Builder keyStoreBuilder, KeyStore trustStore,
        boolean checkRevocation) throws WebServiceException {
    KeyManagerFactory keyManagerFactory;
    try {
        keyManagerFactory = KeyManagerFactory.getInstance("NewSunX509");
    } catch (NoSuchAlgorithmException e) {
        String message = "Unable to create key manager factory";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    }
    KeyStoreBuilderParameters keyStoreBuilderParameters = new KeyStoreBuilderParameters(keyStoreBuilder);
    try {
        keyManagerFactory.init(keyStoreBuilderParameters);
    } catch (InvalidAlgorithmParameterException e) {
        String message = "Unable to initialize key manager factory";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    }
    TrustManagerFactory trustManagerFactory;
    try {
        trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        String message = "Unable to create trust manager factory";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    }
    PKIXBuilderParameters pkixBuilderParameters;
    try {
        pkixBuilderParameters = new PKIXBuilderParameters(trustStore, null);
    } catch (KeyStoreException e) {
        String message = "The trust store is not initialized";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    } catch (InvalidAlgorithmParameterException e) {
        String message = "The trust store does not contain any trusted certificate";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    } catch (NullPointerException e) {
        String message = "The trust store is null";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    }
    pkixBuilderParameters.setRevocationEnabled(checkRevocation);
    CertPathTrustManagerParameters certPathTrustManagerParameters = new CertPathTrustManagerParameters(
            pkixBuilderParameters);
    try {
        trustManagerFactory.init(certPathTrustManagerParameters);
    } catch (InvalidAlgorithmParameterException e) {
        String message = "Unable to initialize trust manager factory";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    }
    SSLContext sslContext;
    try {
        sslContext = SSLContext.getInstance("TLS");
    } catch (NoSuchAlgorithmException e) {
        String message = "Unable to create SSL context";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    }
    try {
        sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
    } catch (KeyManagementException e) {
        String message = "Unable to initialize SSL context";
        LOG.error(message + ": " + e.getMessage());
        throw new WebServiceException(message, e);
    }
    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
    return sslSocketFactory;
}

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

/**
 * Get a DOM document from the supplied URL
 *
 * @param url/*from   ww  w.j a  v a 2 s  .c  o  m*/
 * @return
 */
public static synchronized Document getEventDocFromUrl(String url) {
    InputStream in = null;
    Document doc = null;

    try {
        String webPage = getValidWebpage(url);

        if (StringUtils.isNotBlank(webPage)) {
            in = new ByteArrayInputStream(webPage.getBytes(ENCODING));

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();

            doc = db.parse(in);
            in.close();
            doc.getDocumentElement().normalize();
        }
    } catch (UnsupportedEncodingException ex) {
        throw new WebServiceException(ERROR_UNABLE_TO_ENCODE_URL + url, ex);
    } catch (ParserConfigurationException error) {
        throw new WebServiceException(ERROR_UNABLE_TO_PARSE, error);
    } catch (SAXException error) {
        throw new WebServiceException(ERROR_UNABLE_TO_PARSE, error);
    } catch (IOException error) {
        throw new WebServiceException(ERROR_UNABLE_TO_PARSE, error);
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException ex) {
            // Input Stream was already closed or null
            LOG.trace("Failed to close InputStream", ex);
        }
    }

    return doc;
}

From source file:nl.nn.adapterframework.extensions.cxf.SOAPProviderBase.java

@Override
public SOAPMessage invoke(SOAPMessage request) {
    String result;/*from ww  w  .  jav  a2  s . c  o m*/
    PipeLineSessionBase pipelineSession = new PipeLineSessionBase();
    String correlationId = Misc.createSimpleUUID();
    log.debug(getLogPrefix(correlationId) + "received message");

    if (request == null) {
        String faultcode = "soap:Server";
        String faultstring = "SOAPMessage is null";
        String httpRequestMethod = (String) webServiceContext.getMessageContext()
                .get(MessageContext.HTTP_REQUEST_METHOD);
        if (!"POST".equals(httpRequestMethod)) {
            faultcode = "soap:Client";
            faultstring = "Request was send using '" + httpRequestMethod + "' instead of 'POST'";
        }
        result = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "<soap:Body><soap:Fault>" + "<faultcode>" + faultcode + "</faultcode>" + "<faultstring>"
                + faultstring + "</faultstring>" + "</soap:Fault></soap:Body></soap:Envelope>";
    } else {
        // Make mime headers in request available as session key
        @SuppressWarnings("unchecked")
        Iterator<MimeHeader> mimeHeaders = request.getMimeHeaders().getAllHeaders();
        String mimeHeadersXml = getMimeHeadersXml(mimeHeaders).toXML();
        pipelineSession.put("mimeHeaders", mimeHeadersXml);

        // Make attachments in request (when present) available as session keys
        int i = 1;
        XmlBuilder attachments = new XmlBuilder("attachments");
        @SuppressWarnings("unchecked")
        Iterator<AttachmentPart> attachmentParts = request.getAttachments();
        while (attachmentParts.hasNext()) {
            try {
                InputStreamAttachmentPart attachmentPart = new InputStreamAttachmentPart(
                        attachmentParts.next());

                XmlBuilder attachment = new XmlBuilder("attachment");
                attachments.addSubElement(attachment);
                XmlBuilder sessionKey = new XmlBuilder("sessionKey");
                sessionKey.setValue("attachment" + i);
                attachment.addSubElement(sessionKey);
                pipelineSession.put("attachment" + i, attachmentPart.getInputStream());
                log.debug(getLogPrefix(correlationId) + "adding attachment [attachment" + i + "] to session");

                @SuppressWarnings("unchecked")
                Iterator<MimeHeader> attachmentMimeHeaders = attachmentPart.getAllMimeHeaders();
                attachment.addSubElement(getMimeHeadersXml(attachmentMimeHeaders));
            } catch (SOAPException e) {
                e.printStackTrace();
                log.warn("Could not store attachment in session key", e);
            }
            i++;
        }
        pipelineSession.put("attachments", attachments.toXML());

        // Transform SOAP message to string
        String message;
        try {
            message = XmlUtils.nodeToString(request.getSOAPPart());
            log.debug(getLogPrefix(correlationId) + "transforming from SOAP message");
        } catch (TransformerException e) {
            String m = "Could not transform SOAP message to string";
            log.error(m, e);
            throw new WebServiceException(m, e);
        }

        // Process message via WebServiceListener
        ISecurityHandler securityHandler = new WebServiceContextSecurityHandler(webServiceContext);
        pipelineSession.setSecurityHandler(securityHandler);
        pipelineSession.put(IPipeLineSession.HTTP_REQUEST_KEY,
                webServiceContext.getMessageContext().get(MessageContext.SERVLET_REQUEST));
        pipelineSession.put(IPipeLineSession.HTTP_RESPONSE_KEY,
                webServiceContext.getMessageContext().get(MessageContext.SERVLET_RESPONSE));

        try {
            log.debug(getLogPrefix(correlationId) + "processing message");
            result = processRequest(correlationId, message, pipelineSession);
        } catch (ListenerException e) {
            String m = "Could not process SOAP message: " + e.getMessage();
            log.error(m);
            throw new WebServiceException(m, e);
        }
    }

    // Transform result string to SOAP message
    SOAPMessage soapMessage = null;
    try {
        log.debug(getLogPrefix(correlationId) + "transforming to SOAP message");
        soapMessage = getMessageFactory().createMessage();
        StreamSource streamSource = new StreamSource(new StringReader(result));
        soapMessage.getSOAPPart().setContent(streamSource);
    } catch (SOAPException e) {
        String m = "Could not transform string to SOAP message";
        log.error(m);
        throw new WebServiceException(m, e);
    }

    String multipartXml = (String) pipelineSession.get(attachmentXmlSessionKey);
    log.debug(getLogPrefix(correlationId) + "building multipart message with MultipartXmlSessionKey ["
            + multipartXml + "]");
    if (StringUtils.isNotEmpty(multipartXml)) {
        Element partsElement;
        try {
            partsElement = XmlUtils.buildElement(multipartXml);
        } catch (DomBuilderException e) {
            String m = "error building multipart xml";
            log.error(m, e);
            throw new WebServiceException(m, e);
        }
        Collection<Node> parts = XmlUtils.getChildTags(partsElement, "part");
        if (parts == null || parts.size() == 0) {
            log.warn(getLogPrefix(correlationId) + "no part(s) in multipart xml [" + multipartXml + "]");
        } else {
            Iterator<Node> iter = parts.iterator();
            while (iter.hasNext()) {
                Element partElement = (Element) iter.next();
                //String partType = partElement.getAttribute("type");
                String partName = partElement.getAttribute("name");
                String partSessionKey = partElement.getAttribute("sessionKey");
                String partMimeType = partElement.getAttribute("mimeType");
                Object partObject = pipelineSession.get(partSessionKey);
                if (partObject instanceof InputStream) {
                    InputStream fis = (InputStream) partObject;

                    DataHandler dataHander = null;
                    try {
                        dataHander = new DataHandler(new ByteArrayDataSource(fis, partMimeType));
                    } catch (IOException e) {
                        String m = "Unable to add session key '" + partSessionKey + "' as attachment";
                        log.error(m, e);
                        throw new WebServiceException(m, e);
                    }
                    AttachmentPart attachmentPart = soapMessage.createAttachmentPart(dataHander);
                    attachmentPart.setContentId(partName);
                    soapMessage.addAttachmentPart(attachmentPart);

                    log.debug(getLogPrefix(correlationId) + "appended filepart [" + partSessionKey
                            + "] with value [" + partObject + "] and name [" + partName + "]");
                } else { //String
                    String partValue = (String) partObject;

                    DataHandler dataHander = new DataHandler(new ByteArrayDataSource(partValue, partMimeType));
                    AttachmentPart attachmentPart = soapMessage.createAttachmentPart(dataHander);
                    attachmentPart.setContentId(partName);
                    soapMessage.addAttachmentPart(attachmentPart);

                    log.debug(getLogPrefix(correlationId) + "appended stringpart [" + partSessionKey
                            + "] with value [" + partValue + "]");
                }
            }
        }
    }

    return soapMessage;
}

From source file:org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.java

/**
 * This method will drive the call to WsGen to generate a WSDL file for
 * applications deployed without WSDL. We will then read this file in from
 * disk and create a Definition. After we are done with the file we will
 * remove it from disk.  This method accepts a CatalogManager as a parameter
 * for the eventual use in by an XMLSchemaCollection.
 *///from   w ww .j  ava  2s. com
public void generateWsdl(String className, String bindingType, JAXWSCatalogManager catalogManager)
        throws WebServiceException {

    if (this.axisConfiguration == null) {
        this.axisConfiguration = axisService.getAxisConfiguration();
    }
    File tempFile = (File) axisConfiguration.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR);
    if (tempFile == null) {
        tempFile = new File(getProperty_doPriv("java.io.tmpdir"), "_axis2");
    }

    Parameter servletConfigParam = axisConfiguration.getParameter(HTTPConstants.HTTP_SERVLETCONFIG);

    String webBase = null;
    if (servletConfigParam != null) {
        Object obj = servletConfigParam.getValue();
        ServletContext servletContext;

        if (obj instanceof ServletConfig) {
            ServletConfig servletConfig = (ServletConfig) obj;
            servletContext = servletConfig.getServletContext();
            webBase = servletContext.getRealPath("/WEB-INF");
        }
    }

    if (classPath == null) {
        this.classPath = getDefaultClasspath(webBase);
    }
    if (log.isDebugEnabled()) {
        log.debug("For implementation class " + className + " WsGen classpath: " + classPath);
    }
    String localOutputDirectory = tempFile.getAbsolutePath() + className + "_" + axisService.getName();
    if (log.isDebugEnabled()) {
        log.debug("Output directory for generated WSDL file: " + localOutputDirectory);
    }
    try {

        if (log.isDebugEnabled()) {
            log.debug("Generating new WSDL Definition");
        }

        createOutputDirectory(localOutputDirectory);
        Class clazz;
        try {
            // Try the one in JDK16
            clazz = Class.forName("com.sun.tools.internal.ws.spi.WSToolsObjectFactory");
        } catch (Throwable t) {
            // Look for the RI
            clazz = Class.forName("com.sun.tools.ws.spi.WSToolsObjectFactory");
        }
        Method m1 = clazz.getMethod("newInstance", new Class[] {});
        Object factory = m1.invoke(new Object[] {});
        String[] arguments = getWsGenArguments(className, bindingType, localOutputDirectory);
        OutputStream os = new ByteArrayOutputStream();
        Method m2 = clazz.getMethod("wsgen", new Class[] { OutputStream.class, String[].class });
        m2.invoke(factory, os, arguments);
        os.close();
        wsdlDefMap = readInWSDL(localOutputDirectory);
        if (wsdlDefMap.isEmpty()) {
            throw new Exception(
                    "A WSDL Definition could not be generated for " + "the implementation class: " + className);
        }
        docMap = readInSchema(localOutputDirectory, catalogManager);
    } catch (Throwable t) {
        String msg = "Error occurred generating WSDL file for Web service implementation class " + "{"
                + className + "}";
        log.error(msg, t);
        throw new WebServiceException(msg, t);
    }
}

From source file:org.apache.axis2.jaxws.ExceptionFactory.java

/**
 * Create a WebServiceException//from w w  w .  ja va 2s .c o m
 *
 * @param message
 * @param t       Throwable
 * @return WebServiceException
 */
private static WebServiceException createWebServiceException(String message, Throwable t) {

    // We might have an embedded WebServiceException that has a good message on it
    WebServiceException me = (WebServiceException) findException(t, WebServiceException.class);
    if (me != null) {
        String meMessage = me.getMessage();
        if (meMessage != null) {
            if (message == null) {
                message = meMessage;
            } else {
                message = message + ": " + meMessage;
            }
        }
    }

    // Get the root cause.  We want to strip out the intermediate exceptions (like AxisFault) because
    // these won't make sense to the user.
    Throwable rootCause = null;
    if (t != null) {
        rootCause = getRootCause(t);
    }
    rootCause = rootCause == null ? t : rootCause;
    WebServiceException e = null;

    // The root cause may not have a good message.  We might want to enhance it
    String enhancedMessage = enhanceMessage(rootCause);
    if (enhancedMessage != null) {
        if (message != null)
            message = message + ": " + enhancedMessage;
        else
            message = enhancedMessage;
    }

    if (message != null) {
        e = new WebServiceException(message, rootCause);
    } else {
        e = new WebServiceException(rootCause);
    }

    if (log.isDebugEnabled()) {
        log.debug("Create Exception:", e);
    }
    return e;
}

From source file:org.fireflow.service.callback.ProcessServiceProvider.java

public Source invoke(Source request) {
    Expression correlation = callbackService.getCorrelation();

    final QName responseRootElementQName = new QName(callbackService.getTargetNamespaceUri(),
            this.serviceBinding.getOperationName() + "Response");

    //??/*  ww w.  j av  a  2  s.  co m*/
    /*
    try{
       Transformer transformer = transformerFactory.newTransformer();
       transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
       transformer.setOutputProperty(
       "{http://xml.apache.org/xslt}indent-amount", "2");
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       // transformer.transform()  XML Source? Result
       transformer.transform(request, new StreamResult(
       outputStream));
       System.out.println( outputStream.toString());
    }catch(Exception e){
       e.printStackTrace();
    }
    */

    final Document requestDOM;
    try {
        Transformer transformer = transformerFactory.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(request, domResult);
        requestDOM = (Document) domResult.getNode();//reuqestDOM   
    } catch (TransformerException e) {
        throw new WebServiceException("Can NOT transform request to DOM.", e);
    }

    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(workflowRuntimeContext,
            FireWorkflowSystem.getInstance());
    if (!startNewProcess) {//?
        if (correlation == null || StringUtils.isEmpty(correlation.getBody())) {
            throw new WebServiceException(
                    "The correlation can NOT be empty; the callbackservice is " + callbackService.getName());
        }
        //1?serviceIdservice versioncandidate activityInstance
        WorkflowQuery<ActivityInstance> query = session.createWorkflowQuery(ActivityInstance.class);
        List<ActivityInstance> candidates = query
                .add(Restrictions.eq(ActivityInstanceProperty.SERVICE_ID, callbackService.getId()))
                .add(Restrictions.eq(ActivityInstanceProperty.SERVICE_VERSION, callbackService.getVersion()))
                .add(Restrictions.eq(ActivityInstanceProperty.STATE, ActivityInstanceState.RUNNING)).list();

        //2??correlation
        //correlationbool?processVars.var1==xpath(requestDom,'method1Request/id')
        ProcessInstance theProcessInstance = null;
        ActivityInstance theActivityInstance = null;
        if (candidates != null && candidates.size() > 0) {
            for (ActivityInstance activityInstance : candidates) {
                ProcessInstance processInstance = activityInstance.getProcessInstance(session);
                ((WorkflowSessionLocalImpl) session).setCurrentProcessInstance(processInstance);
                ((WorkflowSessionLocalImpl) session).setCurrentActivityInstance(activityInstance);

                Map<String, Object> varContext = ScriptEngineHelper.fulfillScriptContext(session,
                        workflowRuntimeContext, processInstance, activityInstance);
                varContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

                Object result = ScriptEngineHelper.evaluateExpression(workflowRuntimeContext, correlation,
                        varContext);
                if (result != null && (result instanceof Boolean)) {
                    if ((Boolean) result) {
                        theActivityInstance = activityInstance;
                        theProcessInstance = processInstance;
                        break;
                    }
                }

            }
        }

        final ActivityInstance theMatchedActivityInstance = theActivityInstance;//?activityInstance
        final ProcessInstance theMatchedProcessInstance = theProcessInstance;

        if (theMatchedActivityInstance != null) {

            //1?currentProcessInstanceCurrentActivityInstance
            ((WorkflowSessionLocalImpl) session).setCurrentActivityInstance(theMatchedActivityInstance);
            ((WorkflowSessionLocalImpl) session).setCurrentProcessInstance(theMatchedProcessInstance);

            try {
                this.transactionTemplate.execute(new TransactionCallback() {
                    public Object doInTransaction(TransactionStatus status) {
                        //2????
                        List<Assignment> inputAssignments_ = serviceBinding.getInputAssignments();
                        Map<String, Object> scriptContext = new HashMap<String, Object>();
                        scriptContext.put(ScriptContextVariableNames.INPUTS, requestDOM);
                        try {
                            ScriptEngineHelper.assignOutputToVariable(session, workflowRuntimeContext,
                                    theMatchedProcessInstance, theMatchedActivityInstance, inputAssignments_,
                                    scriptContext);
                        } catch (ScriptException e) {
                            throw new RuntimeException(
                                    "Can NOT assign inputs to process instance varialbes,the callback service is  "
                                            + callbackService.getName(),
                                    e);
                        }

                        //3?closeActivity?   
                        ActivityInstanceManager actInstMgr = workflowRuntimeContext.getEngineModule(
                                ActivityInstanceManager.class, theMatchedProcessInstance.getProcessType());
                        actInstMgr.onServiceCompleted(session, theMatchedActivityInstance);

                        return null;
                    }

                });
            } catch (TransactionException e) {
                throw new WebServiceException(e);
            }
            //4?
            try {
                Map<String, Object> allTheVars = ScriptEngineHelper.fulfillScriptContext(session,
                        workflowRuntimeContext, theMatchedProcessInstance, theMatchedActivityInstance);
                List<Assignment> outputAssignments = serviceBinding.getOutputAssignments();
                Document doc = DOMInitializer.generateDocument(callbackService.getXmlSchemaCollection(),
                        responseRootElementQName);
                allTheVars.put(ScriptContextVariableNames.OUTPUTS, doc);
                Map<String, Object> tmp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                        outputAssignments, allTheVars);
                Document resultDOM = (Document) tmp.get(ScriptContextVariableNames.OUTPUTS);

                return new DOMSource(resultDOM);
            } catch (ScriptException e) {
                throw new WebServiceException(
                        "Can NOT assign process instance varialbes to output,the callback service is  "
                                + callbackService.getName(),
                        e);
            } catch (ParserConfigurationException e) {
                throw new WebServiceException(
                        "Can NOT init output DOM,the callback service is  " + callbackService.getName(), e);
            }
        } else {
            throw new WebServiceException(
                    "Process instance NOT found for the conditions as follows,service id='"
                            + callbackService.getId() + "' and service version='" + callbackService.getVersion()
                            + "' and correlation='" + correlation.getBody() + "'");
        }
    }

    else {//??

        //1????bizId
        final Map<String, Object> processVars;
        final String bizId;
        try {
            List<Assignment> inputAssignments_ = serviceBinding.getInputAssignments();
            Map<String, Object> scriptContext = new HashMap<String, Object>();
            scriptContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

            Map<String, Object> temp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                    inputAssignments_, scriptContext);
            processVars = (Map<String, Object>) temp.get(ScriptContextVariableNames.PROCESS_VARIABLES);

            Map<String, Object> varContext = new HashMap<String, Object>();
            varContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

            Object result = ScriptEngineHelper.evaluateExpression(workflowRuntimeContext, correlation,
                    varContext);
            bizId = result == null ? null : result.toString();
        } catch (ScriptException e) {
            throw new WebServiceException(
                    "Can NOT assign inputs to process instance varialbes,the callback service is  "
                            + callbackService.getName(),
                    e);
        }

        //2???
        ProcessInstance processInstance = null;
        try {
            processInstance = (ProcessInstance) transactionTemplate.execute(new TransactionCallback() {
                public Object doInTransaction(TransactionStatus status) {
                    WorkflowStatement stmt = session.createWorkflowStatement(processType);

                    ProcessInstance procInst = null;
                    try {
                        procInst = stmt.startProcess(processId, bizId, processVars);
                    } catch (InvalidModelException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);
                    } catch (WorkflowProcessNotFoundException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);

                    } catch (InvalidOperationException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);

                    }
                    return procInst;
                }

            });
        } catch (TransactionException e) {
            throw new WebServiceException(e);
        }

        //3?
        try {
            Map<String, Object> allTheVars = ScriptEngineHelper.fulfillScriptContext(session,
                    workflowRuntimeContext, processInstance, null);
            List<Assignment> outputAssignments = serviceBinding.getOutputAssignments();
            //  ?DOM
            Document doc = DOMInitializer.generateDocument(callbackService.getXmlSchemaCollection(),
                    responseRootElementQName);
            allTheVars.put(ScriptContextVariableNames.OUTPUTS, doc);
            Map<String, Object> tmp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                    outputAssignments, allTheVars);
            Document resultDOM = (Document) tmp.get(ScriptContextVariableNames.OUTPUTS);

            return new DOMSource(resultDOM);
        } catch (ScriptException e) {
            throw new WebServiceException(
                    "Can NOT assign process instance varialbes to output,the callback service is  "
                            + callbackService.getName(),
                    e);
        } catch (ParserConfigurationException e) {
            throw new WebServiceException(
                    "Can NOT init output DOM,the callback service is  " + callbackService.getName(), e);
        }

    }

}

From source file:org.onehippo.cms7.essentials.components.rest.BaseRestResource.java

/**
 * Return HippoQuery which scope is site root
 *
 * @param context context/*from w  ww. j  a va 2s .com*/
 * @param clazz   zero or more scope classes
 * @return HstQuery instance
 */

@SuppressWarnings(UNCHECKED)
public HstQuery createQuery(final RestContext context, final Class<? extends HippoBean> clazz,
        final Subtypes subtypes) {
    HstQuery query = null;
    try {
        Node scopeNode = getScopeForContext(context);
        query = getHstQueryManager(context.getRequestContext()).createQuery(scopeNode, clazz,
                subtypes.isIncludeSubtypes());
        final int pageSize = context.getPageSize();
        final int page = context.getPage();
        query.setLimit(pageSize);
        query.setOffset((page - 1) * pageSize);

    } catch (QueryException e) {
        log.error("Error creating HST query", e);
    } catch (RepositoryException e) {
        throw new WebServiceException(INVALID_SCOPE, e);
    }
    if (query == null) {
        throw new WebServiceException("Query was null (failed to create it)");
    }
    return query;
}