1. Introduktion

Eksempel på brug af IDWS hjælpe klasser for service udbydere.

/* Server will setup OIOIDWSFactory */
		final Federation federation = new SOSITestFederation(SignatureUtil.setupCryptoProviderForJVM());
		OIOIDWSFactory oioidwsFactory = new OIOIDWSFactory(federation, spVault);
		
		
		// ****************** HANDLING INPUT ******************
		// Server side input/request document
		SOAPPart soapPart = soapRequestMessage.getSOAPPart();
		SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
		SOAPBody soapBody = soapRequestMessage.getSOAPBody();
		SOAPHeader soapHeader = soapRequestMessage.getSOAPHeader();
		
		/*Parse request document into IDWS request*/
		/*Validation is done in parsing. So if any error - no request object is created*/
		LibertyRequest request = oioidwsFactory.createRequest(soapEnvelope);
		
		/*Work on request*/
		String messageID = request.getMessageID();
		assertNotNull(messageID); // Client did not set MessageID - but in cannot be null
		String to = request.getTo();
		assertEquals("https://myApp", to);
		
		/*Work with CitizenIdentityToken*/
		CitizenIdentityToken identityToken = request.getIdentityToken();
		assertNotNull(identityToken); // Must be there!
		String cpr = identityToken.getCpr();
		assertEquals("2512484916", cpr);
		BasicPrivileges privileges = identityToken.getPrivileges();
		assertNotNull(privileges);
		/*Work with priviliges*/
		List<String> privilegeList = privileges.getPrivileges("urn:dk:healthcare:saml:actThroughProcurationBy:cprNumberIdentifier:1111111118");
		assertNotNull(privilegeList);
		assertEquals(2, privilegeList.size());
		
		/*Work in my app*/
		Tag myAppTag = TagUtil.create("http://demo.dk/custom", "myApp","App");
		Element myApp = TagUtil.getFirstChildElementNS(soapBody, myAppTag);
		String myAppRequestAsString = XmlUtil.node2String(myApp, false, false);
		assertEquals("<myApp:App xmlns:myApp=\"http://demo.dk/custom\"><myApp:Field_1>value1</myApp:Field_1><myApp:Field_2 custom_attribute_2=\"value2\"/></myApp:App>", myAppRequestAsString);
		
		Tag myAppHeaderTag = TagUtil.create("http://demo.dk/custom", "myApp","Header");
		Element myHeader = TagUtil.getFirstChildElementNS(soapHeader, myAppHeaderTag);
		String myAppRequestHeaderAsString = XmlUtil.node2String(myHeader, false, false);
		assertEquals("<myApp:Header xmlns:myApp=\"http://demo.dk/custom\">my_app_header</myApp:Header>", myAppRequestHeaderAsString);
		
		// ****************** CREATING OUTPUT ******************
		Document outputDocument = XmlUtil.readXml(System.getProperties(), MY_SOAP_APP_REPONSE, false);
		
		/*Sign repsonse with test vault*/
		final CredentialVault serverTestVault = CredentialVaultTestUtil.getCredentialVaultFromResource(System.getProperties(), "fmk_idws_test.p12");
		LibertyMessageDOMEnhancer enhancer = oioidwsFactory.createResponseDomEnhancer(serverTestVault, outputDocument, true);
		enhancer.setWSAddressingAction("myApp.response"); //Required
		//enhancer.setWSAddressingMessageID(); //Required - one will be made if not set be server
		enhancer.setWSAddressingRelatesTo(request.getTo()); //Required - Validation will fail if not set
		//enhancer.setWSAddressingTo("client"); //Optional
		
		enhancer.enhanceAndSign(); // Enhance and sign output document into IDWS valid reponse
		
		/*create response message*/
		MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
		soapResponseMessage = messageFactory.createMessage(null, new ByteArrayInputStream(XmlUtil.node2String(outputDocument).getBytes()));
		//return responseSoapMessage
		//System.out.println(XmlUtil.node2String(responseSoapMessage.getSOAPPart().getEnvelope(), true, false));