use of org.apache.cxf.common.i18n.Message in project cxf by apache.
the class PolicyBasedWSS4JInInterceptor method handleMessage.
public void handleMessage(SoapMessage msg) throws Fault {
AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
boolean enableStax = MessageUtils.getContextualBoolean(msg, SecurityConstants.ENABLE_STREAMING_SECURITY);
if (aim != null && !enableStax && !msg.containsKey(SECURITY_PROCESSED) && !isGET(msg) && msg.getExchange() != null) {
try {
// First check to see if we have a security header before we apply the SAAJInInterceptor
// If there is no security header then we can just assert the policies and proceed
String actor = (String) getOption(ConfigurationConstants.ACTOR);
if (actor == null) {
actor = (String) msg.getContextualProperty(SecurityConstants.ACTOR);
}
if (!containsSecurityHeader(msg, actor, msg.getVersion().getVersion() != 1.1)) {
LOG.fine("The request contains no security header, so the SAAJInInterceptor is not applied");
computeAction(msg, new RequestData());
boolean utWithCallbacks = MessageUtils.getContextualBoolean(msg, SecurityConstants.VALIDATE_TOKEN, true);
doResults(msg, actor, null, null, new WSHandlerResult(actor, Collections.emptyList(), Collections.emptyMap()), utWithCallbacks);
msg.put(SECURITY_PROCESSED, Boolean.TRUE);
return;
}
} catch (WSSecurityException e) {
throw WSS4JUtils.createSoapFault(msg, msg.getVersion(), e);
} catch (XMLStreamException e) {
throw new SoapFault(new Message("STAX_EX", LOG), e, msg.getVersion().getSender());
} catch (SOAPException e) {
throw new SoapFault(new Message("SAAJ_EX", LOG), e, msg.getVersion().getSender());
}
super.handleMessage(msg);
}
}
use of org.apache.cxf.common.i18n.Message in project cxf by apache.
the class ClientGenerator method generate.
public void generate(ToolContext penv) throws ToolException {
this.env = penv;
if (passthrough()) {
return;
}
Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
for (JavaModel javaModel : map.values()) {
if (javaModel.getServiceClasses().isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_CLIENT", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
return;
}
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
for (JavaPort jp : js.getPorts()) {
String interfaceName = jp.getInterfaceClass();
JavaInterface intf = interfaces.get(interfaceName);
if (intf == null) {
interfaceName = jp.getPortType();
intf = interfaces.get(interfaceName);
}
String clientClassName = interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Client";
clientClassName = mapClassName(intf.getPackageName(), clientClassName, penv);
clearAttributes();
setAttributes("clientClassName", clientClassName);
setAttributes("intf", intf);
setAttributes("service", js);
setAttributes("port", jp);
setCommonAttributes();
doWrite(CLT_TEMPLATE, parseOutputName(intf.getPackageName(), clientClassName));
}
}
}
}
use of org.apache.cxf.common.i18n.Message in project cxf by apache.
the class SEIGenerator method generate.
public void generate(ToolContext penv) throws ToolException {
this.env = penv;
if (passthrough()) {
return;
}
Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
for (JavaModel javaModel : map.values()) {
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
if (interfaces.isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_SEI", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
continue;
}
for (JavaInterface intf : interfaces.values()) {
if (hasHandlerConfig(intf)) {
HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
// REVISIT: find a better way to handle Handler gen, should not
// pass JavaInterface around.
handlerGen.setJavaInterface(intf);
handlerGen.generate(getEnvironment());
JAnnotation annot = handlerGen.getHandlerAnnotation();
if (handlerGen.getHandlerAnnotation() != null) {
boolean existHandlerAnno = false;
for (JAnnotation jann : intf.getAnnotations()) {
if (jann.getType() == HandlerChain.class) {
existHandlerAnno = true;
}
}
if (!existHandlerAnno) {
intf.addAnnotation(annot);
intf.addImport("javax.jws.HandlerChain");
}
}
}
if (penv.containsKey(ToolConstants.RUNTIME_DATABINDING_CLASS)) {
JAnnotation ann = new JAnnotation(DataBinding.class);
JAnnotationElement el = new JAnnotationElement(null, penv.get(ToolConstants.RUNTIME_DATABINDING_CLASS), true);
ann.addElement(el);
intf.addAnnotation(ann);
}
clearAttributes();
setAttributes("intf", intf);
String seiSc = "";
for (String s : intf.getSuperInterfaces()) {
if (!seiSc.isEmpty()) {
seiSc += ", ";
} else {
seiSc = "extends ";
}
seiSc += s;
}
if (!StringUtils.isEmpty(seiSc)) {
seiSc += " ";
}
setAttributes("seiSuperinterfaceString", seiSc);
setCommonAttributes();
doWrite(SEI_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName()));
}
}
}
use of org.apache.cxf.common.i18n.Message in project cxf by apache.
the class ServiceGenerator method generate.
public void generate(ToolContext penv) throws ToolException {
this.env = penv;
if (passthrough()) {
return;
}
Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
for (JavaModel javaModel : map.values()) {
ClassCollector collector = penv.get(ClassCollector.class);
Map<String, JavaServiceClass> serviceClasses = javaModel.getServiceClasses();
if (serviceClasses.isEmpty()) {
ServiceInfo serviceInfo = env.get(ServiceInfo.class);
String wsdl = serviceInfo.getDescription().getBaseURI();
Message msg = new Message("CAN_NOT_GEN_SERVICE", LOG, wsdl);
if (penv.isVerbose()) {
System.out.println(msg.toString());
}
return;
}
for (JavaServiceClass js : serviceClasses.values()) {
if (js.getHandlerChains() != null) {
HandlerConfigGenerator handlerGen = new HandlerConfigGenerator();
handlerGen.setJavaInterface(js);
handlerGen.generate(getEnvironment());
JAnnotation annot = handlerGen.getHandlerAnnotation();
if (handlerGen.getHandlerAnnotation() != null) {
boolean existHandlerAnno = false;
for (JAnnotation jann : js.getAnnotations()) {
if (jann.getType() == HandlerChain.class) {
existHandlerAnno = true;
}
}
if (!existHandlerAnno) {
js.addAnnotation(annot);
js.addImport("javax.jws.HandlerChain");
}
}
}
Set<String> portNames = new HashSet<>();
for (JavaPort port : js.getPorts()) {
if (!port.getPackageName().equals(js.getPackageName()) && !port.getInterfaceClass().equals(js.getName())) {
js.addImport(port.getFullClassName());
}
portNames.add(port.getInterfaceClass());
}
if ("cxf".equals(env.get(ToolConstants.CFG_FRONTEND))) {
js.addImport(BindingProvider.class.getName());
js.addImport(Client.class.getName());
}
String url = (String) env.get(ToolConstants.CFG_WSDLURL);
String location = (String) env.get(ToolConstants.CFG_WSDLLOCATION);
if (location == null) {
location = url;
}
String serviceSuperclass = (String) env.get("service.superclass");
String simpleServiceName = serviceSuperclass.substring(serviceSuperclass.lastIndexOf('.') + 1);
for (String s : collector.getGeneratedFileInfo()) {
if (s.equals(js.getPackageName() + "." + simpleServiceName)) {
simpleServiceName = serviceSuperclass;
break;
}
}
clearAttributes();
boolean useGetResource = false;
try {
new URL(location);
} catch (MalformedURLException e) {
useGetResource = true;
}
setAttributes("cxfPortClassnames", portNames.toArray(new String[0]));
setAttributes("service", js);
setAttributes("wsdlLocation", location);
setAttributes("useGetResource", useGetResource);
setAttributes("serviceSuperclass", simpleServiceName);
if (!simpleServiceName.equals(serviceSuperclass)) {
js.addImport(serviceSuperclass);
}
setAttributes("wsdlUrl", url);
setCommonAttributes();
String target = (String) env.get("service.target");
setAttributes("serviceTarget", target);
if ("jaxws22".equals(target)) {
setAttributes("jaxws22", true);
}
doWrite(SERVICE_TEMPLATE, parseOutputName(js.getPackageName(), js.getName()));
}
}
}
use of org.apache.cxf.common.i18n.Message in project cxf by apache.
the class WSDLToSoapProcessor method validate.
private void validate() throws ToolException {
if (isBindingExisted()) {
Message msg = new Message("BINDING_ALREADY_EXIST", LOG);
throw new ToolException(msg);
}
if (!isPortTypeExisted()) {
Message msg = new Message("PORTTYPE_NOT_EXIST", LOG);
throw new ToolException(msg);
}
if (!nameSpaceCheck()) {
Message msg = new Message("SOAPBINDING_STYLE_NOT_PROVIDED", LOG);
throw new ToolException(msg);
}
if (WSDLConstants.RPC.equalsIgnoreCase((String) env.get(ToolConstants.CFG_STYLE))) {
Collection<Operation> ops = CastUtils.cast(portType.getOperations());
for (Operation op : ops) {
Input input = op.getInput();
if (input != null && input.getMessage() != null) {
Collection<Part> parts = CastUtils.cast(input.getMessage().getParts().values());
for (Part part : parts) {
if (part.getTypeName() == null || "".equals(part.getTypeName().toString())) {
Message msg = new Message("RPC_PART_ILLEGAL", LOG, new Object[] { part.getName() });
throw new ToolException(msg);
}
}
}
Output output = op.getOutput();
if (output != null && output.getMessage() != null) {
Collection<Part> parts = CastUtils.cast(output.getMessage().getParts().values());
for (Part part : parts) {
if (part.getTypeName() == null || "".equals(part.getTypeName().toString())) {
Message msg = new Message("RPC_PART_ILLEGAL", LOG, new Object[] { part.getName() });
throw new ToolException(msg);
}
}
}
}
}
}
Aggregations