Example usage for javax.xml.soap SOAPFactory newInstance

List of usage examples for javax.xml.soap SOAPFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.soap SOAPFactory newInstance.

Prototype

public static SOAPFactory newInstance() throws SOAPException 

Source Link

Document

Creates a new SOAPFactory object that is an instance of the default implementation (SOAP 1.1).

Usage

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

/**
 * Creates the soap fault./*ww w  .  java 2 s  . co  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:it.cnr.icar.eric.common.BindingUtility.java

public SOAPElement getSOAPElementFromBindingObject(Object obj) throws JAXRException {
    SOAPElement soapElem = null;//w w  w .  j a v a 2s .  co  m

    try {
        SOAPElement parent = SOAPFactory.newInstance().createElement("dummy");

        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.marshal(obj, new DOMResult(parent));

        soapElem = (SOAPElement) parent.getChildElements().next();

    } catch (Exception e) {
        throw new JAXRException(e);
    }

    return soapElem;
}

From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java

/**
* Gets a list of field values of the given document
* @param fieldNames/*from  ww w.ja v a2s  .  c  o  m*/
* @param site
* @param docId
* @return set of the field values
*/
public Map<String, String> getFieldValues(String[] fieldNames, String site, String docLibrary, String docId,
        boolean dspStsWorks) throws ManifoldCFException, ServiceInterruption {
    long currentTime;
    try {
        HashMap<String, String> result = new HashMap<String, String>();

        if (site.compareTo("/") == 0)
            site = ""; // root case

        if (dspStsWorks) {
            StsAdapterWS listService = new StsAdapterWS(baseUrl + site, userName, password, configuration,
                    httpClient);
            StsAdapterSoapStub stub = (StsAdapterSoapStub) listService.getStsAdapterSoapHandler();

            String[] vArray = new String[1];
            vArray[0] = "1.0";
            VersionsHeader myVersion = new VersionsHeader();
            myVersion.setVersion(vArray);

            stub.setHeader("http://schemas.microsoft.com/sharepoint/dsp", "versions", myVersion);

            RequestHeader reqHeader = new RequestHeader();
            reqHeader.setDocument(DocumentType.content);
            reqHeader.setMethod(MethodType.query);

            stub.setHeader("http://schemas.microsoft.com/sharepoint/dsp", "request", reqHeader);

            QueryRequest myRequest = new QueryRequest();

            DSQuery sQuery = new DSQuery();
            sQuery.setSelect("/list[@id='" + docLibrary + "']");
            sQuery.setResultContent(ResultContentType.dataOnly);
            myRequest.setDsQuery(sQuery);

            DspQuery spQuery = new DspQuery();
            spQuery.setRowLimit(1);
            // For the Requested Fields
            if (fieldNames.length > 0) {
                Fields spFields = new Fields();
                Field[] fieldArray = new Field[0];
                ArrayList fields = new ArrayList();

                Field spField = new Field();
                //                      spField.setName( "ID" );
                //                      spField.setAlias( "ID" );
                //                      fields.add( spField );

                for (String fieldName : fieldNames) {
                    spField = new Field();
                    spField.setName(fieldName);
                    spField.setAlias(fieldName);
                    fields.add(spField);
                }
                spFields.setField((Field[]) fields.toArray(fieldArray));
                spQuery.setFields(spFields);
            }
            // Of this document
            DspQueryWhere spWhere = new DspQueryWhere();

            org.apache.axis.message.MessageElement criterion = new org.apache.axis.message.MessageElement(
                    (String) null, "Contains");
            SOAPElement seFieldRef = criterion.addChildElement("FieldRef");
            seFieldRef.addAttribute(SOAPFactory.newInstance().createName("Name"), "FileRef");
            SOAPElement seValue = criterion.addChildElement("Value");
            seValue.addAttribute(SOAPFactory.newInstance().createName("Type"), "String");
            seValue.setValue(docId);

            org.apache.axis.message.MessageElement[] criteria = { criterion };
            spWhere.set_any(criteria);
            spQuery.setWhere((DspQueryWhere) spWhere);

            // Set Criteria
            myRequest.getDsQuery().setQuery(spQuery);

            StsAdapterSoap call = stub;

            // Make Request
            QueryResponse resp = call.query(myRequest);
            org.apache.axis.message.MessageElement[] list = resp.get_any();

            if (Logging.connectors.isDebugEnabled()) {
                Logging.connectors.debug("SharePoint: list xml: '" + list[0].toString() + "'");
            }

            XMLDoc doc = new XMLDoc(list[0].toString());
            ArrayList nodeList = new ArrayList();

            doc.processPath(nodeList, "*", null);
            if (nodeList.size() != 1) {
                throw new ManifoldCFException("Bad xml - missing outer 'ns1:dsQueryResponse' node - there are "
                        + Integer.toString(nodeList.size()) + " nodes");
            }

            Object parent = nodeList.get(0);
            //System.out.println( "Outer NodeName = " + doc.getNodeName(parent) );
            if (!doc.getNodeName(parent).equals("ns1:dsQueryResponse"))
                throw new ManifoldCFException("Bad xml - outer node is not 'ns1:dsQueryResponse'");

            nodeList.clear();
            doc.processPath(nodeList, "*", parent);

            parent = nodeList.get(0); // <Shared_X0020_Documents />

            nodeList.clear();
            doc.processPath(nodeList, "*", parent);

            // Process each result (Should only be one )
            // Get each childs Value and add to return array
            for (int i = 0; i < nodeList.size(); i++) {
                Object documentNode = nodeList.get(i);
                ArrayList fieldList = new ArrayList();

                doc.processPath(fieldList, "*", documentNode);
                for (int j = 0; j < fieldList.size(); j++) {
                    Object field = fieldList.get(j);
                    String fieldData = doc.getData(field);
                    String fieldName = doc.getNodeName(field);
                    // Right now this really only works right for single-valued fields.  For multi-valued
                    // fields, we'd need to know in advance that they were multivalued
                    // so that we could interpret commas as value separators.
                    result.put(fieldName, fieldData);
                }
            }
        } else {
            // SharePoint 2010: Get field values some other way
            // Sharepoint 2010; use Lists service instead
            ListsWS lservice = new ListsWS(baseUrl + site, userName, password, configuration, httpClient);
            ListsSoapStub stub1 = (ListsSoapStub) lservice.getListsSoapHandler();

            String sitePlusDocId = serverLocation + site + docId;
            if (sitePlusDocId.startsWith("/"))
                sitePlusDocId = sitePlusDocId.substring(1);

            GetListItemsQuery q = buildMatchQuery("FileRef", "Text", sitePlusDocId);
            GetListItemsViewFields viewFields = buildViewFields(fieldNames);

            GetListItemsResponseGetListItemsResult items = stub1.getListItems(docLibrary, "", q, viewFields,
                    "1", buildNonPagingQueryOptions(), null);
            if (items == null)
                return result;

            MessageElement[] list = items.get_any();

            if (Logging.connectors.isDebugEnabled()) {
                Logging.connectors.debug("SharePoint: getListItems for '" + docId + "' using FileRef value '"
                        + sitePlusDocId + "' xml response: '" + list[0].toString() + "'");
            }

            ArrayList nodeList = new ArrayList();
            XMLDoc doc = new XMLDoc(list[0].toString());

            doc.processPath(nodeList, "*", null);
            if (nodeList.size() != 1)
                throw new ManifoldCFException("Bad xml - expecting one outer 'ns1:listitems' node - there are "
                        + Integer.toString(nodeList.size()) + " nodes");

            Object parent = nodeList.get(0);
            if (!"ns1:listitems".equals(doc.getNodeName(parent)))
                throw new ManifoldCFException("Bad xml - outer node is not 'ns1:listitems'");

            nodeList.clear();
            doc.processPath(nodeList, "*", parent);

            if (nodeList.size() != 1)
                throw new ManifoldCFException("Expected rsdata result but no results found.");

            Object rsData = nodeList.get(0);

            int itemCount = Integer.parseInt(doc.getValue(rsData, "ItemCount"));
            if (itemCount == 0)
                return result;

            // Now, extract the files from the response document
            ArrayList nodeDocs = new ArrayList();

            doc.processPath(nodeDocs, "*", rsData);

            if (nodeDocs.size() != itemCount)
                throw new ManifoldCFException("itemCount does not match with nodeDocs.size()");

            if (itemCount != 1)
                throw new ManifoldCFException("Expecting only one item, instead saw '" + itemCount + "'");

            Object o = nodeDocs.get(0);

            // Look for all the specified attributes in the record
            for (Object attrName : fieldNames) {
                String attrValue = doc.getValue(o, "ows_" + (String) attrName);
                if (attrValue != null) {
                    result.put(attrName.toString(), valueMunge(attrValue));
                }
            }
        }

        return result;
    } catch (javax.xml.soap.SOAPException e) {
        throw new ManifoldCFException("Soap exception: " + e.getMessage(), e);
    } catch (java.net.MalformedURLException e) {
        throw new ManifoldCFException("Bad SharePoint url: " + e.getMessage(), e);
    } catch (javax.xml.rpc.ServiceException e) {
        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Got a service exception getting field values for site " + site
                    + " library " + docLibrary + " document '" + docId + "' - retrying", e);
        currentTime = System.currentTimeMillis();
        throw new ServiceInterruption("Service exception: " + e.getMessage(), e, currentTime + 300000L,
                currentTime + 12 * 60 * 60000L, -1, true);
    } catch (org.apache.axis.AxisFault e) {
        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
            org.w3c.dom.Element elem = e.lookupFaultDetail(
                    new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
            if (elem != null) {
                elem.normalize();
                String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                if (httpErrorCode.equals("404"))
                    return null;
                else if (httpErrorCode.equals("403"))
                    throw new ManifoldCFException("Remote procedure exception: " + e.getMessage(), e);
                else if (httpErrorCode.equals("401")) {
                    if (Logging.connectors.isDebugEnabled())
                        Logging.connectors.debug(
                                "SharePoint: Crawl user does not have sufficient privileges to get field values for site "
                                        + site + " library " + docLibrary + " - skipping",
                                e);
                    return null;
                }
                throw new ManifoldCFException("Unexpected http error code " + httpErrorCode
                        + " accessing SharePoint at " + baseUrl + site + ": " + e.getMessage(), e);
            }
            throw new ManifoldCFException("Unknown http error occurred: " + e.getMessage(), e);
        }

        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/",
                "Server.userException"))) {
            String exceptionName = e.getFaultString();
            if (exceptionName.equals("java.lang.InterruptedException"))
                throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
        }

        // I don't know if this is what you get when the library is missing, but here's hoping.
        if (e.getMessage().indexOf("List does not exist") != -1)
            return null;

        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("SharePoint: Got a remote exception getting field values for site " + site
                    + " library " + docLibrary + " document [" + docId + "] - retrying", e);
        currentTime = System.currentTimeMillis();
        throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e, currentTime + 300000L,
                currentTime + 3 * 60 * 60000L, -1, false);
    } catch (java.rmi.RemoteException e) {
        throw new ManifoldCFException("Unexpected remote exception occurred: " + e.getMessage(), e);
    }
}

From source file:de.unibi.techfak.bibiserv.BiBiTools.java

/**
 * Returns a SOAPFaultException with specified
 *
 * @param faultcode//from  ww  w  . jav a2  s . c o  m
 * @param faultstring
 * @param hobitstatuscode
 * @param hobitstatusdescription
 * @return
 */
public static SOAPFaultException createSOAPFaultException(String faultcode, String faultstring,
        String hobitstatuscode, String hobitstatusdescription) {
    SOAPFault fault = null;
    try {
        SOAPFactory sfi = SOAPFactory.newInstance();
        fault = sfi.createFault();

        fault.setFaultCode(new QName("http://schemas.xmlsoap.org/soap/envelope/", faultcode, "soap"));
        fault.setFaultString(faultstring);
        if (hobitstatuscode != null && hobitstatusdescription != null) {
            Detail detail = fault.addDetail();
            DetailEntry detailentry = detail.addDetailEntry(new QName(
                    "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "hobitStatuscode", "status"));

            SOAPElement statuscode = detailentry.addChildElement(
                    new QName("http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "statuscode", "status"));
            statuscode.addTextNode(hobitstatuscode);

            SOAPElement description = detailentry.addChildElement(new QName(
                    "http://hobit.sourceforge.net/xsds/hobitStatuscode.xsd", "description", "status"));
            description.addTextNode(hobitstatusdescription);
        }

    } catch (SOAPException e) {
        log.fatal("SOAPException occured : " + e.getMessage());
    }

    return new SOAPFaultException(fault);

}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test/*w  w  w.j a  v  a 2s.c  o  m*/
public void testCreateDetail() {
    try {
        SOAPFactory sf = SOAPFactory.newInstance();
        if (sf == null) {
            fail("SOAPFactory was null");
        }
        Detail d = sf.createDetail();
        if (d == null) {
            fail("Detail was null");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Unexpected Exception " + e);
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test/*from ww w.  j  a  va  2 s .c  o m*/
public void testCreateElement2() {
    try {
        SOAPFactory sf = SOAPFactory.newInstance();
        //SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        if (sf == null) {
            fail("could not create SOAPFactory object");
        }
        log.info("Create a DOMElement");
        DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dbfactory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element de = document.createElementNS("http://MyNamespace.org/", "MyTag");
        //Calling SOAPFactory.createElement(org.w3c.dom.Element)
        SOAPElement se = sf.createElement(de);
        if (!de.getNodeName().equals(se.getNodeName()) || !de.getNamespaceURI().equals(se.getNamespaceURI())) {
            //Node names are not equal
            fail("Got: <URI=" + se.getNamespaceURI() + ", PREFIX=" + se.getPrefix() + ", NAME="
                    + se.getNodeName() + ">" + "Expected: <URI=" + de.getNamespaceURI() + ", PREFIX="
                    + de.getPrefix() + ", NAME=" + de.getNodeName() + ">");
        }
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test/*from ww w .  j av  a  2  s  .co m*/
public void testCreateElement3() {
    try {
        SOAPFactory factory = SOAPFactory.newInstance();
        if (factory == null) {
            fail("createFaultTest1() could not create SOAPFactory object");
        }
        SOAPFault sf = factory.createFault();
        if (sf == null) {
            fail("createFault() returned null");
        } else if (!(sf instanceof SOAPFault)) {
            fail("createFault() did not create a SOAPFault object");
        }
    } catch (Exception e) {
        fail();
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test//from   w ww. j  a v  a 2  s.c om
public void testCreateElement4() {
    try {
        SOAPFactory sf = SOAPFactory.newInstance();
        if (sf == null) {
            fail("createElementTest6() could not create SOAPFactory object");
        }
        QName qname = new QName("http://MyNamespace.org/", "MyTag");
        SOAPElement se1 = sf.createElement(qname);
        //Create second SOAPElement from first SOAPElement
        SOAPElement se2 = sf.createElement(se1);
        //commented to support jdk 1.4 build
        //          if(!se1.isEqualNode(se2) && !se1.isSameNode(se2)) {
        //             fail("The SOAPElement's are not equal and not the same (unexpected)");
        //          }
        if (!se1.getNodeName().equals(se2.getNodeName())
                || !se1.getNamespaceURI().equals(se2.getNamespaceURI())) {
            fail("Got: <URI=" + se1.getNamespaceURI() + ", PREFIX=" + se1.getPrefix() + ", NAME="
                    + se1.getNodeName() + ">" + "Expected: <URI=" + se2.getNamespaceURI() + ", PREFIX="
                    + se2.getPrefix() + ", NAME=" + se2.getNodeName() + ">");
        }
    } catch (Exception e) {
        fail();
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Test
public void testCreateFault1() {
    try {// w ww  .j a v  a  2 s.  c  om
        //SOAPFactory factory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault sf = factory.createFault("This is the fault reason.", SOAPConstants.SOAP_RECEIVER_FAULT);
        assertNotNull(sf);
        QName fc = sf.getFaultCodeAsQName();
        Iterator i = sf.getFaultReasonTexts();

        String reason = "";
        while (i.hasNext()) {
            reason += (String) i.next();
        }
        log.info("Actual ReasonText=" + reason);
        assertNotNull(reason);
        assertTrue(reason.indexOf("This is the fault reason.") > -1);
        assertTrue(fc.equals(SOAPConstants.SOAP_RECEIVER_FAULT));
    } catch (SOAPException e) {
        //Caught expected SOAPException
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}

From source file:org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider.java

public SecurityTokenServiceProvider() throws Exception {
    jaxbContext = JAXBContext.newInstance(JAXB_CONTEXT_PATH);
    soapFactory = SOAPFactory.newInstance();
}