HTTPContentRequest postRequest = httpClient.post();
public Transferable doService(Transferable request, Credential credential, URL facadeUrl, String dcpType, LicenseReference licenseReference) throws ServiceException { String additionalPathInfo = (String) request.getAttributeValue(TransferAttribute.PATHINFO_ATTR); if (additionalPathInfo == null) { additionalPathInfo = ""; } String additionalQueryString = (String) request.getAttributeValue(TransferAttribute.QUERY_STRING_ATTR); if (additionalQueryString == null) { additionalQueryString = ""; } List<HttpHeaderAttribute> headersList = new LinkedList<>(); for (TransferAttribute attrib : request.getAttributes()) { if (attrib instanceof HttpHeaderAttribute) { headersList.add((HttpHeaderAttribute) attrib); } } HttpHeaderAttribute[] headers = headersList.toArray(new HttpHeaderAttribute[headersList.size()]); String postXML = createPostXML("1.1", credential, request, facadeUrl, dcpType, licenseReference); String uri = MessageFormat.format("{0}{1}?{2}", getWssURLString(), additionalPathInfo, additionalQueryString); HTTPContentRequest httpRequest = httpClientFactory.create(uri).post().contentType("text/xml", "UTF-8"); for (HttpHeaderAttribute httpHeaderAttribute : headers) { if (headerNameIs(httpHeaderAttribute, "Content-Type") || headerNameIs(httpHeaderAttribute, "Content-Encoding")) { continue; } httpRequest.header(httpHeaderAttribute.getName(), (String) httpHeaderAttribute.getValue()); } httpRequest.content(postXML); return execute(httpRequest); }
private String getSSOSessionId(String username, char[] password) throws FailedLoginException { HTTPClient client = m_httpClientFactory.create(m_endpoint); HTTPRequest req; switch (m_authnMode) { case AUTHN_MODE_USER_PW: req = client.post().parameter(m_usernameParam, username, m_passwordParam, new String(password)); break; default: req = client.get().basicAuth(username, password); break; } HTTPResponse<String> response = req.asString().start(); if (response.isError()) { if (response.getStatus() == HTTPCode.FORBIDDEN) { throw new FailedLoginException("Wrong credentials"); } LOG.error("Remote service connection failed: " + req.getEndpoint(), response.getError()); throw new FailedLoginException("Remote service connection failed: " + response.getError()); } return response.getContent().trim(); }
public SessionInfo getSession(String version, Credential credential) throws ClientException, ServiceException { String authMethodUrn = guessAuthenticationMethodUrn(credential); // FIXME: if type of the credential is not given, the was urn is used. String authnMethod = authMethodUrn == null ? WASAuthenticationMethod.URN : authMethodUrn; String encodedCredential = getCredentialFactory().encode(authnMethod, credential); HTTPRequest httpRequest = httpClientFactory.create(getWssURLString()).post() .contentType("application/x-www-form-urlencoded", "UTF-8") .parameter("VERSION", version, "CREDENTIALS", encodedCredential, "SERVICE", "WSS", "REQUEST", "GetSession", "AUTHMETHOD", "authnMethod"); HTTPResponse<InputStream> httpResponse = httpRequest.asStream().start(); if (httpResponse.isError()) { LOG.error(httpResponse.getError().getMessage(), httpResponse.getError()); throw new ClientException("I/O exception during GETSESSION request to Security Service:\n" + httpResponse.getError(), ClientException.CONNECTION_FAILED); } String contentType = httpResponse.getContentType(); if (contentType.startsWith("text/xml")) { return SessionInfo.createFromXML(httpResponse.getContent()); } else if (contentType.startsWith("application/vnd.ogc.se_xml")) { throw ServiceException.createFromXML(new InputSource(httpResponse.getContent())); } else { LOG.error("GetSession response contained no session information. Response is: " + StringUtils.streamToString(httpResponse.getContent(), "UTF-8")); throw new ClientException("Security Service response specifies unknown/unexpected MIME type: " + contentType + ". Session information unavailable.", ClientException.UNEXPECTED_MIME_TYPE); } }
HTTPContentRequest contentRequest = factory.create(getUrl()).post().contentType("text/xml","UTF-8");