public static void handlePut(HttpServletRequest req,
			HttpServletResponse resp) throws IOException {
		try {
			UrlParserResult r = parse(req.getPathInfo());

			switch (r.getResourceType()) {
			case Instance:
				String instanceBody = fromStream(req.getInputStream());

				if (instanceRegistry.containsKey(r.getInstanceId())) {
					ServiceInstance si1 = instanceRegistry.get(r
							.getInstanceId());
					ServiceInstance si2 = deserializeInstance(instanceBody);

					if (si1.equals(si2)) {
						resp.getWriter().print(
								creatDashboardUrlJson(req.getScheme(),
										req.getServerName(),
										req.getServerPort()));
						;
						resp.setStatus(200); // ok
					} else {
						resp.getWriter().print("{}");
						resp.setStatus(409); // conflict
					}
				} else {
					ServiceInstance si = deserializeInstance(instanceBody);
					instanceRegistry.put(r.getInstanceId(), si);
					resp.getWriter().print(
							creatDashboardUrlJson(req.getScheme(),
									req.getServerName(), req.getServerPort()));
					;
					resp.setStatus(201); // created
				}

				break;
			case Binding:
				String bindingBody = fromStream(req.getInputStream());

				if (instanceRegistry.containsKey(r.getInstanceId())) {

					if (bindingRegistry.containsKey(r.getBindingId())) {
						ServiceBinding sb1 = bindingRegistry.get(r
								.getBindingId());
						ServiceBinding sb2 = deserializeBinding(bindingBody);

						if (sb1.equals(sb2)) {
							resp.setStatus(200); // ok
							resp.getWriter().print(
									bindingCredentials(req.getScheme(),
											req.getServerName(),
											req.getServerPort()));
						} else {
							errorResponseBody(req, resp, "conflict", 409);
							resp.setStatus(409); // conflict
						}
					} else {
						ServiceBinding sb = deserializeBinding(bindingBody);
						bindingRegistry.put(r.getBindingId(), sb);
						resp.getWriter().print(
								bindingCredentials(req.getScheme(),
										req.getServerName(),
										req.getServerPort()));
						resp.setStatus(201); // created
					}
				} else {
					throw new NotFoundException("instance(" + r.getInstanceId()
							+ ")");
				}

				break;
			default:
				throw new MethodNotAllowedException("PUT");
			}
		} catch (NotFoundException e) {
			errorResponseBody(req, resp, "not found - " + req.getPathInfo(),
					404);
			resp.setStatus(404);
		} catch (MethodNotAllowedException e) {
			errorResponseBody(req, resp, "method not allowed - GET", 405);
			resp.setStatus(405);
		}
	}