List of usage examples for javax.xml.bind JAXBElement JAXBElement
public JAXBElement(QName name, Class<T> declaredType, T value)
From source file:no.digipost.api.xml.Marshalling.java
@SuppressWarnings("unchecked") public static <T> JAXBElement<T> wrap(final QName qName, final T object) { return new JAXBElement<T>(qName, (Class<T>) object.getClass(), object); }
From source file:in.gov.uidai.auth.aua.httpclient.AuthClient.java
private String generateSignedAuthXML(Auth auth) throws JAXBException, Exception { StringWriter authXML = new StringWriter(); JAXBElement authElement = new JAXBElement( new QName("http://www.uidai.gov.in/authentication/uid-auth-request/1.0", "Auth"), Auth.class, auth); JAXBContext.newInstance(Auth.class).createMarshaller().marshal(authElement, authXML); boolean includeKeyInfo = true; if (System.getenv().get("SKIP_DIGITAL_SIGNATURE") != null) { return authXML.toString(); } else {//from w w w . ja va2s . c om return this.digitalSignator.signXML(authXML.toString(), includeKeyInfo); } }
From source file:com.trifork.batchcopy.client.BatchCopyClient.java
private String createRequestString(ReplicationRequestType request) throws JAXBException { StringWriter writer = new StringWriter(); Marshaller marshaller = jaxContext.createMarshaller(); marshaller.marshal(//from w w w.ja v a 2 s. c o m new JAXBElement<ReplicationRequestType>(serviceName, ReplicationRequestType.class, request), writer); return writer.toString(); }
From source file:org.javelin.sws.ext.bind.internal.model.ClassHierarchyTest.java
@Test public void handleXmlAccessTypeProperty() throws Exception { // f3, f4, p1, p2, p3, p4 - properties and annotated fields System.out.println("\nC3"); JAXBContext.newInstance(C3.class).createMarshaller() .marshal(new JAXBElement<C3>(new QName("", "r"), C3.class, new C3()), System.out); JAXBContext ctx = SweJaxbContextFactory.createContext(new Class[] { C3.class }, null); Map<Class<?>, TypedPattern<?>> patterns = (Map<Class<?>, TypedPattern<?>>) ReflectionTestUtils.getField(ctx, "patterns"); ComplexTypePattern<C3> pattern = (ComplexTypePattern<C3>) patterns.get(C3.class); Map<QName, PropertyMetadata<C3, ?>> elements = (Map<QName, PropertyMetadata<C3, ?>>) ReflectionTestUtils .getField(pattern, "elements"); assertThat(elements.size(), equalTo(6)); assertTrue(elements.containsKey(new QName("", "f3"))); assertTrue(elements.containsKey(new QName("", "f4"))); assertTrue(elements.containsKey(new QName("", "p1"))); assertTrue(elements.containsKey(new QName("", "p2"))); assertTrue(elements.containsKey(new QName("", "p3"))); assertTrue(elements.containsKey(new QName("", "p4"))); }
From source file:gov.nih.nci.integration.caaers.CaAERSParticipantServiceClientIntegrationTest.java
/** * Testcase for marshlling participant type * //from ww w. j ava2 s . c o m * @throws JAXBException - JAXBException * @throws DatatypeConfigurationException - DatatypeConfigurationException */ @Test public void marshalParticipantType() throws JAXBException, DatatypeConfigurationException { final ParticipantType pt = new ParticipantType(); pt.setFirstName("fn"); pt.setLastName("ln"); pt.setEthnicity(EthnicityType.NOT_HISPANIC_OR_LATINO); pt.setGender(GenderType.MALE); final DatatypeFactory df = DatatypeFactory.newInstance(); final GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); pt.setBirthDate(df.newXMLGregorianCalendar(gc)); pt.setRace(RaceType.WHITE); final OrganizationAssignedIdentifierType orgId = new OrganizationAssignedIdentifierType(); orgId.setType(ParticipantIdentifierType.MRN); orgId.setValue("123456"); orgId.setPrimaryIndicator(true); final OrganizationType ot = new OrganizationType(); ot.setName("UCSF)"); ot.setNciInstituteCode("UCSF"); orgId.setOrganization(ot); final ParticipantType.Identifiers ids = new ParticipantType.Identifiers(); ids.getOrganizationAssignedIdentifier().add(orgId); pt.setIdentifiers(ids); final AssignmentType at = new AssignmentType(); at.setStudySubjectIdentifier("456"); final StudySiteType sst = new StudySiteType(); final OrganizationType ot2 = new OrganizationType(); ot2.setName("UCSF)"); ot2.setNciInstituteCode("UCSF"); sst.setOrganization(ot2); final StudyType st = new StudyType(); final ReducedIdentifierType rit = new ReducedIdentifierType(); rit.setType(StudyIdentifierType.SITE_IDENTIFIER); rit.setValue("1.2.3.4.5"); final StudyType.Identifiers sids = new StudyType.Identifiers(); sids.setIdentifier(rit); st.setIdentifiers(sids); sst.setStudy(st); at.setStudySite(sst); final Assignments ass = new Assignments(); ass.getAssignment().add(at); pt.setAssignments(ass); final QName qname = new QName("http://webservice.caaers.cabig.nci.nih.gov/participant", "participant"); final JAXBElement<ParticipantType> ptJaxbEle = new JAXBElement<ParticipantType>(qname, ParticipantType.class, pt); final StringWriter sw = new StringWriter(); getMarshaller().marshal(ptJaxbEle, sw); Assert.assertNotNull(sw.toString()); JAXBElement<ParticipantType> jaxbEle = (JAXBElement<ParticipantType>) getUnMarshaller() .unmarshal(new StreamSource(new StringReader(sw.toString())), ParticipantType.class); Assert.assertNotNull(jaxbEle); Assert.assertNotNull(jaxbEle.getValue()); jaxbEle = (JAXBElement<ParticipantType>) getUnMarshaller() .unmarshal(new StreamSource(new StringReader(getPStr())), ParticipantType.class); Assert.assertNotNull(jaxbEle); final ParticipantType ptn = jaxbEle.getValue(); Assert.assertNotNull(ptn); }
From source file:org.gofleet.openLS.monav.MoNaVConnector.java
/** * Route plan using monav daemon. Only geometry. * /*from w ww . j a v a 2 s . c o m*/ * @param param * @return * @throws IOException * @throws ParseException * @throws JAXBException * @throws InterruptedException */ @Override public DetermineRouteResponseType routePlan(DetermineRouteRequestType param, int maxResponses) { DetermineRouteResponseType res = new DetermineRouteResponseType(); Double cost = null; String cmd = "/opt/monav/bin/daemon-test /var/www/monav/routing_yes/"; RouteGeometryType routeGeometry = new RouteGeometryType(); WayPointListType wayPointList = param.getRoutePlan().getWayPointList(); Point point = GeoUtil.getPoint(wayPointList.getStartPoint(), null); cmd += " " + point.getY() + " " + point.getX(); for (WayPointType wayPoint : wayPointList.getViaPoint()) { point = GeoUtil.getPoint(wayPoint, null); cmd += " " + point.getY() + " " + point.getX(); } point = GeoUtil.getPoint(wayPointList.getEndPoint(), null); cmd += " " + point.getY() + " " + point.getX(); LOG.debug(cmd); Process p; try { p = Runtime.getRuntime().exec(cmd); } catch (IOException ex) { throw new RuntimeException(ex); } BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream())); LineStringType lst = new LineStringType(); List<JAXBElement<?>> list = new LinkedList<JAXBElement<?>>(); String l; try { l = br.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } while (l != null) { LOG.info(l); try { if (cost == null && l.indexOf("distance:") >= 0) cost = -1d;// TODO Double x = Double.parseDouble(l.substring(0, l.indexOf(" "))); Double y = Double.parseDouble(l.substring(1 + l.indexOf(" "))); DirectPositionListType e = new DirectPositionListType(); e.getValue().add(y); e.getValue().add(x); JAXBElement<DirectPositionListType> elem = new JAXBElement<DirectPositionListType>( new QName("http://www.opengis.net/gml", "pos", "gml"), DirectPositionListType.class, e); list.add(elem); } catch (Throwable t) { // LOG.error(t); } try { l = br.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } } try { lst.setPosOrPointPropertyOrPointRep(list); routeGeometry.setLineString(lst); res.setRouteGeometry(routeGeometry); res.setRouteHandle(new RouteHandleType()); res.setRouteInstructionsList(new RouteInstructionsListType()); res.setRouteMap(new LinkedList<RouteMapType>()); res.setRouteSummary(new RouteSummaryType()); } catch (Throwable t) { LOG.error("Error generating route response: " + t, t); } return res; }
From source file:org.apache.servicemix.camel.nmr.ws.addressing.WSAddressingTest.java
@Override protected void setUp() throws Exception { applicationContext = createApplicationContext(); super.setUp(); startService();/* w w w . j a va 2s . co m*/ if (staticBus == null) { SpringBusFactory bf = new SpringBusFactory(); staticBus = bf.createBus(getConfigFileName()); } messageIDs.clear(); mapVerifier = new MAPVerifier(); headerVerifier = new HeaderVerifier(); Interceptor[] interceptors = { mapVerifier, headerVerifier }; addInterceptors(staticBus.getInInterceptors(), interceptors); addInterceptors(staticBus.getOutInterceptors(), interceptors); addInterceptors(staticBus.getOutFaultInterceptors(), interceptors); addInterceptors(staticBus.getInFaultInterceptors(), interceptors); EndpointReferenceType target = EndpointReferenceUtils.getEndpointReference(ADDRESS); ReferenceParametersType params = ContextUtils.WSA_OBJECT_FACTORY.createReferenceParametersType(); JAXBElement<String> param = new JAXBElement<String>(CUSTOMER_NAME, String.class, CUSTOMER_KEY); params.getAny().add(param); target.setReferenceParameters(params); ServiceImpl serviceImpl = ServiceDelegateAccessor.get(new SOAPService(WSDL_LOC, SERVICE_NAME)); greeter = serviceImpl.getPort(target, Greeter.class); mapVerifier.verificationCache = this; headerVerifier.verificationCache = this; }
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 ww. jav a 2 s . c om*/ }
From source file:com.mymita.vaadlets.JAXBUtils.java
private static final void marshal(final Writer aWriter, final Vaadlets vaadlets, final Resource theSchemaResource) { try {// w w w.ja v a 2 s. com final JAXBContext jc = JAXBContext.newInstance(CONTEXTPATH); final Marshaller marshaller = jc.createMarshaller(); if (theSchemaResource != null) { final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setResourceResolver(new ClasspathResourceResolver()); final Schema schema = schemaFactory.newSchema(new StreamSource(theSchemaResource.getInputStream())); marshaller.setSchema(schema); } marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper() { @Override public String getPreferredPrefix(final String namespaceUri, final String suggestion, final boolean requirePrefix) { final String subpackage = namespaceUri.replaceFirst("http://www.mymita.com/vaadlets/", ""); if (subpackage.equals("1.0.0")) { return ""; } return Iterables.getFirst(newArrayList(Splitter.on("/").split(subpackage).iterator()), ""); } }); marshaller.marshal( new JAXBElement<Vaadlets>(new QName("http://www.mymita.com/vaadlets/1.0.0", "vaadlets", ""), Vaadlets.class, vaadlets), aWriter); } catch (final JAXBException | SAXException | FactoryConfigurationError | IOException e) { throw new RuntimeException("Can't marschal", e); } }
From source file:hermes.impl.DefaultXMLHelper.java
public void saveContent(MessageSet messages, Writer writer) 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), writer); writer.flush();/*w ww .j a v a 2 s . c o m*/ }