本文整理匯總了Java中org.apache.http.MethodNotSupportedException類的典型用法代碼示例。如果您正苦於以下問題:Java MethodNotSupportedException類的具體用法?Java MethodNotSupportedException怎麽用?Java MethodNotSupportedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MethodNotSupportedException類屬於org.apache.http包,在下文中一共展示了MethodNotSupportedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newHttpRequest
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
private HttpUriRequest newHttpRequest(String method, URI uri)
throws MethodNotSupportedException
{
if (method == "GET")
return new HttpGet(uri);
if (method == "POST")
return new HttpPost(uri);
if (method == "PUT")
return new HttpPut(uri);
if (method == "DELETE")
return new HttpDelete(uri);
if (method == "PATCH")
return new HttpPatch(uri);
throw new MethodNotSupportedException(
"Invalid method \"" + method + "\""
);
}
示例2: handleException
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
/**
* Handles the given exception and generates an HTTP response to be sent
* back to the client to inform about the exceptional condition encountered
* in the course of the request processing.
*
* @param ex the exception.
* @param response the HTTP response.
*/
protected void handleException(final HttpException ex, final HttpResponse response) {
if (ex instanceof MethodNotSupportedException) {
response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
} else if (ex instanceof UnsupportedHttpVersionException) {
response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
} else if (ex instanceof ProtocolException) {
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
} else {
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
String message = ex.getMessage();
if (message == null) {
message = ex.toString();
}
byte[] msg = EncodingUtils.getAsciiBytes(message);
ByteArrayEntity entity = new ByteArrayEntity(msg);
entity.setContentType("text/plain; charset=US-ASCII");
response.setEntity(entity);
}
示例3: newHttpRequest
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
public HttpRequest newHttpRequest(final RequestLine requestline)
throws MethodNotSupportedException {
if (requestline == null) {
throw new IllegalArgumentException("Request line may not be null");
}
String method = requestline.getMethod();
if (isOneOf(RFC2616_COMMON_METHODS, method)) {
return new BasicHttpRequest(requestline);
} else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
return new BasicHttpEntityEnclosingRequest(requestline);
} else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
return new BasicHttpRequest(requestline);
} else {
throw new MethodNotSupportedException(method + " method not supported");
}
}
示例4: handle
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
public void handle(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (!method.equals("GET") && !method.equals("HEAD")) {
throw new MethodNotSupportedException(method + " method not supported");
}
final EntityTemplate body = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write(mJSON);
writer.flush();
}
});
response.setStatusCode(HttpStatus.SC_OK);
body.setContentType("text/json; charset=UTF-8");
response.setEntity(body);
}
示例5: handle
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
/**
* Handles a request by echoing the incoming request entity.
* If there is no request entity, an empty document is returned.
*
* @param request the request
* @param response the response
* @param context the context
*
* @throws org.apache.http.HttpException in case of a problem
* @throws java.io.IOException in case of an IO problem
*/
@Override
public void handle(final HttpRequest request,
final HttpResponse response,
final HttpContext context)
throws HttpException, IOException {
final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT);
if (!"GET".equals(method) &&
!"POST".equals(method) &&
!"PUT".equals(method)
) {
throw new MethodNotSupportedException
(method + " not supported by " + getClass().getName());
}
response.setStatusCode(org.apache.http.HttpStatus.SC_OK);
response.addHeader("Cache-Control",getCacheContent(request));
final byte[] content = getHeaderContent(request);
final ByteArrayEntity bae = new ByteArrayEntity(content);
response.setHeader("Connection","keep-alive");
response.setEntity(bae);
}
示例6: newHttpRequest
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
@Override
public HttpRequest newHttpRequest(String method, String uri)
throws MethodNotSupportedException {
RequestLine line = new BasicRequestLine(method, uri, HttpVersion.HTTP_1_1);
HttpUriRequest request = null;
if(method.equals(HttpGet.METHOD_NAME)){
request = new HttpGet(uri);
}else if(method.equals(HttpPost.METHOD_NAME)){
request = new HttpPost(uri);
}else if(method.equals(HttpPut.METHOD_NAME)){
request = new HttpPut(uri);
}else if(method.equals(HttpPut.METHOD_NAME)){
request = new HttpDelete(uri);
}
return request;
}
示例7: newHttpRequest
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
public HttpRequest newHttpRequest(final RequestLine requestline)
throws MethodNotSupportedException {
if (requestline == null) {
throw new IllegalArgumentException("Request line may not be null");
}
String method = requestline.getMethod();
if (isOneOf(RFC2616_COMMON_METHODS, method)) {
return new RecordedHttpRequest(requestline, messdata);
} else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
return new RecordedHttpEntityEnclosingRequest(requestline, messdata);
} else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
return new RecordedHttpRequest(requestline, messdata);
} else {
throw new MethodNotSupportedException(method + " method not supported");
}
}
示例8: getHttpRequest
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
private HttpRequest getHttpRequest(String user, String pass){
HttpRequestFactory factory = new DefaultHttpRequestFactory();
HttpRequest req = null;
String base64 = new String(Base64.encodeBase64(
user.concat(":").concat(pass).getBytes()));
try {
req = factory.newHttpRequest(
new BasicRequestLine("POST", "https://localhost:8444/",
HttpVersion.HTTP_1_1));
req.addHeader("Accept-Encoding", "gzip,deflate");
req.addHeader("Content-Type", "application/soap+xml;charset=UTF-8");
req.addHeader("User-Agent", "IROND Testsuite/1.0");
req.addHeader("Host", "localhost:8444");
req.addHeader("Content-Length", "198");
req.addHeader("Authorization", "Basic "+base64);
} catch (MethodNotSupportedException e) {
e.printStackTrace();
}
return req;
}
示例9: getBean
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
protected Object getBean() throws MethodNotSupportedException {
Object bean = Socialize.getBean(delegateBean);
if(bean != null) {
return bean;
}
else {
throw new MethodNotSupportedException("No bean with name [" +
delegateBean +
"] found");
}
}
示例10: newHttpRequest
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
public HttpRequest newHttpRequest(final RequestLine requestline)
throws MethodNotSupportedException {
Args.notNull(requestline, "Request line");
final String method = requestline.getMethod();
if (isOneOf(RFC2616_COMMON_METHODS, method)) {
return new BasicHttpRequest(requestline);
} else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
return new BasicHttpEntityEnclosingRequest(requestline);
} else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
return new BasicHttpRequest(requestline);
} else {
throw new MethodNotSupportedException(method + " method not supported");
}
}
示例11: handle
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
/**
* Handles a request by echoing the incoming request entity.
* If there is no request entity, an empty document is returned.
*
* @param request the request
* @param response the response
* @param context the context
*
* @throws HttpException in case of a problem
* @throws IOException in case of an IO problem
*/
@Override
public void handle(final HttpRequest request,
final HttpResponse response,
final HttpContext context)
throws HttpException, IOException {
final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT);
if (!"GET".equals(method) &&
!"POST".equals(method) &&
!"PUT".equals(method)
) {
throw new MethodNotSupportedException
(method + " not supported by " + getClass().getName());
}
HttpEntity entity = null;
if (request instanceof HttpEntityEnclosingRequest) {
entity = ((HttpEntityEnclosingRequest)request).getEntity();
}
// For some reason, just putting the incoming entity into
// the response will not work. We have to buffer the message.
byte[] data;
if (entity == null) {
data = new byte [0];
} else {
data = EntityUtils.toByteArray(entity);
}
final ByteArrayEntity bae = new ByteArrayEntity(data);
if (entity != null) {
bae.setContentType(entity.getContentType());
}
entity = bae;
response.setStatusCode(HttpStatus.SC_OK);
response.setEntity(entity);
}
示例12: handleHasRpcToken
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
/**
*
* Handles method invocations to the {@link HasRpcToken} interface
* implemented by the service. Also handles Annotation of service with
* {@link RpcTokenImplementation}
*
* @throws ClassNotFoundException
* if base service interface class cannot be found if actual
* implemented interface is Async
*
* @since 0.5
*/
protected Object handleHasRpcToken(Object proxy, Method method,
Object[] args) throws MethodNotSupportedException,
NoSuchMethodException, ClassNotFoundException {
if (HasRpcToken.class.getMethod("setRpcToken", RpcToken.class).equals(
method)) {
// Check if service has annotation defining the Token class and
// that this token matches the specified class
Class<?> srvcIntf = determineProxyServiceBaseInterface(proxy);
if (srvcIntf != null) {
RpcTokenImplementation rti = srvcIntf
.getAnnotation(RpcTokenImplementation.class);
// Replace $ in class name in order to handle inner classes
if (rti != null
&& !args[0].getClass().getName().replace("$", ".")
.equals(rti.value())) {
throw new RpcTokenException("Incorrect Token Class. Got "
+ args[0].getClass().getName() + " but expected: "
+ rti.value());
}
}
this.token = (RpcToken) args[0];
return null;
} else if (HasRpcToken.class.getMethod("getRpcToken").equals(method)) {
return this.token;
} else if (HasRpcToken.class.getMethod("setRpcTokenExceptionHandler",
RpcTokenExceptionHandler.class).equals(method)) {
this.rpcTokenExceptionHandler = (RpcTokenExceptionHandler) args[0];
return null;
} else if (HasRpcToken.class.getMethod("setRpcTokenExceptionHandler",
RpcTokenExceptionHandler.class).equals(method)) {
return this.rpcTokenExceptionHandler;
}
throw new MethodNotSupportedException("Method: " + method.getName()
+ " in class: " + method.getDeclaringClass().getName()
+ " not defined for class: " + proxy.getClass().getName());
}
示例13: handleServiceDefTarget
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
/**
* Handles method invocations to the {@link ServiceDefTarget} interface
* implemented by the service.
*/
protected Object handleServiceDefTarget(Object proxy, Method method,
Object[] args) throws Throwable {
if (ServiceDefTarget.class.getMethod("getSerializationPolicyName")
.equals(method)) {
return this.settings.getPolicyName();
} else if (ServiceDefTarget.class.getMethod("setServiceEntryPoint",
String.class).equals(method)) {
this.serviceEntryPoint = (String) args[0];
// Modify current base and relative Path to newly specific
// serviceEntryPoint assuming that base path is part of
// serviceEntryPoint
// TODO May not be a valid assumption
if (this.serviceEntryPoint.contains(this.settings
.getModuleBaseUrl())) {
this.settings
.setRemoteServiceRelativePath(this.serviceEntryPoint
.split(this.settings.getModuleBaseUrl())[1]);
} else {
this.logger.warning("Unable to determine base (orig: "
+ this.settings.getModuleBaseUrl() + ") against: "
+ this.serviceEntryPoint);
throw new SyncProxyException(
determineProxyServiceBaseInterface(proxy),
InfoType.SERVICE_BASE_DELTA);
}
return null;
} else if (ServiceDefTarget.class.getMethod("getServiceEntryPoint")
.equals(method)) {
return this.serviceEntryPoint;
}
// TODO handle all methods
throw new MethodNotSupportedException("Method: " + method.getName()
+ " in class: " + method.getDeclaringClass().getName()
+ " not defined for class: " + proxy.getClass().getName());
}
示例14: createHttpRequest
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
protected HttpUriRequest createHttpRequest(UpnpMessage upnpMessage, UpnpRequest upnpRequestOperation) throws MethodNotSupportedException {
switch (upnpRequestOperation.getMethod()) {
case GET:
return new HttpGet(upnpRequestOperation.getURI());
case SUBSCRIBE:
return new HttpGet(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.SUBSCRIBE.getHttpName();
}
};
case UNSUBSCRIBE:
return new HttpGet(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.UNSUBSCRIBE.getHttpName();
}
};
case POST:
HttpEntityEnclosingRequest post = new HttpPost(upnpRequestOperation.getURI());
post.setEntity(createHttpRequestEntity(upnpMessage));
return (HttpUriRequest) post; // Fantastic API
case NOTIFY:
HttpEntityEnclosingRequest notify = new HttpPost(upnpRequestOperation.getURI()) {
@Override
public String getMethod() {
return UpnpRequest.Method.NOTIFY.getHttpName();
}
};
notify.setEntity(createHttpRequestEntity(upnpMessage));
return (HttpUriRequest) notify; // Fantastic API
default:
throw new MethodNotSupportedException(upnpRequestOperation.getHttpMethodName());
}
}
示例15: newHttpRequest
import org.apache.http.MethodNotSupportedException; //導入依賴的package包/類
public HttpRequest newHttpRequest(final RequestLine requestline)
throws MethodNotSupportedException {
if (requestline == null) {
throw new IllegalArgumentException("Request line may not be null");
}
String method = requestline.getMethod();
String uri = requestline.getUri();
return newHttpRequest(method, uri);
}