/** * writes a client exception XML document according to the specified * OutputStream. */ public void write(final OutputStream out) throws IOException { out.write(getAsXML().getBytes()); out.flush(); }
public String getAsXML() { StringBuffer buf = new StringBuffer(); buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); buf.append("<WebSecurityClient-ExceptionReport>\n"); buf.append("<ClientException>\n"); buf.append("<ExceptionMessage>\n"); buf.append(getMessage()); buf.append("</ExceptionMessage>\n"); if (getCause() != null) { buf.append("<ExceptionCause>\n"); buf.append(getCause()); buf.append("</ExceptionCause>\n"); } buf.append("</ClientException>\n"); buf.append("</WebSecurityClient-ExceptionReport>\n"); return buf.toString(); }
if (ce.getCode() != null && ce.getCode().equals(ClientException.CONNECTION_FAILED)) { errorString.append("<H1>ERROR: Could not connect to service!</H1><br><br>"); if (ce.getCode() != null && ce.getCode().equals(ClientException.UNEXPECTED_MIME_TYPE)) { errorString.append("<H1>ERROR: Service response has got unexpected mime type!</H1><br><br>");
public WSSCapabilitiesDocument getCapabilities(String version, String service) throws ClientException, ServiceException { HTTPRequest httpRequest = httpClientFactory.create(getWssURLString()).get(); httpRequest.parameter("SERVICE", service, "REQUEST", "GetCapabilities"); try { HTTPResponse<InputStream> httpResponse = httpRequest.asStream().start(); if (!httpResponse.getStatus().is(200)) { throw new ClientException("Error during WSS GetCapabilities request: " + httpResponse.getStatus().toString()); } String contentType = httpResponse.getContentType(); if (contentType.startsWith("text/xml")) { return WSSCapabilitiesDocument.parse(httpResponse.getContent()); } else if (contentType.startsWith("application/vnd.ogc.se_xml")) { throw ServiceException.createFromXML(new InputSource(httpResponse.getContent())); } else { throw new ClientException("WSS GetCapabilities response must be of MIME type text/xml. Found: " + contentType + ". Capabilities information unavailable.", ClientException.UNEXPECTED_MIME_TYPE); } } catch (Exception e) { LOG.error(e.getMessage(), e); throw new ClientException("Error while processing GETCAPABILITIES response from Security Service:\n" + e.getMessage(), ClientException.CONNECTION_FAILED); } }
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); } }
throw new ClientException("Error while trying to perform doService-Request.", e);
public Transferable getAsTransferable() { return TransferableFactory.getInstance().createTextualTransferable("text/xml", getAsXML(), "UTF-8"); }
/** * Performs the service request "CloseSession". * * @throws ClientException if something went wrong during the request * @throws org.n52.security.common.artifact.ServiceException if the response is of MIME type * <code>application/vnd.ogc.se_xml */ public void closeSession(String version, String sessionID) throws ClientException, ServiceException { HTTPRequest httpRequest = httpClientFactory.create(getWssURLString()).get(); httpRequest.parameter("VERSION", version, "SESSIONID", sessionID, "SERVICE", "WSS", "REQUEST", "CloseSession"); HTTPResponse<InputStream> httpResponse = httpRequest.asStream().start(); if (httpResponse.isError()) { LOG.error("", httpResponse.getError()); throw new ClientException("I/O exception during CLOSESESSION request to Security Service:\n" + httpResponse.getStatus().getCode() + ": " + ((httpResponse.getError() != null) ? httpResponse.getError().getMessage() : " no exception available")); } }