List of usage examples for org.apache.commons.httpclient HttpStatus SC_FORBIDDEN
int SC_FORBIDDEN
To view the source code for org.apache.commons.httpclient HttpStatus SC_FORBIDDEN.
Click Source Link
From source file:org.eclipse.lyo.testsuite.oslcv2.cm.ChangeRequestJsonTests.java
public ChangeRequestJsonTests(String thisUrl) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, NullPointerException, JSONException { super(thisUrl); // If currentUrl is null, it means that the query didn't match any // records. This isn't exactly a failure, but there's nothing more we // can test.//from w ww .j a v a 2s . co m assumeNotNull(currentUrl); response = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl, basicCreds, OSLCConstants.CT_JSON, headers); responseBody = EntityUtils.toString(response.getEntity()); int sc = response.getStatusLine().getStatusCode(); // Some records in the system might not be accessible to this user. This // isn't a failure, but there's nothing more we can test. assumeTrue(sc != HttpStatus.SC_FORBIDDEN && sc != HttpStatus.SC_UNAUTHORIZED); // Make sure the request succeeded before continuing. assertEquals(HttpStatus.SC_OK, sc); //Get JSON doc from response JSONArtifact userData = JSON.parse(responseBody); if (userData instanceof JSONArtifact) { doc = (JSONObject) userData; } }
From source file:org.eclipse.lyo.testsuite.oslcv2.cm.ChangeRequestRdfXmlTests.java
public ChangeRequestRdfXmlTests(String url) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { super(url);// www . ja va 2s . c o m // If currentUrl is null, it means that the query didn't match any // records. This isn't exactly a failure, but there's nothing more we // can test. assumeNotNull(currentUrl); response = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl, basicCreds, OSLCConstants.CT_RDF, headers); // Some records in the system might not be accessible to this user. This // isn't a failure, but there's nothing more we can test. int sc = response.getStatusLine().getStatusCode(); assumeTrue(sc != HttpStatus.SC_FORBIDDEN && sc != HttpStatus.SC_UNAUTHORIZED); // Make sure the request succeeded before continuing. assertEquals(HttpStatus.SC_OK, sc); fRdfModel.read(response.getEntity().getContent(), OSLCUtils.absoluteUrlFromRelative(setupBaseUrl, currentUrl), OSLCConstants.JENA_RDF_XML); RDFUtils.validateModel(fRdfModel); fResource = (Resource) fRdfModel.getResource(currentUrl); assumeTrue(fRdfModel.contains(fResource, RDF.type, fRdfModel.createResource(OSLCConstants.CM_CHANGE_REQUEST_TYPE))); }
From source file:org.eclipse.lyo.testsuite.oslcv2.cm.ChangeRequestXmlTests.java
public ChangeRequestXmlTests(String thisUrl) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { super(thisUrl); // If currentUrl is null, it means that the query didn't match any // records. This isn't exactly a failure, but there's nothing more we // can test./* w w w .j a v a2s .c o m*/ assumeNotNull(currentUrl); response = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl, basicCreds, OSLCConstants.CT_XML, headers); responseBody = EntityUtils.toString(response.getEntity()); int sc = response.getStatusLine().getStatusCode(); // Some records in the system might not be accessible to this user. This // isn't a failure, but there's nothing more we can test. assumeTrue(sc != HttpStatus.SC_FORBIDDEN && sc != HttpStatus.SC_UNAUTHORIZED); // Make sure the request succeeded before continuing. assertEquals(HttpStatus.SC_OK, sc); //Get XML Doc from response doc = OSLCUtils.createXMLDocFromResponseBody(responseBody); }
From source file:org.eclipse.lyo.testsuite.oslcv2.CoreResourceJsonTests.java
public CoreResourceJsonTests(String thisUrl) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, NullPointerException, JSONException { super(thisUrl); // If currentUrl is null, it means that the query didn't match any // records. This isn't exactly a failure, but there's nothing more we // can test./*w w w. java 2 s .com*/ assumeNotNull(currentUrl); response = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl, creds, OSLCConstants.CT_JSON, headers); responseBody = EntityUtils.toString(response.getEntity()); int sc = response.getStatusLine().getStatusCode(); // Some records in the system might not be accessible to this user. This // isn't a failure, but there's nothing more we can test. assumeTrue(sc != HttpStatus.SC_FORBIDDEN && sc != HttpStatus.SC_UNAUTHORIZED); // Make sure the request succeeded before continuing. assertEquals(HttpStatus.SC_OK, sc); //Get JSON doc from response JSONArtifact userData = JSON.parse(responseBody); if (userData instanceof JSONArtifact) { doc = (JSONObject) userData; } }
From source file:org.eclipse.lyo.testsuite.oslcv2.CoreResourceRdfXmlTests.java
public CoreResourceRdfXmlTests(String thisUrl) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, NullPointerException { super(thisUrl); // If currentUrl is null, it means that the query didn't match any // records. This isn't exactly a failure, but there's nothing more we // can test.// w ww .ja v a 2s. c om assumeNotNull(currentUrl); response = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl, creds, OSLCConstants.CT_RDF, headers); // Some records in the system might not be accessible to this user. This // isn't a failure, but there's nothing more we can test. int sc = response.getStatusLine().getStatusCode(); assumeTrue(sc != HttpStatus.SC_FORBIDDEN && sc != HttpStatus.SC_UNAUTHORIZED); // Make sure the request succeeded before continuing. assertEquals(HttpStatus.SC_OK, sc); fRdfModel.read(response.getEntity().getContent(), OSLCUtils.absoluteUrlFromRelative(setupBaseUrl, currentUrl), OSLCConstants.JENA_RDF_XML); RDFUtils.validateModel(fRdfModel); fResource = (Resource) fRdfModel.getResource(currentUrl); if (logger.isDebugEnabled()) { StringWriter w = new StringWriter(); fRdfModel.write(w, "TURTLE"); logger.debug(String.format("Testing Resource <%s> with type <%s>", currentUrl, getResourceType())); logger.debug(w.toString()); } String resourceType = getResourceType(); if (resourceType != null && !"".equals(resourceType)) { assumeTrue(fRdfModel.contains(fResource, RDF.type, fRdfModel.createResource(getResourceType()))); } }
From source file:org.eclipse.lyo.testsuite.oslcv2.CoreResourceXmlTests.java
public CoreResourceXmlTests(String thisUrl) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { super(thisUrl); // If currentUrl is null, it means that the query didn't match any // records. This isn't exactly a failure, but there's nothing more we // can test./*w w w .j a v a 2 s. co m*/ assumeNotNull(currentUrl); response = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl, creds, OSLCConstants.CT_XML, headers); responseBody = EntityUtils.toString(response.getEntity()); int sc = response.getStatusLine().getStatusCode(); // Some records in the system might not be accessible to this user. This // isn't a failure, but there's nothing more we can test. assumeTrue(sc != HttpStatus.SC_FORBIDDEN && sc != HttpStatus.SC_UNAUTHORIZED); // Make sure the request succeeded before continuing. assertEquals(HttpStatus.SC_OK, sc); //Get XML Doc from response doc = OSLCUtils.createXMLDocFromResponseBody(responseBody); }
From source file:org.eclipse.mylyn.commons.net.http.CommonHttpClient3.java
protected boolean needsReauthentication(int code, IProgressMonitor monitor) throws IOException { final AuthenticationType authenticationType; if (code == HttpStatus.SC_UNAUTHORIZED || code == HttpStatus.SC_FORBIDDEN) { authenticationType = AuthenticationType.HTTP; } else if (code == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { authenticationType = AuthenticationType.PROXY; } else {// w ww . j a v a 2 s . c o m return false; } try { location.requestCredentials(authenticationType, null, monitor); } catch (UnsupportedRequestException e) { IOException ioe = new IOException(HttpStatus.getStatusText(code)); ioe.initCause(e); throw ioe; } catch (UnsupportedOperationException e) { IOException ioe = new IOException(HttpStatus.getStatusText(code)); ioe.initCause(e); throw ioe; } return true; }
From source file:org.eclipse.mylyn.github.internal.GitHubService.java
private void executeMethod(HttpMethod method) throws GitHubServiceException { int status;//from w w w.j av a2 s. co m try { status = httpClient.executeMethod(method); } catch (HttpException e) { throw new GitHubServiceException(e); } catch (IOException e) { throw new GitHubServiceException(e); } if (status != HttpStatus.SC_OK) { switch (status) { case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_FORBIDDEN: throw new PermissionDeniedException(method.getStatusLine()); default: throw new GitHubServiceException(method.getStatusLine()); } } }
From source file:org.eclipse.mylyn.internal.commons.xmlrpc.XmlRpcOperation.java
protected Object executeCall(IProgressMonitor monitor, String method, Object... parameters) throws XmlRpcException { try {/*from w w w . j a va 2 s . co m*/ if (CommonXmlRpcClient.DEBUG_XMLRPC) { System.err.println("Calling " + client.getLocation().getUrl() + ": " + method + " " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + CoreUtil.toString(parameters)); } AuthenticationCredentials credentials = client.updateCredentials(); XmlRpcClientRequest request = new XmlRpcClientRequest(client.getClient().getClientConfig(), getXmlRpcUrl(credentials), method, parameters, monitor); return client.getClient().execute(request); } catch (XmlRpcHttpException e) { handleAuthenticationException(e.code, e.getAuthScheme()); // if not handled, re-throw exception throw e; } catch (XmlRpcIllegalContentTypeException e) { throw e; } catch (XmlRpcException e) { // XXX work-around for http://trac-hacks.org/ticket/5848 if ("XML_RPC privileges are required to perform this operation".equals(e.getMessage()) //$NON-NLS-1$ || e.code == XML_FAULT_PERMISSION_DENIED) { handleAuthenticationException(HttpStatus.SC_FORBIDDEN, null); // should never happen as call above should always throw an exception throw new XmlRpcRemoteException(e); } else if (isNoSuchMethodException(e)) { throw new XmlRpcNoSuchMethodException(e); } else { throw new XmlRpcRemoteException(e); } } catch (OperationCanceledException e) { throw e; } catch (Exception e) { throw new XmlRpcException("Unexpected exception", e); //$NON-NLS-1$ } }
From source file:org.eclipse.mylyn.internal.commons.xmlrpc.XmlRpcOperation.java
protected boolean handleAuthenticationException(int code, AuthScheme authScheme) throws XmlRpcException { if (code == HttpStatus.SC_UNAUTHORIZED) { if (CommonXmlRpcClient.DEBUG_AUTH) { System.err.println(client.getLocation().getUrl() + ": Unauthorized (" + code + ")"); //$NON-NLS-1$ //$NON-NLS-2$ }/*from w w w. j a va2s . com*/ client.digestScheme = null; XmlRpcLoginException exception = new XmlRpcLoginException(); exception.setNtlmAuthRequested(authScheme instanceof NTLMScheme); throw exception; } else if (code == HttpStatus.SC_FORBIDDEN) { if (CommonXmlRpcClient.DEBUG_AUTH) { System.err.println(client.getLocation().getUrl() + ": Forbidden (" + code + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } client.digestScheme = null; throw new XmlRpcPermissionDeniedException(); } else if (code == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { if (CommonXmlRpcClient.DEBUG_AUTH) { System.err .println(client.getLocation().getUrl() + ": Proxy authentication required (" + code + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } throw new XmlRpcProxyAuthenticationException(); } return false; }