javax.xml.soap.SOAPEnvelope Java Examples

The following examples show how to use javax.xml.soap.SOAPEnvelope. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 7 votes vote down vote up
private void addClientElements(SOAPEnvelope env, XRoadServiceConfiguration conf, SOAPHeader header)
    throws SOAPException {
  // TODO: maybe we should create headers differently according to object type?
  XroadObjectType objectType =
      conf.getClientObjectType() != null ? conf.getClientObjectType() : XroadObjectType.SUBSYSTEM;
  SOAPElement client = header.addChildElement("client", protocol.getNamespacePrefix());
  client.addAttribute(env.createName("id:objectType"), objectType.name());
  SOAPElement clientXRoadInstance = client.addChildElement("xRoadInstance", "id");
  clientXRoadInstance.addTextNode(conf.getClientXRoadInstance());
  SOAPElement clientMemberClass = client.addChildElement("memberClass", "id");
  clientMemberClass.addTextNode(conf.getClientMemberClass());
  SOAPElement clientMemberCode = client.addChildElement("memberCode", "id");
  clientMemberCode.addTextNode(conf.getClientMemberCode());

  if (StringUtils.isNotBlank(conf.getClientSubsystemCode())) {
    SOAPElement clientSubsystemCode = client.addChildElement("subsystemCode", "id");
    clientSubsystemCode.addTextNode(conf.getClientSubsystemCode());
  }
}
 
Example #2
Source File: SoapProtocol.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void groupProcessing(
	Value value,
	XSElementDecl xsDecl,
	SOAPElement element,
	SOAPEnvelope envelope,
	boolean first,
	XSModelGroup modelGroup,
	XSSchemaSet sSet,
	String messageNamespace )
	throws SOAPException {

	XSParticle[] children = modelGroup.getChildren();
	XSTerm currTerm;
	for( XSParticle child : children ) {
		currTerm = child.getTerm();
		if( currTerm.isModelGroup() ) {
			groupProcessing( value, xsDecl, element, envelope, first, currTerm.asModelGroup(), sSet,
				messageNamespace );
		} else {
			termProcessing( value, element, envelope, first, currTerm, child.getMaxOccurs(), sSet,
				messageNamespace );
		}
	}
}
 
Example #3
Source File: InsurabilityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void initMessageID(SOAPMessage msg) throws SOAPException {
   SOAPPart part = msg.getSOAPPart();
   if (part != null) {
      SOAPEnvelope soapEnvelope = part.getEnvelope();
      if (soapEnvelope != null) {
         SOAPHeader header = soapEnvelope.getHeader();
         if (header != null && header.getChildElements().hasNext()) {
            Node elementsResponseHeader = (Node)header.getChildElements().next();
            if (elementsResponseHeader != null && elementsResponseHeader.getLocalName() != null && elementsResponseHeader.getLocalName().equals("MessageID")) {
               NodeList elementsheader = elementsResponseHeader.getChildNodes();
               org.w3c.dom.Node element = elementsheader.item(0);
               messageId = element.getNodeValue();
               LOG.info("MyCareNet returned a response with messageId: " + messageId);
            }
         }
      }
   }

}
 
Example #4
Source File: SimpleSoapPayloadPolicy.java    From apiman with Apache License 2.0 6 votes vote down vote up
/**
 * @see io.apiman.gateway.engine.policy.IPolicy#apply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@SuppressWarnings("nls")
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config,
        final IPolicyChain<ApiRequest> chain) {
    try {
        SOAPEnvelope soapPayload = context.getAttribute(PolicyContextKeys.REQUEST_PAYLOAD, (SOAPEnvelope) null);
        if (soapPayload != null) {
            SOAPHeader header = soapPayload.getHeader();
            SOAPHeaderElement header1 = (SOAPHeaderElement) header.examineAllHeaderElements().next();
            String prop1 = header1.getTextContent();
            request.getHeaders().put("X-Property-1", prop1);
            header.addHeaderElement(new QName("urn:ns5", "Property5")).setTextContent("value-5");
        }
        chain.doApply(request);
    } catch (Exception e) {
        chain.throwError(e);
    }
}
 
Example #5
Source File: SoapFaultHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getSoapFaultCode(SOAPMessage msg) throws SOAPException {
   SOAPPart part = msg.getSOAPPart();
   if (part != null) {
      SOAPEnvelope soapEnvelope = part.getEnvelope();
      if (soapEnvelope != null) {
         SOAPBody body = soapEnvelope.getBody();
         if (body != null) {
            SOAPFault fault = body.getFault();
            if (fault != null && !StringUtils.isEmpty(fault.getFaultString()) && fault.getFaultString().contains("SOA-")) {
               return fault.getFaultString();
            }
         }
      }
   }

   return null;
}
 
Example #6
Source File: HubDecryptionHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private void handleDecryption(SOAPMessageContext cxt) {
   try {
      SOAPMessage soapMessage = cxt.getMessage();
      SOAPBody soapBody = soapMessage.getSOAPBody();
      if (soapBody == null) {
         SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
         soapBody = soapEnvelope.getBody();
      }

      FolderDecryptor.decryptFolder(soapBody, this.crypto);
      soapMessage.saveChanges();
   } catch (SOAPException var5) {
      LOG.error("SOAPException when handling the SOAP Body", var5);
      throw new RuntimeException(var5);
   } catch (UnsealConnectorException var6) {
      LOG.error("UnsealConnectorException when handling the SOAP Message: " + var6.getMessage());
      throw new FolderDecryptionRuntimeException(var6.getMessage(), var6);
   } catch (TechnicalConnectorException var7) {
      LOG.error("TechnicalConnectorException when handling the SOAP Message: " + var7.getMessage());
      throw new RuntimeException(var7);
   }
}
 
Example #7
Source File: SoapFaultHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getSoapFaultCode(SOAPMessage msg) throws SOAPException{
  	SOAPPart part = msg.getSOAPPart();
if(part !=null){
	SOAPEnvelope soapEnvelope = part.getEnvelope();
	if(soapEnvelope !=null){
	SOAPBody body = soapEnvelope.getBody();
		if(body !=null){
			SOAPFault fault=body.getFault();
			if(fault !=null && !StringUtils.isEmpty(fault.getFaultString()) && fault.getFaultString().contains("SOA-")){
				return fault.getFaultString();
			}
		}
	}
}
return null;
  }
 
Example #8
Source File: HubDecryptionHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private void handleDecryption(SOAPMessageContext cxt) {
   try {
      SOAPMessage soapMessage = cxt.getMessage();
      SOAPBody soapBody = soapMessage.getSOAPBody();
      if (soapBody == null) {
         SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
         soapBody = soapEnvelope.getBody();
      }

      FolderDecryptor.decryptFolder(soapBody, this.crypto);
      soapMessage.saveChanges();
   } catch (SOAPException var5) {
      LOG.error("SOAPException when handling the SOAP Body", var5);
   } catch (UnsealConnectorException var6) {
      LOG.error("UnsealConnectorException when handling the SOAP Message: " + var6.getMessage());
      throw new FolderDecryptionRuntimeException(var6.getMessage(), var6);
   } catch (TechnicalConnectorException var7) {
      LOG.error("TechnicalConnectorException when handling the SOAP Message: " + var7.getMessage());
   }

}
 
Example #9
Source File: AbstractWsSender.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
protected SOAPMessageContext createSOAPMessageCtx(GenericRequest genericRequest) throws TechnicalConnectorException {
   try {
      SOAPMessage soapMessage = mf.createMessage();
      SOAPPart soapPart = soapMessage.getSOAPPart();
      if (genericRequest.isXopEnabled()) {
         soapMessage.getMimeHeaders().addHeader("Content-Type", "application/xop+xml");
         soapPart.addMimeHeader("Content-ID", "<[email protected]>");
         soapPart.addMimeHeader("Content-Transfer-Encoding", "8bit");
      }

      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(genericRequest.getPayload());
      Map<String, DataHandler> handlers = genericRequest.getDataHandlerMap();

      AttachmentPart part;
      for(Iterator i$ = handlers.entrySet().iterator(); i$.hasNext(); soapMessage.addAttachmentPart(part)) {
         Entry<String, DataHandler> handlerEntry = (Entry)i$.next();
         DataHandler handler = (DataHandler)handlerEntry.getValue();
         part = soapMessage.createAttachmentPart(handler);
         part.setContentType(handler.getContentType());
         if (genericRequest.isXopEnabled()) {
            part.addMimeHeader("Content-Transfer-Encoding", "binary");
            part.setContentId("<" + (String)handlerEntry.getKey() + ">");
         } else {
            part.setContentId((String)handlerEntry.getKey());
         }
      }

      return createSOAPMessageCtx(soapMessage);
   } catch (SOAPException var11) {
      throw translate(var11);
   }
}
 
Example #10
Source File: HubDecryptionHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private void handleDecryption(SOAPMessageContext cxt) {
   try {
      SOAPMessage soapMessage = cxt.getMessage();
      SOAPBody soapBody = soapMessage.getSOAPBody();
      if (soapBody == null) {
         SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
         soapBody = soapEnvelope.getBody();
      }

      FolderDecryptor.decryptFolder(soapBody, this.crypto);
      soapMessage.saveChanges();
   } catch (SOAPException var5) {
      LOG.error("SOAPException when handling the SOAP Body", var5);
      throw new RuntimeException(var5);
   } catch (UnsealConnectorException var6) {
      LOG.error("UnsealConnectorException when handling the SOAP Message: " + var6.getMessage());
      throw new FolderDecryptionRuntimeException(var6.getMessage(), var6);
   } catch (TechnicalConnectorException var7) {
      LOG.error("TechnicalConnectorException when handling the SOAP Message: " + var7.getMessage());
      throw new RuntimeException(var7);
   }
}
 
Example #11
Source File: InsurabilityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void initMessageID(SOAPMessage msg) throws SOAPException {
	SOAPPart part = msg.getSOAPPart();
	if (part != null) {
		SOAPEnvelope soapEnvelope = part.getEnvelope();
		if (soapEnvelope != null) {
			SOAPHeader header = soapEnvelope.getHeader();
			
			if (header != null && header.getChildElements().hasNext()) {
				Node elementsResponseHeader = (Node) header.getChildElements().next();
				if (elementsResponseHeader != null && elementsResponseHeader.getLocalName() != null && elementsResponseHeader.getLocalName().equals("MessageID")) {
					NodeList elementsheader = elementsResponseHeader.getChildNodes();
					org.w3c.dom.Node element = elementsheader.item(0);
					messageId = element.getNodeValue();
					LOG.info("MyCareNet returned a response with messageId: " + messageId);
				}
			}
		}
	}
}
 
Example #12
Source File: SoapFaultHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getSoapFaultCode(SOAPMessage msg) throws SOAPException{
  	SOAPPart part = msg.getSOAPPart();
if(part !=null){
	SOAPEnvelope soapEnvelope = part.getEnvelope();
	if(soapEnvelope !=null){
	SOAPBody body = soapEnvelope.getBody();
		if(body !=null){
			SOAPFault fault=body.getFault();
			if(fault !=null && !StringUtils.isEmpty(fault.getFaultString()) && fault.getFaultString().contains("SOA-")){
				return fault.getFaultString();
			}
		}
	}
}
return null;
  }
 
Example #13
Source File: InsurabilityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void initMessageID(SOAPMessage msg) throws SOAPException {
	SOAPPart part = msg.getSOAPPart();
	if (part != null) {
		SOAPEnvelope soapEnvelope = part.getEnvelope();
		if (soapEnvelope != null) {
			SOAPHeader header = soapEnvelope.getHeader();
			
			if (header != null && header.getChildElements().hasNext()) {
				Node elementsResponseHeader = (Node) header.getChildElements().next();
				if (elementsResponseHeader != null && elementsResponseHeader.getLocalName() != null && elementsResponseHeader.getLocalName().equals("MessageID")) {
					NodeList elementsheader = elementsResponseHeader.getChildNodes();
					org.w3c.dom.Node element = elementsheader.item(0);
					messageId = element.getNodeValue();
					LOG.info("MyCareNet returned a response with messageId: " + messageId);
				}
			}
		}
	}
}
 
Example #14
Source File: SoapFaultHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getSoapFaultCode(SOAPMessage msg) throws SOAPException{
  	SOAPPart part = msg.getSOAPPart();
if(part !=null){
	SOAPEnvelope soapEnvelope = part.getEnvelope();
	if(soapEnvelope !=null){
	SOAPBody body = soapEnvelope.getBody();
		if(body !=null){
			SOAPFault fault=body.getFault();
			if(fault !=null && !StringUtils.isEmpty(fault.getFaultString()) && fault.getFaultString().contains("SOA-")){
				return fault.getFaultString();
			}
		}
	}
}
return null;
  }
 
Example #15
Source File: InsurabilityHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void initMessageID(SOAPMessage msg) throws SOAPException {
	SOAPPart part = msg.getSOAPPart();
	if (part != null) {
		SOAPEnvelope soapEnvelope = part.getEnvelope();
		if (soapEnvelope != null) {
			SOAPHeader header = soapEnvelope.getHeader();
			
			if (header != null && header.getChildElements().hasNext()) {
				Node elementsResponseHeader = (Node) header.getChildElements().next();
				if (elementsResponseHeader != null && elementsResponseHeader.getLocalName() != null && elementsResponseHeader.getLocalName().equals("MessageID")) {
					NodeList elementsheader = elementsResponseHeader.getChildNodes();
					org.w3c.dom.Node element = elementsheader.item(0);
					messageId = element.getNodeValue();
					LOG.info("MyCareNet returned a response with messageId: " + messageId);
				}
			}
		}
	}
}
 
Example #16
Source File: XmlTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private SOAPMessage createMessage(MessageFactory mf) throws SOAPException, IOException {
    SOAPMessage msg = mf.createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    Name name = envelope.createName("hello", "ex", "http://example.com");
    envelope.getBody().addChildElement(name).addTextNode("THERE!");

    String s = "<root><hello>THERE!</hello></root>";

    AttachmentPart ap = msg.createAttachmentPart(
            new StreamSource(new ByteArrayInputStream(s.getBytes())),
            "text/xml"
    );
    msg.addAttachmentPart(ap);
    msg.saveChanges();

    return msg;
}
 
Example #17
Source File: XRoadMessageCallback.java    From j-road with Apache License 2.0 6 votes vote down vote up
public void doWithMessage(WebServiceMessage message) {
  SaajSoapMessage saajMessage = (SaajSoapMessage) message;
  try {
    // Add attachments
    if (attachments != null) {
      for (XRoadAttachment attachment : attachments) {
        saajMessage.addAttachment("<" + attachment.getCid() + ">", attachment, attachment.getContentType());
      }
    }
    SOAPMessage soapmess = saajMessage.getSaajMessage();
    SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();

    protocolVersionStrategy.addNamespaces(env);
    protocolVersionStrategy.addXTeeHeaderElements(env, serviceConfiguration);
  } catch (SOAPException e) {
    throw new RuntimeException(e);
  }
}
 
Example #18
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 6 votes vote down vote up
@Override
public void addXTeeHeaderElements(SOAPEnvelope env, XRoadServiceConfiguration conf) throws SOAPException {
  SOAPHeader header = env.getHeader();
  if(StringUtils.isNotBlank(conf.getIdCode())) {
    SOAPElement userId = header.addChildElement("userId", protocol.getNamespacePrefix());
    userId.addTextNode(conf.getIdCode());
  }
  SOAPElement id = header.addChildElement("id", protocol.getNamespacePrefix());
  id.addTextNode(generateUniqueMessageId(conf));
  if (StringUtils.isNotBlank(conf.getFile())) {
    SOAPElement issue = header.addChildElement("issue", protocol.getNamespacePrefix());
    issue.addTextNode(conf.getFile());
  }
  SOAPElement protocolVersion = header.addChildElement("protocolVersion", protocol.getNamespacePrefix());
  protocolVersion.addTextNode(protocol.getCode());

  addClientElements(env, conf, header);
  addServiceElements(env, conf, header);
}
 
Example #19
Source File: TorXTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
  callback.doWithMessage(message);
  try {
    SaajSoapMessage saajMessage = (SaajSoapMessage) message;
    SOAPMessage soapmess = saajMessage.getSaajMessage();
    SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();
    env.addNamespaceDeclaration("xro", "http://x-road.ee/xsd/x-road.xsd");
    Iterator headers = env.getHeader().getChildElements();
    while (headers.hasNext()) {
      SOAPElement header = (SOAPElement) headers.next();
      if (header.getNamespaceURI().equalsIgnoreCase("http://x-rd.net/xsd/xroad.xsd")) {
        String localHeaderName = header.getLocalName();
        QName qName = new QName("http://x-road.ee/xsd/x-road.xsd", localHeaderName, "xro");
        header.setElementQName(qName);
      }
    }
  } catch (SOAPException e) {
    throw new RuntimeException(e);
  }

}
 
Example #20
Source File: Adsv5XTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
  callback.doWithMessage(message);
  try {
    SaajSoapMessage saajMessage = (SaajSoapMessage) message;
    SOAPMessage soapmess = saajMessage.getSaajMessage();
    SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();
    env.addNamespaceDeclaration("xro", "http://x-road.ee/xsd/x-road.xsd");
    Iterator headers = env.getHeader().getChildElements();
    while (headers.hasNext()) {
      SOAPElement header = (SOAPElement) headers.next();
      if (header.getNamespaceURI().equalsIgnoreCase("http://x-rd.net/xsd/xroad.xsd")) {
        String localHeaderName = header.getLocalName();
        QName qName = new QName("http://x-road.ee/xsd/x-road.xsd", localHeaderName, "xro");
        header.setElementQName(qName);
      }
    }
  } catch (SOAPException e) {
    throw new RuntimeException(e);
  }

}
 
Example #21
Source File: SoapRequestParserTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void parseApiVersion_cm_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("cm.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
 
Example #22
Source File: SoapRequestParserTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Test
public void parseApiVersion_ctmg_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("ctmg.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
 
Example #23
Source File: JPlagClientAccessHandler.java    From jplag with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds an "Access" element to the SOAP header
 */
public boolean handleRequest(MessageContext msgct) {
	if (msgct instanceof SOAPMessageContext) {
		SOAPMessageContext smsgct = (SOAPMessageContext) msgct;
		try {
			SOAPMessage msg = smsgct.getMessage();
			SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
			SOAPHeader header = msg.getSOAPHeader();

			if (header == null)
				header = envelope.addHeader(); // add an header if non exists

			SOAPHeaderElement accessElement = header.addHeaderElement(envelope.createName("Access", "ns0", JPLAG_TYPES_NS));
			SOAPElement usernameelem = accessElement.addChildElement("username");
			usernameelem.addTextNode(username);
			SOAPElement passwordelem = accessElement.addChildElement("password");
			passwordelem.addTextNode(password);
			SOAPElement compatelem = accessElement.addChildElement("compatLevel");
			compatelem.addTextNode(compatibilityLevel + "");
		} catch (SOAPException x) {
			System.out.println("Unable to create access SOAP header!");
			x.printStackTrace();
		}
	}
	return true;
}
 
Example #24
Source File: SoapRequestBean.java    From openxds with Apache License 2.0 6 votes vote down vote up
public SOAPMessage onMessage(SOAPMessage msg){
    //handles the response back from the registry
    PrintStream orig = System.out;
    
    try {
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        Name response = env.createName("response");
        env.getBody().getChildElements(response);
        
    } catch (SOAPException ex) {
        ByteArrayOutputStream logarray = new ByteArrayOutputStream();
        ex.printStackTrace(writeErrorlog(logarray));
        logstring = logarray.toString();
        setlogmsg(logstring);  
    }
    
    return msg;
}
 
Example #25
Source File: SoapProtocol.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void setOutputEncodingStyle( SOAPEnvelope soapEnvelope, String operationName )
	throws IOException, SOAPException {
	Port port = getWSDLPort();
	if( port != null ) {
		BindingOperation bindingOperation = port.getBinding().getBindingOperation( operationName, null, null );
		if( bindingOperation == null ) {
			return;
		}
		BindingOutput output = bindingOperation.getBindingOutput();
		if( output == null ) {
			return;
		}
		for( ExtensibilityElement element : (List< ExtensibilityElement >) output.getExtensibilityElements() ) {
			if( element instanceof javax.wsdl.extensions.soap.SOAPBody ) {
				List< String > list = ((javax.wsdl.extensions.soap.SOAPBody) element).getEncodingStyles();
				if( list != null && list.isEmpty() == false ) {
					soapEnvelope.setEncodingStyle( list.get( 0 ) );
					soapEnvelope.addNamespaceDeclaration( "enc", list.get( 0 ) );
				}
			}
		}
	}
}
 
Example #26
Source File: ConsumerGateway.java    From xroad-rest-gateway with European Union Public License 1.1 6 votes vote down vote up
@Override
protected void serializeRequest(ServiceRequest request, SOAPElement soapRequest, SOAPEnvelope envelope) throws SOAPException {
    SOAPElement payload = SOAPHelper.xmlStrToSOAPElement("<" + Constants.PARAM_ENCRYPTION_WRAPPER + "/>");
    try {
        // Create new symmetric encrypter using of defined key length
        Encrypter symmetricEncrypter = RESTGatewayUtil.createSymmetricEncrypter(this.keyLength);
        // Process request parameters
        handleBody(request, payload);
        // Process request body 
        if (this.requestBody != null && !this.requestBody.isEmpty()) {
            handleAttachment(request, payload, envelope, symmetricEncrypter.encrypt(this.requestBody));
        }
        // Encrypt message with symmetric AES encryption
        String encryptedData = symmetricEncrypter.encrypt(SOAPHelper.toString(payload));
        // Build message body that includes enrypted data,
        // encrypted session key and IV
        RESTGatewayUtil.buildEncryptedBody(symmetricEncrypter, asymmetricEncrypter, soapRequest, encryptedData);
    } catch (NoSuchAlgorithmException ex) {
        logger.error(ex.getMessage(), ex);
        throw new SOAPException("Encrypting SOAP request failed.", ex);
    }
}
 
Example #27
Source File: SOAPRequestBuilder.java    From cougar with Apache License 2.0 5 votes vote down vote up
public void iterate(SOAPEnvelope envelope, Node node,
		SOAPElement parentElement) throws SOAPException {

	// if the node is an element then process it and it's children
	if(node instanceof Element){
		
			Element elemt = (Element) node;
			String localName = elemt.getNodeName();
			SOAPElement newParent = parentElement.addChildElement(localName,"bas", nameSpace);
			
			// If the node has attributes then process them
			if(node.hasAttributes()){
				AttributeMap map = (AttributeMap) node.getAttributes();
				for (int x = 0; x < map.getLength(); x++) {
					String name = map.item(x).getNodeName();
					newParent.setAttribute(name, map.item(x).getNodeValue());
				}
			}
			
			org.w3c.dom.NodeList childNodes = node.getChildNodes();
			// for each of this nodes children recursively call this method
			for (int i = 0; i < childNodes.getLength(); i++) {
				iterate(envelope, childNodes.item(i), newParent);
			}
			
	} else if (node.getNodeType() == Node.TEXT_NODE){ // Node is a text node so add it's value
		String value = node.getNodeValue();
		if (value==null) {
			parentElement.addTextNode("");
		} else {
			parentElement.addTextNode(value);
		}
	}
	// Else is some other kind of node which can be ignored
}
 
Example #28
Source File: TarnXTeeServiceImpl.java    From j-road with Apache License 2.0 5 votes vote down vote up
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
  try {
    SaajSoapMessage saajMessage = (SaajSoapMessage) message;
    SOAPMessage soapmess = saajMessage.getSaajMessage();
    SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();
    env.addNamespaceDeclaration("eto", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
  } catch (SOAPException e) {
    throw new RuntimeException(e);
  }
  callback.doWithMessage(message);
}
 
Example #29
Source File: NBProviderClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private SOAPMessage encodeRequest(MessageFactory factory, String value) throws SOAPException {
    SOAPMessage request = factory.createMessage();
    SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
    request.setProperty("soapaction", "");
    if (value != null) {
        request.getSOAPBody().addBodyElement(envelope.createName(value, "ns1", sayHi.getNamespaceURI()));
    }

    return request;
}
 
Example #30
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 5 votes vote down vote up
@Override
public void addNamespaces(SOAPEnvelope env) throws SOAPException {
  env.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
  env.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
  env.addNamespaceDeclaration(protocol.getNamespacePrefix(), protocol.getNamespaceUri());
  env.addNamespaceDeclaration("id", "http://x-road.eu/xsd/identifiers");
}