本文整理汇总了Java中org.springframework.oxm.Unmarshaller类的典型用法代码示例。如果您正苦于以下问题:Java Unmarshaller类的具体用法?Java Unmarshaller怎么用?Java Unmarshaller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Unmarshaller类属于org.springframework.oxm包,在下文中一共展示了Unmarshaller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readWithMarshallingFailureException
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Test
public void readWithMarshallingFailureException() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);
UnmarshallingFailureException ex = new UnmarshallingFailureException("forced");
Unmarshaller unmarshaller = mock(Unmarshaller.class);
given(unmarshaller.unmarshal(isA(StreamSource.class))).willThrow(ex);
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
converter.setUnmarshaller(unmarshaller);
try {
converter.read(Object.class, inputMessage);
fail("HttpMessageNotReadableException should be thrown");
}
catch (HttpMessageNotReadableException e) {
assertTrue("Invalid exception hierarchy", e.getCause() == ex);
}
}
示例2: MarshallingHttpMessageConverter
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
/**
* Construct a new {@code MarshallingMessageConverter} with the given
* {@code Marshaller} and {@code Unmarshaller}.
* @param marshaller the Marshaller to use
* @param unmarshaller the Unmarshaller to use
*/
public MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) {
Assert.notNull(marshaller, "Marshaller must not be null");
Assert.notNull(unmarshaller, "Unmarshaller must not be null");
this.marshaller = marshaller;
this.unmarshaller = unmarshaller;
}
示例3: MarshallingMessageConverter
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
/**
* Constructor with {@link Marshaller}. If the given {@link Marshaller} also
* implements {@link Unmarshaller}, it is also used for unmarshalling.
* <p>Note that all {@code Marshaller} implementations in Spring also implement
* {@code Unmarshaller} so that you can safely use this constructor.
* @param marshaller object used as marshaller and unmarshaller
*/
public MarshallingMessageConverter(Marshaller marshaller) {
this();
Assert.notNull(marshaller, "Marshaller must not be null");
this.marshaller = marshaller;
if (marshaller instanceof Unmarshaller) {
this.unmarshaller = (Unmarshaller) marshaller;
}
}
示例4: canRead
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Test
public void canRead() throws Exception {
Unmarshaller unmarshaller = mock(Unmarshaller.class);
given(unmarshaller.supports(Integer.class)).willReturn(false);
given(unmarshaller.supports(String.class)).willReturn(true);
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
converter.setUnmarshaller(unmarshaller);
assertFalse(converter.canRead(Boolean.class, MediaType.TEXT_PLAIN));
assertFalse(converter.canRead(Integer.class, MediaType.TEXT_XML));
assertTrue(converter.canRead(String.class, MediaType.TEXT_XML));
}
示例5: read
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Test
public void read() throws Exception {
String body = "<root>Hello World</root>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
Unmarshaller unmarshaller = mock(Unmarshaller.class);
given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(body);
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
converter.setUnmarshaller(unmarshaller);
String result = (String) converter.read(Object.class, inputMessage);
assertEquals("Invalid result", body, result);
}
示例6: readWithTypeMismatchException
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Test(expected = TypeMismatchException.class)
public void readWithTypeMismatchException() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);
Marshaller marshaller = mock(Marshaller.class);
Unmarshaller unmarshaller = mock(Unmarshaller.class);
given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(Integer.valueOf(3));
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller, unmarshaller);
converter.read(String.class, inputMessage);
}
示例7: MarshallingMessageConverter
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
/**
* Construct a new {@code MarshallingMessageConverter} with the given {@link Marshaller} set.
* <p>If the given {@link Marshaller} also implements the {@link Unmarshaller} interface,
* it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.
* <p>Note that all {@link Marshaller} implementations in Spring also implement the
* {@link Unmarshaller} interface, so that you can safely use this constructor.
* @param marshaller object used as marshaller and unmarshaller
* @throws IllegalArgumentException when {@code marshaller} does not implement the
* {@link Unmarshaller} interface as well
*/
public MarshallingMessageConverter(Marshaller marshaller) {
Assert.notNull(marshaller, "Marshaller must not be null");
if (!(marshaller instanceof Unmarshaller)) {
throw new IllegalArgumentException(
"Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
"interface. Please set an Unmarshaller explicitly by using the " +
"MarshallingMessageConverter(Marshaller, Unmarshaller) constructor.");
}
else {
this.marshaller = marshaller;
this.unmarshaller = (Unmarshaller) marshaller;
}
}
示例8: setUp
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
marshallerMock = mock(Marshaller.class);
unmarshallerMock = mock(Unmarshaller.class);
sessionMock = mock(Session.class);
converter = new MarshallingMessageConverter(marshallerMock, unmarshallerMock);
}
示例9: unmarshallXml
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Override
public Object unmarshallXml(final Unmarshaller unmarshaller, final String accessUrl,
final String nameSpace,final String replace, final String with) throws Exception {
LOGGER.info("Calls {}", accessUrl);
final boolean isWeb = accessUrl.toLowerCase(Locale.ENGLISH).startsWith("http://") || accessUrl.toLowerCase(Locale.ENGLISH).startsWith("https://");
String xmlContent;
if (isWeb) {
xmlContent = Request.Get(accessUrl.replace(" ","")).execute().returnContent().asString(StandardCharsets.UTF_8);
} else {
xmlContent = readInputStream(accessUrl.replace(" ",""));
}
if (replace != null) {
xmlContent = xmlContent.replace(replace, with);
}
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
xmlContent.getBytes(StandardCharsets.UTF_8));
Source source;
if (nameSpace != null) {
source = setNameSpaceOnXmlStream(byteArrayInputStream, nameSpace);
} else {
source = new StreamSource(byteArrayInputStream);
}
return unmarshaller.unmarshal(source);
}
示例10: testUnmarshaller
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
/**
* Test method for
* {@link py.una.pol.karaku.configuration.KarakuWSClientConfiguration#unmarshaller()}
* .
*/
@Test
public void testUnmarshaller() {
properties.setFalsificar(true);
Unmarshaller u = wsConf.unmarshaller();
assertNotNull(u);
}
示例11: createUnmarshaller
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Override
protected Unmarshaller createUnmarshaller() throws Exception {
JibxMarshaller unmarshaller = new JibxMarshaller();
unmarshaller.setTargetClass(Flights.class);
unmarshaller.afterPropertiesSet();
return unmarshaller;
}
示例12: createUnmarshaller
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Override
public Unmarshaller createUnmarshaller() throws Exception {
unmarshaller = new Jaxb2Marshaller();
unmarshaller.setContextPath("org.springframework.oxm.jaxb.test");
unmarshaller.setSchema(new ClassPathResource("org/springframework/oxm/flight.xsd"));
unmarshaller.afterPropertiesSet();
return unmarshaller;
}
示例13: createUnmarshaller
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
@Override
protected Unmarshaller createUnmarshaller() throws Exception {
CastorMarshaller marshaller = new CastorMarshaller();
ClassPathResource mappingLocation = new ClassPathResource("mapping.xml", CastorMarshaller.class);
marshaller.setMappingLocation(mappingLocation);
marshaller.afterPropertiesSet();
return marshaller;
}
示例14: setUnmarshaller
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
/**
* Set the {@link Unmarshaller} to be used by this message converter.
*/
public void setUnmarshaller(Unmarshaller unmarshaller) {
this.unmarshaller = unmarshaller;
}
示例15: getUnmarshaller
import org.springframework.oxm.Unmarshaller; //导入依赖的package包/类
/**
* Return the configured unmarshaller.
*/
public Unmarshaller getUnmarshaller() {
return this.unmarshaller;
}