use of org.apache.cxf.io.CachedOutputStream in project camel by apache.
the class CamelOutputStream method commitOutputMessage.
private void commitOutputMessage() throws IOException {
ExchangePattern pattern;
if (isOneWay) {
pattern = ExchangePattern.InOnly;
} else {
pattern = ExchangePattern.InOut;
}
LOG.debug("send the message to endpoint {}", this.targetCamelEndpointUri);
final org.apache.camel.Exchange exchange = this.producer.createExchange(pattern);
exchange.setProperty(Exchange.TO_ENDPOINT, this.targetCamelEndpointUri);
CachedOutputStream outputStream = (CachedOutputStream) outMessage.getContent(OutputStream.class);
// Send out the request message here, copy the protocolHeader back
CxfHeaderHelper.propagateCxfToCamel(this.headerFilterStrategy, outMessage, exchange.getIn(), exchange);
// TODO support different encoding
exchange.getIn().setBody(outputStream.getInputStream());
LOG.debug("template sending request: ", exchange.getIn());
if (outMessage.getExchange().isSynchronous()) {
syncInvoke(exchange);
} else {
// submit the request to the work queue
asyncInvokeFromWorkQueue(exchange);
}
}
use of org.apache.cxf.io.CachedOutputStream in project camel by apache.
the class CxfMessageHelperTest method toString.
private String toString(InputStream is) throws IOException {
StringBuilder out = new StringBuilder();
CachedOutputStream os = new CachedOutputStream();
IOHelper.copy(is, os);
is.close();
os.writeCacheTo(out);
return out.toString();
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class HugeResponseInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
if (type.equals(ResponseInterceptorType.overflow)) {
throw new StackOverflowError();
} else if (type.equals(ResponseInterceptorType.ElementLevelThreshold)) {
InputStream is = message.getContent(InputStream.class);
if (is != null) {
CachedOutputStream bos = new CachedOutputStream();
try {
is = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralRespBreakThreshold.xml");
IOUtils.copy(is, bos);
bos.flush();
is.close();
message.setContent(InputStream.class, bos.getInputStream());
bos.close();
message.setContent(InputStream.class, bos.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
}
} else if (type.equals(ResponseInterceptorType.ElementCountThreshold)) {
InputStream is = message.getContent(InputStream.class);
if (is != null) {
CachedOutputStream bos = new CachedOutputStream();
try {
is = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/systest/dispatch/resources/" + "GreetMeDocLiteralRespBreakElementCountThreshold.xml");
IOUtils.copy(is, bos);
bos.flush();
is.close();
message.setContent(InputStream.class, bos.getInputStream());
bos.close();
message.setContent(InputStream.class, bos.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project 1teamProject by iso159.
the class AnimalController method shelterAnimalList.
// 보호소 등록코드별 보호 유기동물리스트 api
@RequestMapping(value = "/animal/yugiAnimalList", method = RequestMethod.POST)
public void shelterAnimalList(HttpServletResponse response, HttpSession session, @RequestParam(value = "animalStatusKind") String animalStatusKind) {
logger.debug("shelterAnimalList(...) 메서드 호출");
logger.debug("shelterAnimalList(...) 메서드 animalStatusKind is {}", animalStatusKind);
String blCode = (String) session.getAttribute("loginBlCode");
if (blCode == null) {
return;
}
BusinessLicense businessLicense = shelterService.getOneBusinessLicense(blCode);
String careRegNo = businessLicense.getBlShelterRegNumber();
logger.debug("shelterAnimalList(...) 메서드 businessLicense is {}", businessLicense);
logger.debug("shelterAnimalList(...) 메서드 careRegNo is {}", careRegNo);
if (careRegNo == null) {
return;
}
response.setContentType("text/html; charset=utf-8");
String addr = "http://openapi.animal.go.kr/openapi/service/rest/abandonmentPublicSrvc/abandonmentPublic?ServiceKey=";
String serviceKey = "7s3CsUFyR%2F1QMd5tktqM%2BnUw9gAEPUtI0GIsuGWxEUOJHwZP9NVTLOoMOKmVtZH0SmDPuv5Gg78SA94B%2BLMQsQ%3D%3D";
String parameter = "";
URL url = null;
CachedOutputStream bos = null;
InputStream in = null;
parameter = parameter + "&" + "upr_cd=6450000";
parameter = parameter + "&" + "org_cd=4640000";
parameter = parameter + "&" + "care_reg_no=" + careRegNo;
parameter = parameter + "&" + "upkind=417000";
parameter = parameter + "&" + "_type=json";
// 주소에 url + 서비스키 + 조건을 연결
addr = addr + serviceKey + parameter;
String data = null;
PrintWriter out = null;
// 예외처리
try {
// 데이터를 가져올 url 할당
url = new URL(addr);
// url주소와 연결한후 이 연결로부터 입력받을수있는 InputStream을 리턴받음
in = url.openStream();
// 출력을 받기위해 CachedOutputStream 객체 생성
bos = new CachedOutputStream();
// in에서 bos로 데이터 복사
IOUtils.copy(in, bos);
// 복사된 데이터를 String 형태로 data변수에 입력
data = bos.getOut().toString();
// 텍스트형식의 출력 스트림을 얻은후
out = response.getWriter();
// 얻어낸 스트림에 데이터 입력
out.println(data);
logger.debug("data is {}", data);
logger.debug("addr is {}", addr);
JSONObject json = new JSONObject();
// json형태로 데이터를 넣음
json.put("data", data);
logger.debug("shelterAnimalList(...) 메서드 끝");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project 1teamProject by iso159.
the class MemberController method shelterAddressList.
// 유기동물품종 api
@RequestMapping(value = "/member/addressList", method = RequestMethod.POST)
public void shelterAddressList(HttpServletResponse response, HttpSession session) {
logger.debug("shelterAddressList(...) 메서드 호출");
/*String blCode = (String)session.getAttribute("loginBlCode");
if(blCode == null) {
return;
}*/
response.setContentType("text/html; charset=utf-8");
// 호출할 데이터가 있는 url을 addr변수에 입력
String addr = "http://openapi.epost.go.kr/postal/retrieveNewAdressAreaCdService/retrieveNewAdressAreaCdService/getNewAddressListAreaCd?ServiceKey=";
// 서비스키 입력
String serviceKey = "7s3CsUFyR%2F1QMd5tktqM%2BnUw9gAEPUtI0GIsuGWxEUOJHwZP9NVTLOoMOKmVtZH0SmDPuv5Gg78SA94B%2BLMQsQ%3D%3D";
// 요청메시지를 입력받을 parameter변수 선언 및 공백으로 초기화
String parameter = "";
URL url = null;
CachedOutputStream bos = null;
InputStream in = null;
// 요청메세지 추가
parameter = parameter + "&" + "searchSe";
parameter = parameter + "&" + "srchwrd";
parameter = parameter + "&" + "countPerPage";
parameter = parameter + "&" + "currentPage";
// 주소에 url + 서비스키 + 조건을 연결
addr = addr + serviceKey + parameter;
String data = null;
PrintWriter out = null;
// 예외처리
try {
// 데이터를 가져올 url 할당
url = new URL(addr);
// url주소와 연결한후 이 연결로부터 입력받을수있는 InputStream을 리턴받음
in = url.openStream();
// 출력을 받기위해 CachedOutputStream 객체 생성
bos = new CachedOutputStream();
// in에서 bos로 데이터 복사
IOUtils.copy(in, bos);
// 복사된 데이터를 String 형태로 data변수에 입력
data = bos.getOut().toString();
// 텍스트형식의 출력 스트림을 얻은후
out = response.getWriter();
// 얻어낸 스트림에 데이터 입력
out.println(data);
logger.debug("data is {}", data);
logger.debug("addr is {}", addr);
JSONObject json = new JSONObject();
// json형태로 데이터를 넣음
json.put("data", data);
out.print(json);
logger.debug("shelterAnimalBreed(...) 메서드 끝");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations