Ejemplo n.º 1
1
 /** Default constructor initializing jaxb marshaller. */
 public Maven(String workingDirectory) {
   this.workingDirectory = workingDirectory;
   marshaller.setClassesToBeBound(Project.class);
   try {
     marshaller.afterPropertiesSet();
   } catch (Exception e) {
     throw new RuntimeException("Failed to setup marshaller", e);
   }
 }
Ejemplo n.º 2
1
  /**
   * Serialize Maven POM object tree.
   *
   * @param outputStream
   */
  public void serialize(Project project, OutputStream outputStream) {
    StreamResult stream = new StreamResult(outputStream);

    Map<String, Object> marshallerProperties = new HashMap<String, Object>();
    marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshallerProperties.put(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "");

    marshaller.setMarshallerProperties(marshallerProperties);
    marshaller.marshal(project, stream);
  }
 @Bean
 public Jaxb2Marshaller getJaxb2Marshaller() {
   Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
   jaxb2Marshaller.setClassesToBeBound(ServiceConfig.class);
   jaxb2Marshaller.setClassesToBeBound(ServiceConfigDefinition.class);
   return jaxb2Marshaller;
 }
 public void init() {
   marshaller = new Jaxb2Marshaller();
   marshaller.setClassesToBeBound(Protein.class);
   Map<String, Boolean> properties = new HashMap<String, Boolean>();
   properties.put("jaxb.formatted.output", true);
   marshaller.setMarshallerProperties(properties);
 }
Ejemplo n.º 5
0
 @Override
 protected Lfm unmarshalllData(String xmlData) {
   try {
     oxmLastFMTrackSearch.setSchema(new ClassPathResource("xsd/LastFMTrackSearch.xsd"));
     Lfm returnXMl =
         (Lfm) oxmLastFMTrackSearch.unmarshal(new StreamSource(new StringReader(xmlData)));
     return returnXMl;
   } catch (XmlMappingException e) {
     LOGGER.warn("Error while unmarshalling normal data", e);
     return null;
   }
 }
Ejemplo n.º 6
0
  /**
   * Method for creating the Marshaller for device management.
   *
   * @return Jaxb2Marshaller
   */
  @Bean
  public Jaxb2Marshaller deviceManagementMarshaller() {
    LOGGER.debug("Creating Device Management Marshaller Bean");

    final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

    marshaller.setContextPath(
        this.environment.getRequiredProperty(
            PROPERTY_NAME_MARSHALLER_CONTEXT_PATH_DEVICE_MANAGEMENT));

    return marshaller;
  }
  /* Shared JAXB marshaller/unmarshaller instance
   * @return The marshaller/unmarshaller instance
   */
  @Bean(name = "wsMarshaller")
  public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setMtomEnabled(true);
    marshaller.setClassesToBeBound(String.class, HelloRequest.class, HelloResponse.class);
    Map props = new HashMap<String, Object>();
    props.put("jaxb.formatted.output", true);
    marshaller.setMarshallerProperties(props);
    marshaller.setCheckForXmlRootElement(true);

    return marshaller;
  }
Ejemplo n.º 8
0
  @Test
  public void JaxbGet03Test() {
    Jaxb2Marshaller jaxb2Marshaller = (Jaxb2Marshaller) context.getBean("getJaxb2Marshaller");

    EvcomResponseHead erh = new EvcomResponseHead(324, 234, "cid string", 234, "rms string", 2989);

    GET03 erb = new GET03();

    EvcomResGet03 ergprm03 = new EvcomResGet03(erh, erb);

    jaxb2Marshaller.setClassesToBeBound(EvcomResGet03.class, EvcomResponseHead.class, GET03.class);

    StreamResult result = new StreamResult(System.out);
    jaxb2Marshaller.marshal(ergprm03, result);
  }
Ejemplo n.º 9
0
 /**
  * Loads project from normal POM location in working directory.
  *
  * @return
  */
 public Project fromPom() {
   try {
     return (Project) marshaller.unmarshal(new StreamSource(getPomFile().getInputStream()));
   } catch (IOException e) {
     throw new RuntimeException("Failed to read Maven pom.xml", e);
   }
 }
  @Test
  public void testProcessErrorResponse() throws Exception {
    final HttpClientUtilResponse response = new HttpClientUtilResponse();
    final String mockError =
        "<error>\n"
            + "<errorCode>905</errorCode>\n"
            + "<message>contactZipCode parameter should be 5 numeric characters</message>\n"
            + "</error>";
    response.setResponseByteArray(mockError.getBytes("UTF-8"));

    final ServiceResponseException mockServiceResponseException = new ServiceResponseException();
    mockServiceResponseException.setErrorCode("905");
    mockServiceResponseException.setMessage(
        "contactZipCode parameter should be 5 numeric characters");

    PowerMockito.when(marshaller.unmarshal(Mockito.any(Source.class)))
        .thenReturn(mockServiceResponseException);

    final FormHandlerResponseInterface result =
        customerCareService.processErrorResponse(null, response, true);

    assertNotNull(result);
    assertEquals(new Integer(905), ((Errors) result).getErrors().get(0).getCode());
    assertEquals(
        "contactZipCode parameter should be 5 numeric characters",
        ((Errors) result).getErrors().get(0).getMessage());
  }
Ejemplo n.º 11
0
  @Test
  public void JaxbPos14Test() {

    Jaxb2Marshaller jaxb2Marshaller = (Jaxb2Marshaller) context.getBean("getJaxb2Marshaller");

    EvcomRequestHead erh = new EvcomRequestHead(32423423, 234, "cid string", 234, 2989);

    StringReader reader =
        new StringReader(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<evcom>\n"
                + "<hd>\n"
                + " <stm v=\"20151126105322\"/>\n"
                + " <sid v=\"2\"/>\n"
                + " <cid v=\"01\"/>\n"
                + " <sts v=\"111111\"/>\n"
                + " <tid v=\"2323\"/>\n"
                + "</hd>\n"
                + "<bd>\n"
                + "  <pg>\n"
                + "    <pg_knd v=\"완속 1\"/>\n"
                + "    <ver v=\"fw ver 1.2\"/>\n"
                + "  </pg>\n"
                + "  <pg>\n"
                + "    <pg_knd v=\"급속 2\"/>\n"
                + "    <ver v=\"fw ver 0.8\"/>\n"
                + "  </pg>\n"
                + "  <pg>\n"
                + "    <pg_knd v=\"완속 2\"/>\n"
                + "    <ver v=\"fw ver 1.5\"/>\n"
                + "  </pg>\n"
                + "  <pg>\n"
                + "    <pg_knd v=\"급속 1\"/>\n"
                + "    <ver v=\"fw ver 0.8.1\"/>\n"
                + "  </pg>\n"
                + "</bd>\n"
                + "</evcom>");
    EvcomReqPos14 pos14 = (EvcomReqPos14) jaxb2Marshaller.unmarshal(new StreamSource(reader));

    StreamResult result = new StreamResult(System.out);
    jaxb2Marshaller.marshal(pos14, result);
  }
Ejemplo n.º 12
0
  @SuppressWarnings("rawtypes")
  private static RestTemplate getTemplate() {

    RestTemplate restTemplate = new RestTemplate();

    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    Class[] vetor = {Resultado.class};
    marshaller.setClassesToBeBound(vetor);
    // conversor de objetos
    MarshallingHttpMessageConverter marshallingHttpConverter =
        new MarshallingHttpMessageConverter(marshaller);
    marshallingHttpConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_XML));
    restTemplate.getMessageConverters().add(marshallingHttpConverter);

    // conversor de string
    StringHttpMessageConverter sCOnverter = new StringHttpMessageConverter();
    sCOnverter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
    restTemplate.getMessageConverters().add(sCOnverter);

    return restTemplate;
  }
Ejemplo n.º 13
0
  private byte[] createMasseutsendelse(MessageBatch messageBatch) {
    XmlMasseutsendelse xml =
        MasseutsendelseBuilder.newMasseutsendelse()
            .withAvsender(config.getSenderId())
            .withJobbId(messageBatch.digipostJobbId)
            .withRecipients(messageBatch.getMessages())
            .build();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshal(xml, new StreamResult(baos));
    return baos.toByteArray();
  }
  private static WebServiceTemplate createWebServiceTemplate(URI defaultURI) throws SOAPException {

    SaajSoapMessageFactory messageFactory =
        new SaajSoapMessageFactory(MessageFactory.newInstance());
    messageFactory.setSoapVersion(SOAP_11);

    HttpComponentsMessageSender httpSender = new HttpComponentsMessageSender();
    httpSender.setConnectionTimeout(1200000);
    httpSender.setReadTimeout(1200000);

    Jaxb2Marshaller serviceMarshaller = new Jaxb2Marshaller();
    serviceMarshaller.setContextPath("org.apromore.model");

    WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory);
    webServiceTemplate.setMarshaller(serviceMarshaller);
    webServiceTemplate.setUnmarshaller(serviceMarshaller);
    webServiceTemplate.setMessageSender(httpSender);
    webServiceTemplate.setDefaultUri(defaultURI.toString());

    return webServiceTemplate;
  }
Ejemplo n.º 15
0
  @Test
  public void JaxbGet01Test() {
    Jaxb2Marshaller jaxb2Marshaller = (Jaxb2Marshaller) context.getBean("getJaxb2Marshaller");

    EvcomResponseHead erh = new EvcomResponseHead(324, 234, "cid string", 234, "rms string", 2989);

    GET01 erb = new GET01(123423, 2343, "ccfg");
    List<PRM> leip = new ArrayList<>();
    leip.add(new EIP("eip value"));
    leip.add(new EPT("ept value"));
    leip.add(new VIP("vip value"));
    leip.add(new VPT("vpp value"));
    erb.setPrm(leip);

    EvcomResGet01 ergprm = new EvcomResGet01(erh, erb);

    jaxb2Marshaller.setClassesToBeBound(EvcomResGet01.class, EvcomResponseHead.class, GET01.class);

    StreamResult result = new StreamResult(System.out);
    jaxb2Marshaller.marshal(ergprm, result);
  }
  private WebServiceTemplate initializeConnection() {
    // Create message factory
    SOAPMessageFactory1_1Impl impl = new SOAPMessageFactory1_1Impl();
    SaajSoapMessageFactory msgFactory = new SaajSoapMessageFactory(impl);

    msgFactory.setSoapVersion(SoapVersion.SOAP_11);

    // Create an instance of jaxbmarshaller
    HashMap<String, Object> properties = new HashMap<String, Object>();
    properties.put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, false);
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

    marshaller.setContextPaths("com.andrewcraft.schema");
    marshaller.setMarshallerProperties(properties);

    CommonsHttpMessageSender msgSender = new CommonsHttpMessageSender();

    WebServiceTemplate wsTemplate = new WebServiceTemplate(msgFactory);
    wsTemplate.setMarshaller(marshaller);
    wsTemplate.setUnmarshaller(marshaller);
    wsTemplate.setMessageSender(msgSender);
    wsTemplate.setDefaultUri(session.getServerAddress());
    return wsTemplate;
  }
  private String newXML(IdentifiedObject resource)
      throws DatatypeConfigurationException, FeedException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    EntryType entry = new EntryType();
    entry.getLinks().add(new LinkType(LinkType.SELF, "self"));
    entry.setTitle("entry");
    entry.setId("id");
    entry.setPublished(new DateTimeType());
    entry.setUpdated(new DateTimeType());
    ContentType content = new ContentType();
    content.setResources(Lists.<IdentifiedObject>newArrayList(resource));
    entry.setContent(content);

    fragmentMarshaller.marshal(entry, new StreamResult(os));

    return os.toString();
  }
Ejemplo n.º 18
0
  @Test
  public void marshallTest()
      throws TransformerConfigurationException, TransformerException,
          TransformerFactoryConfigurationError {
    Job job = new Job();
    job.setSessionId(1);
    job.setName("Test");
    job.setDescription("Test Desc");

    List<Integer> start = new ArrayList<Integer>();
    start.add(1);
    start.add(2);

    job.setFirst(start);

    List<Integer> end = new ArrayList<Integer>();
    end.add(1);
    end.add(2);

    job.setLast(end);

    List<JobTask> tasks = new ArrayList<JobTask>();
    tasks.add(new JobTask(1, 1, "source/file/path", "result/file/path"));
    tasks.add(new JobTask(2, 1, "source/file/path", "result/file/path"));
    tasks.add(new JobTask(3, 1, "source/file/path", "result/file/path"));

    job.setTasks(tasks);

    DOMResult result = new DOMResult();
    marshaller.marshal(job, result);

    StringWriter writer = new StringWriter();
    TransformerFactory.newInstance()
        .newTransformer()
        .transform(new DOMSource(result.getNode()), new StreamResult(writer));

    String textResult = writer.toString();

    assertNotNull(textResult);
  }
  @Test
  public void testProcessCustomerCareServiceResponse() throws Exception {
    final HttpClientUtilResponse mockResponse = new HttpClientUtilResponse();
    final String sample =
        "<customer-care-case>\n"
            + "<vin>WAURFAFR7AA078877</vin>\n"
            + "<case-number>71300077</case-number>\n"
            + "</customer-care-case>\n";
    mockResponse.setResponseByteArray(sample.getBytes("UTF-8"));

    final CustomerCareServiceResponseVO mockMarshallResponse = new CustomerCareServiceResponseVO();
    mockMarshallResponse.setVin("WAURFAFR7AA078877");
    mockMarshallResponse.setCaseNumber("71300077");

    PowerMockito.when(marshaller.unmarshal(Mockito.any(Source.class)))
        .thenReturn(mockMarshallResponse);

    final FormHandlerResponseInterface result =
        customerCareService.processCustomerCareServiceResponse(null, mockResponse);

    assertNotNull(result);
    assertEquals("WAURFAFR7AA078877", ((Formhandler) result).getVin());
    assertEquals("71300077", ((Formhandler) result).getCaseNumber());
  }
Ejemplo n.º 20
0
 @Bean
 public Unmarshaller unmarshaller() {
   Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
   marshaller.setContextPath("springbook.user.sqlservice.jaxb");
   return marshaller;
 }
Ejemplo n.º 21
0
 @Bean
 public Jaxb2Marshaller marshaller() {
   Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
   marshaller.setContextPath("aBergler.eBraendli.wsdl");
   return marshaller;
 }
Ejemplo n.º 22
0
 @Test
 public void unmarshallTest() throws XmlMappingException, DocumentException {
   Object obj =
       marshaller.unmarshal(new DocumentSource(DocumentHelper.parseText(Themes.scenerioTemplate)));
   assertNotNull(obj);
 }
Ejemplo n.º 23
0
 @Bean
 Jaxb2Marshaller jaxb2Marshaller() {
   Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
   jaxb2Marshaller.setContextPath("no.lyse.ikt.ms.intelecom.schemas");
   return jaxb2Marshaller;
 }
 @Bean
 public Jaxb2Marshaller marshaller() {
   Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
   marshaller.setContextPath("net.lkrnac.book.eiws.chapter03.ws.boot.model");
   return marshaller;
 }