List of usage examples for javax.xml.namespace QName QName
public QName(String namespaceURI, String localPart, String prefix)
QName
constructor specifying the Namespace URI, local part and prefix.
If the Namespace URI is null
, it is set to javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI .
From source file:eu.esdihumboldt.hale.io.wfs.ui.describefeature.WFSDescribeFeatureSource.java
@Override public boolean updateConfiguration(ImportProvider provider) { boolean success = super.updateConfiguration(provider); if (success && provider instanceof XmlSchemaReader) { // analyze URI and determine relevant elements URI loc = provider.getSource().getLocation(); if (loc != null) { URIBuilder b = new URIBuilder(loc); String namespace = null; String typename = null; for (NameValuePair param : b.getQueryParams()) { switch (param.getName().toLowerCase()) { case "namespace": case "namespaces": namespace = param.getValue(); break; case "typename": case "typenames": typename = param.getValue(); break; }/* w w w. j a v a2 s.c om*/ } if (typename != null && !typename.isEmpty()) { // parse namespaces Map<String, String> prefixToNamespace = new HashMap<>(); if (namespace != null && !namespace.isEmpty()) { Pattern ex = Pattern.compile("xmlns\\((([\\w\\d_\\.\\-]+)(=|,))?([^)]+)\\)"); Matcher matcher = ex.matcher(namespace); while (matcher.find()) { String prefix = matcher.group(2); if (prefix == null) { prefix = XMLConstants.DEFAULT_NS_PREFIX; } String ns = matcher.group(4); prefixToNamespace.put(prefix, ns); } // previously used implementation below does not support // comma separator inside xmlns(...) // for (String xmlns : Splitter.on(',').omitEmptyStrings().trimResults() // .split(namespace)) { // if (xmlns.startsWith("xmlns(") && xmlns.endsWith(")")) { // String mapping = xmlns.substring("xmlns(".length(), // xmlns.length() - 1); // List<String> mp = Splitter.on('=').limit(2).trimResults() // .splitToList(mapping); // if (mp.size() == 2) { // prefixToNamespace.put(mp.get(0), mp.get(1)); // } // else { // // mapping for default namespace // prefixToNamespace.put(XMLConstants.DEFAULT_NS_PREFIX, mp.get(0)); // } // } // } } Set<QName> elements = new HashSet<>(); // parse type names for (String type : Splitter.on(',').omitEmptyStrings().trimResults().split(typename)) { List<String> nameParts = Splitter.on(':').limit(2).trimResults().splitToList(type); QName name; if (nameParts.size() == 2) { // prefix and name String prefix = nameParts.get(0); String ns = prefixToNamespace.get(prefix); if (ns != null) { name = new QName(ns, nameParts.get(1), prefix); } else { // namespace unknown - fall back to local name // only name = new QName(nameParts.get(1)); } } else { // only local name name = new QName(nameParts.get(0)); } elements.add(name); } ((XmlSchemaReader) provider).setRelevantElements(elements); } } } return success; }
From source file:whitelabel.cloud.wsclient.WebServiceAuthenticator.java
public void authenticateWithDigest(final SOAPMessage request, final String username, final String password) throws WsAuthenticationException { if (request == null) { LOG.error(" SoapMessage request not defined"); throw new WsAuthenticationException("SOAP_REQUEST_NOT_DEFINED"); }/* w ww .j a va2 s . co m*/ if (username == null || password == null || username.trim().length() == 0 || password.trim().length() == 0) { LOG.error("Username: " + username + " password: " + password + " - invalid parameters"); throw new WsAuthenticationException("INVALID_PARAMETERS"); } String nonceValue = generateNonceBase64(16); String createdValue = dfe.print(new Date()); String userValue = username; String pwdValue = crypthPassword(nonceValue, createdValue, password); String pwdType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"; QName securityQName = new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"); QName usernameTokenQName = new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken", "wsse"); QName usernameQName = new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Username", "wsse"); QName PasswordQName = new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Password", "wsse"); QName PasswordTypeQName = new QName("Type"); QName nonceQName = new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Nonce", "wsse"); QName createdQName = new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Created", "wsu"); SOAPElement securitySoap; try { securitySoap = request.getSOAPHeader().addChildElement(securityQName); SOAPElement usernameTokenSoap = securitySoap.addChildElement(usernameTokenQName); SOAPElement usernameSoap = usernameTokenSoap.addChildElement(usernameQName); usernameSoap.addTextNode(userValue); SOAPElement passwordSoap = usernameTokenSoap.addChildElement(PasswordQName); passwordSoap.addTextNode(pwdValue); passwordSoap.addAttribute(PasswordTypeQName, pwdType); SOAPElement nonceSoap = usernameTokenSoap.addChildElement(nonceQName); nonceSoap.addTextNode(nonceValue); SOAPElement creadedSoap = usernameTokenSoap.addChildElement(createdQName); creadedSoap.addTextNode(createdValue); } catch (SOAPException se) { LOG.error(se); throw new WsAuthenticationException("SOAPHEADER_CREATION", se); } }
From source file:com.cloud.bridge.service.controller.s3.S3ObjectAction.java
private void executeGetObjectAcl(HttpServletRequest request, HttpServletResponse response) throws IOException { String bucketName = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY); String key = (String) request.getAttribute(S3Constants.OBJECT_ATTR_KEY); S3GetObjectAccessControlPolicyRequest engineRequest = new S3GetObjectAccessControlPolicyRequest(); engineRequest.setBucketName(bucketName); engineRequest.setKey(key);//from w w w.j av a 2s. c om S3AccessControlPolicy engineResponse = ServiceProvider.getInstance().getS3Engine() .handleRequest(engineRequest); // -> serialize using the apache's Axiom classes GetObjectAccessControlPolicyResponse onePolicy = S3SoapServiceImpl .toGetObjectAccessControlPolicyResponse(engineResponse); try { OutputStream os = response.getOutputStream(); response.setStatus(200); response.setContentType("text/xml; charset=UTF-8"); XMLStreamWriter xmlWriter = xmlOutFactory.createXMLStreamWriter(os); String documentStart = new String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); os.write(documentStart.getBytes()); MTOMAwareXMLSerializer MTOMWriter = new MTOMAwareXMLSerializer(xmlWriter); onePolicy.serialize(new QName("http://s3.amazonaws.com/doc/2006-03-01/", "GetObjectAccessControlPolicyResponse", "ns1"), factory, MTOMWriter); xmlWriter.flush(); xmlWriter.close(); os.close(); } catch (XMLStreamException e) { throw new IOException(e.toString()); } }
From source file:eu.artist.postmigration.eubt.helpers.SOAPHelper.java
/** * Migrated request operation ==> Original request operation(s) * // w ww . ja va 2s . c o m * @param migratedOperationModel migrated operation model * @param migratedOperationAttributes operation attributes (= attribute name * and value) * @return original soap envelops corresponding to the given migrated * operation */ public static List<SOAPEnvelope> generateOriginalRequestSoapEnvelops(final TargetElement migratedOperationModel, final Map<String, String> migratedOperationAttributes, final WSMigrationTraceHandler wsMigrationTraceHandler) { final Map<SourceElement, OMElement> oparationMap = new LinkedHashMap<SourceElement, OMElement>(); final SOAP11Factory factory = new SOAP11Factory(); // For every migrated parameter, create its corresponding original parameter within their original operation(s) for (final TargetParameter migratedParameter : migratedOperationModel.getParameters()) { // in which original operation does this parameter exist? final MultiMap<SourceElement, SourceParameter> originalOperationParameters = wsMigrationTraceHandler .getSourceParameters(migratedOperationModel, migratedParameter); // for any original operation in which the migrated parameter exist --> create/extend original operation and parameter for (final SourceElement originalOperation : originalOperationParameters.keySet()) { OMElement operationElement = null; if (!oparationMap.containsKey(originalOperation)) { // new operation encountered --> create new operation final QName operationName = new QName(originalOperation.getElementNamespace().getNamespaceURI(), originalOperation.getElementName(), originalOperation.getElementNamespace().getNamespacePrefix()); operationElement = factory.createOMElement(operationName); } else { // existing operation encountered --> extend operationElement = oparationMap.get(originalOperation); } // obtain corresponding original parameter by checking the source parameter's target parameter back-link SourceParameter originalParameter = null; for (final SourceParameter sourceParameter : originalOperation.getParameters()) { for (final TargetParameter sourcesTargetParameter : sourceParameter.getTargetParameter()) { if (sourcesTargetParameter.equals(migratedParameter)) { originalParameter = sourceParameter; } } } // if there is a corresponding original attribute in the model --> create attribute if (originalParameter != null) { // create operation parameter final QName operationElementAttributeName = new QName(originalParameter.getParameterName()); final OMElement operationElementAttribute = factory .createOMElement(operationElementAttributeName); // obtain attribute value final OMText operationElementAttributeValue = factory.createOMText(operationElementAttribute, migratedOperationAttributes.get(migratedParameter.getParameterName())); // add attribute value to attribute operationElementAttribute.addChild(operationElementAttributeValue); // add attribute to operation operationElement.addChild(operationElementAttribute); // add operation to operation map oparationMap.put(originalOperation, operationElement); } } // for each original operation } // for each migrated parameter // Obtain corresponding original operation(s) final List<SourceElement> originalOperations = wsMigrationTraceHandler .getSourceElements(migratedOperationModel); // create new soap envelope for each original operation final List<SOAPEnvelope> soapEnvelops = new ArrayList<SOAPEnvelope>(); for (final SourceElement originalOperation : originalOperations) { // create operation element final OMElement operationElement = oparationMap.get(originalOperation); //OMNamespace operationNamespace = factory.createOMNamespace(originalOperation.getElementNamespace().getNamespaceURI(), originalOperation.getElementNamespace().getNamespacePrefix()); final SOAPEnvelope soapEnvelope = factory.createSOAPEnvelope(); final SOAPBody soapBody = factory.createSOAPBody(soapEnvelope); soapBody.addChild(operationElement); // populate list of soap envelops soapEnvelops.add(soapEnvelope); } return soapEnvelops; }