final String rootUri, HttpParams params) throws UnsupportedEncodingException {
if (log.isDebugEnabled()) log.debug("Preparing http request...");
// convenience variables...
BindingInput bindingInput = opBinding.getBindingInput();
HTTPOperation httpOperation = (HTTPOperation) WsdlUtils.getOperationExtension(opBinding);
MIMEContent content = WsdlUtils.getMimeContent(bindingInput.getExtensibilityElements());
String contentType = content == null ? "" : content.getType();
boolean useUrlEncoded = WsdlUtils.useUrlEncoded(bindingInput) || PostMethod.FORM_URL_ENCODED_CONTENT_TYPE.equalsIgnoreCase(contentType);
boolean useUrlReplacement = WsdlUtils.useUrlReplacement(bindingInput);
// the http method to be built and returned
HttpMethod method = null;
// the 4 elements the http method may be made of
String relativeUri = httpOperation.getLocationURI();
String queryPath = null;
RequestEntity requestEntity;
String encodedParams = null;
// ODE supports uri template in both port and operation location.
// so assemble the final url *before* replacement
String completeUri = rootUri;
if (StringUtils.isNotEmpty(relativeUri)) {
completeUri = completeUri + (completeUri.endsWith("/") || relativeUri.startsWith("/") ? "" : "/") + relativeUri;
}
if (useUrlReplacement) {
// insert part values in the url
completeUri = new UrlReplacementTransformer().transform(completeUri, partValues);
} else if (useUrlEncoded) {
// encode part values
encodedParams = new URLEncodedTransformer().transform(partValues);
}
// http-client api is not really neat
// something similar to the following would save some if/else manipulations.
// But we have to deal with it as-is.
//
// method = new Method(verb);
// method.setRequestEnity(..)
// etc...
if ("GET".equalsIgnoreCase(verb) || "DELETE".equalsIgnoreCase(verb)) {
if ("GET".equalsIgnoreCase(verb)) {
method = new GetMethod();
} else if ("DELETE".equalsIgnoreCase(verb)) {
method = new DeleteMethod();
}
if (useUrlEncoded) {
queryPath = encodedParams;
}
// Let http-client manage the redirection
// see org.apache.commons.httpclient.params.HttpClientParams.MAX_REDIRECTS
// default is 100
method.setFollowRedirects(true);
} else if ("POST".equalsIgnoreCase(verb) || "PUT".equalsIgnoreCase(verb)) {
if ("POST".equalsIgnoreCase(verb)) {
method = new PostMethod();
} else if ("PUT".equalsIgnoreCase(verb)) {
method = new PutMethod();
}
// some body-building...
if (useUrlEncoded) {
requestEntity = new StringRequestEntity(encodedParams, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE, method.getParams().getContentCharset());
} else if (contentType.endsWith(CONTENT_TYPE_TEXT_XML)) {
// get the part to be put in the body
Part part = opBinding.getOperation().getInput().getMessage().getPart(content.getPart());
Element partValue = partValues.get(part.getName());
// if the part has an element name, we must take the first element
if (part.getElementName() != null) {
partValue = DOMUtils.getFirstChildElement(partValue);
}