本文整理汇总了Java中org.springframework.oxm.jaxb.Jaxb2Marshaller.setClassesToBeBound方法的典型用法代码示例。如果您正苦于以下问题:Java Jaxb2Marshaller.setClassesToBeBound方法的具体用法?Java Jaxb2Marshaller.setClassesToBeBound怎么用?Java Jaxb2Marshaller.setClassesToBeBound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.oxm.jaxb.Jaxb2Marshaller
的用法示例。
在下文中一共展示了Jaxb2Marshaller.setClassesToBeBound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMarshaller
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Bean
public Jaxb2Marshaller getMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClassesToBeBound(Kml.class);
final Map<String,Object> map = new HashMap<>();
map.put("jaxb.formatted.output", true);
jaxb2Marshaller.setMarshallerProperties(map);
return jaxb2Marshaller;
}
示例2: jaxb2Marshaller
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Bean
public Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(
com.marklogic.spring.batch.core.AdaptedJobExecution.class,
com.marklogic.spring.batch.core.AdaptedJobInstance.class,
com.marklogic.spring.batch.core.AdaptedJobParameters.class,
com.marklogic.spring.batch.core.AdaptedStepExecution.class,
com.marklogic.spring.batch.core.AdaptedExecutionContext.class);
marshaller.setAdapters(
new ExecutionContextAdapter(),
new JobExecutionAdapter(),
new JobInstanceAdapter(),
new JobParametersAdapter(),
new StepExecutionAdapter());
//marshaller.setMarshallerProperties(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
return marshaller;
}
示例3: xmlWriter
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Bean("writer2")
public ItemWriter<Permanent> xmlWriter() {
StaxEventItemWriter<Permanent> xmlFileWriter = new StaxEventItemWriter<>();
String exportFilePath = "./src/main/resources/emps.xml";
xmlFileWriter.setResource(new FileSystemResource(exportFilePath));
xmlFileWriter.setRootTagName("employees");
Jaxb2Marshaller empMarshaller = new Jaxb2Marshaller();
empMarshaller.setClassesToBeBound(Permanent.class);
xmlFileWriter.setMarshaller(empMarshaller);
System.out.println("marshalling");;
return xmlFileWriter;
}
示例4: setMarshallerUnmarshallerClass
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
/**
* 设置需要进行Marshaller或Unmarshaller的Java类
* @param clazzs 用于进行Marshaller或Unmarshaller操作的Java类数组
*/
public void setMarshallerUnmarshallerClass(Class<?>[] clazzs){
Jaxb2Marshaller marshaller=new Jaxb2Marshaller();
marshaller.setClassesToBeBound(clazzs);
this.setMarshaller(marshaller);
this.setUnmarshaller(marshaller);
}
示例5: createMarshaller
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Before
public void createMarshaller() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(MyBean.class);
marshaller.afterPropertiesSet();
this.converter = new MarshallingMessageConverter(marshaller);
}
示例6: responseBodyArgMismatch
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Test
public void responseBodyArgMismatch() throws ServletException, IOException {
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(RequestBodyArgMismatchController.class));
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(A.class, B.class);
try {
marshaller.afterPropertiesSet();
}
catch (Exception ex) {
throw new BeanCreationException(ex.getMessage(), ex);
}
MarshallingHttpMessageConverter messageConverter = new MarshallingHttpMessageConverter(marshaller);
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
adapterDef.getPropertyValues().add("messageConverters", messageConverter);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
String requestBody = "<b/>";
request.setContent(requestBody.getBytes("UTF-8"));
request.addHeader("Content-Type", "application/xml; charset=utf-8");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals(400, response.getStatus());
}
示例7: testXmlOnly
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Test
public void testXmlOnly() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Person.class);
standaloneSetup(new PersonController()).setSingleView(new MarshallingView(marshaller)).build()
.perform(get("/person/Corea"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_XML))
.andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
示例8: testContentNegotiation
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Test
public void testContentNegotiation() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Person.class);
List<View> viewList = new ArrayList<View>();
viewList.add(new MappingJackson2JsonView());
viewList.add(new MarshallingView(marshaller));
ContentNegotiationManager manager = new ContentNegotiationManager(
new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(MediaType.TEXT_HTML));
ContentNegotiatingViewResolver cnViewResolver = new ContentNegotiatingViewResolver();
cnViewResolver.setDefaultViews(viewList);
cnViewResolver.setContentNegotiationManager(manager);
cnViewResolver.afterPropertiesSet();
MockMvc mockMvc =
standaloneSetup(new PersonController())
.setViewResolvers(cnViewResolver, new InternalResourceViewResolver())
.build();
mockMvc.perform(get("/person/Corea"))
.andExpect(status().isOk())
.andExpect(model().size(1))
.andExpect(model().attributeExists("person"))
.andExpect(forwardedUrl("person/show"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.person.name").value("Corea"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_XML))
.andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
示例9: unmarshallXmlSuccessTest
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
/**
* Unmarshall xml success test.
*
* @throws Exception
* the exception
*/
@Test
public void unmarshallXmlSuccessTest() throws Exception {
final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClassesToBeBound(SimpleXml.class);
final SimpleXml simpleXml = (SimpleXml) xmlAgent.unmarshallXml(jaxb2Marshaller, XmlAgentImplITest.class.getResource("/simplexml.xml").toString());
assertEquals(new SimpleXml("abc123"), simpleXml);
}
示例10: unmarshallXmlMissingNamespaceSuccessTest
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
/**
* Unmarshall xml missing namespace success test.
*
* @throws Exception
* the exception
*/
@Test
public void unmarshallXmlMissingNamespaceSuccessTest() throws Exception {
final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClassesToBeBound(SimpleXml.class);
final SimpleXml simpleXml = (SimpleXml) xmlAgent.unmarshallXml(jaxb2Marshaller, XmlAgentImplITest.class.getResource("/simplexml-missing-namespace.xml").toString(),"com.hack23.cia.service.external.common.impl.test",null,null);
assertEquals(new SimpleXml("abc123"), simpleXml);
}
示例11: unmarshallXmlMissingNamespaceAndReplaceSuccessTest
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
/**
* Unmarshall xml missing namespace and replace success test.
*
* @throws Exception
* the exception
*/
@Test
public void unmarshallXmlMissingNamespaceAndReplaceSuccessTest() throws Exception {
final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClassesToBeBound(SimpleXml.class);
final SimpleXml simpleXml = (SimpleXml) xmlAgent.unmarshallXml(jaxb2Marshaller, XmlAgentImplITest.class.getResource("/simplexml-missing-namespace.xml").toString(),"com.hack23.cia.service.external.common.impl.test","abc123","ABC123");
assertEquals(new SimpleXml("ABC123"), simpleXml);
}
示例12: taxiiStatusMarshaller
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Bean
public Jaxb2Marshaller taxiiStatusMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClassesToBeBound(TaxiiStatus.class);
jaxb2Marshaller.setMarshallerProperties(ImmutableMap.of(
javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true));
return jaxb2Marshaller;
}
示例13: testCustomizeFaultObjectExceptionSoapFault
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
/**
* Test method for
* {@link py.una.pol.karaku.services.server.EndpointExceptionResolver#customizeFault(java.lang.Object, java.lang.Exception, org.springframework.ws.soap.SoapFault)}
* .
*
* @throws SecurityException
* @throws NoSuchMethodException
*/
@Test
public void testCustomizeFaultObjectExceptionSoapFault() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(HTTPExceptionDTO.class);
EndpointExceptionResolver eer = new EndpointExceptionResolver();
eer.setMarshaller(marshaller);
Method m = Endpoint.class.getMethod("call", String.class);
MethodEndpoint me = new MethodEndpoint(new Endpoint(), m);
Fault f = new Fault();
eer.customizeFault(me, new HTTPException("1", "code"), f);
StringResult result = f.getFaultDetail().getResult();
// @formatter:off
String expectedResult = ""
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<ns2:HTTPException xmlns:ns2=\"http://sigh.med.una.py/2013/schemas/base\">"
+ "<code>1</code>"
+ "<summary>code</summary>"
+ "</ns2:HTTPException>";
// @formatter:on
assertEquals(result.toString(), expectedResult);
}
示例14: testResolveFault_HTTPException
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
/**
* Test method for
* {@link py.una.pol.karaku.services.client.KarakuFaultMessageResolver#resolveFault(org.springframework.ws.WebServiceMessage)}
* .
*/
@Test
public void testResolveFault_HTTPException() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(HTTPExceptionDTO.class);
KarakuFaultMessageResolver resolver = new KarakuFaultMessageResolver(
marshaller);
// @formatter:off
SOAPMessage message = getFromString(""
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> " +
" <SOAP-ENV:Header/> " +
" <SOAP-ENV:Body> " +
" <SOAP-ENV:Fault> " +
" <faultcode>SOAP-ENV:Client</faultcode> " +
" <faultstring xml:lang=\"en\">Invalid request</faultstring> " +
" <detail> " +
" <ns4:HTTPException xmlns:ns4=\"http://sigh.med.una.py/2013/schemas/base\"> " +
" <code>1</code>" +
" <summary>2</summary>" +
" </ns4:HTTPException>" +
" </detail>" +
" </SOAP-ENV:Fault>" +
" </SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>");
// @formatter:on
SaajSoapMessage ssm = new SaajSoapMessage(message);
try {
resolver.resolveFault(ssm);
fail();
} catch (HTTPException exception) {
assertEquals("1", exception.getCode());
assertEquals("2", exception.getShortDescription());
}
}
示例15: testResolvXteFault_NormalException
import org.springframework.oxm.jaxb.Jaxb2Marshaller; //导入方法依赖的package包/类
@Test
public void testResolvXteFault_NormalException() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(HTTPExceptionDTO.class);
KarakuFaultMessageResolver resolver = new KarakuFaultMessageResolver(
marshaller);
// @formatter:off
SOAPMessage message = getFromString(""
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> " +
" <SOAP-ENV:Header/> " +
" <SOAP-ENV:Body> " +
" <SOAP-ENV:Fault> " +
" <faultcode>SOAP-ENV:Client</faultcode> " +
" <faultstring xml:lang=\"en\">Invalid request</faultstring> " +
" </SOAP-ENV:Fault>" +
" </SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>");
// @formatter:on
SaajSoapMessage ssm = new SaajSoapMessage(message);
try {
resolver.resolveFault(ssm);
fail();
} catch (SoapFaultClientException exception) {
assertEquals("Client", exception.getFaultCode().getLocalPart());
assertEquals("Invalid request", exception.getFaultStringOrReason());
}
}