use of javax.xml.bind.JAXBElement in project ddf by codice.
the class TestWfs10JTStoGML200Converter method extractLineStringMemberCoordinates.
private String extractLineStringMemberCoordinates(JAXBElement element1) throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
assertThat(Wfs10Constants.LINESTRING_MEMBER.getLocalPart().equals(element1.getName().getLocalPart()), is(Boolean.TRUE));
LineStringMemberType lsMemberType1 = (LineStringMemberType) element1.getValue();
JAXBElement geometry1 = lsMemberType1.getGeometry();
LineStringType lineStringType = (LineStringType) geometry1.getValue();
return lineStringType.getCoordinates().getValue().replaceAll("\n", "").trim();
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class TestWfs10JTStoGML200Converter method testPointTypeToJAXB.
@Test
public void testPointTypeToJAXB() throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
String pointGML = Wfs10JTStoGML200Converter.convertGeometryToGML(getGeometryFromWkt(POINT));
PointType pointType = (PointType) Wfs10JTStoGML200Converter.convertGMLToGeometryType(pointGML, Wfs10Constants.POINT);
JAXBElement<PointType> pointTypeJAXBElement = (JAXBElement<PointType>) Wfs10JTStoGML200Converter.convertGeometryTypeToJAXB(pointType);
JAXB.marshal(pointTypeJAXBElement, writer);
String xml = writer.toString();
Diff diff = XMLUnit.compareXML(xml, POINT_GML);
assertTrue(XMLUNIT_SIMILAR, diff.similar());
assertThat(diff.similar(), is(Boolean.TRUE));
assertThat(diff.identical(), is(Boolean.FALSE));
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class WssBasicAuthenticationHandler method getBaseAuthenticationToken.
protected BaseAuthenticationToken getBaseAuthenticationToken(String realm, String username, String password) {
if (null == parser) {
throw new IllegalStateException("XMLParser must be configured.");
}
UsernameTokenType usernameTokenType = new UsernameTokenType();
AttributedString user = new AttributedString();
user.setValue(username);
usernameTokenType.setUsername(user);
String usernameToken = null;
// Add a password
PasswordString pass = new PasswordString();
pass.setValue(password);
pass.setType(WSConstants.PASSWORD_TEXT);
JAXBElement<PasswordString> passwordType = new JAXBElement<>(QNameConstants.PASSWORD, PasswordString.class, pass);
usernameTokenType.getAny().add(passwordType);
// Marshall the received JAXB object into a DOM Element
List<String> ctxPath = new ArrayList<>(2);
ctxPath.add(ObjectFactory.class.getPackage().getName());
ctxPath.add(org.apache.cxf.ws.security.sts.provider.model.wstrust14.ObjectFactory.class.getPackage().getName());
ParserConfigurator configurator = parser.configureParser(ctxPath, WssBasicAuthenticationHandler.class.getClassLoader());
ByteArrayOutputStream os = new ByteArrayOutputStream();
JAXBElement<UsernameTokenType> tokenType = new JAXBElement<>(QNameConstants.USERNAME_TOKEN, UsernameTokenType.class, usernameTokenType);
try {
parser.marshal(configurator, tokenType, os);
usernameToken = os.toString("UTF-8");
} catch (ParserException | UnsupportedEncodingException ex) {
LOGGER.info("Unable to parse username token.", ex);
}
BaseAuthenticationToken baseAuthenticationToken = new BaseAuthenticationToken(null, "", usernameToken);
baseAuthenticationToken.setUseWssSts(true);
return baseAuthenticationToken;
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class BSTAuthenticationToken method getBinarySecurityToken.
/**
* Creates a binary security token based on the provided credential.
*/
private synchronized String getBinarySecurityToken(String credential) {
Writer writer = new StringWriter();
Marshaller marshaller = null;
BinarySecurityTokenType binarySecurityTokenType = createBinarySecurityTokenType(credential);
JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement = new JAXBElement<BinarySecurityTokenType>(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "BinarySecurityToken"), BinarySecurityTokenType.class, binarySecurityTokenType);
if (BINARY_TOKEN_CONTEXT != null) {
try {
marshaller = BINARY_TOKEN_CONTEXT.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
} catch (JAXBException e) {
LOGGER.debug("Exception while creating UsernameToken marshaller.", e);
}
if (marshaller != null) {
try {
marshaller.marshal(binarySecurityTokenElement, writer);
} catch (JAXBException e) {
LOGGER.debug("Exception while writing username token.", e);
}
}
}
String binarySecurityToken = writer.toString();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Binary Security Token: {}", binarySecurityToken);
}
return binarySecurityToken;
}
use of javax.xml.bind.JAXBElement in project ddf by codice.
the class TestGetRecordsResponseConverter method getRecords.
private void getRecords(final int maxRecords, final int startPosition, final int totalResults, final int expectedNext, final int expectedReturn) throws JAXBException, UnsupportedEncodingException {
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType query = new GetRecordsType();
query.setMaxRecords(BigInteger.valueOf(maxRecords));
query.setStartPosition(BigInteger.valueOf(startPosition));
CswRecordCollection collection = createCswRecordCollection(query, totalResults);
collection.setStartPosition(startPosition);
String xml = xstream.toXML(collection);
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
assertThat(response.getSearchResults().getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(response.getSearchResults().getNumberOfRecordsReturned().intValue(), is(expectedReturn));
assertThat(response.getSearchResults().getAbstractRecord().size(), is(expectedReturn));
assertThat(response.getSearchResults().getNextRecord().intValue(), is(expectedNext));
}
Aggregations