本文整理汇总了Java中org.opensaml.ws.soap.soap11.Envelope类的典型用法代码示例。如果您正苦于以下问题:Java Envelope类的具体用法?Java Envelope怎么用?Java Envelope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Envelope类属于org.opensaml.ws.soap.soap11包,在下文中一共展示了Envelope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractRequest
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
private OIOLogoutRequest extractRequest(HttpServletRequest request) throws IOException {
InputStream is = request.getInputStream();
// Unpack the <LogoutRequest>
String xml = IOUtils.toString(is, "UTF-8");
XMLObject xmlObject = SAMLUtil.unmarshallElementFromString(xml);
if (log.isDebugEnabled()) log.debug("Request..:" + xml);
if (xmlObject != null && xmlObject instanceof Envelope) {
Envelope envelope = (Envelope) xmlObject;
Body body = envelope.getBody();
xmlObject = (XMLObject) body.getUnknownXMLObjects().get(0);
if (xmlObject != null && xmlObject instanceof LogoutRequest) {
LogoutRequest logoutRequest = (LogoutRequest) xmlObject;
return new OIOLogoutRequest(logoutRequest);
}
}
throw new RuntimeException("SOAP request did not contain a LogoutRequest on the body");
}
示例2: buildSOAPMessage
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
@Override
protected Envelope buildSOAPMessage(final SAMLObject samlMessage) {
final XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
final SOAPObjectBuilder<Envelope> envBuilder =
(SOAPObjectBuilder<Envelope>) builderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
final Envelope envelope = envBuilder.buildObject(
SOAPConstants.SOAP11_NS, Envelope.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX);
final SOAPObjectBuilder<Body> bodyBuilder =
(SOAPObjectBuilder<Body>) builderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME);
final Body body = bodyBuilder.buildObject(
SOAPConstants.SOAP11_NS, Body.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX);
body.getUnknownXMLObjects().add(samlMessage);
envelope.setBody(body);
return envelope;
}
示例3: send
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/** {@inheritDoc} */
public void send(String endpoint, SOAPMessageContext messageContext) throws SOAPException, SecurityException {
PostMethod post = null;
try {
post = createPostMethod(endpoint, (HttpSOAPRequestParameters) messageContext.getSOAPRequestParameters(),
(Envelope) messageContext.getOutboundMessage());
int result = httpClient.executeMethod(post);
log.debug("Received HTTP status code of {} when POSTing SOAP message to {}", result, endpoint);
if (result == HttpStatus.SC_OK) {
processSuccessfulResponse(post, messageContext);
} else if (result == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
processFaultResponse(post, messageContext);
} else {
throw new SOAPClientException("Received " + result + " HTTP response status code from HTTP request to "
+ endpoint);
}
} catch (IOException e) {
throw new SOAPClientException("Unable to send request to " + endpoint, e);
} finally {
if (post != null) {
post.releaseConnection();
}
}
}
示例4: createRequestEntity
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Creates the request entity that makes up the POST message body.
*
* @param message message to be sent
* @param charset character set used for the message
*
* @return request entity that makes up the POST message body
*
* @throws SOAPClientException thrown if the message could not be marshalled
*/
protected RequestEntity createRequestEntity(Envelope message, Charset charset) throws SOAPClientException {
try {
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset);
if (log.isDebugEnabled()) {
log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message)));
}
XMLHelper.writeNode(marshaller.marshall(message), writer);
return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml");
} catch (MarshallingException e) {
throw new SOAPClientException("Unable to marshall SOAP envelope", e);
}
}
示例5: processFaultResponse
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Processes a SOAP fault, as determined by an HTTP 500 status code, response.
*
* @param httpMethod the HTTP method used to send the request and receive the response
* @param messageContext current messages context
*
* @throws SOAPClientException thrown if the response can not be read from the {@link PostMethod}
* @throws SOAPFaultException an exception containing the SOAP fault
*/
protected void processFaultResponse(PostMethod httpMethod, SOAPMessageContext messageContext)
throws SOAPClientException, SOAPFaultException {
try {
Envelope response = unmarshallResponse(httpMethod.getResponseBodyAsStream());
messageContext.setInboundMessage(response);
List<XMLObject> faults = response.getBody().getUnknownXMLObjects(Fault.DEFAULT_ELEMENT_NAME);
if (faults.size() < 1) {
throw new SOAPClientException("HTTP status code was 500 but SOAP response did not contain a Fault");
}
Fault fault = (Fault) faults.get(0);
log.debug("SOAP fault code {} with message {}", fault.getCode().getValue(), fault.getMessage().getValue());
SOAPFaultException faultException = new SOAPFaultException("SOAP Fault: " + fault.getCode().getValue()
+ " Fault Message: " + fault.getMessage().getValue());
faultException.setFault(fault);
throw faultException;
} catch (IOException e) {
throw new SOAPClientException("Unable to read response", e);
}
}
示例6: checkUnderstoodSOAPHeaders
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Check that all headers which carry the <code>soap11:mustUnderstand</code> attribute
* and which are targeted to this SOAP node via the <code>soap11:actor</code> were understood by the
* decoder.
*
* @param messageContext the message context being processed
*
* @throws MessageDecodingException thrown if a SOAP header requires understanding by
* this node but was not understood
*/
private void checkUnderstoodSOAPHeaders(MessageContext messageContext)
throws MessageDecodingException {
Envelope envelope = (Envelope) messageContext.getInboundMessage();
Header soapHeader = envelope.getHeader();
if (soapHeader == null) {
log.debug("SOAP Envelope contained no Header");
return;
}
List<XMLObject> headers = soapHeader.getUnknownXMLObjects();
if (headers == null || headers.isEmpty()) {
log.debug("SOAP Envelope header list was either null or empty");
return;
}
for (XMLObject header : headers) {
//TODO
}
}
示例7: getInboundHeaderBlock
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Get a header block from the SOAP envelope contained within the specified message context's
* {@link MessageContext#getInboundMessage()}.
*
* @param msgContext the message context being processed
* @param headerName the name of the header block to return
* @param targetNodes the explicitly specified SOAP node actors (1.1) or roles (1.2) for which the header is desired
* @param isFinalDestination true specifies that headers targeted for message final destination should be returned,
* false means they should not be returned
* @return the list of matching header blocks
*/
public static List<XMLObject> getInboundHeaderBlock(MessageContext msgContext, QName headerName,
Set<String> targetNodes, boolean isFinalDestination) {
XMLObject inboundEnvelope = msgContext.getInboundMessage();
if (inboundEnvelope == null) {
throw new IllegalArgumentException("Message context does not contain an inbound SOAP envelope");
}
// SOAP 1.1 Envelope
if (inboundEnvelope instanceof Envelope) {
return getSOAP11HeaderBlock((Envelope) inboundEnvelope, headerName, targetNodes, isFinalDestination);
}
//TODO SOAP 1.2 support when object providers are implemented
return Collections.emptyList();
}
示例8: getOutboundHeaderBlock
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Get a header block from the SOAP envelope contained within the specified message context's
* {@link MessageContext#getOutboundMessage()}.
*
* @param msgContext the message context being processed
* @param headerName the name of the header block to return
* @param targetNodes the explicitly specified SOAP node actors (1.1) or roles (1.2) for which the header is desired
* @param isFinalDestination true specifies that headers targeted for message final destination should be returned,
* false specifies they should not be returned
* @return the list of matching header blocks
*/
public static List<XMLObject> getOutboundHeaderBlock(MessageContext msgContext, QName headerName,
Set<String> targetNodes, boolean isFinalDestination) {
XMLObject outboundEnvelope = msgContext.getOutboundMessage();
if (outboundEnvelope == null) {
throw new IllegalArgumentException("Message context does not contain an outbound SOAP envelope");
}
// SOAP 1.1 Envelope
if (outboundEnvelope instanceof Envelope) {
return getSOAP11HeaderBlock((Envelope) outboundEnvelope, headerName, targetNodes, isFinalDestination);
}
//TODO SOAP 1.2 support when object providers are implemented
return Collections.emptyList();
}
示例9: getSOAP11HeaderBlock
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Get a header block from the SOAP 1.1 envelope.
*
* @param envelope the SOAP 1.1 envelope to process
* @param headerName the name of the header block to return
* @param targetNodes the explicitly specified SOAP node actors for which the header is desired
* @param isFinalDestination true specifies that headers targeted for message final destination should be returned,
* false specifies they should not be returned
* @return the list of matching header blocks
*/
public static List<XMLObject> getSOAP11HeaderBlock(Envelope envelope, QName headerName, Set<String> targetNodes,
boolean isFinalDestination) {
Header envelopeHeader = envelope.getHeader();
if (envelopeHeader == null) {
return Collections.emptyList();
}
ArrayList<XMLObject> headers = new ArrayList<XMLObject>();
for (XMLObject header : envelopeHeader.getUnknownXMLObjects(headerName)) {
if (isSOAP11HeaderTargetedToNode(header, targetNodes, isFinalDestination)) {
headers.add(header);
}
}
return headers;
}
示例10: buildSOAPMessage
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Builds the SOAP message to be encoded.
*
* @param samlMessage body of the SOAP message
*
* @return the SOAP message
*/
@SuppressWarnings("unchecked")
protected Envelope buildSOAPMessage(SAMLObject samlMessage) {
log.debug("Building SOAP message");
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory
.getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
Envelope envelope = envBuilder.buildObject();
log.debug("Adding SAML message to the SOAP message's body");
SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory
.getBuilder(Body.DEFAULT_ELEMENT_NAME);
Body body = bodyBuilder.buildObject();
body.getUnknownXMLObjects().add(samlMessage);
envelope.setBody(body);
return envelope;
}
示例11: buildSOAPMessage
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Builds the SOAP message to be encoded.
*
* @param samlMessage body of the SOAP message
*
* @return the SOAP message
*/
@SuppressWarnings("unchecked")
protected Envelope buildSOAPMessage(SAMLObject samlMessage) {
if (log.isDebugEnabled()) {
log.debug("Building SOAP message");
}
XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory
.getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
Envelope envelope = envBuilder.buildObject();
if (log.isDebugEnabled()) {
log.debug("Adding SAML message to the SOAP message's body");
}
SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory
.getBuilder(Body.DEFAULT_ELEMENT_NAME);
Body body = bodyBuilder.buildObject();
body.getUnknownXMLObjects().add(samlMessage);
envelope.setBody(body);
return envelope;
}
示例12: prepareMessageContext
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Perform final binding-specific processing of message context and prepare it for encoding
* to the transport.
*
* <p>
* This should include constructing and populating all binding-specific structure and data that needs to be
* reflected by the message context's properties.
* </p>
*
* <p>
* This method is called prior to {@link #processOutboundHandlerChain(MessageContext)}.
* </p>
*
* @param messageContext the message context to process
* @throws MessageEncodingException thrown if there is a problem preparing the message context
* for encoding
*/
protected void prepareMessageContext(MessageContext messageContext) throws MessageEncodingException {
SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;
SAMLObject samlMessage = samlMsgCtx.getOutboundSAMLMessage();
if (samlMessage == null) {
throw new MessageEncodingException("No outbound SAML message contained in message context");
}
signMessage(samlMsgCtx);
log.debug("Building SOAP envelope");
Envelope envelope = envBuilder.buildObject();
Body body = bodyBuilder.buildObject();
envelope.setBody(body);
body.getUnknownXMLObjects().add(samlMessage);
messageContext.setOutboundMessage(envelope);
}
示例13: missingFrameworkHeaderShouldFail
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
@Test
public void missingFrameworkHeaderShouldFail() throws Exception {
SOAPClientStub soapClient = new SOAPClientStub();
serviceClient.setSOAPClient(soapClient);
serviceClient.sendRequest(req, getProperty("endpoint"), getProperty("action"), null, null);
Envelope env = (Envelope) SAMLUtil.unmarshallElementFromString(soapClient.xml);
env.getHeader().getUnknownXMLObjects().remove(env.getHeader().getUnknownXMLObjects(new QName("urn:liberty:sb:2006-08", "Framework")).get(0));
env.getHeader().getUnknownXMLObjects().remove(SAMLUtil.getFirstElement(env.getHeader(), Security.class));
OIOSoapEnvelope e = new OIOSoapEnvelope(env, true, new SigningPolicy(true));
e.addSecurityTokenReference(token, Boolean.valueOf(getProperty("protectTokens")));
e.setTimestamp(5);
try {
new HttpSOAPClient().wsCall(getProperty("endpoint"), null, null, true, XMLHelper.nodeToString(e.sign(credential)), getProperty("action"));
} catch (SOAPException ex) {
assertNotNull(ex.getFault());
assertNotNull(ex.getFault().getCode());
assertEquals(new QName("urn:liberty:sb:2006-08", "FrameworkVersionMismatch"), ex.getFault().getCode().getValue());
}
}
示例14: wrongFrameworkHeaderShouldFail
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
@Test
public void wrongFrameworkHeaderShouldFail() throws Exception {
SOAPClientStub soapClient = new SOAPClientStub();
serviceClient.setSOAPClient(soapClient);
serviceClient.sendRequest(req, getProperty("endpoint"), getProperty("action"), null, null);
Envelope env = (Envelope) SAMLUtil.unmarshallElementFromString(soapClient.xml);
XSAny framework = (XSAny) env.getHeader().getUnknownXMLObjects(new QName("urn:liberty:sb:2006-08", "Framework")).get(0);
framework.getUnknownAttributes().put(new QName("version"), "1.0");
env.getHeader().getUnknownXMLObjects().remove(SAMLUtil.getFirstElement(env.getHeader(), Security.class));
OIOSoapEnvelope e = new OIOSoapEnvelope(env, true, new SigningPolicy(true));
e.addSecurityTokenReference(token, Boolean.valueOf(getProperty("protectTokens")));
e.setTimestamp(5);
try {
new HttpSOAPClient().wsCall(getProperty("endpoint"), null, null, true, XMLHelper.nodeToString(e.sign(credential)), getProperty("action"));
} catch (SOAPException ex) {
assertEquals(new QName("urn:liberty:sb:2006-08", "FrameworkVersionMismatch"), ex.getFault().getCode().getValue());
}
}
示例15: buildEnvelope
import org.opensaml.ws.soap.soap11.Envelope; //导入依赖的package包/类
/**
* Build a new soap envelope with standard OIO headers.
*
* Standard headers include sbf:Framework, wsa:MessageID, and an empty Security header.
*/
public static OIOSoapEnvelope buildEnvelope(String soapVersion, SigningPolicy signingPolicy, boolean includeFrameworkHeader) {
Envelope env = envelopeBuilder.buildObject(soapVersion, "Envelope", "s");
Header header = headerBuilder.buildObject(soapVersion, "Header", "s");
env.setHeader(header);
MessageID msgId = SAMLUtil.buildXMLObject(MessageID.class);
msgId.setValue("urn:uuid:" + UUID.randomUUID().toString());
header.getUnknownXMLObjects().add(msgId);
XSAny framework = null;
if (includeFrameworkHeader) {
framework = new XSAnyBuilder().buildObject("urn:liberty:sb:2006-08", "Framework", "sbf");
framework.getUnknownAttributes().put(new QName("version"), "2.0");
framework.getUnknownAttributes().put(new QName("urn:liberty:sb:profile", "profile"), "urn:liberty:sb:profile:basic");
framework.getUnknownAttributes().put(new QName(soapVersion, "mustUnderstand"), "1");
header.getUnknownXMLObjects().add(framework);
}
Security security = SAMLUtil.buildXMLObject(Security.class);
security.getUnknownAttributes().put(new QName(env.getElementQName().getNamespaceURI(), "mustUnderstand"), "1");
env.getHeader().getUnknownXMLObjects().add(security);
return new OIOSoapEnvelope(env, msgId, framework, signingPolicy);
}