cancel
Showing results for 
Search instead for 
Did you mean: 

First Steps WS with CMIS from JAX-WS

mcdroemmel
Champ in-the-making
Champ in-the-making
Hello,

i want to start with first tests connecting using the cmis-ws to alfresco.
for that i thought to use the getRepositories Service.

I'm working with sap netweaver server 7.1 (JEE5 compliant) and created a java bean for using the service.
sap is using jax-ws as a WS-Framework.
following is my bean with the method which should consume the web-service.


@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;
   }
}


accessing that bean-method from my application always result in the following exception:
Exeption:javax.xml.ws.soap.SOAPFaultException: An error was discovered processing the <wsseSmiley Frustratedecurity> header

Pyhsical connection works, because the exception is returned by the alfresco-server.

Is there a special "beginner" tutorial for consuming cmis-ws available or can someone tell me what is wrong here and to get my bean working.

thanx in advance and regards
McD
2 REPLIES 2

gressho
Champ in-the-making
Champ in-the-making
How do you provide your wsseSmiley Frustratedecurity header? For JBoss (and the JAX-WS RI) I had to implement a handler of my own and attach it to the handler chain, so
I could generate the header I needed.

The handler looks like this (and you should really make sure the header is inserted before the SOAP body):

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
}

The code to insert the handler in the handler chain look like this:

            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();

I hope this helps!

mcdroemmel
Champ in-the-making
Champ in-the-making
Hello,

thanx for your support. It seems that your hint works great also on SAP NetWeaver 7.1. Unfortunatly i ran in the next problem, but thats another story.

thanx so far.
regards
Matthias