本文整理匯總了Java中org.mortbay.http.HttpException類的典型用法代碼示例。如果您正苦於以下問題:Java HttpException類的具體用法?Java HttpException怎麽用?Java HttpException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpException類屬於org.mortbay.http包,在下文中一共展示了HttpException類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import org.mortbay.http.HttpException; //導入依賴的package包/類
@Setup @SuppressWarnings({ "unused", "serial" })
private void setUp(JettyServer server, HttpChannel channel) throws Exception {
this.server = server;
final String path = "/" + channel.getServiceName();
handler = new AbstractHttpHandler() {
public void handle(String pathInContext, String pathParams,
HttpRequest request, HttpResponse response) throws HttpException,
IOException {
if (pathInContext.equals(path)) {
JettyEndpoint.this.handle(pathParams, request, response);
request.setHandled(true);
}
}
};
server.getContext().addHandler(handler);
handler.start();
}
示例2: handle
import org.mortbay.http.HttpException; //導入依賴的package包/類
@Override
protected void handle(String pathParams, HttpRequest request,
HttpResponse response) throws HttpException, IOException {
response.setContentType(request.getContentType());
response.addField("X-Test-Header", "test value");
IOUtils.copy(request.getInputStream(), response.getOutputStream());
}
示例3: handle
import org.mortbay.http.HttpException; //導入依賴的package包/類
@Override
protected IncomingMessage<RESTMessage> handle(HttpRequest request)
throws HttpException, IOException {
List<Parameter> parameters = new LinkedList<Parameter>();
for (Map.Entry<String,List<String>> entry :
((Map<String,List<String>>)request.getParameters()).entrySet()) {
for (String value : entry.getValue()) {
parameters.add(new Parameter(entry.getKey(), value));
}
}
return new IncomingMessage<RESTMessage>(null, new RESTMessage(parameters.toArray(
new Parameter[parameters.size()])));
}
示例4: testGet
import org.mortbay.http.HttpException; //導入依賴的package包/類
@Validated @Test
public void testGet() throws Exception {
Server server = new Server();
SocketListener listener = new SocketListener();
server.addListener(listener);
HttpContext context = new HttpContext(server, "/*");
HttpHandler handler = new AbstractHttpHandler() {
public void handle(String pathInContext, String pathParams,
HttpRequest request, HttpResponse response) throws HttpException, IOException {
try {
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPBody body = message.getSOAPBody();
body.addChildElement("root");
response.setContentType(SOAPConstants.SOAP_1_1_CONTENT_TYPE);
message.writeTo(response.getOutputStream());
request.setHandled(true);
} catch (SOAPException ex) {
throw new RuntimeException("Failed to generate SOAP message", ex);
}
}
};
context.addHandler(handler);
server.start();
try {
SOAPConnectionFactory sf = new SOAPConnectionFactoryImpl();
SOAPConnection con = sf.createConnection();
URL urlEndpoint = new URL("http", "localhost", listener.getPort(), "/test");
SOAPMessage reply = con.get(urlEndpoint);
SOAPElement bodyElement = (SOAPElement)reply.getSOAPBody().getChildElements().next();
assertEquals("root", bodyElement.getLocalName());
} finally {
server.stop();
}
}
示例5: simulateDelay
import org.mortbay.http.HttpException; //導入依賴的package包/類
/**
* Simulates delays in processing requests.
*/
private void simulateDelay() throws HttpException {
try {
Thread.sleep(this.delay);
} catch (InterruptedException e) {
throw new HttpException(500, e.getMessage());
}
}
示例6: handle
import org.mortbay.http.HttpException; //導入依賴的package包/類
@Override
protected void handle(String pathParams, HttpRequest request, HttpResponse response)
throws HttpException, IOException {
support.putMessage(handle(request));
}
示例7: handle
import org.mortbay.http.HttpException; //導入依賴的package包/類
protected abstract void handle(String pathParams, HttpRequest request, HttpResponse response)
throws HttpException, IOException;
示例8: service
import org.mortbay.http.HttpException; //導入依賴的package包/類
@Override
public HttpContext service(final HttpRequest request, final HttpResponse response)
throws IOException, HttpException {
request.setState(HttpMessage.__MSG_EDITABLE);
this.authorizationHttpHeaders.add(request.getHeader().get("Authorization"));
// Read the raw bytes from the request.
final byte[] rawRequestBytes = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return request.getInputStream();
}
}.read();
// Inflate the raw bytes if they are in gzip format.
boolean isGzipFormat = "gzip".equals(request.getHeader().get(HttpFields.__ContentEncoding));
byte[] requestBytes;
if (isGzipFormat) {
requestBytes = new ByteSource(){
@Override
public InputStream openStream() throws IOException {
return new GZIPInputStream(ByteSource.wrap(rawRequestBytes).openStream());
}
}.read();
} else {
requestBytes = rawRequestBytes;
}
// Convert the (possibly inflated) request bytes to a string.
this.requestBodies.add(
ByteSource.wrap(requestBytes).asCharSource(Charset.forName(UTF_8)).read());
this.requestBodiesCompressionStates.add(isGzipFormat);
// Simulate a delay in processing.
simulateDelay();
new ByteSink() {
@Override
public OutputStream openStream() {
return response.getOutputStream();
}
}.asCharSink(Charset.forName(UTF_8)).write(mockResponseBodies.get(numInteractions++));
return getContext(getServerUrl());
}