This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.codehaus.mojo</groupId> | |
<artifactId>jaxb2-maven-plugin</artifactId> | |
<version>1.3.1</version> | |
<executions> | |
<execution> | |
<id>Generate Java</id> | |
<goals> | |
<goal>xjc</goal> | |
</goals> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//WordList is a @XmlRootElement annotated class. | |
JAXBContext jaxbContext = JAXBContext.newInstance(WordList.class); | |
//Setting a Schema to validate against. | |
Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new SAXSource(new InputSource(getClass().getClassLoader().getResourceAsStream("schema.xsd")))); | |
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); | |
unmarshaller.setSchema(schema); | |
File inputFile; //initialize input file | |
WordList wordList = (WordList) unmarshaller.unmarshal(inputFile); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//WordList is a @XmlRootElement annotated class. | |
JAXBContext jaxbContext = JAXBContext.newInstance(WordList.class); | |
//Schema to validate against. | |
Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new SAXSource(new InputSource(getClass().getClassLoader().getResourceAsStream("schema.xsd")))); | |
Marshaller marshaller = jaxbContext.createMarshaller(); | |
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); | |
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://mysite.com/schema/v1/ xsd/schema.xsd"); | |
marshaller.setSchema(schema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" | |
version="2.1" jaxb:extensionBindingPrefixes="xjc"> | |
<jaxb:bindings schemaLocation="../schema/dto.xsd" node="/xs:schema"> | |
<jaxb:schemaBindings> | |
<jaxb:package name="com.annagurban.nazar.dto.v1"/> | |
<jaxb:nameXmlTransform> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.service; | |
import com.example.domain.Ticket; | |
import com.example.service.mapper.Mapper; | |
import com.example.service.remote.RemoteTicketService; | |
import com.example.service.remote.TicketDto; | |
import java.util.Collections; | |
import java.util.List; | |
import javax.inject.Inject; | |
import javax.inject.Named; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.service; | |
import com.example.domain.Ticket; | |
import com.example.service.mapper.Mapper; | |
import com.example.service.remote.RemoteTicketService; | |
import com.example.service.remote.TicketDto; | |
import java.util.Arrays; | |
import java.util.List; | |
import org.junit.Test; | |
import static org.junit.Assert.*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.service; | |
import com.example.domain.Ticket; | |
import java.util.List; | |
import javax.inject.Inject; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
import org.junit.runner.RunWith; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface BlogService { | |
List<MyPost> getPosts(); | |
MyPost getPost(int id); | |
int addPost(MyPost post); | |
boolean updatePost(int id, MyPost post); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("/blog") | |
@Consumes("application/xml") | |
@Produces("application/xml") | |
public interface BlogRestfulService { | |
@GET | |
@Path("/posts") | |
List<Post> getPosts(); | |
@GET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Named | |
@Scope("request") | |
public class BlogServiceImpl implements BlogRestfulService { | |
@Inject | |
private BlogService service; | |
@Inject | |
private Mapper mapper; | |
@Override |