1. 程式人生 > >Java Code Examples for com.sun.net.httpserver.HttpExchange.getResponseHeaders()

Java Code Examples for com.sun.net.httpserver.HttpExchange.getResponseHeaders()

The following are Jave code examples for showing how to use getResponseHeaders() of theclass. You can vote up the examples you like. Your votes will be used in our system to get more good examples. 

+ Save this method Example 1
Project: fourinone-master View Source
Vote up 6 votes
publicvoid handle(HttpExchange exchange)throwsIOException{/*InputStream is = t.getRequestBody();
    String response = "response ok";
    t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length());
    OutputStream os = t.getResponseBody();
    os.write(response.getBytes());
    os.close();
    */
Headers responseHeaders = exchange.getResponseHeaders(); responseHeaders.set("Content-Type","text/html");String response =ConfigContext.getRequest(ConfigContext.getProp("RSPE404")); exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, response.length());OutputStream os = exchange.getResponseBody
(); os.write(response.getBytes()); os.close();}
Example 2
Project: victims-lib-java-master View Source Vote up 6 votes
publicvoid handle(HttpExchange exchange){try{Headers headers = exchange.getResponseHeaders();
        headers.add("Content-Type","application/json");

        exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK,
                json.length);OutputStream os = exchange.getResponseBody();
        os.write(json);
        os.close();}catch(Exception e){
        e.printStackTrace();}}
Example 3
Project: Fourinone-master View Source Vote up 6 votes
publicvoid handle(HttpExchange exchange)throwsIOException{/*InputStream is = t.getRequestBody();
    String response = "response ok";
    t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length());
    OutputStream os = t.getResponseBody();
    os.write(response.getBytes());
    os.close();
    */Headers responseHeaders = exchange.getResponseHeaders();
	responseHeaders.set("Content-Type","text/html");String response =ConfigContext.getRequest(ConfigContext.getProp("RSPE404"));
	exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, response.length());OutputStream os = exchange.getResponseBody();
	os.write(response.getBytes());
	os.close();}
Example 4
Project: mock-httpserver-master View Source Vote up 6 votes
privatevoid sendHeaders(HttpExchange httpExchange,Response response)throwsIOException{int length = response.getContent().getLength();int statusCode = response.getStatus().getStatusCode();Headers responseHeaders = httpExchange.getResponseHeaders();Header headers = response.getHeader();for(String headerField : headers.getHeaderFields()){for(Header.Parameter value : headers.getHeaderParameter(headerField)){
            responseHeaders.add(headerField, value.toString());}}
    addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_ENCODING, response.getContent().getEncoding());
    addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_LANGUAGE, response.getContent().getLanguage());
    addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_MD5, response.getContent().getMd5());
    addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_TYPE, response.getContent().getComposedContentType());
    addHeaderIfSet(responseHeaders,Header.Fields.CONTENT_RANGE, response.getContent().getRange());
    httpExchange.sendResponseHeaders(statusCode, max(0, length));}
Example 5
Project: product-esb-master View Source Vote up 6 votes
publicvoid handle(HttpExchange t)throwsIOException{Headers h = t.getResponseHeaders();
			h.add("Content-Type", contentType);String response ="This Content type test case";
			t.sendResponseHeaders(200, response.length());OutputStream os = t.getResponseBody();
			os.write(response.getBytes());
			os.close();}
Example 6
Project: werval-master 

相關推薦

Java Code Examples for com.sun.net.httpserver.HttpExchange.getResponseHeaders()

The following are Jave code examples for showing how to use getResponseHeaders() of theclass. You can vote up the examples you like. Your votes wi

Java Code Examples for com.mongodb.client.gridfs.GridFSBucket

Mongo Java Code Examples for com.mongodb.client.gridfs.GridFSBucket 以下是顯示如何使用com.mongodb.client.gridfs.GridFSBucket的示例。 Exa

Java Code Examples for javax.persistence.criteria.CriteriaBuilder

Java Code Examples for javax.persistence.criteria.Root The following are top voted examples for showing how to use javax.persiste

Https協議報錯:com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl解決方法

toc 使用 地址 bae aaaaa line 點擊 pro details 旭日Follow_24 的CSDN 博客 ,全文地址請點擊: https://blog.csdn.net/xuri24/article/details/82220333 所用應用服務器:JBos

java.lang.NullPointerException at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmen

ant的時候,老是ant failed, 報的錯誤是空指標 BUILD FAILED build.xml:210: java.lang.NullPointerException         at

java.io.IOException: Server returned HTTP response code: 411 for URL: http://upas.d.com/upas/......

最近專案升版本,遇到一些問題,寫出來分享一下: 第一,pom.xml檔案中版本的資訊已經改了,但是在編譯打包的時候,還有以前的版本資訊,觀察Dependency Hierarchy,發現別的包依賴以前的版本資訊,在pom.xml中強行轉化成新版本: 但是改過後,以前的版本資訊還是存在,百思不

SpringCloud服務註冊啟動的時候報錯(com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException)

啟動服務提供者的時候突然給我報這個錯,一開始也是有點懵逼的,因為Eureka服務端已經被我正常啟動了,註冊服務啟動卻報錯了,上網查了相關的錯誤也都是在說:Eureka服務端 需要加兩條配置,不然服務端會自己註冊自己之類的,但是那兩條配置都是已經存在的 相應的註解在啟動類上也都是添加了的,服

Spring Boot專案啟動報錯com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connec

報錯內容: com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect 或者com.netflix.discovery.s

Eureka報錯“com.sun.jersey.api.client.ClientHandlerException : java.net.ConnectException : Connection”

場景: 一個eureka server,一個client,且eureka server配置如下: spring.application.name=eureka server.port=9100 eureka.client.register-with-eureka=false eu

Problem: Spring Cloud:com.sun.jersey.api.client.ClientHandlerException:java.net.UnknownHostException

Problem com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: mss-eureka1 Caused by: java.net.UnknownHostException

Eureka報錯“com.sun.jersey.api.client.ClientHandlerException : java.net.ConnectException : Connection”

場景: 一個eureka server,一個client,且eureka server配置如下: spring.application.name=eureka server.port=9100 eureka.client.register-with-eureka

java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger for JUnit test case for Java mail

The JavaMail API is available as an optional package for use with Java SE platform and is also included in the Java EE platform. 99% that

springcloud 向Eureka中註冊服務異常 com.sun.jersey.api.client.ClientHandlerException:java.net.ConnectException: Connection refused: connect

默認 handle cte localhost 文件 con refused exce idt 異常如下: 通過debug發現,服務端的url地址仍然是默認的http://localhost:8761/eureka/apps/,也就是說yml文件中配置沒有生效,檢查後發

java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener

java lang class <!-- 導入java ee jar 包 --> <dependency> <groupId>javax</groupId> <artif

關於java.io.IOException: Server returned HTTP response code: 400 for URL報錯和string.getBytes()字符集

cep amr 單引號 驗證 sco app response spa tin 400 請求出錯:由於語法格式有誤,服務器無法理解此請求總論:這種錯誤應該會有很多原因,這裏指出的是因為字符集編碼的原因導致400,主要代碼:向服務器發送請求傳輸json參數用的是out.wri

java.lang.ClassNotFoundException: com.sun.xml.ws.spi.ProviderImpl解決辦法

get -- 現在 rim otf jar eclips 示例 升級 問題現象:   這種很可能出現在獨立一個簡單示例項目中可以用,但是在把webService模塊加入系統後,報出這類錯誤。 Exception in thread "main" javax.xml.ws.

java.lang.NoSuchMethodException: com.sun.proxy.$Proxy

eth AC nsa nal class dex 整合 成功 method 刪掉了@Transactional註解,結果成功了 是這個註解造成的。 是ssh2的整合強制我們使用分層架構。java.lang.NoSuchMethodException: com.sun.pro

java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC 問題

今天寫一個client 呼叫webservice 出現了一個這個問題,找了好久也沒有一個答案,老報錯, javax.xml.bind.JAXBException - with linked exception: [java.lang.ClassNotFoundException: com/su

java.uti.List包和com.sun.util.List包區別

                          java.uti.List包和com.sun.util.List包區別 先來理一下ssm框架:首先請求呼叫cont

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger解決方法

今天用MailUitl工具類傳送郵件報如下錯誤。。。 錯誤提示: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger at javax.mail.Session.