public SecurityToken logon( String anEndpointReference, String aUserName, String aPassword, String anApplicationID) throws LogonManagerException, SOAPException, IOException { SecurityToken result; SOAPMessage message; SOAPConnection conn = null; try { result = null; String request = REQUEST_FORMAT.format( ((Object) (new Object[] {fURL, aUserName, aPassword, anEndpointReference}))); message = MessageFactory.newInstance() .createMessage(new MimeHeaders(), new ByteArrayInputStream(request.getBytes())); conn = SOAPConnectionFactory.newInstance().createConnection(); SOAPMessage response = conn.call(message, fURL); SOAPBody body = response.getSOAPBody(); if (body.hasFault()) throw new LogonManagerException(body.getFault()); result = new SecurityToken(); result.setSOAPBody(body); for (Iterator it = body.getChildElements(); it.hasNext(); fill(result, (Node) it.next())) ; return result; } finally { if (conn != null) conn.close(); } }
public ExtensibilityElement unmarshall( Class parentType, QName elementType, Element el, Definition def, ExtensionRegistry extReg) throws WSDLException { SOAPBody soapBody = (SOAPBody) extReg.createExtension(parentType, elementType); String partsStr = DOMUtils.getAttribute(el, SOAPConstants.ATTR_PARTS); String use = DOMUtils.getAttribute(el, SOAPConstants.ATTR_USE); String encStyleStr = DOMUtils.getAttribute(el, SOAPConstants.ATTR_ENCODING_STYLE); String namespaceURI = DOMUtils.getAttribute(el, Constants.ATTR_NAMESPACE); String requiredStr = DOMUtils.getAttributeNS(el, Constants.NS_URI_WSDL, Constants.ATTR_REQUIRED); if (partsStr != null) { soapBody.setParts(StringUtils.parseNMTokens(partsStr)); } if (use != null) { soapBody.setUse(use); } if (encStyleStr != null) { soapBody.setEncodingStyles(StringUtils.parseNMTokens(encStyleStr)); } if (namespaceURI != null) { soapBody.setNamespaceURI(namespaceURI); } if (requiredStr != null) { soapBody.setRequired(new Boolean(requiredStr)); } return soapBody; }
public void marshall( Class parentType, QName elementType, ExtensibilityElement extension, PrintWriter pw, Definition def, ExtensionRegistry extReg) throws WSDLException { SOAPBody soapBody = (SOAPBody) extension; if (soapBody != null) { String tagName = DOMUtils.getQualifiedValue(SOAPConstants.NS_URI_SOAP, "body", def); if (parentType != null && MIMEPart.class.isAssignableFrom(parentType)) { pw.print(" "); } pw.print(" <" + tagName); DOMUtils.printAttribute( SOAPConstants.ATTR_PARTS, StringUtils.getNMTokens(soapBody.getParts()), pw); DOMUtils.printAttribute(SOAPConstants.ATTR_USE, soapBody.getUse(), pw); DOMUtils.printAttribute( SOAPConstants.ATTR_ENCODING_STYLE, StringUtils.getNMTokens(soapBody.getEncodingStyles()), pw); DOMUtils.printAttribute(Constants.ATTR_NAMESPACE, soapBody.getNamespaceURI(), pw); Boolean required = soapBody.getRequired(); if (required != null) { DOMUtils.printQualifiedAttribute(Constants.Q_ATTR_REQUIRED, required.toString(), def, pw); } pw.println("/>"); } }
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { String retval = "<html> <H4>"; try { // Create a message factory. MessageFactory mf = MessageFactory.newInstance(); // Create a message from the message factory. SOAPMessage msg = mf.createMessage(); // Message creation takes care of creating the SOAPPart - a // required part of the message as per the SOAP 1.1 // specification. SOAPPart sp = msg.getSOAPPart(); // Retrieve the envelope from the soap part to start building // the soap message. SOAPEnvelope envelope = sp.getEnvelope(); // Create a soap header from the envelope. SOAPHeader hdr = envelope.getHeader(); // Create a soap body from the envelope. SOAPBody bdy = envelope.getBody(); // Add a soap body element to the soap body SOAPBodyElement gltp = bdy.addBodyElement( envelope.createName("GetLastTradePrice", "ztrade", "http://wombat.ztrade.com")); gltp.addChildElement(envelope.createName("symbol", "ztrade", "http://wombat.ztrade.com")) .addTextNode("SUNW"); StringBuffer urlSB = new StringBuffer(); urlSB.append(req.getScheme()).append("://").append(req.getServerName()); urlSB.append(":").append(req.getServerPort()).append(req.getContextPath()); String reqBase = urlSB.toString(); if (data == null) { data = reqBase + "/index.html"; } // Want to set an attachment from the following url. // Get context URL url = new URL(data); AttachmentPart ap = msg.createAttachmentPart(new DataHandler(url)); ap.setContentType("text/html"); // Add the attachment part to the message. msg.addAttachmentPart(ap); // Create an endpoint for the recipient of the message. if (to == null) { to = reqBase + "/receiver"; } URL urlEndpoint = new URL(to); System.err.println("Sending message to URL: " + urlEndpoint); System.err.println("Sent message is logged in \"sent.msg\""); retval += " Sent message (check \"sent.msg\") and "; FileOutputStream sentFile = new FileOutputStream("sent.msg"); msg.writeTo(sentFile); sentFile.close(); // Send the message to the provider using the connection. SOAPMessage reply = con.call(msg, urlEndpoint); if (reply != null) { FileOutputStream replyFile = new FileOutputStream("reply.msg"); reply.writeTo(replyFile); replyFile.close(); System.err.println("Reply logged in \"reply.msg\""); retval += " received reply (check \"reply.msg\").</H4> </html>"; } else { System.err.println("No reply"); retval += " no reply was received. </H4> </html>"; } } catch (Throwable e) { e.printStackTrace(); logger.severe("Error in constructing or sending message " + e.getMessage()); retval += " There was an error " + "in constructing or sending message. </H4> </html>"; } try { OutputStream os = resp.getOutputStream(); os.write(retval.getBytes()); os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); logger.severe("Error in outputting servlet response " + e.getMessage()); } }
private void makePOXFault(MessageContext synCtx, SynapseLog synLog) { OMFactory fac = synCtx.getEnvelope().getOMFactory(); OMElement faultPayload = fac.createOMElement(new QName("Exception")); if (faultDetail != null) { if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Setting the fault detail : " + faultDetail + " as the POX Fault"); } faultPayload.setText(faultDetail); } else if (faultDetailExpr != null) { String faultDetail = faultDetailExpr.stringValueOf(synCtx); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Setting the fault detail : " + faultDetail + " as the POX Fault"); } faultPayload.setText(faultDetail); } else if (faultReasonValue != null) { if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Setting the fault reason : " + faultReasonValue + " as the POX Fault"); } faultPayload.setText(faultReasonValue); } else if (faultReasonExpr != null) { String faultReason = faultReasonExpr.stringValueOf(synCtx); faultPayload.setText(faultReason); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Setting the fault reason : " + faultReason + " as the POX Fault"); } } SOAPBody body = synCtx.getEnvelope().getBody(); if (body != null) { if (body.getFirstElement() != null) { body.getFirstElement().detach(); } synCtx.setFaultResponse(true); ((Axis2MessageContext) synCtx).getAxis2MessageContext().setProcessingFault(true); if (synLog.isTraceOrDebugEnabled()) { String msg = "Original SOAP Message : " + synCtx.getEnvelope().toString() + "POXFault Message created : " + faultPayload.toString(); synLog.traceTrace(msg); if (log.isTraceEnabled()) { log.trace(msg); } } body.addChild(faultPayload); } }