List of usage examples for javax.xml.soap SOAPElement setValue
public void setValue(String value);
From source file:com.offbynull.portmapper.upnpigd.UpnpIgdController.java
private byte[] createRequestXml(String action, ImmutablePair<String, String>... params) { try {/*from w w w . jav a2 s .c o m*/ MessageFactory factory = MessageFactory.newInstance(); SOAPMessage soapMessage = factory.createMessage(); SOAPBodyElement actionElement = soapMessage.getSOAPBody().addBodyElement(new QName(null, action, "m")); actionElement.addNamespaceDeclaration("m", serviceType); for (Pair<String, String> param : params) { SOAPElement paramElement = actionElement.addChildElement(QName.valueOf(param.getKey())); paramElement.setValue(param.getValue()); } soapMessage.getSOAPPart().setXmlStandalone(true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(soapMessage.getSOAPPart()), new StreamResult(baos)); return baos.toByteArray(); } catch (IllegalArgumentException | SOAPException | TransformerException | DOMException e) { throw new IllegalStateException(e); // should never happen } }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/* w w w . j a va2s . c o m*/ public void testSetValueNoChildren() { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); String value = "test"; element.setValue(value); assertEquals(value, element.getValue()); Node child = element.getFirstChild(); assertTrue(child instanceof Text); assertEquals(value, ((Text) child).getValue()); assertNull(child.getNextSibling()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test(expected = IllegalStateException.class) public void testSetValueTwoTextChildren() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.addTextNode("foo"); element.addTextNode("bar"); element.setValue("test"); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from w w w . ja v a2s.c o m*/ public void testSetValueSingleTextChild() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.addTextNode("initial content"); Text text = (Text) element.getFirstChild(); String value = "new value"; element.setValue(value); assertEquals(value, text.getValue()); }
From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SPSProxyHelper.java
/** * Gets a list of field values of the given document * @param fieldNames// w ww . j ava2 s .c om * @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:org.jbpm.bpel.integration.soap.SoapUtil.java
public static void setQNameValue(SOAPElement elem, QName value) throws SOAPException { elem.setValue(formatQName(value, elem)); }
From source file:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java
public void sign(final SOAPMessage message) { try {/* w w w . j ava 2s.c om*/ loadCertificate(); final long startMs = System.currentTimeMillis(); final SOAPPart doc = message.getSOAPPart(); final QName wsuId = doc.getEnvelope().createQName("Id", "wsu"); final SOAPHeader header = message.getSOAPHeader(); final QName actor = header.createQName("actor", header.getPrefix()); final SOAPElement security = header.addChildElement("Security", "wsse", WSSE); security.addAttribute(actor, ACTOR_SMEV); SOAPElement binarySecurityToken = security.addChildElement("BinarySecurityToken", "wsse"); binarySecurityToken.setAttribute("EncodingType", WSS_BASE64_BINARY); binarySecurityToken.setAttribute("ValueType", WSS_X509V3); binarySecurityToken.setValue(DatatypeConverter.printBase64Binary(cert.getEncoded())); binarySecurityToken.addAttribute(wsuId, "CertId"); XMLSignature signature = new XMLSignature(doc, "", XMLSignature.ALGO_ID_SIGNATURE_GOST_GOST3410_3411, Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); { Element element = signature.getElement(); Element keyInfo = doc.createElementNS(Constants.SignatureSpecNS, "KeyInfo"); Element securityTokenReference = doc.createElementNS(WSSE, "SecurityTokenReference"); Element reference = doc.createElementNS(WSSE, "Reference"); reference.setAttribute("URI", "#CertId"); reference.setAttribute("ValueType", WSS_X509V3); securityTokenReference.appendChild(reference); keyInfo.appendChild(securityTokenReference); element.appendChild(keyInfo); security.appendChild(element); } Transforms transforms = new Transforms(doc); transforms.addTransform(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); signature.addDocument("#body", transforms, MessageDigestAlgorithm.ALGO_ID_DIGEST_GOST3411); signature.sign(privateKey); if (log.isDebugEnabled()) { log.debug("SIGN: " + (System.currentTimeMillis() - startMs) + "ms"); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }