public static Name newName(final QName faultCode, final SOAPEnvelope soapEnvelope) throws SOAPException { return soapEnvelope.createName(faultCode.getLocalPart(), faultCode.getPrefix(), faultCode.getNamespaceURI()); }
protected void addParameterList(SOAPEnvelope envelope, SOAPElement eParent, String typeName, String listName, Map params) throws SOAPException { Name nPara = envelope.createName(typeName, "", XMLA_URI); SOAPElement eType = eParent.addChildElement(nPara); nPara = envelope.createName(listName, "", XMLA_URI); SOAPElement eList = eType.addChildElement(nPara); if (params == null) return; Iterator it = params.keySet().iterator(); while (it.hasNext()) { String tag = (String) it.next(); String value = (String) params.get(tag); nPara = envelope.createName(tag, "", XMLA_URI); SOAPElement eTag = eList.addChildElement(nPara); eTag.addTextNode(value); } }
private void writeEchoResponse(SOAPMessage message) throws SOAPException { SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); Name echoResponseName = envelope.createName("echoResponse", PREFIX, NAMESPACE_URI); SOAPBodyElement echoResponseElement = (SOAPBodyElement) message .getSOAPBody().getChildElements(echoResponseName).next(); String echoValue = echoResponseElement.getTextContent(); System.out.println(); System.out.println("Echo Response [" + echoValue + "]"); System.out.println(); }
SOAPConnectionFactory soapfactory=SOAPConnectionFactory.newInstance(); SOAPConnection soapconnection=soapfactory.createConnection(); MessageFactory messagefactory=MessageFactory.newInstance(); SOAPMessage messege=messagefactory.createMessage(); SOAPEnvelope envelop=messege.getSOAPPart().getEnvelope(); SOAPHeader header=messege.getSOAPHeader(); SOAPBody body=messege.getSOAPBody(); Name header_context=envelop.createName("context", null,"urn:zimbra"); Name auth_request=envelop.createName("AuthRequest",null,"urn:zimbraAccount"); Name account=envelop.createName("account"); Name password=envelop.createName("password"); header.addHeaderElement(header_context); SOAPBodyElement auth_body=body.addBodyElement(auth_request); auth_body.addChildElement(account).addAttribute(envelop.createName("by"),"name").addTextNode("abc");//(abc==your username) auth_body.addChildElement(password).addTextNode("1234");//(1234=your password) URL url=new URL("http://192.168.1.67/service/soap/AuthRequest"); SOAPMessage response=soapconnection.call(messege, url);
/** * Add body element to envelope. * * @param naam the naam * @param prefix the prefix * @param namespaceUri the namespace uri * @throws SOAPException the soap exception */ public void addBodyElementToEnvelope(String naam, String prefix, String namespaceUri) throws SOAPException { SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement bodyElement = soapMessage.getSOAPBody().addBodyElement(envelope.createName(naam, prefix, namespaceUri)); this.elements.put(naam, bodyElement); }
/** * Add body element to envelope. * * @param naam the naam * @throws SOAPException the soap exception */ public void addBodyElementToEnvelope(String naam) throws SOAPException { SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement bodyElement = soapMessage.getSOAPBody().addBodyElement(envelope.createName(naam)); this.elements.put(naam, bodyElement); }
/** * Add child element to element. * * @param parentElementNaam the parent element naam * @param elementNaam the element naam * @param value the value * @throws SOAPException the soap exception */ public void addChildElementToElement(String parentElementNaam, String elementNaam, String value) throws SOAPException { SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); Name name = envelope.createName(elementNaam); addElementToElement(parentElementNaam, elementNaam, name, value); }
/** * Add child element to element. * * @param parentElementNaam the parent element naam * @param elementNaam the element naam * @param prefix the prefix * @param namespaceUri the namespace uri * @param value the value * @throws SOAPException the soap exception */ public void addChildElementToElement(String parentElementNaam, String elementNaam, String prefix, String namespaceUri, String value) throws SOAPException { SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); Name name = envelope.createName(elementNaam, prefix, namespaceUri); addElementToElement(parentElementNaam, elementNaam, name, value); }
public boolean handleMessage(SOAPMessageContext context) { if (callbackAddress == null) { callbackAddress = endpointService.getEndpointUrl(callbackUri); } try { SOAPMessage soapMessage = context.getMessage(); SOAPHeader header = soapMessage.getSOAPHeader(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement element = header.addHeaderElement(envelope.createName("From", "wsa", WSA)); element.addChildElement(envelope.createName("Address", "wsa", WSA)).addTextNode(callbackAddress.toString()); } catch (SOAPException e) { throw new ServiceRuntimeException(e); } return true; }
private SOAPMessage createSoapMessage( SOAPVersion soapVersion, String contentId ) throws SOAPException { String soapProtocol = SOAPConstants.SOAP_1_2_PROTOCOL; if ( isSoap11( soapVersion ) ) soapProtocol = SOAPConstants.SOAP_1_1_PROTOCOL; MessageFactory messageFactory = MessageFactory.newInstance( soapProtocol ); SOAPMessage message = messageFactory.createMessage(); SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody body = envelope.getBody(); envelope.createName( "response", CommonNamespaces.WMS_PREFIX, CommonNamespaces.WMSNS ); Name name = envelope.createName( "response", CommonNamespaces.WMS_PREFIX, CommonNamespaces.WMSNS ); SOAPBodyElement bodyElement = body.addBodyElement( name ); bodyElement.setTextContent( contentId ); return message; }
private void createPaosRequestHeader(SOAPEnvelope envelope) throws SOAPException { SOAPHeader headers = envelope.getHeader(); SOAPHeaderElement paosRequestHeader = headers.addHeaderElement(envelope.createQName(JBossSAMLConstants.REQUEST.get(), NS_PREFIX_PAOS_BINDING)); paosRequestHeader.setMustUnderstand(true); paosRequestHeader.setActor("http://schemas.xmlsoap.org/soap/actor/next"); paosRequestHeader.addAttribute(envelope.createName("service"), JBossSAMLURIConstants.ECP_PROFILE.get()); paosRequestHeader.addAttribute(envelope.createName("responseConsumerURL"), getResponseConsumerUrl()); }
private void createEcpRequestHeader(SOAPEnvelope envelope) throws SOAPException { SOAPHeader headers = envelope.getHeader(); SOAPHeaderElement ecpRequestHeader = headers.addHeaderElement(envelope.createQName(JBossSAMLConstants.REQUEST.get(), NS_PREFIX_PROFILE_ECP)); ecpRequestHeader.setMustUnderstand(true); ecpRequestHeader.setActor("http://schemas.xmlsoap.org/soap/actor/next"); ecpRequestHeader.addAttribute(envelope.createName("ProviderName"), deployment.getEntityID()); ecpRequestHeader.addAttribute(envelope.createName("IsPassive"), "0"); ecpRequestHeader.addChildElement(envelope.createQName("Issuer", "saml")).setValue(deployment.getEntityID()); ecpRequestHeader.addChildElement(envelope.createQName("IDPList", "samlp")) .addChildElement(envelope.createQName("IDPEntry", "samlp")) .addAttribute(envelope.createName("ProviderID"), deployment.getIDP().getEntityID()) .addAttribute(envelope.createName("Name"), deployment.getIDP().getEntityID()) .addAttribute(envelope.createName("Loc"), deployment.getIDP().getSingleSignOnService().getRequestBindingUrl()); }
SOAPMessage soapMessage = soapContext.getMessage(); SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope(); SOAPHeader soapHeader = soapEnvelope.getHeader(); /* If no header, add one */ if (soapHeader == null) { soapHeader = soapEnvelope.addHeader(); } /* Add a soap header, name as AUTH_ID_KEY */ Name name = soapEnvelope.createName(AUTH_ID_KEY); SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(name); soapHeaderElement.addTextNode(authId); soapMessage.saveChanges();
private SOAPMessage createEchoRequest() throws SOAPException { SOAPMessage message = messageFactory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); Name echoRequestName = envelope.createName("echoRequest", PREFIX, NAMESPACE_URI); SOAPBodyElement echoRequestElement = message.getSOAPBody() .addBodyElement(echoRequestName); echoRequestElement.setValue("Hello"); return message; }
/** * Converts this instance into a SOAP header element. * * @param version WS-Addressing version to use * @param env Envelope to put the header into * @param actorURI Actor URI * @param name Element name * @return Created element * @throws SOAPException If an error occurs */ protected SOAPHeaderElement toSOAPHeaderElement(AddressingVersion version, SOAPEnvelope env, String actorURI, String name) throws SOAPException { if (name == null) { throw new IllegalArgumentException("A null name is not allowed."); } Name qname = env.createName(name, Constants.NS_PREFIX_ADDRESSING, version .getNamespace()); SOAPHeader header = env.getHeader(); if (header == null) { header = env.addHeader(); } // add the new header element SOAPHeaderElement headerElement = header.addHeaderElement(qname); headerElement.setActor(actorURI); headerElement.addTextNode(this.toString()); return headerElement; }
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage message = messageFactory.createMessage(); SOAPPart SOAPPart = message.getSOAPPart(); SOAPEnvelope envelope = SOAPPart.getEnvelope(); SOAPBody body = envelope.getBody(); SOAPElement bodyElement = body.addChildElement(envelope.createName("echo", "req", "http://localhost:8080/axis2/services/MyService/")); bodyElement.addChildElement("category").addTextNode("classifieds"); message.saveChanges(); SOAPPart SOAPpartbefore = message.getSOAPPart(); SOAPEnvelope reqenv = SOAPpartbefore.getEnvelope(); System.out.println(reqenv.toString());
SOAPHeader soapHeader = envelope.addHeader(); Name header = envelope.createName("Header", "soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
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; }
MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("ns", "website"); envelope.addNamespaceDeclaration("com", "website/Common"); envelope.addNamespaceDeclaration("xm", "http://www.w3.org/2005/05/xmlmime"); SOAPBody soapBody = envelope.getBody(); SOAPElement element = soapBody.addChildElement("RequestName", "ns"); SOAPElement modelElement = element.addChildElement("model", "ns"); SOAPElement soapElement = modelElement.addChildElement("keys", "ns"); soapElement.addAttribute(envelope.createName("query"), "myquery;"); modelElement.addChildElement("instance", "ns"); soapMessage.saveChanges(); soapMessage.writeTo(System.out);
/** * {@inheritDoc} */ public SOAPHeaderElement toSOAPHeaderElement(AddressingVersion version, SOAPEnvelope env, String actorURI) throws SOAPException { Name nm = env.createName(Constants.RELATES_TO, Constants.NS_PREFIX_ADDRESSING, version.getNamespace()); SOAPHeader header = env.getHeader(); if (header == null) { header = env.addHeader(); } SOAPHeaderElement headerElement = (SOAPHeaderElement) header.addHeaderElement(nm); headerElement.setActor(actorURI); String typeIRI = this.getTypeIRI(); QName type = this.getType(); if (typeIRI != null) { headerElement.addAttribute("", Constants.RELATIONSHIP_TYPE, typeIRI); } else if (type != null) { headerElement.addAttribute("", Constants.RELATIONSHIP_TYPE, type); } headerElement.addTextNode(this.getURI().toString()); return headerElement; }