11-21-2008 09:05 AM
@Stateless(name="AlfRepBean")
public class AlfRepBean implements AlfRepLocal {
@WebServiceRef(name="RepositoryService")
private RepositoryService rService;
public String repServiceList ()
{
String result = "";
RepositoryServicePort rPort = rService.getRepositoryServicePort(); // –> Exception is thrown here
try
{
String rList = "";
for (CmisRepositoryEntryType rEntry : rPort.getRepositories())
{
rList = rList + ">REntry:ID="+rEntry.getRepositoryID()+";Name="+rEntry.getRepositoryName()+";URI="+rEntry.getRepositoryURI()+":<";
}
result = rList;
}
catch (Exception ex)
{
result = "!Exeption:" + ex.toString();
ex.printStackTrace();
}
return result;
}
}
11-24-2008 07:42 AM
public class SecurityHandler implements SOAPHandler<SOAPMessageContext> {
private static String WS_SECEXT = "http://docs.oasis-open.org/wss/" +
"2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
private static String WS_SECUTILITY = "http://docs.oasis-open.org/wss/" +
"2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
private static String WS_USER_TOKEN_PROFILE = "http://docs.oasis-open.org" +
"/wss/2004/01/oasis-200401-wss-username-token-profile-1.0" +
"#PasswordText";
public boolean handleMessage(SOAPMessageContext messageContext) {
if ((Boolean) messageContext.get(
MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
try {
DatatypeFactory factory = DatatypeFactory.newInstance();
GregorianCalendar now = new GregorianCalendar();
GregorianCalendar fiveMinutesLater = new GregorianCalendar();
fiveMinutesLater.add(GregorianCalendar.MINUTE, 5);
XMLGregorianCalendar xmlNow =
factory.newXMLGregorianCalendar(now);
XMLGregorianCalendar xmlFiveMinutesLater =
factory.newXMLGregorianCalendar(fiveMinutesLater);
String xmlNowDate = xmlNow.toXMLFormat().substring(0,
xmlNow.toXMLFormat().length() - 6) + "Z";
String xmlFiveMinutesLaterDate = xmlFiveMinutesLater
.toXMLFormat().substring(0,
xmlFiveMinutesLater.toXMLFormat().length() - 6) + "Z";
SOAPMessage msg = messageContext.getMessage();
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader;
if (envelope.getHeader() != null) {
soapHeader = envelope.getHeader();
} else {
soapHeader = envelope.addHeader();
}
SOAPHeaderElement headerElement = soapHeader.addHeaderElement(
new QName(WS_SECEXT, "Security", "wsse"));
headerElement.setMustUnderstand(true);
SOAPElement timestamp = headerElement.addChildElement(
new QName(WS_SECUTILITY, "Timestamp", "wsu"));
timestamp.addAttribute(
new QName(WS_SECUTILITY, "Id", "wsu"), "Timestamp");
SOAPElement created = timestamp.addChildElement(
new QName(WS_SECUTILITY, "Created", "wsu"));
created.addTextNode(xmlNowDate);
SOAPElement expired = timestamp.addChildElement(
new QName(WS_SECUTILITY, "Expired", "wsu"));
expired.addTextNode(xmlFiveMinutesLaterDate);
SOAPElement usernameToken = headerElement.addChildElement(
new QName(WS_SECEXT, "UsernameToken", "wsse"));
SOAPElement username = usernameToken.addChildElement(
new QName(WS_SECEXT, "Username", "wsse"));
username.addTextNode("admin");
SOAPElement password = usernameToken.addChildElement(
new QName(WS_SECEXT, "Password", "wsse"));
password.addAttribute(new QName("Type"), WS_USER_TOKEN_PROFILE);
password.addTextNode("admin");
} catch (Exception ex) {
Logger.getLogger(SecurityHandler.class.getName()).log(
Level.SEVERE, null, ex);
}
}
return true;
}
public Set<QName> getHeaders() {
return new HashSet<QName>();
}
public boolean handleFault(SOAPMessageContext context) {
return true;
}
public void close(MessageContext context) {
return;
}
// other methods
}
securityHandler = new SecurityHandler();
RepositoryService repositoryService = new RepositoryService();
repositoryServicePort =
repositoryService.getRepositoryServicePort();
Binding repositoryBinding =
((BindingProvider) repositoryServicePort).getBinding();
List<Handler> repositoryHandlerChain =
repositoryBinding.getHandlerChain();
repositoryHandlerChain.add(securityHandler);
repositoryBinding.setHandlerChain(repositoryHandlerChain);
List<CmisRepositoryEntryType> repositories =
repositoryServicePort.getRepositories();
repositoryId = repositories.get(0).getRepositoryID();
11-25-2008 02:50 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.