Java Code Examples for javax.xml.soap.SOAPElement#getValue()

The following examples show how to use javax.xml.soap.SOAPElement#getValue() . 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: Fault1_2Impl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getFaultNode() {
    SOAPElement faultNode = findAndConvertChildElement(getFaultNodeName());
    if (faultNode == null) {
        return null;
    }
    return faultNode.getValue();
}
 
Example 2
Source File: Fault1_2Impl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Iterator<QName> getFaultSubcodes() {
    if (this.faultCodeElement == null)
        findFaultCodeElement();
    final List<QName> subcodeList = new ArrayList<>();
    SOAPElement currentCodeElement = this.faultCodeElement;
    Iterator subcodeElements =
        currentCodeElement.getChildElements(subcodeName);
    while (subcodeElements.hasNext()) {
        currentCodeElement = (ElementImpl) subcodeElements.next();
        Iterator valueElements =
            currentCodeElement.getChildElements(valueName);
        SOAPElement valueElement = (SOAPElement) valueElements.next();
        String code = valueElement.getValue();
        subcodeList.add(convertCodeToQName(code, valueElement));
        subcodeElements = currentCodeElement.getChildElements(subcodeName);
    }
    //return subcodeList.iterator();
    return new Iterator<QName>() {
        Iterator<QName> subCodeIter = subcodeList.iterator();

        @Override
        public boolean hasNext() {
            return subCodeIter.hasNext();
        }

        @Override
        public QName next() {
            return subCodeIter.next();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException(
                "Method remove() not supported on SubCodes Iterator");
        }
    };
}
 
Example 3
Source File: JPlagServerAccessHandler.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts the username out of the header of a SOAP message
 */
public static String extractUsername(SOAPMessageContext smsg) {
	try {
		SOAPHeader header = smsg.getMessage().getSOAPHeader();
		if (header != null) {
			@SuppressWarnings("unchecked")
			Iterator<SOAPHeaderElement> headers = header.examineAllHeaderElements();
			while (headers.hasNext()) {
				SOAPHeaderElement he = headers.next();

				if (he.getElementName().getLocalName().equals("Access")) {
					@SuppressWarnings("unchecked")
					Iterator<SOAPElement> elements = he.getChildElements();
					while (elements.hasNext()) {
						SOAPElement e = elements.next();
						String name = e.getElementName().getLocalName();
						if (name.equals("username"))
							return e.getValue();
					}
				}
			}
		}
	} catch (SOAPException x) {
		x.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: JRXmlaQueryExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void parseCellDataElement(SOAPElement cellDataElement) throws SOAPException
{
	Name name = sf.createName("Cell", "", MDD_URI);
	Iterator<?> itCells = cellDataElement.getChildElements(name);
	while (itCells.hasNext())
	{
		SOAPElement cellElement = (SOAPElement) itCells.next();
		
		Name errorName = sf.createName("Error", "", MDD_URI);
		Iterator<?> errorElems = cellElement.getChildElements(errorName);
		if (errorElems.hasNext())
		{
			handleCellErrors(errorElems);
		}
		
		Name ordinalName = sf.createName("CellOrdinal");
		String cellOrdinal = cellElement.getAttributeValue(ordinalName);

		Object value = null;
		Iterator<?> valueElements = cellElement.getChildElements(sf.createName("Value", "", MDD_URI));
		if (valueElements.hasNext())
		{
			SOAPElement valueElement = (SOAPElement) valueElements.next();
			String valueType = valueElement.getAttribute("xsi:type");
			if (valueType.equals("xsd:int"))
			{
				value = Long.valueOf(valueElement.getValue());
			}
			else if (
				valueType.equals("xsd:double")
				|| valueType.equals("xsd:decimal")
				)
			{
				value = Double.valueOf(valueElement.getValue());
			}
			else
			{
				value = valueElement.getValue();
			}
		}

		String fmtValue = "";
		Iterator<?> fmtValueElements = cellElement.getChildElements(sf.createName("FmtValue", "", MDD_URI));
		if (fmtValueElements.hasNext())
		{
			SOAPElement fmtValueElement = ((SOAPElement) fmtValueElements.next());
			fmtValue = fmtValueElement.getValue();
		}

		int pos = Integer.parseInt(cellOrdinal);
		JRXmlaCell cell = new JRXmlaCell(value, fmtValue);
		xmlaResult.setCell(cell, pos);
	}
}
 
Example 5
Source File: JPlagServerAccessHandler.java    From jplag with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Checks whether the SOAP message contains a valid Access element (correct
 * username + password) and whether the account may still be used
 */
public boolean handleRequest(MessageContext context) {
	String username = null;
	String password = null;
	int compatLevel = 0;
	if (context instanceof SOAPMessageContext) {
		SOAPMessageContext smsg = (SOAPMessageContext) context;

		/*
		 * Iterator iter = context.getPropertyNames();
		 * System.out.println("Context properties:"); while(iter.hasNext())
		 * { String propname = (String) iter.next();
		 * System.out.println(propname + " = " +
		 * context.getProperty(propname).toString()); }
		 * 
		 * HttpServletRequest request = (HttpServletRequest)
		 * context.getProperty(
		 * "com.sun.xml.rpc.server.http.HttpServletRequest");
		 * System.out.println("Client IP: " + request.getRemoteAddr());
		 */

		try {
			SOAPHeader header = smsg.getMessage().getSOAPHeader();
			if (header != null) {
				@SuppressWarnings("unchecked")
				Iterator<SOAPHeaderElement> headers = header.examineAllHeaderElements();
				while (headers.hasNext()) {
					SOAPHeaderElement he = headers.next();

					if (he.getElementName().getLocalName().equals("Access")) {
						@SuppressWarnings("unchecked")
						Iterator<SOAPElement> elements = he.getChildElements();
						while (elements.hasNext()) {
							SOAPElement e = elements.next();
							String name = e.getElementName().getLocalName();
							if (name.equals("username"))
								username = e.getValue();
							else if (name.equals("password"))
								password = e.getValue();
							else if (name.equals("compatLevel")) {
								try {
									compatLevel = Integer.parseInt(e.getValue());
								} catch (NumberFormatException ex) {
									compatLevel = -1;
								}
							}
						}
					}
				}
				if (compatLevel < compatibilityLevel) {
					replaceByJPlagException(smsg, "Client outdated!", "Please update your client " + "to compatibility level "
							+ compatibilityLevel + ".");
					return false;
				}
				if (username != null && password != null) {
					int state = JPlagCentral.getInstance().getUserAdmin().getLoginState(username, password);
					if ((state & UserAdmin.MASK_EXPIRED) != 0) {
						replaceByJPlagException(smsg, "Access denied!", "Your account has " + "expired! Please contact the JPlag "
								+ "administrator to reactivate it!");
						return false;
					} else if ((state & UserAdmin.MASK_DEACTIVATED) != 0) {
						replaceByJPlagException(smsg, "Access denied!", "Your account has " + "been deactivated! Please contact the "
								+ "JPlag administrator to reactivate it!");
						return false;
					} else if (state != UserAdmin.USER_INVALID)
						return true;
				}
			} else {
				System.out.println("No header available!");
				replaceByJPlagException(smsg, "Access denied!", "The SOAP message doesn't contain an access header!");
				return false;
			}
		} catch (SOAPException x) {
			x.printStackTrace();
		}
		System.out.println("[" + new Date() + "] Access denied for user \"" + username + "\"!");

		replaceByJPlagException(smsg, "Access denied!", "Check your username and password!");
		return false;
	}
	System.out.println("Not a SOAP message context!!!");
	return false;
}