List of usage examples for javax.xml.namespace QName QName
public QName(final String namespaceURI, final String localPart)
QName
constructor specifying the Namespace URI and local part.
If the Namespace URI is null
, it is set to javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI .
From source file:hermes.impl.DefaultXMLHelper.java
public void saveContent(MessageSet messages, OutputStream ostream) throws Exception { JAXBContext jc = JAXBContext.newInstance("hermes.xml"); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(new JAXBElement<MessageSet>(new QName("", "content"), MessageSet.class, messages), ostream); ostream.flush();//from w w w .j a v a2s .co m }
From source file:eu.domibus.ebms3.sender.ReliabilityChecker.java
public boolean check(SOAPMessage request, SOAPMessage response, String pmodeKey) throws EbMS3Exception { LegConfiguration legConfiguration = this.pModeProvider.getLegConfiguration(pmodeKey); assert legConfiguration != null; // we would have crashed in the security handler if (legConfiguration.getReliability() != null && ReplyPattern.RESPONSE.equals(legConfiguration.getReliability().getReplyPattern())) { ReliabilityChecker.LOG.debug("Checking reliability for outgoing message"); Messaging messaging;// w w w .ja v a2 s . c o m try { messaging = this.jaxbContext .createUnmarshaller().unmarshal((Node) response.getSOAPHeader() .getChildElements(ObjectFactory._Messaging_QNAME).next(), Messaging.class) .getValue(); } catch (JAXBException | SOAPException e) { ReliabilityChecker.LOG.error(e.getMessage(), e); return false; } SignalMessage signalMessage = messaging.getSignalMessage(); //ReceiptionAwareness or NRR found but not expected? report if configuration=true //TODO: make configurable in domibus.properties //SignalMessage with Receipt expected if (signalMessage.getReceipt() != null && signalMessage.getReceipt().getAny().size() == 1) { String contentOfReceiptString = signalMessage.getReceipt().getAny().get(0); try { if (!legConfiguration.getReliability().isNonRepudiation()) { UserMessage userMessage = this.jaxbContext.createUnmarshaller() .unmarshal( new StreamSource( new ByteArrayInputStream(contentOfReceiptString.getBytes())), UserMessage.class) .getValue(); UserMessage userMessageInRequest = this.jaxbContext.createUnmarshaller() .unmarshal( (Node) request.getSOAPHeader() .getChildElements(ObjectFactory._Messaging_QNAME).next(), Messaging.class) .getValue().getUserMessage(); return userMessage.equals(userMessageInRequest); } Iterator<Element> elementIterator = response.getSOAPHeader() .getChildElements(new QName(WSConstants.WSSE_NS, WSConstants.WSSE_LN)); if (!elementIterator.hasNext()) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "Invalid NonRepudiationInformation: No security header found", null, MSHRole.SENDING); } Element securityHeaderResponse = elementIterator.next(); if (elementIterator.hasNext()) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "Invalid NonRepudiationInformation: Multiple security headers found", null, MSHRole.SENDING); } String wsuIdOfMEssagingElement = messaging.getOtherAttributes() .get(new QName(WSConstants.WSU_NS, "Id")); ReliabilityChecker.LOG.debug(wsuIdOfMEssagingElement); NodeList nodeList = securityHeaderResponse.getElementsByTagNameNS(WSConstants.SIG_NS, WSConstants.REF_LN); boolean signatureFound = false; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (this.compareReferenceIgnoreHashtag( node.getAttributes().getNamedItem("URI").getNodeValue(), wsuIdOfMEssagingElement)) { signatureFound = true; break; } } if (!signatureFound) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "Invalid NonRepudiationInformation: eb:Messaging not signed", null, MSHRole.SENDING); } NodeList referencesFromSecurityHeader = this.getNonRepudiationNodeList(request.getSOAPHeader() .getElementsByTagNameNS(WSConstants.SIG_NS, WSConstants.SIG_LN).item(0)); NodeList referencesFromNonRepudiationInformation = this.getNonRepudiationNodeList(response .getSOAPHeader() .getElementsByTagNameNS(NonRepudiationConstants.NS_NRR, NonRepudiationConstants.NRR_LN) .item(0)); if (!this.compareUnorderedReferenceNodeLists(referencesFromSecurityHeader, referencesFromNonRepudiationInformation)) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "Invalid NonRepudiationInformation: non repudiation information and request message do not match", null, MSHRole.SENDING); } return true; } catch (JAXBException e) { ReliabilityChecker.LOG.error("", e); } catch (SOAPException e) { ReliabilityChecker.LOG.error("", e); } } else { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0302, "There is no content inside the receipt element received by the responding gateway", signalMessage.getMessageInfo().getMessageId(), signalMessage.getMessageInfo().getMessageId(), null, MSHRole.SENDING); } } return false; }
From source file:org.github.alexwibowo.opentext.client.AxiomVRDClient.java
@Override public void getDocument(String recordID, String section, String renditionType, VRDDocumentVersion version, OutputStream outputStream) throws Exception { // create vrd namespace without prefix. This is important, as crazy VRD doesnt like prefix. OMNamespace vrdNamespace = factory.createOMNamespace("http://record.webservices.rd.vignette.com/", ""); OMElement getRenditionElement = factory.createOMElement("getRendition", vrdNamespace); OMElement recordIdElement = factory.createOMElement("recordID", vrdNamespace); recordIdElement.setText(recordID);/*from w w w . j a v a2s .c om*/ getRenditionElement.addChild(recordIdElement); OMElement sectionElement = factory.createOMElement("section", vrdNamespace); sectionElement.setText(section); getRenditionElement.addChild(sectionElement); OMElement subSectionElement = factory.createOMElement("subSection", vrdNamespace); subSectionElement.setText("0"); getRenditionElement.addChild(subSectionElement); OMElement renditionTypeElement = factory.createOMElement("renditionType", vrdNamespace); renditionTypeElement.setText(StringUtils.isBlank(renditionType) ? "ORIGINAL" : renditionType); getRenditionElement.addChild(renditionTypeElement); OMElement versionElement = factory.createOMElement("version", vrdNamespace); versionElement.setText(version.name()); getRenditionElement.addChild(versionElement); SOAPMessageBuilder soap11MessageBuilder = new AxiomSOAP11MessageBuilder(jaxbContext, soap11Factory) .withPayload(getRenditionElement) .withUsernameToken(configuration.getUsername(), configuration.getPassword()); SOAPEnvelope envelope = (SOAPEnvelope) soap11MessageBuilder.build(); HttpResponse httpResponse = postAsMultipart(envelope, GetRendition.getQName()); if (httpResponse.getStatusLine() != null && httpResponse.getStatusLine().getStatusCode() == 200) { if (httpResponse.getEntity() != null && httpResponse.getEntity().getContent() != null) { String contentType = httpResponse.getFirstHeader("Content-Type").getValue(); InputStream responseAsStream = httpResponse.getEntity().getContent(); MultipartHttpResponseDataSource dataSource = new MultipartHttpResponseDataSource(responseAsStream, contentType); WibMimeMultipart mp = new WibMimeMultipart(dataSource); BodyPart bodyPart = mp.getBodyPart(1); ByteArrayInputStream content = (ByteArrayInputStream) bodyPart.getContent(); copy(content, outputStream); } else { throw new GeneralVRDException("No valid response for getting document from VRD.", null); // need a better structure here.. } } else { InputStream in = httpResponse.getEntity().getContent(); SOAPEnvelope response = OMXMLBuilderFactory.createSOAPModelBuilder(in, "UTF-8").getSOAPEnvelope(); OMElement fault = response.getBody() .getFirstChildWithName(new QName("http://schemas.xmlsoap.org/soap/envelope/", "Fault")); OMElement detail = fault.getFirstChildWithName(new QName("detail")).getFirstElement(); String vrdResponseXML = detail.toString(); throw new GeneralVRDException(vrdResponseXML, null); // need a better structure here.. } }
From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractX509CredentialBeanDefinitionParser.java
/** * Parses the CRLs from the credential configuration. * //from w ww.j av a 2 s . c o m * @param configChildren children of the credential element * @param builder credential build */ protected void parseCRLs(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) { List<Element> crlElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "CRL")); if (crlElems == null || crlElems.isEmpty()) { return; } log.debug("Parsing x509 credential CRLs"); ArrayList<X509CRL> crls = new ArrayList<X509CRL>(); byte[] encodedCRL; Collection<X509CRL> decodedCRLs; for (Element crlElem : crlElems) { encodedCRL = getEncodedCRL(DatatypeHelper.safeTrimOrNullString(crlElem.getTextContent())); if (encodedCRL == null) { continue; } try { decodedCRLs = X509Util.decodeCRLs(encodedCRL); crls.addAll(decodedCRLs); } catch (CRLException e) { throw new FatalBeanException("Unable to create X509 credential, unable to parse CRLs", e); } } builder.addPropertyValue("crls", crls); }
From source file:be.fedict.eid.idp.sp.protocol.ws_federation.sts.SecurityTokenServiceClient.java
/** * Validates the given SAML assertion via the eID IdP WS-Trust STS * validation service.//from w w w . jav a 2 s. c o m * * @param samlAssertionElement * the SAML assertion DOM element to be validated. * @param expectedSAMLAudience * the optional (but recommended) expected value for SAML * Audience. */ public void validateToken(Element samlAssertionElement, String expectedSAMLAudience) { RequestSecurityTokenType request = this.objectFactory.createRequestSecurityTokenType(); List<Object> requestContent = request.getAny(); requestContent.add(this.objectFactory.createRequestType(WSTrustConstants.VALIDATE_REQUEST_TYPE)); requestContent.add(this.objectFactory.createTokenType(WSTrustConstants.STATUS_TOKEN_TYPE)); ValidateTargetType validateTarget = this.objectFactory.createValidateTargetType(); requestContent.add(this.objectFactory.createValidateTarget(validateTarget)); BindingProvider bindingProvider = (BindingProvider) this.port; WSSecuritySoapHandler.setAssertion(samlAssertionElement, bindingProvider); SecurityTokenReferenceType securityTokenReference = this.wsseObjectFactory .createSecurityTokenReferenceType(); validateTarget.setAny(this.wsseObjectFactory.createSecurityTokenReference(securityTokenReference)); securityTokenReference.getOtherAttributes().put( new QName(WSTrustConstants.WS_SECURITY_11_NAMESPACE, "TokenType"), WSTrustConstants.SAML2_WSSE11_TOKEN_TYPE); KeyIdentifierType keyIdentifier = this.wsseObjectFactory.createKeyIdentifierType(); securityTokenReference.getAny().add(this.wsseObjectFactory.createKeyIdentifier(keyIdentifier)); String samlAssertionId = samlAssertionElement.getAttribute("ID"); LOG.debug("SAML assertion ID: " + samlAssertionId); keyIdentifier.setValue(samlAssertionId); keyIdentifier.getOtherAttributes().put(new QName(WSTrustConstants.WS_SECURITY_NAMESPACE, "ValueType"), "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID"); if (null != expectedSAMLAudience) { AppliesTo appliesTo = this.policyObjectFactory.createAppliesTo(); requestContent.add(appliesTo); EndpointReferenceType endpointReference = this.addrObjectFactory.createEndpointReferenceType(); appliesTo.getAny().add(this.addrObjectFactory.createEndpointReference(endpointReference)); AttributedURIType address = this.addrObjectFactory.createAttributedURIType(); endpointReference.setAddress(address); address.setValue(expectedSAMLAudience); } RequestSecurityTokenResponseCollectionType response = this.port.requestSecurityToken(request); if (null == response) { throw new SecurityException("missing RSTRC"); } List<RequestSecurityTokenResponseType> responseList = response.getRequestSecurityTokenResponse(); if (1 != responseList.size()) { throw new SecurityException("response list should contain 1 entry"); } RequestSecurityTokenResponseType requestSecurityTokenResponse = responseList.get(0); List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny(); boolean hasStatus = false; for (Object requestSecurityTokenResponseObject : requestSecurityTokenResponseContent) { if (requestSecurityTokenResponseObject instanceof JAXBElement) { JAXBElement jaxbElement = (JAXBElement) requestSecurityTokenResponseObject; QName qname = jaxbElement.getName(); if (WSTrustConstants.TOKEN_TYPE_QNAME.equals(qname)) { String tokenType = (String) jaxbElement.getValue(); if (false == WSTrustConstants.STATUS_TOKEN_TYPE.equals(tokenType)) { throw new SecurityException("invalid response token type: " + tokenType); } } else if (STATUS_QNAME.equals(qname)) { StatusType status = (StatusType) jaxbElement.getValue(); String statusCode = status.getCode(); if (false == WSTrustConstants.VALID_STATUS_CODE.equals(statusCode)) { String reason = status.getReason(); throw new SecurityException("invalid token: " + reason); } hasStatus = true; } } } if (false == hasStatus) { throw new SecurityException("missing wst:Status"); } }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlMimeMessageResponse.java
private void expandMtomAttachments(WsdlRequest wsdlRequest) { try {//w w w. j ava 2 s . c om // XmlObject xmlObject = XmlObject.Factory.parse( getContentAsString() // ); XmlObject xmlObject = XmlUtils.createXmlObject(getContentAsString()); XmlObject[] includes = xmlObject .selectPath("declare namespace xop='http://www.w3.org/2004/08/xop/include'; //xop:Include"); for (XmlObject include : includes) { Element elm = (Element) include.getDomNode(); String href = elm.getAttribute("href"); Attachment attachment = getMmSupport().getAttachmentWithContentId("<" + href.substring(4) + ">"); if (attachment != null) { ByteArrayOutputStream data = Tools.readAll(attachment.getInputStream(), 0); byte[] byteArray = data.toByteArray(); XmlCursor cursor = include.newCursor(); cursor.toParent(); XmlObject parentXmlObject = cursor.getObject(); cursor.dispose(); SchemaType schemaType = parentXmlObject.schemaType(); Node parentNode = elm.getParentNode(); if (schemaType.isNoType()) { SchemaTypeSystem typeSystem = wsdlRequest.getOperation().getInterface().getWsdlContext() .getSchemaTypeSystem(); SchemaGlobalElement schemaElement = typeSystem .findElement(new QName(parentNode.getNamespaceURI(), parentNode.getLocalName())); if (schemaElement != null) { schemaType = schemaElement.getType(); } } String txt = null; if (SchemaUtils.isInstanceOf(schemaType, XmlHexBinary.type)) { txt = new String(Hex.encodeHex(byteArray)); } else { txt = new String(Base64.encodeBase64(byteArray)); } parentNode.replaceChild(elm.getOwnerDocument().createTextNode(txt), elm); } } getMmSupport().setResponseContent(xmlObject.toString()); } catch (Exception e) { SoapUI.logError(e); } }
From source file:io.apiman.gateway.engine.es.ESSharedStateComponent.java
/** * @param namespace/* ww w.j av a 2 s . c o m*/ * @param propertyName */ private String getPropertyId(String namespace, String propertyName) { String qn = new QName(namespace, propertyName).toString(); return Base64.encodeBase64String(qn.getBytes()); }
From source file:com.emental.mindraider.ui.dialogs.AddTripletJDialog.java
/** * Create a triplet.//ww w. j av a2s . c om */ protected void createTriplet() { if (StringUtils.isEmpty(predicateNs.getText())) { predicateNs.setText(MindRaiderConstants.MR_RDF_NS); } if (StringUtils.isEmpty(predicateLocalName.getText())) { predicateLocalName.setText(MindRaiderConstants.MR_RDF_PREDICATE); } if (StringUtils.isEmpty(objectNs.getText())) { objectNs.setText(MindRaiderConstants.MR_RDF_NS); } if (StringUtils.isEmpty(objectLocalName.getText())) { JOptionPane.showMessageDialog(MindRaider.mainJFrame, "You must specify object name.", "Statement Creation Error", JOptionPane.ERROR_MESSAGE); return; } MindRaider.spidersGraph.createStatement(new QName(predicateNs.getText(), predicateLocalName.getText()), new QName(objectNs.getText(), objectLocalName.getText()), literalCheckBox.isSelected()); AddTripletJDialog.this.dispose(); }
From source file:org.mule.providers.soap.axis.wsdl.wsrf.aspect.WsAddressingAdvice.java
/** * set Reference Properties. injecting Resource Key Ws-Addressing information * /*from ww w . ja v a2 s . com*/ * @param headers headers * @param event event */ private void setReferenceProperties(AddressingHeaders headers, UMOEvent event) { String serviceNamespace = (String) event.getMessage().getProperty(WSRFParameter.SERVICE_NAMESPACE); String resourceKeyName = (String) event.getMessage().getProperty(WSRFParameter.RESOURCE_KEY_NAME); QName keyName = new QName(serviceNamespace, resourceKeyName); String keyValue = (String) event.getMessage().getProperty(WSRFParameter.RESOURCE_KEY); //avoid to add ReferencesProperties if resource key is not define if (keyValue == null) { Logger.getLogger(this.getClass()).log(Level.DEBUG, this.getClass().getName() + " : ReferencesProperties IGNORED . Resource key not found.."); return; } SimpleResourceKey key = new SimpleResourceKey(keyName, keyValue); ReferencePropertiesType props = headers.getReferenceProperties(); if (props == null) { props = new ReferencePropertiesType(); } try { props.add(key.toSOAPElement()); } catch (SerializationException e) { e.printStackTrace(); } Logger.getLogger(this.getClass()).log(Level.DEBUG, this.getClass().getName() + " : ReferencesProperties injected.."); headers.setReferenceProperties(props); }
From source file:org.apache.servicemix.jms.JMSComponentTest.java
public void testConsumerInOut() throws Exception { // JMS Component JmsComponent component = new JmsComponent(); container.activateComponent(component, "JMSComponent"); // Add an echo component EchoComponent echo = new EchoComponent(); ActivationSpec asEcho = new ActivationSpec("receiver", echo); asEcho.setService(new QName("http://jms.servicemix.org/Test", "Echo")); container.activateComponent(asEcho); // Deploy Consumer SU URL url = getClass().getClassLoader().getResource("consumer/jms.wsdl"); File path = new File(new URI(url.toString())); path = path.getParentFile();//w ww. j a va2 s . c om component.getServiceUnitManager().deploy("consumer", path.getAbsolutePath()); component.getServiceUnitManager().init("consumer", path.getAbsolutePath()); component.getServiceUnitManager().start("consumer"); // Send test message jmsTemplate.setDefaultDestinationName("queue/A"); jmsTemplate.afterPropertiesSet(); jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { Message m = session.createTextMessage("<hello>world</hello>"); m.setJMSReplyTo(session.createQueue("queue/B")); return m; } }); // Receive echo message TextMessage reply = (TextMessage) jmsTemplate.receive("queue/B"); assertNotNull(reply); logger.info(reply.getText()); }