Пример #1
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);
  }
 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);
 }
  /* 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;
  }
  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;
  }