/** * Sets a single header. * @param name * @param value */ public void setHeader(String name, String value) { getHeaders().put(name, value); }
/** * @param body the body to set * @param type the content type of the body */ public void setBody(Object body, MediaType type) { this.body = body; this.bodyType = type; setHeader("Content-Type", type.toString()); //$NON-NLS-1$ }
throws IOException, WebApplicationException { Object entity = t.getBody(); Class<?> entityType = entity.getClass(); MessageBodyWriter entityWriter = providers.getMessageBodyWriter(entityType, null, null, t.getBodyType()); long size = entityWriter.getSize(entity, entityType, null, null, t.getBodyType()); if (size > -1) { t.setHeader(HttpHeaderNames.CONTENT_LENGTH, Integer.toString((int) size)); t.setHeader("Content-Classname", entityType.getName()); //$NON-NLS-1$ writer.print(t.getCode()); writer.print(" "); //$NON-NLS-1$ writer.println(t.getStatus()); for (Entry<String, String> entry : t.getHeaders().entrySet()) { String name = entry.getKey(); String value = entry.getValue(); writer.flush(); entityWriter.writeTo(entity, entityType, null, null, t.getBodyType(), null, entityStream);
String path = contentId.substring(1, contentId.lastIndexOf('@')); HttpResponseBean rbean = part.getBody(HttpResponseBean.class, null); if (rbean.getCode() == 201) { Entry entry = (Entry) rbean.getBody(); BaseArtifactType artifact = SrampAtomUtils.unwrapSrampArtifact(entry); rval.put(path, artifact); } else if (rbean.getCode() == 409) { if (MediaType.APPLICATION_SRAMP_ATOM_EXCEPTION.equals(rbean.getHeaders().get("Content-Type"))) { //$NON-NLS-1$ SrampAtomException exception = (SrampAtomException) rbean.getBody(); rval.put(path, exception); } else { String errorReason = (String) rbean.getBody(); SrampAtomException exception = new SrampAtomException(errorReason); rval.put(path, exception); SrampAtomException exception = new SrampAtomException(Messages.i18n.format("BAD_RETURN_CODE", rbean.getCode(), contentId)); //$NON-NLS-1$ rval.put(path, exception);
String status = line1.substring(idx2 + 1); HttpResponseBean rval = new HttpResponseBean(code, status); String key = line.substring(0, idx).trim(); String val = line.substring(idx + 1).trim(); rval.setHeader(key, val); line = reader.readLine(); String contentType = rval.getHeaders().get("Content-Type"); //$NON-NLS-1$ String contentClassName = rval.getHeaders().get("Content-Classname"); //$NON-NLS-1$ Class<?> entityClass = String.class; try { Object bodyEntity = entityReader.readFrom(entityClass, null, null, bodyMediaType, null, entityStream); rval.setBody(bodyEntity, bodyMediaType);
/** * Constructor. * @param code * @param status */ public HttpResponseBean(int code, String status) { this.code = code; this.status = status; setHeader("Date", (new Date()).toString()); //$NON-NLS-1$ }