List of usage examples for java.net HttpURLConnection HTTP_CREATED
int HTTP_CREATED
To view the source code for java.net HttpURLConnection HTTP_CREATED.
Click Source Link
From source file:com.aptana.jira.core.JiraManager.java
/** * Creates a JIRA ticket.//from w w w. ja v a2s . com * * @param type * the issue type (bug, feature, or improvement) * @param priority * the issue's priority * @param severity * the issue's severity (Blocker, Major, Minor, Trivial, None) * @param summary * the summary of the ticket * @param description * the description of the ticket * @return the JIRA issue created * @throws JiraException * @throws IOException */ public JiraIssue createIssue(JiraIssueType type, JiraIssueSeverity severity, String summary, String description) throws JiraException, IOException { if (user == null) { throw new JiraException(Messages.JiraManager_ERR_NotLoggedIn); } HttpURLConnection connection = null; try { connection = createConnection(getCreateIssueURL(), user.getUsername(), user.getPassword()); connection.setRequestMethod("POST"); //$NON-NLS-1$ connection.setDoOutput(true); String severityJSON; String versionString; if ((TITANIUM_COMMUNITY.equals(projectKey) && type == JiraIssueType.IMPROVEMENT) || (!TITANIUM_COMMUNITY.equals(projectKey) && type != JiraIssueType.BUG)) { // Improvements in TC don't get Severities, nor do Story or Improvements in Aptana Studio! severityJSON = StringUtil.EMPTY; } else { severityJSON = severity.getParameterValue() + ",\n"; //$NON-NLS-1$ } // If we're submitting against TC, we can't do version, we need to stuff that into the Environment if (TITANIUM_COMMUNITY.equals(projectKey)) { versionString = MessageFormat.format("\"{0}\": \"{1}\"", PARAM_ENVIRONMENT, getProjectVersion()); //$NON-NLS-1$ } else { versionString = "\"" + PARAM_VERSION + "\": [{\"name\": \"" + getProjectVersion() + "\"}]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } // @formatter:off String data = "{\n" + //$NON-NLS-1$ " \"fields\": {\n" + //$NON-NLS-1$ " \"project\":\n" + //$NON-NLS-1$ " { \n" + //$NON-NLS-1$ " \"key\": \"" + projectKey + "\"\n" + //$NON-NLS-1$ //$NON-NLS-2$ " },\n" + //$NON-NLS-1$ " \"summary\": \"" + summary.replaceAll("\"", "'") + "\",\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ " \"description\": \"" //$NON-NLS-1$ + description.replaceAll("\"", "'").replaceAll("\n", Matcher.quoteReplacement("\\n")) + "\",\n" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$ + " \"issuetype\": {\n" + " \"name\": \"" + type.getParameterValue(projectKey) + "\"\n" + //$NON-NLS-3$ " },\n" + //$NON-NLS-1$ severityJSON + " " + versionString + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ " }\n" + //$NON-NLS-1$ "}"; //$NON-NLS-1$ // @formatter:on OutputStream out = connection.getOutputStream(); IOUtil.write(out, data); out.close(); int responseCode = connection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED) { String output = IOUtil.read(connection.getInputStream()); return createIssueFromJSON(output); } // failed to create the ticket // TODO Parse the response as JSON! throw new JiraException(IOUtil.read(connection.getErrorStream())); } catch (JiraException je) { throw je; } catch (Exception e) { throw new JiraException(e.getMessage(), e); } finally { if (connection != null) { connection.disconnect(); } } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitStatusTest.java
@Test public void testStatusUntracked() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project/folder metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject folder = new JSONObject(response.getText()); String fileName = "new.txt"; request = getPostFilesRequest(folder.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); assertStatus(new StatusResult().setUntrackedNames(fileName), gitStatusUri); }//from w w w . j a v a 2 s . co m }
From source file:org.apache.taverna.activities.interaction.InteractionActivityRunnable.java
private void postInteractionMessage(final String id, final Entry entry, final String interactionUrlString, final String runId) throws IOException { entry.addLink(StringEscapeUtils.escapeXml(interactionUrlString), "presentation"); entry.setContentAsXhtml("<p><a href=\"" + StringEscapeUtils.escapeXml(interactionUrlString) + "\">Open: " + StringEscapeUtils.escapeXml(interactionUrlString) + "</a></p>"); URL feedUrl;/*from w w w.j av a 2 s. c o m*/ feedUrl = new URL(interactionPreference.getFeedUrlString()); final String entryContent = ((FOMElement) entry).toFormattedString(); final HttpURLConnection httpCon = (HttpURLConnection) feedUrl.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestProperty("Content-Type", "application/atom+xml;type=entry;charset=UTF-8"); httpCon.setRequestProperty("Content-Length", "" + entryContent.length()); httpCon.setRequestProperty("Slug", id); httpCon.setRequestMethod("POST"); httpCon.setConnectTimeout(5000); final OutputStream outputStream = httpCon.getOutputStream(); IOUtils.write(entryContent, outputStream, "UTF-8"); outputStream.close(); final int response = httpCon.getResponseCode(); if ((response < 0) || (response >= 400)) { logger.error("Received response code" + response); throw (new IOException("Received response code " + response)); } if (response == HttpURLConnection.HTTP_CREATED) { interactionRecorder.addResource(runId, id, httpCon.getHeaderField("Location")); } }
From source file:i5.las2peer.services.gamificationQuestService.GamificationQuestService.java
/** * Post a new quest// w w w . j av a 2 s .com * @param appId applicationId * @param contentB content JSON * @return HttpResponse with the returnString */ @POST @Path("/{appId}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "{\"status\": 3, \"message\": \"Quests upload success ( (questid) )\"}"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "{\"status\": 3, \"message\": \"Failed to upload (questid)\"}"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "{\"status\": 1, \"message\": \"Failed to add the quest. Quest ID already exist!\"}"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "{\"status\": =, \"message\": \"Quest ID cannot be null!\"}"), }) @ApiOperation(value = "createNewQuest", notes = "A method to store a new quest with details") public HttpResponse createNewQuest( @ApiParam(value = "Application ID to store a new quest", required = true) @PathParam("appId") String appId, @ApiParam(value = "Quest detail in JSON", required = true) @ContentParam byte[] contentB) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "POST " + "gamification/quests/" + appId); long randomLong = new Random().nextLong(); //To be able to match // parse given multipart form data JSONObject objResponse = new JSONObject(); UserAgent userAgent = (UserAgent) getContext().getMainAgent(); String name = userAgent.getLoginName(); if (name.equals("anonymous")) { return unauthorizedMessage(); } String questid = null; String questname; String questdescription; String queststatus; String questachievementid; boolean questquestflag = false; String questquestidcompleted = null; boolean questpointflag = false; int questpointvalue = 0; List<Pair<String, Integer>> questactionids = new ArrayList<Pair<String, Integer>>(); boolean questnotifcheck = false; String questnotifmessage = ""; Connection conn = null; try { conn = dbm.getConnection(); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_14, "" + randomLong); String content = new String(contentB); if (content.equals(null)) { objResponse.put("message", "Cannot create quest. Cannot parse json data into string"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } JSONObject obj = (JSONObject) JSONValue.parseWithException(content); try { if (!questAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot create quest. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } } catch (SQLException e1) { e1.printStackTrace(); objResponse.put("message", "Cannot create quest. Cannot check whether application ID exist or not. Database error. " + e1.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } questid = stringfromJSON(obj, "questid"); if (questAccess.isQuestIdExist(conn, appId, questid)) { objResponse.put("message", "Cannot create quest. Failed to add the quest. Quest ID already exist! "); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } questname = stringfromJSON(obj, "questname"); queststatus = stringfromJSON(obj, "queststatus"); questachievementid = stringfromJSON(obj, "questachievementid"); questquestflag = boolfromJSON(obj, "questquestflag"); questpointflag = boolfromJSON(obj, "questpointflag"); questpointvalue = intfromJSON(obj, "questpointvalue"); questactionids = listPairfromJSON(obj, "questactionids", "action", "times"); // OK to be null questdescription = (String) obj.get("questdescription"); if (questdescription.equals(null)) { questdescription = ""; } questquestidcompleted = (String) obj.get("questidcompleted"); if (questquestflag) { if (questquestidcompleted.equals(null)) { objResponse.put("message", "Cannot create quest. Completed quest ID cannot be null if it is selected"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } } else { questquestidcompleted = null; } questnotifcheck = boolfromJSON(obj, "questnotificationcheck"); if (questnotifcheck) { questnotifmessage = stringfromJSON(obj, "questnotificationmessage"); } System.out.println(questquestidcompleted); QuestModel model = new QuestModel(questid, questname, questdescription, QuestStatus.valueOf(queststatus), questachievementid, questquestflag, questquestidcompleted, questpointflag, questpointvalue, questnotifcheck, questnotifmessage); model.setActionIds(questactionids); questAccess.addNewQuest(conn, appId, model); objResponse.put("message", "New quest created " + questid); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_15, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_24, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_25, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_CREATED); } catch (MalformedStreamException e) { // the stream failed to follow required syntax objResponse.put("message", "Cannot create quest. MalformedStreamException. Failed to upload " + questid + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } catch (IOException e) { // a read or write error occurred objResponse.put("message", "Cannot create quest. IO Exception. Failed to upload " + questid + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot create quest. Database error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (NullPointerException e) { e.printStackTrace(); objResponse.put("message", "Cannot create quest. NullPointerException. Failed to upload " + questid + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (ParseException e) { e.printStackTrace(); objResponse.put("message", "Cannot create quest. ParseException. Failed to parse JSON. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } // always close connections finally { try { conn.close(); } catch (SQLException e) { logger.printStackTrace(e); } } }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient.java
public boolean upload(String sessionId, StreamingOutput output, String encoding, String dataspace, String path) throws Exception { StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL) .append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspace); ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory) .build();/* ww w . j a v a 2 s. c o m*/ ResteasyWebTarget target = client.target(uriTmpl.toString()).path(path); Response response = null; try { response = target.request().header("sessionid", sessionId).put(Entity.entity(output, new Variant(MediaType.APPLICATION_OCTET_STREAM_TYPE, (Locale) null, encoding))); if (response.getStatus() != HttpURLConnection.HTTP_CREATED) { if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new NotConnectedRestException("User not authenticated or session timeout."); } else { throwException(String.format("File upload failed. Status code: %d" + response.getStatus()), response); } } return true; } finally { if (response != null) { response.close(); } } }
From source file:jp.realglobe.util.uploader.DirectoryUploader.java
/** * ????/*from w w w .j ava 2s . co m*/ * @return * @throws IOException ? */ private String getRemoteToken() throws IOException { try (CloseableHttpClient client = HttpClients.createDefault()) { final HttpPost post = new HttpPost(this.tokenUrl); post.setEntity(new StringEntity((new TokenRequestBody(this.userId, this.id, this.name)).toJson(), ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = client.execute(post)) { if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_CREATED) { return TokenResponseBody.parse(Utils.readAll(response.getEntity().getContent())).getToken(); } LOG.warning(response.toString()); LOG.info("Retrying request is not implemented"); return null; } } }
From source file:es.tekniker.framework.ktek.questionnaire.mng.server.EventServiceClient.java
public boolean subscribeContext(String codUser, String nameContext) { HttpURLConnection conn = null; StringBuffer strBOutput = new StringBuffer(); boolean boolOK = true; String input = null;/*w ww. j ava 2 s . c om*/ StringBuffer stbInput = new StringBuffer(); try { log.debug("subscribeContext Start "); conn = getEventServiceSEConnection(methodSubscribeContext, endpointEventService, headerContentTypeJSON); stbInput.append("{\"entities\": [{\"type\": \"" + typeContextValue + "\",\"isPattern\": \"false\",\"id\": \"" + codUser + "\" } ],"); stbInput.append("\"attributes\": [\"" + nameContext + "\"] ,"); stbInput.append("\"reference\": \"" + notificationEndpoint + "\","); stbInput.append("\"duration\": \"P1M\","); stbInput.append("\"notifyConditions\": [ {\"type\": \"ONCHANGE\",\"condValues\": [\"" + nameContext + "\"]}],\"throttling\": \"PT5S\"}"); input = stbInput.toString(); log.debug(input); OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); if (conn.getResponseCode() == 200) { log.debug("subscribeContext Response code " + conn.getResponseCode()); } else { if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) { throw new RuntimeException( "subscribeContext Failed : HTTP error code : " + conn.getResponseCode()); } } log.debug("subscribeContext OutputStream wrote"); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); log.debug("subscribeContext Waiting server response "); String output; log.debug("subscribeContext Output from Server .... \n"); while ((output = br.readLine()) != null) { strBOutput.append(output); log.debug(output); } conn.disconnect(); boolOK = true; } catch (MalformedURLException e) { log.error("subscribeContext MalformedURLException " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { log.error("subscribeContext IOException " + e.getMessage()); e.printStackTrace(); } return boolOK; }
From source file:org.eclipse.orion.server.tests.servlets.git.GitCommitTest.java
@Test public void testCommitAllInFolder() throws Exception { // see bug 349480 URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project metadata WebRequest request = getGetRequest(contentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject cloneFolder = new JSONObject(response.getText()); String fileName = "folder2.txt"; JSONObject folder = getChild(cloneFolder, "folder"); request = getPostFilesRequest(folder.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject testTxt = getChild(cloneFolder, "test.txt"); // drill down to 'folder' JSONObject folderGitSection = folder.getJSONObject(GitConstants.KEY_GIT); String folderGitStatusUri = folderGitSection.getString(GitConstants.KEY_STATUS); String folderGitCloneUri = folderGitSection.getString(GitConstants.KEY_CLONE); JSONObject folder2Txt = getChild(folder, "folder2.txt"); JSONObject folderTxt = getChild(folder, "folder.txt"); // git section for the new file JSONObject folder2TxtGitSection = folder2Txt.getJSONObject(GitConstants.KEY_GIT); String folder2TxtGitIndexUri = folder2TxtGitSection.getString(GitConstants.KEY_INDEX); String folder2TxtGitHeadUri = folder2TxtGitSection.getString(GitConstants.KEY_HEAD); // stage the new file request = GitAddTest.getPutGitIndexRequest(folder2TxtGitIndexUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // commit the new file request = getPostGitCommitRequest(folder2TxtGitHeadUri, "folder/folder2.txt added", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // check status - clean assertStatus(StatusResult.CLEAN, folderGitStatusUri); // modify all modifyFile(testTxt, "change"); modifyFile(folderTxt, "change"); modifyFile(folder2Txt, "change"); // check status - modified=3 assertStatus(new StatusResult().setModified(3), folderGitStatusUri); addFile(folderTxt);//from w ww . j a v a2s.c o m addFile(testTxt); // check status - modified=1, changed=2 assertStatus(new StatusResult().setModified(1).setChanged(2), folderGitStatusUri); // commit all // XXX: using HEAD URI for folder will commit all files in the folder, regardless of index state // request = getPostGitCommitRequest(folderGitHeadUri, "test.txt and folder/folder.txt changed", false); // the UI should use HEAD URI for the clone/root to commit all staged files JSONObject clone = getCloneForGitResource(folder); String cloneFolderGitHeadUri = clone.getString(GitConstants.KEY_HEAD); request = getPostGitCommitRequest(cloneFolderGitHeadUri, "test.txt and folder/folder.txt changed", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // check status - changed=1 assertStatus(new StatusResult().setModifiedNames("folder/folder2.txt"), folderGitStatusUri); // check the last commit for the repo JSONArray commitsArray = log(cloneFolderGitHeadUri); assertEquals(3, commitsArray.length()); JSONObject commit = commitsArray.getJSONObject(0); assertEquals("test.txt and folder/folder.txt changed", commit.get(GitConstants.KEY_COMMIT_MESSAGE)); JSONArray diffs = commit.getJSONArray(GitConstants.KEY_COMMIT_DIFFS); assertEquals(2, diffs.length()); String oldPath = diffs.getJSONObject(0).getString(GitConstants.KEY_COMMIT_DIFF_OLDPATH); assertTrue("folder/folder.txt".equals(oldPath) || "test.txt".equals(oldPath)); oldPath = diffs.getJSONObject(1).getString(GitConstants.KEY_COMMIT_DIFF_OLDPATH); assertTrue("folder/folder.txt".equals(oldPath) || "test.txt".equals(oldPath)); } }
From source file:com.flurry.proguard.UploadMapping.java
/** * Register this upload with the metadata service * * @param projectId the id of the project * @param payload the JSON body to send//from w w w.j a v a 2s . c o m * @param token the Flurry auth token * @return the id of the created upload */ private static String createUpload(String projectId, String payload, String token) throws IOException { String postUrl = String.format("%s/project/%s/uploads", METADATA_BASE, projectId); List<Header> requestHeaders = getMetadataHeaders(token); HttpPost postRequest = new HttpPost(postUrl); postRequest.setEntity(new StringEntity(payload, Charset.forName("UTF-8"))); try (CloseableHttpResponse response = executeHttpRequest(postRequest, requestHeaders)) { expectStatus(response, HttpURLConnection.HTTP_CREATED); JSONObject jsonObject = getJsonFromEntity(response.getEntity()); return jsonObject.getJSONObject("data").get("id").toString(); } finally { postRequest.releaseConnection(); } }
From source file:org.eclipse.orion.server.tests.metastore.RemoteMetaStoreTests.java
/** * Create a project on the Orion server for the test user. * /*from w w w. j a v a2 s . c o m*/ * @param webConversation * @param login * @param password * @param projectName * @return * @throws IOException * @throws JSONException * @throws URISyntaxException * @throws SAXException */ protected int createProject(WebConversation webConversation, String login, String password, String projectName) throws IOException, JSONException, URISyntaxException, SAXException { assertEquals(HttpURLConnection.HTTP_OK, login(webConversation, login, password)); JSONObject jsonObject = new JSONObject(); InputStream inputStream = IOUtilities.toInputStream(jsonObject.toString()); WebRequest request = new PostMethodWebRequest(getOrionServerURI("/workspace/" + getWorkspaceId(login)), inputStream, "UTF-8"); request.setHeaderField(ProtocolConstants.HEADER_SLUG, projectName); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); jsonObject = new JSONObject(response.getText()); String location = jsonObject.getString("ContentLocation"); String name = jsonObject.getString("Name"); System.out.println("Created Project: " + name + " at Location: " + location); return response.getResponseCode(); }