use of javax.servlet.ServletOutputStream in project Openfire by igniterealtime.
the class ImageServlet method writeBytesToStream.
/**
* Writes out a <code>byte</code> to the ServletOuputStream.
*
* @param bytes the bytes to write to the <code>ServletOutputStream</code>.
* @param response the HttpServeltResponse.
*/
public void writeBytesToStream(byte[] bytes, HttpServletResponse response) {
if (bytes == null) {
return;
}
response.setContentType(CONTENT_TYPE);
// Send back image
try {
ServletOutputStream sos = response.getOutputStream();
sos.write(bytes);
sos.flush();
sos.close();
} catch (IOException e) {
// Ignore.
}
}
use of javax.servlet.ServletOutputStream in project OpenAM by OpenRock.
the class FSSSOAndFedService method returnSOAPMessage.
/**
* Forms and Returns SOAP message to the requested client.
*
* @param msg <code>SOAPMessage</code> to be returned
* @param response <code>HttpServletResponse</code> object
*/
private void returnSOAPMessage(SOAPMessage msg, HttpServletResponse response) {
try {
if (msg != null) {
SAMLUtils.setMimeHeaders(msg.getMimeHeaders(), response);
ServletOutputStream servletoutputstream = response.getOutputStream();
msg.writeTo(servletoutputstream);
servletoutputstream.flush();
return;
} else {
response.flushBuffer();
return;
}
} catch (Exception e) {
FSUtils.debug.error("FSSSOAndFedService.returnSOAPMessage: " + "Exception::", e);
return;
}
}
use of javax.servlet.ServletOutputStream in project OpenAM by OpenRock.
the class CDCServlet method showError.
private void showError(HttpServletResponse response, String msg) {
ServletOutputStream out = null;
try {
out = response.getOutputStream();
out.println(msg);
out.flush();
} catch (IOException e) {
debug.error("CDCServlet.showError: " + "Could not show error message to the user", e);
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException ex) {
//ignored
}
}
}
use of javax.servlet.ServletOutputStream in project OpenAM by OpenRock.
the class SSOTokenSampleServlet method doGet.
public void doGet(HttpServletRequest request, HttpServletResponse response) {
ServletOutputStream out = null;
try {
try {
response.setContentType("text/html");
out = response.getOutputStream();
// create the sso token from http request
SSOTokenManager manager = SSOTokenManager.getInstance();
SSOToken token = manager.createSSOToken(request);
if (manager.isValidToken(token)) {
//print some of the values from the token.
String host = token.getHostName();
java.security.Principal principal = token.getPrincipal();
String authType = token.getAuthType();
int level = token.getAuthLevel();
InetAddress ipAddress = token.getIPAddress();
out.println("SSOToken host name: " + host);
out.println("<br />");
out.println("SSOToken Principal name: " + principal.getName());
out.println("<br />");
out.println("Authentication type used: " + authType);
out.println("<br />");
out.println("IPAddress of the host: " + ipAddress.getHostAddress());
out.println("<br />");
}
/* Validate the token again, with another method.
* if token is invalid, this method throws exception
*/
manager.validateToken(token);
out.println("SSO Token validation test succeeded");
out.println("<br />");
// Get the SSOTokenID associated with the token and print it.
SSOTokenID tokenId = token.getTokenID();
out.println("The token id is " + tokenId.toString());
out.println("<br />");
// Set and get some properties in the token.
token.setProperty("Company", "Sun Microsystems");
token.setProperty("Country", "USA");
String name = token.getProperty("Company");
String country = token.getProperty("Country");
out.println("Property: Company: " + name);
out.println("<br />");
out.println("Property: Country: " + country);
out.println("<br />");
// Retrieve user profile and print them
AMIdentity userIdentity = IdUtils.getIdentity(token);
Map attrs = userIdentity.getAttributes();
out.println("User Attributes: " + attrs);
/* let us add a listener to the SSOToken. Whenever a token
* event arrives, ssoTokenChanged method of the listener will
* get called.
*/
SSOTokenListener myListener = new SampleTokenListener();
token.addSSOTokenListener(myListener);
} catch (SSOException e) {
out.println("SSO Exception: " + e);
out.println("<p>Authenticate to OpenAM server before visiting this page.</p>");
e.printStackTrace();
} catch (IdRepoException e) {
out.println("IdRepo Exception: " + e);
e.printStackTrace();
} catch (IOException e) {
out.println("IO Exception: " + e);
e.printStackTrace();
} finally {
out.flush();
}
} catch (IOException e) {
// ignored
}
}
use of javax.servlet.ServletOutputStream in project OpenAM by OpenRock.
the class SOAPReceiver method doPost.
/**
* Processes HTTP request and sends back HTTP response. It gets called
* internally by the servlet engine.
*
* @param request the HTTP request.
* @param response the HTTP response.
* @throws IOException if an IO error occurs while processing
the request
* @throws ServletException if an servlet error occurs while processing
* the request
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
MimeHeaders mimeHeaders = SAMLUtils.getMimeHeaders(request);
ServletInputStream sInputStream = request.getInputStream();
SOAPMessage soapMessage = msgFactory.createMessage(mimeHeaders, sInputStream);
SOAPMessage soapMessageReply = this.onMessage(soapMessage, request);
if (soapMessageReply != null) {
SAMLUtils.setMimeHeaders(soapMessageReply.getMimeHeaders(), response);
ServletOutputStream sOutputStream = response.getOutputStream();
soapMessageReply.writeTo(sOutputStream);
sOutputStream.flush();
} else {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} catch (SOAPException se) {
throw new ServletException(se);
}
}
Aggregations