Java Reference
In-Depth Information
Click here to view code image
@Path("/Customer")
public class CustomerService {
public static final String DATA_STORE = "CustomerDATA.txt";
public static final Logger logger =
Log-
ger.getLogger(CustomerService.class.getCanonicalName());
...
@POST
@Consumes({"application/xml", "application/json"})
public Response createCustomer(Customer customer) {
try {
long customerId = persist(customer);
return Response.created(URI.create("/" + customer-
Id)).build();
} catch (Exception e) {
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
}
}
...
private long persist(Customer customer) throws IOException {
File dataFile = new File(DATA_STORE);
if (!dataFile.exists()) {
dataFile.createNewFile();
}
long customerId = customer.getId();
Address address = customer.getAddress();
Properties properties = new Properties();
properties.load(new FileInputStream(dataFile));
properties.setProperty(String.valueOf(customerId),
customer.getFirstname() + ","
+ customer.getLastname() + ","
+ address.getNumber() + ","
+ address.getStreet() + ","
+ address.getCity() + ","
+ address.getState() + ","
Search WWH ::




Custom Search