javax.xml.namespace.QName Java Examples

The following examples show how to use javax.xml.namespace.QName. 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: XmlAsserter.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private static String convert(Object obj) {
   try {
      Class clazz = obj.getClass();
      if (!jaxbContextMap.containsKey(clazz)) {
         jaxbContextMap.put(clazz, JAXBContext.newInstance(clazz));
      }

      JAXBContext context = (JAXBContext)jaxbContextMap.get(clazz);
      Marshaller marshaller = context.createMarshaller();
      StringWriter writer = new StringWriter();
      if (obj.getClass().isAnnotationPresent(XmlRootElement.class)) {
         marshaller.marshal(obj, (Writer)writer);
      } else if (obj.getClass().isAnnotationPresent(XmlType.class)) {
         JAXBElement jaxbElement = new JAXBElement(new QName("", obj.getClass().getSimpleName()), clazz, obj);
         marshaller.marshal(jaxbElement, (Writer)writer);
      }

      return writer.toString();
   } catch (Exception var6) {
      LOG.error(var6.getMessage(), var6);
      Assert.fail(var6.getMessage());
      return null;
   }
}
 
Example #2
Source File: HttpAdapterList.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a PortAddressResolver that maps portname to its address
 *
 * @param endpointImpl application endpoint Class that eventually serves the request.
 */
public PortAddressResolver createPortAddressResolver(final String baseAddress, final Class<?> endpointImpl) {
    return new PortAddressResolver() {
        @Override
        public String getAddressFor(@NotNull QName serviceName, @NotNull String portName) {
            String urlPattern = addressMap.get(new PortInfo(serviceName,portName, endpointImpl));
            if (urlPattern == null) {
                //if a WSDL defines more ports, urlpattern is null (portName does not match endpointImpl)
                //so fallback to the default behaviour where only serviceName/portName is checked
                for (Entry<PortInfo, String> e : addressMap.entrySet()) {
                    if (serviceName.equals(e.getKey().serviceName) && portName.equals(e.getKey().portName)) {
                            urlPattern = e.getValue();
                            break;
                    }
                }
            }
            return (urlPattern == null) ? null : baseAddress+urlPattern;
        }
    };
}
 
Example #3
Source File: SOAPHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #4
Source File: RELAXNGCompiler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void mapToClass(DElementPattern p) {
    NameClass nc = p.getName();
    if(nc.isOpen())
        return;   // infinite name. can't map to a class.

    Set<QName> names = nc.listNames();

    CClassInfo[] types = new CClassInfo[names.size()];
    int i=0;
    for( QName n : names ) {
        // TODO: read class names from customization
        String name = model.getNameConverter().toClassName(n.getLocalPart());

        bindQueue.put(
            types[i++] = new CClassInfo(model,pkg,name,p.getLocation(),null,n,null,null/*TODO*/),
            p.getChild() );
    }

    classes.put(p,types);
}
 
Example #5
Source File: ElementInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
final QName parseElementName(XmlElementDecl e) {
    String local = e.name();
    String nsUri = e.namespace();
    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,
            nav().getDeclaringClassForMethod(method),this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
Example #6
Source File: WSDLOptionsSpecifiedSourceUrlTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description = "- Logging proxy" + "- Publish WSDL Options - Specified source url")
public void testLoggingProxy() throws Exception {

    OMElement response = axis2Client
            .sendSimpleStockQuoteRequest(getProxyServiceURLHttp("wsdlOptionsFromSourceUrlLoggingProxy"), null,
                    "WSO2");

    String lastPrice = response.getFirstElement()
            .getFirstChildWithName(new QName("http://services.samples/xsd", "last")).getText();
    assertNotNull(lastPrice, "Fault: response message 'last' price null");

    String symbol = response.getFirstElement()
            .getFirstChildWithName(new QName("http://services.samples/xsd", "symbol")).getText();
    assertEquals(symbol, "WSO2", "Fault: value 'symbol' mismatched");

}
 
Example #7
Source File: AssertionData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
public StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);
    final String innerDoubleIndent = PolicyUtils.Text.createIndent(indentLevel + 2);

    buffer.append(indent);
    if (type == ModelNode.Type.ASSERTION) {
        buffer.append("assertion data {");
    } else {
        buffer.append("assertion parameter data {");
    }
    buffer.append(PolicyUtils.Text.NEW_LINE);

    buffer.append(innerIndent).append("namespace = '").append(name.getNamespaceURI()).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("prefix = '").append(name.getPrefix()).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("local name = '").append(name.getLocalPart()).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("value = '").append(value).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("optional = '").append(optional).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("ignorable = '").append(ignorable).append('\'').append(PolicyUtils.Text.NEW_LINE);
    synchronized (attributes) {
        if (attributes.isEmpty()) {
            buffer.append(innerIndent).append("no attributes");
        } else {

            buffer.append(innerIndent).append("attributes {").append(PolicyUtils.Text.NEW_LINE);
            for(Map.Entry<QName, String> entry : attributes.entrySet()) {
                final QName aName = entry.getKey();
                buffer.append(innerDoubleIndent).append("name = '").append(aName.getNamespaceURI()).append(':').append(aName.getLocalPart());
                buffer.append("', value = '").append(entry.getValue()).append('\'').append(PolicyUtils.Text.NEW_LINE);
            }
            buffer.append(innerIndent).append('}');
        }
    }

    buffer.append(PolicyUtils.Text.NEW_LINE).append(indent).append('}');

    return buffer;
}
 
Example #8
Source File: WSServiceDelegate.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private QName addPortEpr(WSEndpointReference wsepr) {
    if (wsepr == null)
        throw new WebServiceException(ProviderApiMessages.NULL_EPR());
    QName eprPortName = getPortNameFromEPR(wsepr, null);
    //add Port, if it does n't exist;
    // TODO: what if it has different epr address?
    {
        PortInfo portInfo = new PortInfo(this, (wsepr.getAddress() == null) ? null : EndpointAddress.create(wsepr.getAddress()), eprPortName,
                getPortModel(wsdlService, eprPortName).getBinding().getBindingId());
        if (!ports.containsKey(eprPortName)) {
            ports.put(eprPortName, portInfo);
        }
    }
    return eprPortName;
}
 
Example #9
Source File: UserStoreConfigXMLProcessor.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static OMElement serialize(RealmConfiguration realmConfig) {
    OMFactory factory = OMAbstractFactory.getOMFactory();

    // add the user store manager properties
    OMElement userStoreManagerElement = factory.createOMElement(new QName(
            UserCoreConstants.RealmConfig.LOCAL_NAME_USER_STORE_MANAGER));
    addPropertyElements(factory, userStoreManagerElement, realmConfig.getUserStoreClass(), realmConfig.getUserStoreProperties());

    return userStoreManagerElement;
}
 
Example #10
Source File: TubelineAssemblyController.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private URI createEndpointComponentUri(@NotNull QName serviceName, @NotNull QName portName) {
    StringBuilder sb = new StringBuilder(serviceName.getNamespaceURI()).append("#wsdl11.port(").append(serviceName.getLocalPart()).append('/').append(portName.getLocalPart()).append(')');
    try {
        return new URI(sb.toString());
    } catch (URISyntaxException ex) {
        Logger.getLogger(TubelineAssemblyController.class).warning(
                TubelineassemblyMessages.MASM_0020_ERROR_CREATING_URI_FROM_GENERATED_STRING(sb.toString()),
                ex);
        return null;
    }
}
 
Example #11
Source File: EncodingPolicyValidator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Fitness validateServerSide(PolicyAssertion assertion) {
    QName assertionName = assertion.getName();
    if (serverSideSupportedAssertions.contains(assertionName)) {
        return Fitness.SUPPORTED;
    } else if (clientSideSupportedAssertions.contains(assertionName)) {
        return Fitness.UNSUPPORTED;
    } else {
        return Fitness.UNKNOWN;
    }
}
 
Example #12
Source File: EnrichIntegrationReplaceEnvelopTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = "wso2.esb", description = "Tests-Replace out going message envelop")
public void testReplaceEnvelop() throws AxisFault {

    response = axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp("enrichReplaceEnvelopTestProxy"), null, "WSO2");
    assertNotNull(response, "Response is null");
    assertEquals(response.getQName().getLocalPart(), "getQuote");
    assertEquals(response.getFirstElement().getLocalName().toString(),
                 "request", "Local name does not match");
    assertEquals(response.getFirstElement().getFirstChildWithName
            (new QName("http://services.samples", "symbol")).getText(),
                 "WSO2", "Tag does not match");
}
 
Example #13
Source File: AbstractSchemaValidationTube.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SDDocument resolve(String systemId) {
    SDDocument sdi = docs.get(systemId);
    if (sdi == null) {
        SDDocumentSource sds;
        try {
            sds = SDDocumentSource.create(new URL(systemId));
        } catch(MalformedURLException e) {
            throw new WebServiceException(e);
        }
        sdi = SDDocumentImpl.create(sds, new QName(""), new QName(""));
        docs.put(systemId, sdi);
    }
    return sdi;
}
 
Example #14
Source File: Body1_2Impl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected SOAPElement addElement(QName name) throws SOAPException {
    if (hasFault()) {
        log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
        throw new SOAPExceptionImpl(
            "No other element except Fault allowed in SOAPBody");
    }
    return super.addElement(name);
}
 
Example #15
Source File: HeaderList.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
    public Set<QName> getUnderstoodHeaders() {
        Set<QName> understoodHdrs = new HashSet<QName>();
        for (int i = 0; i < size(); i++) {
            if (isUnderstood(i)) {
                Header header = get(i);
                understoodHdrs.add(new QName(header.getNamespaceURI(), header.getLocalPart()));
            }
        }
        return understoodHdrs;
//        throw new UnsupportedOperationException("getUnderstoodHeaders() is not implemented by HeaderList");
    }
 
Example #16
Source File: WSDLGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void generateSOAPHeaders(TypedXmlWriter writer, List<ParameterImpl> parameters, QName message) {

        for (ParameterImpl headerParam : parameters) {
            Header header = writer._element(Header.class);
            header.message(message);
            header.part(headerParam.getPartName());
            header.use(LITERAL);
        }
    }
 
Example #17
Source File: NamedEvent.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public NamedEvent(String prefix, String uri, String localpart) {
    this.name = new QName(uri, localpart, prefix);
}
 
Example #18
Source File: RuntimeModeler.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void processClass(Class clazz) {
        classUsesWebMethod = new HashSet<Class>();
        determineWebMethodUse(clazz);
        WebService webService = getAnnotation(clazz, WebService.class);
        QName portTypeName = getPortTypeName(clazz, targetNamespace, metadataReader);
//        String portTypeLocalName  = clazz.getSimpleName();
//        if (webService.name().length() >0)
//            portTypeLocalName = webService.name();
//
//        targetNamespace = webService.targetNamespace();
        packageName = "";
        if (clazz.getPackage() != null)
            packageName = clazz.getPackage().getName();
//        if (targetNamespace.length() == 0) {
//            targetNamespace = getNamespace(packageName);
//        }
//        model.setTargetNamespace(targetNamespace);
//        QName portTypeName = new QName(targetNamespace, portTypeLocalName);
        targetNamespace = portTypeName.getNamespaceURI();
        model.setPortTypeName(portTypeName);
        model.setTargetNamespace(targetNamespace);
        model.defaultSchemaNamespaceSuffix = config.getMappingInfo().getDefaultSchemaNamespaceSuffix();
        model.setWSDLLocation(webService.wsdlLocation());

        SOAPBinding soapBinding = getAnnotation(clazz, SOAPBinding.class);
        if (soapBinding != null) {
            if (soapBinding.style() == SOAPBinding.Style.RPC && soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) {
                throw new RuntimeModelerException("runtime.modeler.invalid.soapbinding.parameterstyle",
                        soapBinding, clazz);

            }
            isWrapped = soapBinding.parameterStyle()== WRAPPED;
        }
        defaultBinding = createBinding(soapBinding);
        /*
         * if clazz != portClass then there is an SEI.  If there is an
         * SEI, then all methods should be processed.  However, if there is
         * no SEI, and the implementation class uses at least one
         * WebMethod annotation, then only methods with this annotation
         * will be processed.
         */
/*        if (clazz == portClass) {
            WebMethod webMethod;
            for (Method method : clazz.getMethods()) {
                webMethod = getPrivMethodAnnotation(method, WebMethod.class);
                if (webMethod != null &&
                    !webMethod.exclude()) {
                    usesWebMethod = true;
                    break;
                }
            }
        }*/

        for (Method method : clazz.getMethods()) {
            if (!clazz.isInterface()) {     // if clazz is SEI, then all methods are web methods
                if (method.getDeclaringClass() == Object.class) continue;
                if (!getBooleanSystemProperty("com.sun.xml.internal.ws.legacyWebMethod")) {  // legacy webMethod computation behaviour to be used
                    if (!isWebMethodBySpec(method, clazz))
                        continue;
                } else {
                    if (!isWebMethod(method))
                        continue;
                }
            }
            // TODO: binding can be null. We need to figure out how to post-process
            // RuntimeModel to link to WSDLModel
            processMethod(method);
        }
        //Add additional jaxb classes referenced by {@link XmlSeeAlso}
        XmlSeeAlso xmlSeeAlso = getAnnotation(clazz, XmlSeeAlso.class);
        if(xmlSeeAlso != null)
            model.addAdditionalClasses(xmlSeeAlso.value());
    }
 
Example #19
Source File: JAXBContextImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public int compare(QName lhs, QName rhs) {
    int r = lhs.getLocalPart().compareTo(rhs.getLocalPart());
    if(r!=0)    return r;

    return lhs.getNamespaceURI().compareTo(rhs.getNamespaceURI());
}
 
Example #20
Source File: DatatypeFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test {@link DatatypeFactory.newDurationYearMonth(String
 * lexicalRepresentation)}.
 */
@Test
public final void testNewDurationYearMonthLexicalRepresentation() {

    /**
     * Lexical test values to test.
     */
    final String[] TEST_VALUES_LEXICAL = { null, TEST_VALUE_FAIL, "", TEST_VALUE_FAIL, "-", TEST_VALUE_FAIL, "P", TEST_VALUE_FAIL, "-P", TEST_VALUE_FAIL,
            "P1D", TEST_VALUE_FAIL, "P1Y1M1D", TEST_VALUE_FAIL, "P1M", "P1M", "-P1M", "-P1M", "P1Y", "P1Y", "-P1Y", "-P1Y", "P1Y1M", "P1Y1M", "-P1Y1M",
            "-P1Y1M" };

    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException datatypeConfigurationException) {
        Assert.fail(datatypeConfigurationException.toString());
    }

    if (DEBUG) {
        System.err.println("DatatypeFactory created: " + datatypeFactory.toString());
    }

    // test each value
    for (int onTestValue = 0; onTestValue < TEST_VALUES_LEXICAL.length; onTestValue = onTestValue + 2) {

        if (DEBUG) {
            System.err.println("testing value: \"" + TEST_VALUES_LEXICAL[onTestValue] + "\", expecting: \"" + TEST_VALUES_LEXICAL[onTestValue + 1] + "\"");
        }

        try {
            Duration duration = datatypeFactory.newDurationYearMonth(TEST_VALUES_LEXICAL[onTestValue]);

            if (DEBUG) {
                System.err.println("Duration created: \"" + duration.toString() + "\"");
            }

            // was this expected to fail?
            if (TEST_VALUES_LEXICAL[onTestValue + 1].equals(TEST_VALUE_FAIL)) {
                Assert.fail("the value \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" is invalid yet it created the Duration \"" + duration.toString() + "\"");
            }

            // right XMLSchemaType?
            // TODO: enable test, it should pass, it fails with Exception(s)
            // for now due to a bug
            try {
                QName xmlSchemaType = duration.getXMLSchemaType();
                if (!xmlSchemaType.equals(DatatypeConstants.DURATION_YEARMONTH)) {
                    Assert.fail("Duration created with XMLSchemaType of\"" + xmlSchemaType + "\" was expected to be \""
                            + DatatypeConstants.DURATION_YEARMONTH + "\" and has the value \"" + duration.toString() + "\"");
                }
            } catch (IllegalStateException illegalStateException) {
                // TODO; this test really should pass
                System.err.println("Please fix this bug that is being ignored, for now: " + illegalStateException.getMessage());
            }

            // does it have the right value?
            if (!TEST_VALUES_LEXICAL[onTestValue + 1].equals(duration.toString())) {
                Assert.fail("Duration created with \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" was expected to be \""
                        + TEST_VALUES_LEXICAL[onTestValue + 1] + "\" and has the value \"" + duration.toString() + "\"");
            }

            // Duration created with correct value
        } catch (Exception exception) {

            if (DEBUG) {
                System.err.println("Exception in creating duration: \"" + exception.toString() + "\"");
            }

            // was this expected to succed?
            if (!TEST_VALUES_LEXICAL[onTestValue + 1].equals(TEST_VALUE_FAIL)) {
                Assert.fail("the value \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" is valid yet it failed with \"" + exception.toString() + "\"");
            }
            // expected failure
        }
    }
}
 
Example #21
Source File: SubcodeType.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public SubcodeType(QName value) {
    Value = value;
}
 
Example #22
Source File: StAXParserWrapper.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public QName getAttributeName(int index) {
    return _reader.getAttributeName(index);
}
 
Example #23
Source File: Trust13.java    From steady with Apache License 2.0 4 votes vote down vote up
public QName getRealName() {
    return SP12Constants.TRUST_13;
}
 
Example #24
Source File: SP12Constants.java    From steady with Apache License 2.0 4 votes vote down vote up
public QName getSpnegoContextToken() {
    return SPNEGO_CONTEXT_TOKEN;
}
 
Example #25
Source File: DatatypeConverterImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Deprecated
public String printQName(QName val, NamespaceContext nsc) {
    return _printQName(val, nsc);
}
 
Example #26
Source File: StAXParserWrapper.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public QName getAttributeName(int index) {
    return _reader.getAttributeName(index);
}
 
Example #27
Source File: MonitorRootService.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@ManagedAttribute
@Description("WSDLPort bound port type")
public QName wsdlPortTypeName() {
    return endpoint.getPort() != null ?
           endpoint.getPort().getBinding().getPortTypeName() : null;
}
 
Example #28
Source File: WSDLModelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public @NotNull Map<QName, ? extends EditableWSDLBoundPortType> getBindings() {
    return unmBindings;
}
 
Example #29
Source File: SOAP12ExtensionHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected QName getHeaderfaultQName() {
    return SOAP12Constants.QNAME_HEADERFAULT;
}
 
Example #30
Source File: WSDLDirectProperties.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public QName getWSDLPortType() {
    return null;
}