當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpException類代碼示例

本文整理匯總了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();
}
 
開發者ID:wso2,項目名稱:wso2-axis2-transports,代碼行數:19,代碼來源:JettyEndpoint.java

示例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());
}
 
開發者ID:wso2,項目名稱:wso2-axis2-transports,代碼行數:9,代碼來源:JettyEchoEndpoint.java

示例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()])));
}
 
開發者ID:wso2,項目名稱:wso2-axis2-transports,代碼行數:15,代碼來源:JettyRESTAsyncEndpoint.java

示例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();
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:36,代碼來源:SOAPConnectionTest.java

示例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());
  }
}
 
開發者ID:googleads,項目名稱:googleads-java-lib,代碼行數:11,代碼來源:TestHttpServer.java

示例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));
}
 
開發者ID:wso2,項目名稱:wso2-axis2-transports,代碼行數:7,代碼來源:JettyAsyncEndpoint.java

示例7: handle

import org.mortbay.http.HttpException; //導入依賴的package包/類
protected abstract void handle(String pathParams, HttpRequest request, HttpResponse response)
throws HttpException, IOException;
 
開發者ID:wso2,項目名稱:wso2-axis2-transports,代碼行數:3,代碼來源:JettyEndpoint.java

示例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());
}
 
開發者ID:googleads,項目名稱:googleads-java-lib,代碼行數:47,代碼來源:TestHttpServer.java


注:本文中的org.mortbay.http.HttpException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。