List of usage examples for org.apache.commons.httpclient HeaderElement getParameterByName
public NameValuePair getParameterByName(String paramString)
From source file:com.intellij.tasks.impl.httpclient.ResponseUtil.java
public static Reader getResponseContentAsReader(@Nonnull HttpMethod response) throws IOException { //if (!response.hasBeenUsed()) { // return new StringReader(""); //}//w w w. j a v a 2 s .c o m InputStream stream = response.getResponseBodyAsStream(); String charsetName = null; org.apache.commons.httpclient.Header header = response.getResponseHeader(HTTP.CONTENT_TYPE); if (header != null) { // find out encoding for (HeaderElement part : header.getElements()) { NameValuePair pair = part.getParameterByName("charset"); if (pair != null) { charsetName = pair.getValue(); } } } return new InputStreamReader(stream, charsetName == null ? DEFAULT_CHARSET_NAME : charsetName); }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.MimeMessageResponse.java
public MimeMessageResponse(AbstractHttpRequestInterface<?> httpRequest, ExtendedHttpMethod httpMethod, String requestContent, PropertyExpansionContext context) { super(httpMethod, httpRequest, context); if (getRequestContent() == null || !getRequestContent().equals(requestContent)) this.requestContent = requestContent; try {/*from ww w . j av a 2 s.c om*/ postResponseDataSource = new PostResponseDataSource(httpMethod); responseContentLength = postResponseDataSource.getDataSize(); Header h = httpMethod.getResponseHeader("Content-Type"); HeaderElement[] elements = h.getElements(); String rootPartId = null; for (HeaderElement element : elements) { String name = element.getName().toUpperCase(); if (name.startsWith("MULTIPART/")) { NameValuePair parameter = element.getParameterByName("start"); if (parameter != null) rootPartId = parameter.getValue(); } } mmSupport = new MultipartMessageSupport(postResponseDataSource, rootPartId, (AbstractHttpOperation) httpRequest.getOperation(), false, httpRequest.isPrettyPrint()); if (httpRequest.getSettings().getBoolean(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN)) this.timeTaken += httpMethod.getResponseReadTime(); } catch (Exception e) { SoapUI.logError(e); } }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.HttpMethodSupport.java
/** * Handles charset specified in Content-Encoding headers * /* w ww .ja v a 2 s.c o m*/ * @return */ public String getResponseCharset() { Header header = httpMethod.getResponseHeader("Content-Type"); if (header != null) { for (HeaderElement headerElement : header.getElements()) { NameValuePair parameter = headerElement.getParameterByName("charset"); if (parameter != null) return parameter.getValue(); } } Header contentEncodingHeader = httpMethod.getResponseHeader("Content-Encoding"); if (contentEncodingHeader != null) { try { String value = contentEncodingHeader.getValue(); if (CompressionSupport.getAvailableAlgorithm(value) == null) { new String("").getBytes(value); return value; } } catch (Exception e) { } } return null; }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.MimeMessageResponse.java
public MimeMessageResponse(WsdlRequest wsdlRequest, final TimeablePostMethod postMethod, String requestContent) {//from www .java 2s. c om this.wsdlRequest = wsdlRequest; this.requestContent = requestContent; this.timeTaken = postMethod.getTimeTaken(); responseContentLength = postMethod.getResponseContentLength(); try { initHeaders(postMethod); MimeMultipart mp = new MimeMultipart(new PostResponseDataSource(postMethod)); message = new MimeMessage(HttpClientRequestTransport.JAVAMAIL_SESSION); message.setContent(mp); Header h = postMethod.getResponseHeader("Content-Type"); HeaderElement[] elements = h.getElements(); String rootPartId = null; for (HeaderElement element : elements) { if (element.getName().toUpperCase().startsWith("MULTIPART/")) { NameValuePair parameter = element.getParameterByName("start"); if (parameter != null) rootPartId = parameter.getValue(); } } for (int c = 0; c < mp.getCount(); c++) { BodyPart bodyPart = mp.getBodyPart(c); if (bodyPart.getContentType().toUpperCase().startsWith("MULTIPART/")) { MimeMultipart mp2 = new MimeMultipart(new BodyPartDataSource(bodyPart)); for (int i = 0; i < mp2.getCount(); i++) { result.add(new BodyPartAttachment(mp2.getBodyPart(i))); } } else { BodyPartAttachment attachment = new BodyPartAttachment(bodyPart); String[] contentIdHeaders = bodyPart.getHeader("Content-ID"); if (contentIdHeaders != null && contentIdHeaders.length > 0 && contentIdHeaders[0].equals(rootPartId)) { rootPart = attachment; } else result.add(attachment); } } // if no explicit root part has been set, use the first one in the result if (rootPart == null) rootPart = result.remove(0); if (wsdlRequest.getSettings().getBoolean(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN)) this.timeTaken = postMethod.getTimeTakenUntilNow(); } catch (Exception e) { e.printStackTrace(); } }