It's all about the answers!

Ask a question

HTTP/1.1 409 Conflict on POST to create a storage area


Debdoot Mukherjee (512118) | asked Jun 18 '10, 3:49 a.m.
Can anyone please throw some light on why there may be "HTTP/1.1 409 Conflict" error on a POST request to the JFS storage service to create a new storage area?

The following spec only discusses 409 error in context of PUT/DELETE

Can there be platform issue? My code to create a storage area works fine on Windows machines, but it is failing on a Linux box.

Any help will be greatly appreciated

Thanks

4 answers



permanent link
John Vasta (2.6k15) | answered Jun 18 '10, 8:53 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
A 409 will be returned by the storage service for POST if a resource with the specified name already exists. If you are creating the storage area as part of servicing a request, then if your service receives more than one request in parallel, it will try to create the storage area more than once. You might need to protect such code against multiple thread execution, and check to make sure the storage area doesn't already exist before trying to create it.

Can anyone please throw some light on why there may be "HTTP/1.1 409 Conflict" error on a POST request to the JFS storage service to create a new storage area?

The following spec only discusses 409 error in context of PUT/DELETE

Can there be platform issue? My code to create a storage area works fine on Windows machines, but it is failing on a Linux box.

Any help will be greatly appreciated

Thanks

permanent link
Debdoot Mukherjee (512118) | answered Jun 21 '10, 3:15 a.m.
I already have the code to create a storage area in a synchronized block. Also,when I check whether such a named resource exists I cannot any such resource. As I mentioned, the problem only occurs on Linux servers. I attach my source code here -- I will glad if you can provide some insight as to what could go wrong here.


private synchronized void createStorageArea() throws HttpException, IOException, URISyntaxException, JfsHttpException{
String STORAGEAREA_CONTENT =
"<StorageArea>" +
" <rdfs>" + Constants.CADW_STORAGE_AREA_NAME + "</rdfs>\n" +
" <frontsideURL>" + config.getCADWFrontSideURL() + "</frontsideURL>\n" +
"</StorageArea>";
// get URL for the storage area
String storageAreaURL = config.getCADWStorageAreaURL();

// if the storage area already exists, delete it first
if(checkResourceExists(storageAreaURL)) {
deleteResource(storageAreaURL);
}

// create the storage area
createResource(config.getStorageServiceURL(),
Constants.CADW_STORAGE_AREA_NAME,
Constants.RDF_XML_CONTENT_TYPE,
STORAGEAREA_CONTENT);
}
private HttpResponse createResource(String uri, String name, String contentType, String content) throws HttpException, IOException, URISyntaxException, JfsHttpException {
HttpPost request = new HttpPost(uri);
request.addHeader("Name", name);

// set the content of the resource
StringEntity entity = new StringEntity(content, "UTF-8");
entity.setContentType(contentType + HTTP.CHARSET_PARAM + "UTF-8");
request.setEntity(entity);

// send the request
System.out.println("Creating Resource");
System.out.println("Content: " + content);
HttpResponse response = httpClient.send(request);
int status = response.getStatusLine().getStatusCode();

if(status == HttpStatus.SC_UNAUTHORIZED)
throw new HttpUnauthorizedException();

else if(status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED)
throw new HttpException("Failed to create resource: " + name + ". Response Status Line: " + response.getStatusLine());

// just print all headers
System.out.println("Response Headers");
Header[] headers = response.getAllHeaders();
for(Header header:headers){
System.out.println(header.getName()+": " + header.getValue());
}
System.out.println("End of Creating Resource");
return response;
}


I get the following message:

Failed to create resource: jfs.cadworkbench.storage. Response Status Line: HTTP/1.1 409 Conflict

Thanks for your help
Regards
Debdoot

A 409 will be returned by the storage service for POST if a resource with the specified name already exists. If you are creating the storage area as part of servicing a request, then if your service receives more than one request in parallel, it will try to create the storage area more than once. You might need to protect such code against multiple thread execution, and check to make sure the storage area doesn't already exist before trying to create it.

Can anyone please throw some light on why there may be "HTTP/1.1 409 Conflict" error on a POST request to the JFS storage service to create a new storage area?

The following spec only discusses 409 error in context of PUT/DELETE

Can there be platform issue? My code to create a storage area works fine on Windows machines, but it is failing on a Linux box.

Any help will be greatly appreciated

Thanks

		                                        

permanent link
John Vasta (2.6k15) | answered Jun 21 '10, 9:49 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Your code looks OK to me, though you didn't post the key parts: the checkResourceExists method and the config.getCADWStorageAreaURL method. If the URL is not being constructed correctly, or the existence of the resource is not being determined correctly, then the code would try to create the storage area repeatedly.

Another comment: if you're calling the createStorageArea method for every incoming request to your service, then you'll be checking for the existence of the storage area on every request, which will be using CPU and network resources unnecessarily.

I already have the code to create a storage area in a synchronized block. Also,when I check whether such a named resource exists I cannot any such resource. As I mentioned, the problem only occurs on Linux servers. I attach my source code here -- I will glad if you can provide some insight as to what could go wrong here.


see previous message...


I get the following message:

Failed to create resource: jfs.cadworkbench.storage. Response Status Line: HTTP/1.1 409 Conflict

Thanks for your help
Regards
Debdoot

permanent link
Debdoot Mukherjee (512118) | answered Jun 21 '10, 10:17 a.m.
Thanks a lot for your help. The problem was resolved on cleaning the databases with repotools.

Cheers
Debdoot


Your code looks OK to me, though you didn't post the key parts: the checkResourceExists method and the config.getCADWStorageAreaURL method. If the URL is not being constructed correctly, or the existence of the resource is not being determined correctly, then the code would try to create the storage area repeatedly.

Another comment: if you're calling the createStorageArea method for every incoming request to your service, then you'll be checking for the existence of the storage area on every request, which will be using CPU and network resources unnecessarily.

I already have the code to create a storage area in a synchronized block. Also,when I check whether such a named resource exists I cannot any such resource. As I mentioned, the problem only occurs on Linux servers. I attach my source code here -- I will glad if you can provide some insight as to what could go wrong here.


see previous message...


I get the following message:

Failed to create resource: jfs.cadworkbench.storage. Response Status Line: HTTP/1.1 409 Conflict

Thanks for your help
Regards
Debdoot

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.