List of usage examples for javax.xml.namespace QName valueOf
public static QName valueOf(String qNameAsString)
From source file:edu.jhu.hlt.concrete.ingesters.bolt.BoltForumPostIngester.java
@Override public Communication fromCharacterBasedFile(final Path path) throws IngestException { if (!Files.exists(path)) throw new IngestException("No file at: " + path.toString()); AnalyticUUIDGeneratorFactory f = new AnalyticUUIDGeneratorFactory(); AnalyticUUIDGenerator gen = f.create(); Communication c = new Communication(); c.setUuid(gen.next());// w ww . j ava 2 s.co m c.setType(this.getKind()); c.setMetadata(TooledMetadataConverter.convert(this)); try { ExistingNonDirectoryFile ef = new ExistingNonDirectoryFile(path); c.setId(ef.getName().split("\\.")[0]); } catch (NoSuchFileException | NotFileException e) { // might throw if path is a directory. throw new IngestException(path.toString() + " is not a file, or is a directory."); } String content; try (InputStream is = Files.newInputStream(path); BufferedInputStream bin = new BufferedInputStream(is, 1024 * 8 * 8);) { content = IOUtils.toString(bin, StandardCharsets.UTF_8); c.setText(content); } catch (IOException e) { throw new IngestException(e); } try (InputStream is = Files.newInputStream(path); BufferedInputStream bin = new BufferedInputStream(is, 1024 * 8 * 8); BufferedReader reader = new BufferedReader(new InputStreamReader(bin, StandardCharsets.UTF_8));) { XMLEventReader rdr = null; try { rdr = inF.createXMLEventReader(reader); // Below method moves the reader // to the first post element. Section headline = handleHeadline(rdr, content); headline.setUuid(gen.next()); c.addToSectionList(headline); int start = headline.getTextSpan().getStart(); int ending = headline.getTextSpan().getEnding(); if (ending < start) ending = start; // @tongfei: handle empty headlines String htxt = c.getText().substring(start, ending); LOGGER.debug("headline text: {}", htxt); // Section indices. int sectNumber = 1; int subSect = 0; // Move iterator to post start element. this.iterateToPosts(rdr); // Offset pointer. int currOff = -1; SectionFactory sf = new SectionFactory(gen); // First post element. while (rdr.hasNext()) { XMLEvent nextEvent = rdr.nextEvent(); currOff = nextEvent.getLocation().getCharacterOffset(); if (currOff > 0) { int currOffPlus = currOff + 20; int currOffLess = currOff - 20; LOGGER.debug("Offset: {}", currOff); if (currOffPlus < content.length()) LOGGER.debug("Surrounding text: {}", content.substring(currOffLess, currOffPlus)); } // First: see if document is going to end. // If yes: exit. if (nextEvent.isEndDocument()) break; // XMLEvent peeker = rdr.peek(); // Check if start element. if (nextEvent.isStartElement()) { StartElement se = nextEvent.asStartElement(); QName name = se.getName(); final String localName = name.getLocalPart(); LOGGER.debug("Hit start element: {}", localName); //region // Add sections for authors and datetimes for each bolt post // by Tongfei Chen Attribute attrAuthor = se.getAttributeByName(QName.valueOf("author")); Attribute attrDateTime = se.getAttributeByName(QName.valueOf("datetime")); if (attrAuthor != null && attrDateTime != null) { int loc = attrAuthor.getLocation().getCharacterOffset(); int sectAuthorBeginningOffset = loc + "<post author=\"".length(); Section sectAuthor = sf.fromTextSpan(new TextSpan(sectAuthorBeginningOffset, sectAuthorBeginningOffset + attrAuthor.getValue().length()), "author"); c.addToSectionList(sectAuthor); int sectDateTimeBeginningOffset = sectAuthorBeginningOffset + attrAuthor.getValue().length() + " datetime=".length(); Section sectDateTime = sf.fromTextSpan( new TextSpan(sectDateTimeBeginningOffset, sectDateTimeBeginningOffset + attrDateTime.getValue().length()), "datetime"); c.addToSectionList(sectDateTime); } //endregion // Move past quotes, images, and links. if (localName.equals(QUOTE_LOCAL_NAME)) { this.handleQuote(rdr); } else if (localName.equals(IMG_LOCAL_NAME)) { this.handleImg(rdr); } else if (localName.equals(LINK_LOCAL_NAME)) { this.handleLink(rdr); } // not a start element } else if (nextEvent.isCharacters()) { Characters chars = nextEvent.asCharacters(); int coff = chars.getLocation().getCharacterOffset(); if (!chars.isWhiteSpace()) { // content to be captured String fpContent = chars.getData(); LOGGER.debug("Character offset: {}", coff); LOGGER.debug("Character based data: {}", fpContent); // LOGGER.debug("Character data via offset diff: {}", content.substring(coff - fpContent.length(), coff)); SimpleImmutableEntry<Integer, Integer> pads = trimSpacing(fpContent); final int tsb = currOff + pads.getKey(); final int tse = currOff + fpContent.length() - pads.getValue(); final String subs = content.substring(tsb, tse); if (subs.replaceAll("\\p{Zs}", "").replaceAll("\\n", "").isEmpty()) { LOGGER.info("Found empty section: skipping."); continue; } LOGGER.debug("Section text: {}", subs); TextSpan ts = new TextSpan(tsb, tse); Section s = sf.fromTextSpan(ts, "post"); List<Integer> intList = new ArrayList<>(); intList.add(sectNumber); intList.add(subSect); s.setNumberList(intList); c.addToSectionList(s); subSect++; } } else if (nextEvent.isEndElement()) { EndElement ee = nextEvent.asEndElement(); currOff = ee.getLocation().getCharacterOffset(); QName name = ee.getName(); String localName = name.getLocalPart(); LOGGER.debug("Hit end element: {}", localName); if (localName.equalsIgnoreCase(POST_LOCAL_NAME)) { sectNumber++; subSect = 0; } } } return c; } catch (XMLStreamException | ConcreteException | StringIndexOutOfBoundsException x) { throw new IngestException(x); } finally { if (rdr != null) try { rdr.close(); } catch (XMLStreamException e) { // not likely. LOGGER.info("Error closing XMLReader.", e); } } } catch (IOException e) { throw new IngestException(e); } }
From source file:com.snaplogic.snaps.checkfree.CheckfreeExecute.java
@Override public void configure(final PropertyValues propertyValues) throws ConfigurationException { wsdlUrl = propertyValues.get(PROP_WSDL_URL); serviceName = propertyValues.get(PROP_SERVICE); // keystoreUrl = propertyValues.get(PROP_KEYSTORE_URL); // keystorePass = propertyValues.get(PROP_KEYSTORE_PASS); portName = propertyValues.get(PROP_ENDPOINT); operation = propertyValues.get(PROP_OPERATION); boolean shouldEncodeAttr = Boolean.TRUE.equals(propertyValues.get(PROP_ENCODE_ATTRIBUTE)); String defaultValueForSubstitution = propertyValues.get(PROP_DEFAULT_VALUE); useDefaultValueChecked = Boolean.TRUE.equals(propertyValues.get(PROP_USE_DEFAULT_VALUE)); if (useDefaultValueChecked) { if (defaultValueForSubstitution == null) { defaultValueForSubstitution = StringUtils.EMPTY; }//from w ww .j ava2 s . co m } Integer timeout = ((BigInteger) propertyValues.get(PROP_TIMEOUT)).intValue(); trustAllCerts = Boolean.TRUE.equals(propertyValues.get(TRUST_ALL_CERTS_PROP)); QName serviceQName = QName.valueOf(serviceName); QName portQName = QName.valueOf(portName); QName operationQName = QName.valueOf(operation); final List<Map<String, Object>> httpHeader = propertyValues.get(PropertiesTemplate.HTTP_HEADER_PROP); if (httpHeader != null) { for (Map<String, Object> item : httpHeader) { ExpressionProperty keyProp = propertyValues.getExpressionPropertyFor(item, PropertiesTemplate.HEADER_KEY_PROP); ExpressionProperty valueProp = propertyValues.getExpressionPropertyFor(item, PropertiesTemplate.HEADER_VALUE_PROP); httpHeaders.add(Pair.of(keyProp, valueProp)); } } // TODO - MK: this is a problem, the headers can be expressions, // here we set it up during configure so that the wsdl parsing can access them. That // won't work if the header is created dynamically using input variables. List<Header> headerList = soapUtils.buildHeaderList(httpHeaders); HttpContextProvider httpContextProvider = new SoapHttpContextProvider(headerList, null, trustAllCerts); clientBuilder = invocationService.createClientBuilderFor(wsdlUrl, serviceQName, portQName, operationQName, httpContextProvider); configureDispatch(clientBuilder.getDispatchClient(), clientBuilder.getSoapAction()); ((SOAPExecuteTemplateEvaluatorImpl) templateEvaluator) .withDefaultValue(useDefaultValueChecked ? defaultValueForSubstitution : XmlUtilsImpl.NO_DATA); if (shouldEncodeAttr) { ((SOAPExecuteTemplateEvaluatorImpl) templateEvaluator).attrEncoded(); } EditorSuggestionProvider editorSuggestionProvider = soapUtils.initializeSuggestionProvider(wsdlUrl, serviceQName, portQName, operationQName, shouldEncodeAttr, clientBuilder, httpContextProvider); editorProperty = propertyValues.getEditorProperty(soapEditorContentProvider, templateEvaluator, editorSuggestionProvider); bus = BusFactory.getDefaultBus(true); List<Interceptor<? extends Message>> inInterceptors = bus.getInInterceptors(); soapUtils.resetInterceptors(inInterceptors, ResponseInterceptor.class); inInterceptors.add(responseInterceptor); // account.withClientBuilder(clientBuilder) // .withTimeout(timeout) // .connect(); }
From source file:com.offbynull.portmapper.upnpigd.UpnpIgdController.java
private byte[] createRequestXml(String action, ImmutablePair<String, String>... params) { try {// w ww . j a v a 2 s . co 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:org.apache.servicemix.jbi.cluster.engine.ClusterEngine.java
/** * Process a JMS message/* w ww. jav a 2 s . com*/ * * @param requestor the item to use * @throws JMSException if an error occur */ protected void process(JmsRequestor requestor) throws JMSException { javax.jms.Message message = requestor.getMessage(); int type = message.getIntProperty(JBI_MESSAGE); switch (type) { case JBI_MESSAGE_DONE: { String corrId = message.getStringProperty(PROPERTY_CORR_ID); if (corrId == null) { throw new IllegalStateException("Incoming JMS message has no correlationId"); } Exchange exchange = exchanges.remove(corrId); if (exchange == null) { throw new IllegalStateException("Exchange not found for id " + corrId); } done(exchange); break; } case JBI_MESSAGE_ERROR: { String corrId = message.getStringProperty(PROPERTY_CORR_ID); if (corrId == null) { throw new IllegalStateException("Incoming JMS message has no correlationId"); } Exchange exchange = exchanges.remove(corrId); if (exchange == null) { throw new IllegalStateException("Exchange not found for id " + corrId); } fail(exchange, (Exception) ((ObjectMessage) message).getObject()); break; } case JBI_MESSAGE_IN: { String mep = message.getStringProperty(JBI_MEP); if (mep == null) { throw new IllegalStateException( "Exchange MEP not found for JMS message " + message.getJMSMessageID()); } Exchange exchange = getChannel().createExchange(Pattern.fromWsdlUri(mep)); exchange.setProperty(PROPERTY_ROLLBACK_ON_ERRORS + "." + name, message.getBooleanProperty(PROPERTY_ROLLBACK_ON_ERRORS)); if (message.propertyExists(JBI_INTERFACE)) { exchange.setProperty(MessageExchangeImpl.INTERFACE_NAME_PROP, QName.valueOf(message.getStringProperty(JBI_INTERFACE))); } if (message.propertyExists(JBI_OPERATION)) { exchange.setOperation(QName.valueOf(message.getStringProperty(JBI_OPERATION))); } if (message.propertyExists(JBI_SERVICE)) { exchange.setProperty(MessageExchangeImpl.SERVICE_NAME_PROP, QName.valueOf(message.getStringProperty(JBI_SERVICE))); } if (message.propertyExists(JBI_ENDPOINT)) { QName q = QName.valueOf(message.getStringProperty(JBI_ENDPOINT)); String e = q.getLocalPart(); q = QName.valueOf(q.getNamespaceURI()); ServiceEndpoint se = getEndpoint(q, e); // TODO: check that endpoint exists exchange.setProperty(MessageExchangeImpl.SERVICE_ENDPOINT_PROP, se); } // Re-process JBI addressing DeliveryChannelImpl.createTarget(getChannel().getNMR(), exchange); // TODO: read exchange properties Message msg = (Message) ((ObjectMessage) message).getObject(); exchange.setIn(msg); exchanges.put(exchange.getId(), exchange); if (pendingExchanges.incrementAndGet() >= maxPendingExchanges) { if (pauseConsumption.compareAndSet(false, true)) { invalidateSelector(); } } exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId()); requestor.suspend(exchange.getId()); if (requestor.getTransaction() != null) { exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, requestor.getTransaction()); } send(exchange); break; } case JBI_MESSAGE_OUT: { String corrId = message.getStringProperty(PROPERTY_CORR_ID); if (corrId == null) { throw new IllegalStateException("Incoming JMS message has no correlationId"); } Exchange exchange = exchanges.get(corrId); if (exchange == null) { throw new IllegalStateException("Exchange not found for id " + corrId); } Message msg = (Message) ((ObjectMessage) message).getObject(); exchange.setOut(msg); exchanges.put(exchange.getId(), exchange); exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId()); requestor.suspend(exchange.getId()); if (requestor.getTransaction() != null) { exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, requestor.getTransaction()); } send(exchange); break; } case JBI_MESSAGE_FAULT: { String corrId = message.getStringProperty(PROPERTY_CORR_ID); if (corrId == null) { throw new IllegalStateException("Incoming JMS message has no correlationId"); } Exchange exchange = exchanges.get(corrId); if (exchange == null) { throw new IllegalStateException("Exchange not found for id " + corrId); } Message msg = (Message) ((ObjectMessage) message).getObject(); exchange.setFault(msg); exchanges.put(exchange.getId(), exchange); exchange.setProperty(PROPERTY_CORR_ID + "." + name, exchange.getId()); requestor.suspend(exchange.getId()); if (requestor.getTransaction() != null) { exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, requestor.getTransaction()); } send(exchange); break; } default: { throw new IllegalStateException("Received unknown message type: " + type); } } }
From source file:org.eclipse.winery.repository.client.WineryRepositoryClient.java
/** * {@inheritDoc}/*from ww w . j ava 2s .com*/ */ @Override public QName getArtifactTypeQNameForExtension(String extension) { // we try all repositories until the first hit for (WebResource wr : this.repositoryResources) { WebResource artifactTypesResource = wr.path("artifacttypes").queryParam("extension", extension); ClientResponse response = artifactTypesResource.accept(MediaType.TEXT_PLAIN).get(ClientResponse.class); if (response.getClientResponseStatus() == ClientResponse.Status.OK) { QName res = QName.valueOf(response.getEntity(String.class)); return res; } } return null; }
From source file:org.apache.camel.component.cxf.util.CxfEndpointUtils.java
public static QName getQName(final String name) { QName qName = null;/*w w w . j a v a2s . c om*/ if (name != null) { try { qName = QName.valueOf(name); } catch (Exception ex) { ex.printStackTrace(); } } return qName; }
From source file:org.apache.cxf.ws.security.sts.provider.operation.IssueDelegateTest.java
@Test public void testIssueDelegateWithCert() throws CertificateException { IssueDelegate id = new IssueDelegate(); assertNotNull(id);//from w ww .j a v a 2s .com CertificateVerifierConfig certificateVerifierConfig = new CertificateVerifierConfig(); certificateVerifierConfig.setTrustCertAliases(Arrays.asList("myclientkey")); certificateVerifierConfig.setKeySignAlias(keySignAlias); certificateVerifierConfig.setKeySignPwd(keySignPwd); certificateVerifierConfig.setStorePath(storePath); certificateVerifierConfig.setStorePwd(storePwd); certificateVerifierConfig.setVerifySelfSignedCert(true); id.setCertificateVerifierConfig(certificateVerifierConfig); JAXBElement<byte[]> jX509Certificate = new JAXBElement<byte[]>(QName.valueOf("X509Certificate"), byte[].class, Base64.decodeBase64(CERT_DATA.getBytes())); X509DataType x509DataType = new X509DataType(); x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName().add(jX509Certificate); JAXBElement<X509DataType> jX509DataType = new JAXBElement<X509DataType>(QName.valueOf("X509Data"), X509DataType.class, x509DataType); KeyInfoType keyInfoType = new KeyInfoType(); keyInfoType.getContent().add(jX509DataType); JAXBElement<KeyInfoType> jKeyInfoType = new JAXBElement<KeyInfoType>(QName.valueOf("KeyInfo"), KeyInfoType.class, keyInfoType); UseKeyType useKeyType = new UseKeyType(); useKeyType.setAny(jKeyInfoType); JAXBElement<UseKeyType> jUseKeyType = new JAXBElement<UseKeyType>(QName.valueOf("UseKey"), UseKeyType.class, useKeyType); JAXBElement<String> tokenType = new JAXBElement<String>( new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512", "TokenType"), String.class, "urn:oasis:names:tc:SAML:1.0:assertion"); EasyMock.expect(requestMock.getAny()) .andStubReturn(Arrays.asList((Object) jUseKeyType, (Object) tokenType)); EasyMock.replay(requestMock); EasyMock.expect(passwordCallbackMock.resetUsername()).andReturn(null); EasyMock.replay(passwordCallbackMock); id.setPasswordCallback(passwordCallbackMock); TokenProvider tp1 = new Saml1TokenProvider(); TokenProvider tp2 = new Saml2TokenProvider(); id.setTokenProviders(Arrays.asList(tp1, tp2)); id.issue(requestMock); verify(requestMock); }
From source file:org.apache.cxf.ws.security.sts.provider.operation.IssueDelegateTest.java
@Test public void testIssueDelegateWithCertWithWrongStorePass() throws CertificateException { IssueDelegate id = new IssueDelegate(); CertificateVerifierConfig certificateVerifierConfig = new CertificateVerifierConfig(); certificateVerifierConfig.setTrustCertAliases(Arrays.asList("myclientkey")); certificateVerifierConfig.setKeySignAlias(keySignAlias); certificateVerifierConfig.setKeySignPwd(keySignPwd); certificateVerifierConfig.setStorePath(storePath); certificateVerifierConfig.setStorePwd("xxx"); id.setCertificateVerifierConfig(certificateVerifierConfig); JAXBElement<byte[]> jX509Certificate = new JAXBElement<byte[]>(QName.valueOf("X509Certificate"), byte[].class, Base64.decodeBase64(CERT_DATA.getBytes())); X509DataType x509DataType = new X509DataType(); x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName().add(jX509Certificate); JAXBElement<X509DataType> jX509DataType = new JAXBElement<X509DataType>(QName.valueOf("X509Data"), X509DataType.class, x509DataType); KeyInfoType keyInfoType = new KeyInfoType(); keyInfoType.getContent().add(jX509DataType); JAXBElement<KeyInfoType> jKeyInfoType = new JAXBElement<KeyInfoType>(QName.valueOf("KeyInfo"), KeyInfoType.class, keyInfoType); UseKeyType useKeyType = new UseKeyType(); useKeyType.setAny(jKeyInfoType);/*from w ww . j av a 2s.com*/ JAXBElement<UseKeyType> jUseKeyType = new JAXBElement<UseKeyType>(QName.valueOf("UseKey"), UseKeyType.class, useKeyType); JAXBElement<String> tokenType = new JAXBElement<String>( new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512", "TokenType"), String.class, "urn:oasis:names:tc:SAML:1.0:assertion"); EasyMock.expect(requestMock.getAny()) .andStubReturn(Arrays.asList((Object) jUseKeyType, (Object) tokenType)); EasyMock.replay(requestMock); EasyMock.expect(passwordCallbackMock.resetUsername()).andReturn(null); EasyMock.replay(passwordCallbackMock); id.setPasswordCallback(passwordCallbackMock); TokenProvider tp1 = new Saml1TokenProvider(); TokenProvider tp2 = new Saml2TokenProvider(); id.setTokenProviders(Arrays.asList(tp1, tp2)); try { id.issue(requestMock); fail("STSException should be thrown"); } catch (STSException e) { // expected } finally { verify(requestMock); } }
From source file:org.apache.cxf.ws.security.sts.provider.operation.IssueDelegateTest.java
@Test public void testIssueDelegateWithCertWithoutTokenProvidersAndTokenType() throws CertificateException { IssueDelegate id = new IssueDelegate(); CertificateVerifierConfig certificateVerifierConfig = new CertificateVerifierConfig(); certificateVerifierConfig.setTrustCertAliases(Arrays.asList("myclientkey")); certificateVerifierConfig.setKeySignAlias(keySignAlias); certificateVerifierConfig.setKeySignPwd(keySignPwd); certificateVerifierConfig.setStorePath(storePath); certificateVerifierConfig.setStorePwd(storePwd); id.setCertificateVerifierConfig(certificateVerifierConfig); JAXBElement<byte[]> jX509Certificate = new JAXBElement<byte[]>(QName.valueOf("X509Certificate"), byte[].class, Base64.decodeBase64(CERT_DATA.getBytes())); X509DataType x509DataType = new X509DataType(); x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName().add(jX509Certificate); JAXBElement<X509DataType> jX509DataType = new JAXBElement<X509DataType>(QName.valueOf("X509Data"), X509DataType.class, x509DataType); KeyInfoType keyInfoType = new KeyInfoType(); keyInfoType.getContent().add(jX509DataType); JAXBElement<KeyInfoType> jKeyInfoType = new JAXBElement<KeyInfoType>(QName.valueOf("KeyInfo"), KeyInfoType.class, keyInfoType); UseKeyType useKeyType = new UseKeyType(); useKeyType.setAny(jKeyInfoType);/*from w ww . j ava 2 s. co m*/ JAXBElement<UseKeyType> jUseKeyType = new JAXBElement<UseKeyType>(QName.valueOf("UseKey"), UseKeyType.class, useKeyType); EasyMock.expect(requestMock.getAny()).andStubReturn(Arrays.asList((Object) jUseKeyType)); EasyMock.replay(requestMock); EasyMock.expect(passwordCallbackMock.resetUsername()).andReturn(null); EasyMock.replay(passwordCallbackMock); id.setPasswordCallback(passwordCallbackMock); List<TokenProvider> tps = Collections.emptyList(); id.setTokenProviders(tps); try { id.issue(requestMock); fail("STSException should be thrown"); } catch (STSException e) { // expected } finally { verify(requestMock); } }
From source file:org.apache.cxf.ws.security.sts.provider.operation.IssueDelegateTest.java
@Test public void testIssueDelegateWithInvalidCert() throws CertificateException { IssueDelegate id = new IssueDelegate(); assertNotNull(id);// ww w . j a v a 2 s .c o m // CertificateFactory certificateFactory = // CertificateFactory.getInstance("X.509"); // X509Certificate x509Certificate = null; // try { // x509Certificate = // (X509Certificate)certificateFactory.generateCertificate(new // ByteArrayInputStream(Base64.decodeBase64(CERT_DATA.getBytes()))); // } catch (CertificateException e) { // e.printStackTrace(); // } // JAXBElement<X509Certificate> jX509Certificate = new // JAXBElement<X509Certificate>(QName.valueOf("X509Certificate"), // X509Certificate.class, x509Certificate); JAXBElement<byte[]> jX509Certificate = new JAXBElement<byte[]>(QName.valueOf("X509Certificate"), byte[].class, CERT_DATA.getBytes()); X509DataType x509DataType = new X509DataType(); x509DataType.getX509IssuerSerialOrX509SKIOrX509SubjectName().add(jX509Certificate); JAXBElement<X509DataType> jX509DataType = new JAXBElement<X509DataType>(QName.valueOf("X509Data"), X509DataType.class, x509DataType); KeyInfoType keyInfoType = new KeyInfoType(); keyInfoType.getContent().add(jX509DataType); JAXBElement<KeyInfoType> jKeyInfoType = new JAXBElement<KeyInfoType>(QName.valueOf("KeyInfo"), KeyInfoType.class, keyInfoType); UseKeyType useKeyType = new UseKeyType(); useKeyType.setAny(jKeyInfoType); JAXBElement<UseKeyType> jUseKeyType = new JAXBElement<UseKeyType>(QName.valueOf("UseKey"), UseKeyType.class, useKeyType); EasyMock.expect(requestMock.getAny()).andStubReturn(Arrays.asList((Object) jUseKeyType)); EasyMock.replay(requestMock); EasyMock.expect(passwordCallbackMock.resetUsername()).andReturn(null); EasyMock.replay(passwordCallbackMock); id.setPasswordCallback(passwordCallbackMock); TokenProvider tp1 = new Saml1TokenProvider(); TokenProvider tp2 = new Saml2TokenProvider(); id.setTokenProviders(Arrays.asList(tp1, tp2)); try { id.issue(requestMock); fail("STSException should be thrown"); } catch (STSException e) { } verify(requestMock); }