Example usage for java.net HttpURLConnection HTTP_ACCEPTED

List of usage examples for java.net HttpURLConnection HTTP_ACCEPTED

Introduction

In this page you can find the example usage for java.net HttpURLConnection HTTP_ACCEPTED.

Prototype

int HTTP_ACCEPTED

To view the source code for java.net HttpURLConnection HTTP_ACCEPTED.

Click Source Link

Document

HTTP Status-Code 202: Accepted.

Usage

From source file:ste.xtest.net.BugFreeStubURLConnection.java

@Test
public void set_status() throws Exception {
    then(C.status(HttpURLConnection.HTTP_ACCEPTED)).isSameAs(C);
    then(C.getStatus()).isEqualTo(HttpURLConnection.HTTP_ACCEPTED);

    then(C.status(HttpURLConnection.HTTP_FORBIDDEN)).isSameAs(C);
    then(C.getStatus()).isEqualTo(HttpURLConnection.HTTP_FORBIDDEN);
}

From source file:com.mobile.godot.core.controller.CoreController.java

public synchronized void approach(String username, String carName) {

    String servlet = "Approach";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("username", username));
    params.add(new BasicNameValuePair("carName", carName));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_ACCEPTED, GodotMessage.Core.DRIVER_UPDATED);
    mMessageMap.append(HttpURLConnection.HTTP_CREATED, GodotMessage.Core.MESSAGE_SENT);
    mMessageMap.append(HttpURLConnection.HTTP_NOT_FOUND, GodotMessage.Core.CAR_NOT_FOUND);
    mMessageMap.append(HttpURLConnection.HTTP_UNAUTHORIZED, GodotMessage.Error.UNAUTHORIZED);

    GodotAction action = new GodotAction(servlet, params, mMessageMap, mHandler);
    Thread tAction = new Thread(action);
    tAction.start();//w  w w.j  a  v a  2  s.co  m

}

From source file:gsn.wrappers.general.HttpGetWrapper.java

public void run() {
    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(1024 * 20);
    byte[] buffer = new byte[16 * 1024];
    BufferedInputStream content;/*from   ww w . j a  va2 s  . c  o m*/
    while (isActive()) {
        try {
            Thread.sleep(rate);
            httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.connect();
            if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_ACCEPTED)
                continue;
            content = new BufferedInputStream(httpURLConnection.getInputStream(), 4096);
            arrayOutputStream.reset();
            int readIndex = -1;
            while ((readIndex = content.read(buffer)) != -1)
                arrayOutputStream.write(buffer, 0, readIndex);
            postStreamElement(arrayOutputStream.toByteArray());
        } catch (InterruptedException e) {
            logger.error(e.getMessage(), e);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:com.adaptris.http.HttpClientTransport.java

/**
 * Is the HTTP response code considered to be a success.
 * <p>//from w w  w .  j a v  a2  s . co  m
 * There are 7 possible HTTP codes that signify success or partial success :-
 * <code>200,201,202,203,204,205,206</code>
 * </p>
 * 
 * @return true if the transaction was successful.
 */
private boolean wasSuccessful(HttpSession session) {

    boolean rc = false;
    switch (session.getResponseLine().getResponseCode()) {
    case HttpURLConnection.HTTP_ACCEPTED:
    case HttpURLConnection.HTTP_CREATED:
    case HttpURLConnection.HTTP_NO_CONTENT:
    case HttpURLConnection.HTTP_NOT_AUTHORITATIVE:
    case HttpURLConnection.HTTP_OK:
    case HttpURLConnection.HTTP_PARTIAL:
    case HttpURLConnection.HTTP_RESET: {
        rc = true;
        break;
    }
    default: {
        rc = false;
        break;
    }
    }
    return rc;
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitBranchTest.java

@Test
public void testAddRemoveBranch() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    JSONObject clone = clone(clonePath);
    String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);

    String[] branchNames = { "dev", "change/1/1", "working@bug1" };
    for (String branchName : branchNames) {
        // create branch
        WebResponse response = branch(branchesLocation, branchName);
        String branchLocation = response.getHeaderField(ProtocolConstants.HEADER_LOCATION);

        // check details
        WebRequest request = getGetRequest(branchLocation);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        JSONObject branches = listBranches(branchesLocation);
        JSONArray branchesArray = branches.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertEquals(2, branchesArray.length());
        JSONObject branch0 = branchesArray.getJSONObject(0);
        JSONObject branch1 = branchesArray.getJSONObject(1);
        if (branch0.optBoolean(GitConstants.KEY_BRANCH_CURRENT, false))
            assertFalse(branch1.optBoolean(GitConstants.KEY_BRANCH_CURRENT, false));
        else/*w w w .jav  a  2  s . c om*/
            assertTrue(branch1.optBoolean(GitConstants.KEY_BRANCH_CURRENT, false));

        // remove branch
        request = getDeleteGitBranchRequest(branchLocation);
        response = webConversation.getResponse(request);
        assertTrue(HttpURLConnection.HTTP_OK == response.getResponseCode()
                || HttpURLConnection.HTTP_ACCEPTED == response.getResponseCode());

        // list branches again, make sure it's gone
        request = getGetRequest(branchesLocation);
        response = webConversation.getResponse(request);
        ServerStatus status = waitForTask(response);
        assertTrue(status.toString(), status.isOK());
        branches = status.getJsonData();
        branchesArray = branches.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertEquals(1, branchesArray.length());
        JSONObject branch = branchesArray.getJSONObject(0);
        assertTrue(branch.optBoolean(GitConstants.KEY_BRANCH_CURRENT, false));
    }
}

From source file:phex.download.PushRequestSleeper.java

private boolean requestViaPushProxies() {
    assert pushProxyAddresses != null && pushProxyAddresses.length > 0;

    // format: /gnet/push-proxy?guid=<ServentIdAsABase16UrlEncodedString>
    String requestPart = "/gnet/push-proxy?guid=" + clientGUID.toHexString();

    ((SimpleStatisticProvider) statsService
            .getStatisticProvider(StatisticsManager.PUSH_DLDPUSHPROXY_ATTEMPTS_PROVIDER)).increment(1);

    for (int i = 0; i < pushProxyAddresses.length; i++) {
        String urlStr = "http://" + pushProxyAddresses[i].getFullHostName() + requestPart;
        NLogger.debug(PushRequestSleeper.class, "PUSH via push proxy: " + urlStr);

        HttpClient httpClient = HttpClientFactory.createHttpClient();
        httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(1, false));

        httpClient.getParams().setSoTimeout(10000);
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        HeadMethod method = null;//  w  w  w.j  av a 2  s .c o m
        try {
            method = new HeadMethod(urlStr);
            method.addRequestHeader(GnutellaHeaderNames.X_NODE, serventAddress.getFullHostName());
            method.addRequestHeader("Cache-Control", "no-cache");
            method.addRequestHeader(HTTPHeaderNames.CONNECTION, "close");

            int responseCode = httpClient.executeMethod(method);

            NLogger.debug(PushRequestSleeper.class,
                    "PUSH via push proxy response code: " + responseCode + " (" + urlStr + ')');

            // if 202
            if (responseCode == HttpURLConnection.HTTP_ACCEPTED) {
                ((SimpleStatisticProvider) statsService
                        .getStatisticProvider(StatisticsManager.PUSH_DLDPUSHPROXY_SUCESS_PROVIDER))
                                .increment(1);
                return true;
            }
        } catch (IOException exp) {
            NLogger.warn(PushRequestSleeper.class, exp);
        } finally {
            if (method != null) {
                method.releaseConnection();
            }
        }
    }
    return false;
}

From source file:org.eclipse.osee.framework.core.util.HttpProcessor.java

public static boolean isAlive(URL url) {
    boolean isAlive = false;
    boolean recheck = true;
    String key = toIsAliveKey(url);
    Pair<Integer, Long> lastChecked = isAliveMap.get(key);
    if (lastChecked != null) {
        long checkedOffset = System.currentTimeMillis() - lastChecked.getSecond().longValue();
        if (checkedOffset < CHECK_WINDOW) {
            recheck = false;/*w w  w.ja  va  2s . c  o m*/
            isAlive = lastChecked.getFirst() != -1;
        }
    }

    if (recheck) {
        try {
            GetMethod method = new GetMethod(url.toString());
            try {
                HttpMethodParams params = new HttpMethodParams();
                params.setParameter(HttpMethodParams.RETRY_HANDLER,
                        new DefaultHttpMethodRetryHandler(0, false));
                params.setSoTimeout(1000);
                method.setParams(params);
                int responseCode = executeMethod(url, method);
                if (responseCode == HttpURLConnection.HTTP_NOT_FOUND
                        || responseCode == HttpURLConnection.HTTP_ACCEPTED
                        || responseCode == HttpURLConnection.HTTP_ACCEPTED
                        || responseCode == HttpURLConnection.HTTP_OK) {
                    isAlive = true;
                }
            } finally {
                method.releaseConnection();
            }
        } catch (Exception ex) {
            // Do Nothing
        }
    }
    return isAlive;
}

From source file:org.eclipse.orion.server.tests.metastore.RemoteMetaStoreTests.java

/**
 * Create a git close on the Orion server for the test user. Also creates an operation in the metastore for the user.
 * /*  w  ww. ja  va 2  s.c om*/
 * @param webConversation
 * @param login
 * @param password
 * @param project
 * @return
 * @throws URISyntaxException
 * @throws IOException
 * @throws JSONException
 * @throws SAXException 
 */
protected int createGitClone(WebConversation webConversation, String login, String password, String project)
        throws URISyntaxException, IOException, JSONException, SAXException {
    assertEquals(HttpURLConnection.HTTP_OK, login(webConversation, login, password));

    String name = "ahunter orion";
    JSONObject json = new JSONObject();
    json.put("GitUrl", "https://github.com/ahunter-orion/ahunter-orion.github.com.git");
    json.put("Location", "/workspace/" + getWorkspaceId(login));
    WebRequest request = new PostMethodWebRequest(getOrionServerURI("/gitapi/clone/"),
            IOUtilities.toInputStream(json.toString()), "application/json");
    request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_ACCEPTED, response.getResponseCode());

    JSONObject responseJsonObject = new JSONObject(response.getText());
    String location = responseJsonObject.getString("Location");
    JSONObject task = new JSONObject();
    task.put("expires", System.currentTimeMillis() + 86400000);
    task.put("Name", "Cloning repository " + name);
    json = new JSONObject();
    json.put(location, task);
    request = new PutMethodWebRequest(getOrionServerURI("/prefs/user/operations/"),
            IOUtilities.toInputStream(json.toString()), "application/json");
    request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode());

    System.out.println("Created Git Clone: " + name + " at Location: " + location);
    return response.getResponseCode();
}

From source file:com.facebook.buck.rules.HttpArtifactCache.java

public void storeImpl(RuleKey ruleKey, final File file) throws IOException {
    Request request = createRequestBuilder(ruleKey.toString()).put(new RequestBody() {
        @Override//from  ww w. j a  v  a 2 s .  c  om
        public MediaType contentType() {
            return OCTET_STREAM;
        }

        @Override
        public long contentLength() throws IOException {
            return Long.SIZE / Byte.SIZE + projectFilesystem.getFileSize(file.toPath())
                    + hashFunction.bits() / Byte.SIZE;
        }

        @Override
        public void writeTo(BufferedSink sink) throws IOException {
            try (DataOutputStream output = new DataOutputStream(sink.outputStream());
                    InputStream input = projectFilesystem.newFileInputStream(file.toPath());
                    HashingInputStream hasher = new HashingInputStream(hashFunction, input)) {
                output.writeLong(projectFilesystem.getFileSize(file.toPath()));
                ByteStreams.copy(hasher, output);
                output.write(hasher.hash().asBytes());
            }
        }
    }).build();

    Response response = storeCall(request);

    if (response.code() != HttpURLConnection.HTTP_ACCEPTED) {
        LOGGER.warn("store(%s): unexpected response: %d", ruleKey, response.code());
    }
}

From source file:com.tonyodev.fetch.FetchRunnable.java

private boolean isResponseOk(int responseCode) {

    switch (responseCode) {
    case HttpURLConnection.HTTP_OK:
    case HttpURLConnection.HTTP_PARTIAL:
    case HttpURLConnection.HTTP_ACCEPTED:
        return true;
    default:/*from w ww.j a va 2  s .c o  m*/
        return false;
    }
}