Changeset 1512


Ignore:
Timestamp:
2010-04-20 14:51:18 (3 years ago)
Author:
freya
Message:

trac #235 : set a 201 response after succesfull post in dbmock

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/kauri-dbresources/kauri-dbresources-impl/src/main/java/org/kauriproject/dbresources/mock/DbMockResource.java

    r1332 r1512  
    3636import java.io.FileNotFoundException; 
    3737import java.io.IOException; 
     38import java.io.Serializable; 
    3839import java.util.Iterator; 
    3940import java.util.List; 
     
    178179        try { 
    179180            DbMockUtils.updateContents(new File(filename), jsonFromDisk.toString(3)); 
     181         
    180182        } catch (FileNotFoundException e) { 
    181183            getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT, 
     
    184186            getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT, 
    185187                    "Writing to file " + filename + "failed"); 
    186  
    187188        } 
    188189    } 
     
    196197            jsonRequest = (JSONObject) JSONSerializer.toJSON(this.getRequest().getEntity().getText()); 
    197198            // resource ref must be directory 
    198             filename += File.separator + DbMockUtils.findAvailableFilename(filename) + ".json"; 
     199            String identifier = DbMockUtils.findAvailableFilename(filename) + ".json"; 
     200            filename += File.separator + identifier; 
    199201 
    200202            DbMockUtils.setContents(new File(filename), jsonRequest.toString(2)); 
    201         } catch (IOException e) { 
    202             // TODO Auto-generated catch block 
    203             e.printStackTrace(); 
     203             
     204            getResponse().setStatus(Status.SUCCESS_CREATED); 
     205            getResponse().setLocationRef(getRequest().getResourceRef() + "/" + identifier); 
     206             
     207        } catch (IOException e) { 
     208            log.error(e); 
     209            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); 
    204210        } 
    205211    } 
Note: See TracChangeset for help on using the changeset viewer.